]> Kevux Git Server - fll/commitdiff
Update: Add unit tests for f_serialize.
authorKevin Day <thekevinday@gmail.com>
Thu, 19 May 2022 05:58:02 +0000 (00:58 -0500)
committerKevin Day <thekevinday@gmail.com>
Thu, 19 May 2022 05:58:02 +0000 (00:58 -0500)
16 files changed:
level_0/f_serialize/data/build/dependencies-tests [new file with mode: 0644]
level_0/f_serialize/data/build/settings-mocks [new file with mode: 0644]
level_0/f_serialize/data/build/settings-tests [new file with mode: 0644]
level_0/f_serialize/data/build/testfile [new file with mode: 0644]
level_0/f_serialize/tests/unit/c/test-serialize-from_simple.c [new file with mode: 0644]
level_0/f_serialize/tests/unit/c/test-serialize-from_simple.h [new file with mode: 0644]
level_0/f_serialize/tests/unit/c/test-serialize-from_simple_get.c [new file with mode: 0644]
level_0/f_serialize/tests/unit/c/test-serialize-from_simple_get.h [new file with mode: 0644]
level_0/f_serialize/tests/unit/c/test-serialize-from_simple_range.c [new file with mode: 0644]
level_0/f_serialize/tests/unit/c/test-serialize-from_simple_range.h [new file with mode: 0644]
level_0/f_serialize/tests/unit/c/test-serialize-from_simple_select.c [new file with mode: 0644]
level_0/f_serialize/tests/unit/c/test-serialize-from_simple_select.h [new file with mode: 0644]
level_0/f_serialize/tests/unit/c/test-serialize-to_simple.c [new file with mode: 0644]
level_0/f_serialize/tests/unit/c/test-serialize-to_simple.h [new file with mode: 0644]
level_0/f_serialize/tests/unit/c/test-serialize.c [new file with mode: 0644]
level_0/f_serialize/tests/unit/c/test-serialize.h [new file with mode: 0644]

