diff options
-rw-r--r-- | include/rin/uuid.h | 29 | ||||
-rw-r--r-- | meson.build | 1 | ||||
-rw-r--r-- | test/main.c | 4 | ||||
-rw-r--r-- | test/meson.build | 3 | ||||
-rw-r--r-- | test/uuid.c | 65 | ||||
-rw-r--r-- | test/uuid_test.h | 28 | ||||
-rw-r--r-- | test/uuid_test_private.h | 30 |
7 files changed, 158 insertions, 2 deletions
diff --git a/include/rin/uuid.h b/include/rin/uuid.h new file mode 100644 index 0000000..53c7fc6 --- /dev/null +++ b/include/rin/uuid.h @@ -0,0 +1,29 @@ +/* + * The Rin Library – uuid handling module + * + * Copyright (C) 2015 Gediminas Jakutis + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; version 2.1 + * of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef LIBRIN_UUID_INCLUDED +#define LIBRIN_UUID_INCLUDED + +#define PRIUUID "%.2hhx%.2hhx%.2hhx%.2hhx-%.2hhx%.2hhx-%.2hhx%.2hhx-" \ + "%.2hhx%.2hhx-%.2hhx%.2hhx%.2hhx%.2hhx%.2hhx%.2hhx" +#define PRIUUIDARG(a) a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], \ + a[9], a[10], a[11], a[12], a[13], a[14], a[15] + +#endif /* LIBRIN_UUID_INCLUDED */ diff --git a/meson.build b/meson.build index 057e6d4..17de118 100644 --- a/meson.build +++ b/meson.build @@ -43,4 +43,5 @@ if get_option('tests') test('time compare more or equal', test_e, args : ['time', 'cmpmoreequal']) test('time compare equal', test_e, args : ['time', 'cmpequal']) test('time compare nonequal', test_e, args : ['time', 'cmpnonequal']) + test('uuid print fromat macros', test_e, args : ['uuid', 'formatmacro']) endif diff --git a/test/main.c b/test/main.c index 3ad8540..03b2211 100644 --- a/test/main.c +++ b/test/main.c @@ -22,6 +22,7 @@ #include "float_test.h" #include "diagnostic_test.h" #include "time_test.h" +#include "uuid_test.h" /* TODO: allow individual tests to be selected */ @@ -30,7 +31,8 @@ int main(int argc, char **argv) static const struct section sections[] = { {"float", float_test}, {"diagnostic", diagnostic_test}, - {"time", time_test} }; + {"time", time_test}, + {"uuid", uuid_test} }; size_t i; if (argc != 3) { diff --git a/test/meson.build b/test/meson.build index bae6851..8070f27 100644 --- a/test/meson.build +++ b/test/meson.build @@ -3,7 +3,8 @@ test_filenames = [ 'test.c', 'float.c', 'diagnostic.c', - 'time.c' + 'time.c', + 'uuid.c' ] test_sources = files(test_filenames) diff --git a/test/uuid.c b/test/uuid.c new file mode 100644 index 0000000..a77ebcc --- /dev/null +++ b/test/uuid.c @@ -0,0 +1,65 @@ +/* + * The Rin Library – library "conformance" tests + * + * Copyright (C) 2015-2017 Gediminas Jakutis + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; version 2.1 + * of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "test.h" +#include "uuid_test_private.h" + +int uuid_test(char *testname) +{ + static const struct test tests[] = { + {"formatmacro", rin_uuid_format_macro_test} }; + size_t i; + + for (i = 0; i < arrlen(tests); ++i) { + if (!strcmp(testname, tests[i].name)) { + return tests[i].testfunc(); + } + } + + return EXIT_FAILURE; +} + +static int rin_uuid_format_macro_test(void) +{ + int ret; + size_t i; + char buf[64]; + static const char in[][16] = { + { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, + { 0 }, + { (char) 0xff, (char) 0xff, (char) 0xff, (char) 0xff, + (char) 0xff, (char) 0xff, (char) 0xff, (char) 0xff, + (char) 0xff, (char) 0xff, (char) 0xff, (char) 0xff, + (char) 0xff, (char) 0xff, (char) 0xff, (char) 0xff}}; + static const char *expected[] = { "00010203-0405-0607-0809-0a0b0c0d0e0f", + "00000000-0000-0000-0000-000000000000", + "ffffffff-ffff-ffff-ffff-ffffffffffff" }; + + for (i = 0; i < arrlen(expected); ++i) { + snprintf(buf, sizeof(buf), PRIUUID, PRIUUIDARG(in[i])); + ret = ok(strcmp(buf, expected[i]), + "%s: expected: %s, got: %s", + __func__, + expected[i], + buf); + } + + return ret; +} diff --git a/test/uuid_test.h b/test/uuid_test.h new file mode 100644 index 0000000..fb50fc3 --- /dev/null +++ b/test/uuid_test.h @@ -0,0 +1,28 @@ +/* + * The Rin Library – library "conformance" tests + * + * Copyright (C) 2015-2017 Gediminas Jakutis + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; version 2.1 + * of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef LIBRIN_UUID_TEST_INCLUDED +#define LIBRIN_UUID_TEST_INCLUDED + +#include "test.h" + +int uuid_test(char *testname); + +#endif /* LIBRIN_UUID_TEST_INCLUDED */ diff --git a/test/uuid_test_private.h b/test/uuid_test_private.h new file mode 100644 index 0000000..1852bcf --- /dev/null +++ b/test/uuid_test_private.h @@ -0,0 +1,30 @@ +/* + * The Rin Library – library "conformance" tests + * + * Copyright (C) 2015-2017 Gediminas Jakutis + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; version 2.1 + * of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef LIBRIN_UUID_TEST_PRIVATE_INCLUDED +#define LIBRIN_UUID_TEST_PRIVATE_INCLUDED + +#include <stddef.h> +#include <stdio.h> +#include "rin/uuid.h" + +static int rin_uuid_format_macro_test(void); + +#endif /* LIBRIN_UUID_TEST_PRIVATE_INCLUDED */ |