diff --git a/level_0/f_serialize/data/build/dependencies-tests b/level_0/f_serialize/data/build/dependencies-tests
new file mode 100644 (file)
index 0000000..dea3179
--- /dev/null
@@ -0,0 +1,3 @@
+# fss-0001
+
+cmocka 1.*
diff --git a/level_0/f_serialize/data/build/settings-mocks b/level_0/f_serialize/data/build/settings-mocks
new file mode 100644 (file)
index 0000000..cb85be4
--- /dev/null
@@ -0,0 +1,60 @@
+# fss-0001
+#
+# Build the project with appropriate mocks linked in via the dynamic linker's "--wrap" functionality.
+#
+# The -Wl,--wrap does not work across shared files.
+# Therefore, this file is a work-around to inject the mocks into the library for testing purposes.
+# This should exactly match the "settings" file, except for the additional "-Wl,--wrap" parts and the additional mock source file.
+#
+# The flags -o0 must be passed to prevent the compiler from optimizing away any functions being mocked (which results in the mock not happening and a real function being called).
+# Alternatively, figure out which optimization that is disabled by -o0 and have that specific optimization disabled.
+#
+
+build_name f_serialize
+
+version_major 0
+version_minor 5
+version_micro 9
+version_file micro
+version_target minor
+
+modes individual clang test
+modes_default individual
+
+build_compiler gcc
+build_compiler-clang clang
+build_indexer ar
+build_indexer_arguments rcs
+build_language c
+
+build_libraries -lc
+build_libraries-individual -lf_memory -lf_string -lf_utf
+
+build_sources_library serialize.c private-serialize.c serialize/common.c ../../tests/unit/c/mock-serialize.c
+
+build_sources_headers serialize.h serialize/common.h
+
+build_script yes
+build_shared yes
+build_static no
+
+path_headers fll/level_0
+path_library_script script
+path_library_shared shared
+path_library_static static
+
+has_path_standard yes
+preserve_path_headers yes
+
+search_exclusive yes
+search_shared yes
+search_static yes
+
+flags -O0 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-parentheses
+flags-clang -Wno-logical-op-parentheses
+flags-test -fstack-protector
+
+flags_library -fPIC
+
+# Inject mocks.
+flags -Wl,--wrap=sysconf
diff --git a/level_0/f_serialize/data/build/settings-tests b/level_0/f_serialize/data/build/settings-tests
new file mode 100644 (file)
index 0000000..d5450e2
--- /dev/null
@@ -0,0 +1,53 @@
+# fss-0001
+#
+# Builds a program that is links to the generated library and is executed to perform tests.
+#
+# Memory leaks in the test program can be checked for by running valgrind with this executable.
+#
+
+build_name test-f_serialize
+
+version_major 0
+version_minor 5
+version_micro 9
+version_file major
+version_target major
+
+modes individual clang test
+modes_default individual
+
+build_compiler gcc
+build_compiler-clang clang
+build_indexer ar
+build_indexer_arguments rcs
+build_language c
+
+build_libraries -lc -lcmocka
+build_libraries-individual -lf_memory -lf_string -lf_type_array -lf_serialize
+
+build_sources_program test-serialize-from_simple.c test-serialize-from_simple_get.c test-serialize-from_simple_range.c test-serialize-from_simple_select.c test-serialize-to_simple.c
+build_sources_program test-serialize.c
+
+build_script no
+build_shared yes
+build_static no
+
+path_headers tests/unit/c
+path_sources tests/unit/c
+
+has_path_standard no
+preserve_path_headers yes
+
+search_exclusive yes
+search_shared yes
+search_static yes
+
+defines -Ibuild/includes
+defines_static -Lbuild/libraries/static
+defines_shared -Lbuild/libraries/shared
+
+flags -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-parentheses
+flags-clang -Wno-logical-op-parentheses
+flags-test -fstack-protector -Wall
+
+flags_program -fPIE
diff --git a/level_0/f_serialize/data/build/testfile b/level_0/f_serialize/data/build/testfile
new file mode 100644 (file)
index 0000000..1193600
--- /dev/null
@@ -0,0 +1,55 @@
+# fss-0005 iki-0002
+
+settings:
+  load_build yes
+  fail exit
+
+  environment LD_LIBRARY_PATH
+  environment CMOCKA_XML_FILE CMOCKA_MESSAGE_OUTPUT CMOCKA_TEST_ABORT
+
+  # Cmcka is not fully thread-safe, set this to "1" to have cmocka call abort() on a test failure.
+  #CMOCKA_TEST_ABORT 1
+
+  # One of: STDOUT, SUBUNIT, TAP, or XML.
+  #define CMOCKA_MESSAGE_OUTPUT STDOUT
+
+  # When in "XML" output mode, output to this file rather than stdout.
+  #define CMOCKA_XML_FILE ./out.xml
+
+main:
+  build settings
+  build settings-tests
+
+  operate ld_library_path
+
+  if exists build/programs/shared/test-f_serialize
+    shell build/programs/shared/test-f_serialize
+
+  if exists build/programs/static/test-f_serialize
+    shell build/programs/static/test-f_serialize
+
+  if not exists build/programs/shared/test-f_serialize
+  and not exists build/programs/static/test-f_serialize
+    operate not_created
+
+not_created:
+  print
+  print 'context:"error"Failed to test due to being unable to find either a shared or static test binary to perform tests. context:"reset"'
+
+  exit failure
+
+ld_library_path:
+  if defined environment LD_LIBRARY_PATH
+  and defined parameter work
+    define LD_LIBRARY_PATH 'build/libraries/shared:parameter:"work:value"libraries/shared:define:"LD_LIBRARY_PATH"'
+
+  else
+  if defined environment LD_LIBRARY_PATH
+    define LD_LIBRARY_PATH 'build/libraries/shared:parameter:define:"LD_LIBRARY_PATH"'
+
+  else
+  if defined parameter work
+    define LD_LIBRARY_PATH 'build/libraries/shared:parameter:"work:value"libraries/shared'
+
+  else
+    define LD_LIBRARY_PATH build/libraries/shared
diff --git a/level_0/f_serialize/tests/unit/c/test-serialize-from_simple.c b/level_0/f_serialize/tests/unit/c/test-serialize-from_simple.c
new file mode 100644 (file)
index 0000000..e308c73
--- /dev/null
@@ -0,0 +1,120 @@
+#include "test-serialize.h"
+#include "test-serialize-from_simple.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_serialize_from_simple__parameter_checking(void **state) {
+
+  const f_string_static_t source = macro_f_string_static_t_initialize("test", 0, 4);
+
+  {
+    const f_status_t status = f_serialize_from_simple(source, 0);
+
+    assert_int_equal(F_status_set_fine(status), F_parameter);
+  }
+}
+
+void test__f_serialize_from_simple__returns_data_not(void **state) {
+
+  const f_string_static_t source = f_string_static_t_initialize;
+
+  f_string_dynamics_t destination = f_string_dynamics_t_initialize;
+
+  {
+    const f_status_t status = f_serialize_from_simple(source, &destination);
+
+    assert_int_equal(status, F_data_not);
+  }
+
+  f_string_dynamics_resize(0, &destination);
+}
+
+void test__f_serialize_from_simple__works(void **state) {
+
+  f_string_static_t sources[] = {
+    macro_f_string_static_t_initialize("", 0, 1),
+    macro_f_string_static_t_initialize("first", 0, 5),
+    macro_f_string_static_t_initialize(".:", 0, 2),
+    macro_f_string_static_t_initialize(":cc", 0, 3),
+    macro_f_string_static_t_initialize("first:2::蠇", 0, 12),
+    macro_f_string_static_t_initialize("им:蠇", 0, 8),
+    macro_f_string_static_t_initialize("им:?", 0, 6),
+  };
+
+  f_string_static_t individuals[] = {
+    f_string_empty_s,
+    macro_f_string_static_t_initialize("", 0, 1),
+    macro_f_string_static_t_initialize("first", 0, 5),
+    macro_f_string_static_t_initialize(".", 0, 1),
+    macro_f_string_static_t_initialize("?", 0, 1),
+    macro_f_string_static_t_initialize("cc", 0, 2),
+    macro_f_string_static_t_initialize("2", 0, 1),
+    macro_f_string_static_t_initialize("蠇", 0, 3),
+    macro_f_string_static_t_initialize("им", 0, 4),
+  };
+
+  f_string_static_t expected_array_0[] = { individuals[1] };
+  f_string_static_t expected_array_1[] = { individuals[2] };
+  f_string_static_t expected_array_2[] = { individuals[3], individuals[0] };
+  f_string_static_t expected_array_3[] = { individuals[0], individuals[5] };
+  f_string_static_t expected_array_4[] = { individuals[2], individuals[6], individuals[0], individuals[7] };
+  f_string_static_t expected_array_5[] = { individuals[8], individuals[7] };
+  f_string_static_t expected_array_6[] = { individuals[8], individuals[4] };
+
+  f_string_statics_t expecteds[] = {
+    macro_f_string_statics_t_initialize(expected_array_0, 0, 1),
+    macro_f_string_statics_t_initialize(expected_array_1, 0, 1),
+    macro_f_string_statics_t_initialize(expected_array_2, 0, 2),
+    macro_f_string_statics_t_initialize(expected_array_3, 0, 2),
+    macro_f_string_statics_t_initialize(expected_array_4, 0, 4),
+    macro_f_string_statics_t_initialize(expected_array_5, 0, 2),
+    macro_f_string_statics_t_initialize(expected_array_6, 0, 2),
+  };
+
+  f_string_dynamics_t destination = f_string_dynamics_t_initialize;
+
+  for (uint8_t i = 0; i < 7; ++i) {
+
+    const f_status_t status = f_serialize_from_simple(sources[i], &destination);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(destination.used, expecteds[i].used);
+
+    for (uint8_t j = 0; j < destination.used; ++j) {
+
+      assert_int_equal(destination.array[j].used, expecteds[i].array[j].used);
+
+      if (destination.array[j].used) {
+        assert_string_equal(destination.array[j].string, expecteds[i].array[j].string);
+      }
+    } // for
+
+    destination.used = 0;
+  } // for
+
+  {
+    const f_string_static_t incompletes[] = {
+      macro_f_string_static_t_initialize("蠇", 0, 2),
+      macro_f_string_static_t_initialize("蠇", 0, 1),
+    };
+
+    for (uint8_t i = 0; i < 2; ++i) {
+
+      destination.used = 0;
+
+      const f_status_t status = f_serialize_from_simple(incompletes[i], &destination);
+
+      assert_int_equal(status, F_complete_not_utf_eos);
+      assert_int_equal(destination.used, 1);
+      assert_int_equal(destination.array[destination.used - 1].used, 0);
+    } // for
+  }
+
+  f_string_dynamics_resize(0, &destination);
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_serialize/tests/unit/c/test-serialize-from_simple.h b/level_0/f_serialize/tests/unit/c/test-serialize-from_simple.h
new file mode 100644 (file)
index 0000000..8de5682
--- /dev/null
@@ -0,0 +1,34 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Serialize
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the serialize project.
+ */
+#ifndef _TEST__F_serialize_from_simple_h
+#define _TEST__F_serialize_from_simple_h
+
+/**
+ * Test that parameter checking works as expected.
+ *
+ * @see f_serialize_from_simple()
+ */
+extern void test__f_serialize_from_simple__parameter_checking(void **state);
+
+/**
+ * Test that function works but returns F_data_not.
+ *
+ * @see f_serialize_from_simple()
+ */
+extern void test__f_serialize_from_simple__returns_data_not(void **state);
+
+/**
+ * Test that function works.
+ *
+ * @see f_serialize_from_simple()
+ */
+extern void test__f_serialize_from_simple__works(void **state);
+
+#endif // _TEST__F_serialize_from_simple_h
diff --git a/level_0/f_serialize/tests/unit/c/test-serialize-from_simple_get.c b/level_0/f_serialize/tests/unit/c/test-serialize-from_simple_get.c
new file mode 100644 (file)
index 0000000..cd87b4a
--- /dev/null
@@ -0,0 +1,68 @@
+#include "test-serialize.h"
+#include "test-serialize-from_simple_get.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_serialize_from_simple_get__parameter_checking(void **state) {
+
+  const f_string_static_t source = macro_f_string_static_t_initialize("test", 0, 4);
+
+  {
+    const f_status_t status = f_serialize_from_simple_get(source, 0, 0);
+
+    assert_int_equal(F_status_set_fine(status), F_parameter);
+  }
+}
+
+void test__f_serialize_from_simple_get__returns_data_not(void **state) {
+
+  f_string_dynamic_t destination = f_string_dynamic_t_initialize;
+
+  {
+    const f_status_t status = f_serialize_from_simple_get(f_string_empty_s, 0, &destination);
+
+    assert_int_equal(status, F_data_not);
+  }
+
+  f_string_dynamic_resize(0, &destination);
+}
+
+void test__f_serialize_from_simple_get__works(void **state) {
+
+  const f_string_static_t source = macro_f_string_static_t_initialize("test:2::other:им:蠇:м:", 0, 26);
+
+  const f_string_static_t matchs[] = {
+    macro_f_string_static_t_initialize("test", 0, 4),
+    macro_f_string_static_t_initialize("2", 0, 1),
+    f_string_empty_s,
+    macro_f_string_static_t_initialize("other", 0, 5),
+    macro_f_string_static_t_initialize("им", 0, 4),
+    macro_f_string_static_t_initialize("蠇", 0, 3),
+    macro_f_string_static_t_initialize("м", 0, 2),
+    f_string_empty_s,
+  };
+
+  f_string_dynamic_t destination = f_string_dynamic_t_initialize;
+
+  for (uint8_t i = 0; i < 8; ++i) {
+
+    destination.used = 0;
+
+    const f_status_t status = f_serialize_from_simple_get(source, i, &destination);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(destination.used, matchs[i].used);
+
+    if (destination.used) {
+      assert_string_equal(destination.string, matchs[i].string);
+    }
+  } // for
+
+  f_string_dynamic_resize(0, &destination);
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_serialize/tests/unit/c/test-serialize-from_simple_get.h b/level_0/f_serialize/tests/unit/c/test-serialize-from_simple_get.h
new file mode 100644 (file)
index 0000000..a4418f4
--- /dev/null
@@ -0,0 +1,34 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Serialize
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the serialize project.
+ */
+#ifndef _TEST__F_serialize_from_simple_get_h
+#define _TEST__F_serialize_from_simple_get_h
+
+/**
+ * Test that parameter checking works as expected.
+ *
+ * @see f_serialize_from_simple_get()
+ */
+extern void test__f_serialize_from_simple_get__parameter_checking(void **state);
+
+/**
+ * Test that function works but returns F_data_not.
+ *
+ * @see f_serialize_from_simple_get()
+ */
+extern void test__f_serialize_from_simple_get__returns_data_not(void **state);
+
+/**
+ * Test that function works.
+ *
+ * @see f_serialize_from_simple_get()
+ */
+extern void test__f_serialize_from_simple_get__works(void **state);
+
+#endif // _TEST__F_serialize_from_simple_get_h
diff --git a/level_0/f_serialize/tests/unit/c/test-serialize-from_simple_range.c b/level_0/f_serialize/tests/unit/c/test-serialize-from_simple_range.c
new file mode 100644 (file)
index 0000000..85f658d
--- /dev/null
@@ -0,0 +1,106 @@
+#include "test-serialize.h"
+#include "test-serialize-from_simple_range.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_serialize_from_simple_range__parameter_checking(void **state) {
+
+  const f_string_static_t source = macro_f_string_static_t_initialize("test", 0, 4);
+
+  {
+    const f_status_t status = f_serialize_from_simple_range(source, 0);
+
+    assert_int_equal(F_status_set_fine(status), F_parameter);
+  }
+}
+
+void test__f_serialize_from_simple_range__returns_data_not(void **state) {
+
+  const f_string_static_t source = f_string_static_t_initialize;
+
+  f_string_ranges_t ranges = f_string_ranges_t_initialize;
+
+  {
+    const f_status_t status = f_serialize_from_simple_range(source, &ranges);
+
+    assert_int_equal(status, F_data_not);
+  }
+
+  f_string_ranges_resize(0, &ranges);
+}
+
+void test__f_serialize_from_simple_range__works(void **state) {
+
+  f_string_static_t sources[] = {
+    macro_f_string_static_t_initialize("", 0, 1),
+    macro_f_string_static_t_initialize("first", 0, 5),
+    macro_f_string_static_t_initialize(".:", 0, 2),
+    macro_f_string_static_t_initialize(":cc", 0, 3),
+    macro_f_string_static_t_initialize("first:2::蠇", 0, 12),
+    macro_f_string_static_t_initialize("им:蠇", 0, 8),
+    macro_f_string_static_t_initialize("им:?", 0, 6),
+  };
+
+  f_string_range_t expected_array_0[] = { { 0, 0 } };
+  f_string_range_t expected_array_1[] = { { 0, 4 } };
+  f_string_range_t expected_array_2[] = { { 0, 0 }, { 1, 0 } };
+  f_string_range_t expected_array_3[] = { { 1, 0 }, { 1, 2 } };
+  f_string_range_t expected_array_4[] = { { 0, 4 }, { 6, 6 }, { 1, 0 }, { 9, 11 } };
+  f_string_range_t expected_array_5[] = { { 0, 3 }, { 5, 7 } };
+  f_string_range_t expected_array_6[] = { { 0, 3 }, { 5, 5 } };
+
+  f_string_ranges_t expecteds[] = {
+    macro_f_string_statics_t_initialize(expected_array_0, 0, 1),
+    macro_f_string_statics_t_initialize(expected_array_1, 0, 1),
+    macro_f_string_statics_t_initialize(expected_array_2, 0, 2),
+    macro_f_string_statics_t_initialize(expected_array_3, 0, 2),
+    macro_f_string_statics_t_initialize(expected_array_4, 0, 4),
+    macro_f_string_statics_t_initialize(expected_array_5, 0, 2),
+    macro_f_string_statics_t_initialize(expected_array_6, 0, 2),
+  };
+
+  f_string_ranges_t ranges = f_string_ranges_t_initialize;
+
+  for (uint8_t i = 0; i < 7; ++i) {
+
+    const f_status_t status = f_serialize_from_simple_range(sources[i], &ranges);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(ranges.used, expecteds[i].used);
+
+    for (uint8_t j = 0; j < ranges.used; ++j) {
+
+      assert_int_equal(ranges.array[j].start, expecteds[i].array[j].start);
+      assert_int_equal(ranges.array[j].stop, expecteds[i].array[j].stop);
+    } // for
+
+    ranges.used = 0;
+  } // for
+
+  {
+    const f_string_static_t incompletes[] = {
+      macro_f_string_static_t_initialize("蠇", 0, 2),
+      macro_f_string_static_t_initialize("蠇", 0, 1),
+    };
+
+    for (uint8_t i = 0; i < 2; ++i) {
+
+      ranges.used = 0;
+
+      const f_status_t status = f_serialize_from_simple_range(incompletes[i], &ranges);
+
+      assert_int_equal(status, F_complete_not_utf_eos);
+      assert_int_equal(ranges.used, 1);
+      assert_int_equal(ranges.array[ranges.used - 1].start, 1);
+      assert_int_equal(ranges.array[ranges.used - 1].stop, 0);
+    } // for
+  }
+
+  f_string_ranges_resize(0, &ranges);
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_serialize/tests/unit/c/test-serialize-from_simple_range.h b/level_0/f_serialize/tests/unit/c/test-serialize-from_simple_range.h
new file mode 100644 (file)
index 0000000..baf8cc9
--- /dev/null
@@ -0,0 +1,34 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Serialize
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the serialize project.
+ */
+#ifndef _TEST__F_serialize_from_simple_range_h
+#define _TEST__F_serialize_from_simple_range_h
+
+/**
+ * Test that parameter checking works as expected.
+ *
+ * @see f_serialize_from_simple_range()
+ */
+extern void test__f_serialize_from_simple_range__parameter_checking(void **state);
+
+/**
+ * Test that function works but returns F_data_not.
+ *
+ * @see f_serialize_from_simple_range()
+ */
+extern void test__f_serialize_from_simple_range__returns_data_not(void **state);
+
+/**
+ * Test that function works.
+ *
+ * @see f_serialize_from_simple_range()
+ */
+extern void test__f_serialize_from_simple_range__works(void **state);
+
+#endif // _TEST__F_serialize_from_simple_range_h
diff --git a/level_0/f_serialize/tests/unit/c/test-serialize-from_simple_select.c b/level_0/f_serialize/tests/unit/c/test-serialize-from_simple_select.c
new file mode 100644 (file)
index 0000000..8c5668f
--- /dev/null
@@ -0,0 +1,59 @@
+#include "test-serialize.h"
+#include "test-serialize-from_simple_select.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_serialize_from_simple_select__parameter_checking(void **state) {
+
+  const f_string_static_t source = macro_f_string_static_t_initialize("test", 0, 4);
+
+  {
+    const f_status_t status = f_serialize_from_simple_select(source, 0, 0);
+
+    assert_int_equal(F_status_set_fine(status), F_parameter);
+  }
+}
+
+void test__f_serialize_from_simple_select__returns_data_not(void **state) {
+
+  f_string_range_t range = f_string_range_t_initialize;
+
+  {
+    const f_status_t status = f_serialize_from_simple_select(f_string_empty_s, 0, &range);
+
+    assert_int_equal(status, F_data_not);
+  }
+}
+
+void test__f_serialize_from_simple_select__works(void **state) {
+
+  const f_string_static_t source = macro_f_string_static_t_initialize("test:2::other:им:蠇:м:", 0, 26);
+
+  const f_string_range_t ranges[] = {
+    { 0, 3 },
+    { 5, 5 },
+    { 1, 0 },
+    { 8, 12 },
+    { 14, 17 },
+    { 19, 21 },
+    { 23, 24 },
+    { 1, 0 },
+  };
+
+  for (uint8_t i = 0; i < 8; ++i) {
+
+    f_string_range_t range = f_string_range_t_initialize;
+
+    const f_status_t status = f_serialize_from_simple_select(source, i, &range);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(range.start, ranges[i].start);
+    assert_int_equal(range.stop, ranges[i].stop);
+  } // for
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_serialize/tests/unit/c/test-serialize-from_simple_select.h b/level_0/f_serialize/tests/unit/c/test-serialize-from_simple_select.h
new file mode 100644 (file)
index 0000000..e765d40
--- /dev/null
@@ -0,0 +1,34 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Serialize
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the serialize project.
+ */
+#ifndef _TEST__F_serialize_from_simple_select_h
+#define _TEST__F_serialize_from_simple_select_h
+
+/**
+ * Test that parameter checking works as expected.
+ *
+ * @see f_serialize_from_simple_select()
+ */
+extern void test__f_serialize_from_simple_select__parameter_checking(void **state);
+
+/**
+ * Test that function works but returns F_data_not.
+ *
+ * @see f_serialize_from_simple_select()
+ */
+extern void test__f_serialize_from_simple_select__returns_data_not(void **state);
+
+/**
+ * Test that function works.
+ *
+ * @see f_serialize_from_simple_select()
+ */
+extern void test__f_serialize_from_simple_select__works(void **state);
+
+#endif // _TEST__F_serialize_from_simple_select_h
diff --git a/level_0/f_serialize/tests/unit/c/test-serialize-to_simple.c b/level_0/f_serialize/tests/unit/c/test-serialize-to_simple.c
new file mode 100644 (file)
index 0000000..fac323a
--- /dev/null
@@ -0,0 +1,60 @@
+#include "test-serialize.h"
+#include "test-serialize-to_simple.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_serialize_to_simple__parameter_checking(void **state) {
+
+  const f_string_static_t source = macro_f_string_static_t_initialize("test", 0, 4);
+
+  {
+    const f_status_t status = f_serialize_to_simple(source, 0);
+
+    assert_int_equal(F_status_set_fine(status), F_parameter);
+  }
+}
+
+void test__f_serialize_to_simple__returns_data_not(void **state) {
+
+  const f_string_static_t source = f_string_static_t_initialize;
+
+  f_string_dynamic_t destination = f_string_dynamic_t_initialize;
+
+  {
+    const f_status_t status = f_serialize_to_simple(source, &destination);
+
+    assert_int_equal(status, F_data_not);
+  }
+
+  f_string_dynamic_resize(0, &destination);
+}
+
+void test__f_serialize_to_simple__works(void **state) {
+
+  const f_string_static_t source = macro_f_string_static_t_initialize("test", 0, 4);
+  const f_string_static_t multiple = macro_f_string_static_t_initialize("test:test", 0, 9);
+
+  f_string_dynamic_t destination = f_string_dynamic_t_initialize;
+
+  {
+    const f_status_t status = f_serialize_to_simple(source, &destination);
+
+    assert_int_equal(status, F_none);
+    assert_string_equal(destination.string, source.string);
+  }
+
+  {
+    const f_status_t status = f_serialize_to_simple(source, &destination);
+
+    assert_int_equal(status, F_none);
+    assert_string_equal(destination.string, multiple.string);
+  }
+
+  f_string_dynamic_resize(0, &destination);
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_serialize/tests/unit/c/test-serialize-to_simple.h b/level_0/f_serialize/tests/unit/c/test-serialize-to_simple.h
new file mode 100644 (file)
index 0000000..fc717f7
--- /dev/null
@@ -0,0 +1,34 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Serialize
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the serialize project.
+ */
+#ifndef _TEST__F_serialize_to_simple_h
+#define _TEST__F_serialize_to_simple_h
+
+/**
+ * Test that parameter checking works as expected.
+ *
+ * @see f_serialize_to_simple()
+ */
+extern void test__f_serialize_to_simple__parameter_checking(void **state);
+
+/**
+ * Test that function works but returns F_data_not.
+ *
+ * @see f_serialize_to_simple()
+ */
+extern void test__f_serialize_to_simple__returns_data_not(void **state);
+
+/**
+ * Test that function works.
+ *
+ * @see f_serialize_to_simple()
+ */
+extern void test__f_serialize_to_simple__works(void **state);
+
+#endif // _TEST__F_serialize_to_simple_h
diff --git a/level_0/f_serialize/tests/unit/c/test-serialize.c b/level_0/f_serialize/tests/unit/c/test-serialize.c
new file mode 100644 (file)
index 0000000..15cea96
--- /dev/null
@@ -0,0 +1,51 @@
+#include "test-serialize.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int setup(void **state) {
+
+  return 0;
+}
+
+int setdown(void **state) {
+
+  errno = 0;
+
+  return 0;
+}
+
+int main(void) {
+
+  const struct CMUnitTest tests[] = {
+    cmocka_unit_test(test__f_serialize_from_simple__returns_data_not),
+    cmocka_unit_test(test__f_serialize_from_simple__works),
+
+    cmocka_unit_test(test__f_serialize_from_simple_get__returns_data_not),
+    cmocka_unit_test(test__f_serialize_from_simple_get__works),
+
+    cmocka_unit_test(test__f_serialize_from_simple_select__returns_data_not),
+    cmocka_unit_test(test__f_serialize_from_simple_select__works),
+
+    cmocka_unit_test(test__f_serialize_from_simple_range__returns_data_not),
+    cmocka_unit_test(test__f_serialize_from_simple_range__works),
+
+    cmocka_unit_test(test__f_serialize_to_simple__returns_data_not),
+    cmocka_unit_test(test__f_serialize_to_simple__works),
+
+    #ifndef _di_level_0_parameter_checking_
+      cmocka_unit_test(test__f_serialize_from_simple__parameter_checking),
+      cmocka_unit_test(test__f_serialize_from_simple_get__parameter_checking),
+      cmocka_unit_test(test__f_serialize_from_simple_range__parameter_checking),
+      cmocka_unit_test(test__f_serialize_from_simple_select__parameter_checking),
+      cmocka_unit_test(test__f_serialize_to_simple__parameter_checking),
+    #endif // _di_level_0_parameter_checking_
+  };
+
+  return cmocka_run_group_tests(tests, setup, setdown);
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_serialize/tests/unit/c/test-serialize.h b/level_0/f_serialize/tests/unit/c/test-serialize.h
new file mode 100644 (file)
index 0000000..1508b7a
--- /dev/null
@@ -0,0 +1,76 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Serialize
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the serialize project.
+ */
+#ifndef _TEST__F_serialize_h
+#define _TEST__F_serialize_h
+
+// Libc includes.
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <stdint.h>
+
+// cmocka includes.
+#include <cmocka.h>
+
+// FLL-0 includes.
+#include <fll/level_0/serialize.h>
+
+// Mock includes.
+//#include "mock-serialize.h"
+
+// Test includes.
+#include "test-serialize-from_simple.h"
+#include "test-serialize-from_simple_get.h"
+#include "test-serialize-from_simple_range.h"
+#include "test-serialize-from_simple_select.h"
+#include "test-serialize-to_simple.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Perform any setup operations.
+ *
+ * @param state
+ *   The test state.
+ *
+ * @return
+ *   The status of this function, where 0 means success.
+ */
+extern int setup(void **state);
+
+/**
+ * Peform any setdown operations.
+ *
+ * @param state
+ *   The test state.
+ *
+ * @return
+ *   The status of this function, where 0 means success.
+ */
+extern int setdown(void **state);
+
+/**
+ * Run all tests.
+ *
+ * @return
+ *   The final result of the tests.
+ *
+ * @see cmocka_run_group_tests()
+ * @see cmocka_unit_test()
+ */
+extern int main(void);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // _TEST__F_serialize_h