]> Kevux Git Server - fll/commitdiff
Update: Add f_control_group unit tests.
authorKevin Day <thekevinday@gmail.com>
Mon, 24 Jan 2022 03:51:02 +0000 (21:51 -0600)
committerKevin Day <thekevinday@gmail.com>
Mon, 24 Jan 2022 03:51:02 +0000 (21:51 -0600)
level_0/f_control_group/data/build/settings-tests [new file with mode: 0644]
level_0/f_control_group/data/build/testfile [new file with mode: 0644]
level_0/f_control_group/tests/c/test-control_group-copy.c [new file with mode: 0644]
level_0/f_control_group/tests/c/test-control_group-copy.h [new file with mode: 0644]
level_0/f_control_group/tests/c/test-control_group.c [new file with mode: 0644]
level_0/f_control_group/tests/c/test-control_group.h [new file with mode: 0644]

diff --git a/level_0/f_control_group/data/build/settings-tests b/level_0/f_control_group/data/build/settings-tests
new file mode 100644 (file)
index 0000000..a2b1953
--- /dev/null
@@ -0,0 +1,45 @@
+# fss-0001
+
+project_name test-f_control_group
+
+version_major 0
+version_minor 5
+version_micro 8
+version_file major
+version_target major
+
+modes individual level monolithic
+modes_default individual
+
+build_compiler gcc
+build_indexer ar
+build_indexer_arguments rcs
+build_language c
+build_libraries -lc -lcmocka
+build_libraries-individual -lf_memory -lf_string -lf_control_group
+build_libraries-level -lfll_0
+build_libraries-monolithic -lfll
+build_sources_program test-control_group-copy.c test-control_group.c
+build_script no
+build_shared yes
+build_static no
+
+path_headers tests/c
+path_headers_preserve no
+path_sources tests/c
+path_standard no
+
+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-logical-op-parentheses -Wno-parentheses
+flags_program -fPIE
+flags_program_shared
+flags_program_static
+flags_shared
+flags_static
diff --git a/level_0/f_control_group/data/build/testfile b/level_0/f_control_group/data/build/testfile
new file mode 100644 (file)
index 0000000..a9369e8
--- /dev/null
@@ -0,0 +1,45 @@
+# fss-0005 iki-0002
+
+settings:
+  load_build yes
+  fail exit
+
+  environment LD_LIBRARY_PATH
+
+main:
+  build settings
+  build settings-tests
+
+  operate ld_library_path
+
+  if exists build/programs/shared/test-f_control_group
+    shell build/programs/shared/test-f_control_group
+
+  if exists build/programs/static/test-f_control_group
+    shell build/programs/static/test-f_control_group
+
+  if not exists build/programs/shared/test-f_control_group
+  and not exists build/programs/static/test-f_control_group
+    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:"error"
+
+  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_control_group/tests/c/test-control_group-copy.c b/level_0/f_control_group/tests/c/test-control_group-copy.c
new file mode 100644 (file)
index 0000000..93dfa10
--- /dev/null
@@ -0,0 +1,169 @@
+#include "test-control_group.h"
+#include "test-control_group-copy.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef _di_level_0_parameter_checking_
+  void test__f_control_group_copy__parameter_checking(void **state) {
+
+    const f_control_group_t source = f_control_group_t_initialize;
+
+    {
+      const f_status_t status = f_control_group_copy(source, 0);
+
+      assert_int_equal(F_status_set_fine(status), F_parameter);
+    }
+  }
+#endif // _di_level_0_parameter_checking_
+
+void test__f_control_group_copy__works(void **state) {
+
+  f_control_group_t source = f_control_group_t_initialize;
+
+  {
+    source.as_new = F_true;
+
+    f_control_group_t destination = f_control_group_t_initialize;
+
+    const f_status_t status = f_control_group_copy(source, &destination);
+
+    assert_int_equal(status, F_none);
+
+    macro_f_control_group_t_delete_simple(destination);
+
+    assert_int_equal(destination.as_new, source.as_new);
+
+    assert_null(destination.path.string);
+    assert_int_equal(destination.path.used, 0);
+
+    assert_null(destination.groups.array);
+    assert_int_equal(destination.groups.used, 0);
+  }
+
+  {
+    f_control_group_t destination = f_control_group_t_initialize;
+
+    source.as_new = F_true;
+    source.path.string = "source.path";
+    source.path.used = 11;
+    source.path.size = 0;
+
+    const f_status_t status = f_control_group_copy(source, &destination);
+
+    assert_int_equal(status, F_none);
+
+    assert_int_equal(destination.as_new, source.as_new);
+
+    assert_string_equal(destination.path.string, source.path.string);
+    assert_int_equal(destination.path.used, source.path.used);
+
+    assert_null(destination.groups.array);
+    assert_int_equal(destination.groups.used, 0);
+
+    macro_f_control_group_t_delete_simple(destination);
+  }
+
+  {
+    f_control_group_t destination = f_control_group_t_initialize;
+
+    source.as_new = F_true;
+    source.path.string = 0;
+    source.path.used = 0;
+    source.path.size = 0;
+
+    f_string_static_t groups[] = {
+      f_string_static_t_initialize,
+      f_string_static_t_initialize,
+    };
+
+    groups[0].string = "group_1";
+    groups[0].used = 7;
+    groups[0].size = 0;
+
+    groups[1].string = "group_2";
+    groups[1].used = 7;
+    groups[1].size = 0;
+
+    source.groups.array = groups;
+    source.groups.used = 2;
+    source.groups.size = 0;
+
+    const f_status_t status = f_control_group_copy(source, &destination);
+
+    assert_int_equal(status, F_none);
+
+    assert_int_equal(destination.as_new, source.as_new);
+
+    assert_null(destination.path.string);
+    assert_int_equal(destination.path.used, source.path.used);
+
+    assert_non_null(destination.groups.array);
+    assert_int_equal(destination.groups.used, source.groups.used);
+
+    assert_string_equal(destination.groups.array[0].string, source.groups.array[0].string);
+    assert_string_equal(destination.groups.array[1].string, source.groups.array[1].string);
+
+    assert_int_equal(destination.groups.array[0].used, source.groups.array[0].used);
+    assert_int_equal(destination.groups.array[1].used, source.groups.array[1].used);
+
+    macro_f_control_group_t_delete_simple(destination);
+  }
+
+  {
+    f_control_group_t destination = f_control_group_t_initialize;
+
+    source.as_new = F_false;
+    source.path.string = "source.path";
+    source.path.used = 11;
+    source.path.size = 0;
+
+    f_string_static_t groups[] = {
+      f_string_static_t_initialize,
+      f_string_static_t_initialize,
+    };
+
+    groups[0].string = "group_1";
+    groups[0].used = 7;
+    groups[0].size = 0;
+
+    groups[1].string = "group_2";
+    groups[1].used = 7;
+    groups[1].size = 0;
+
+    groups[2].string = "group_3";
+    groups[2].used = 7;
+    groups[2].size = 0;
+
+    source.groups.array = groups;
+    source.groups.used = 3;
+    source.groups.size = 0;
+
+    const f_status_t status = f_control_group_copy(source, &destination);
+
+    assert_int_equal(status, F_none);
+
+    assert_int_equal(destination.as_new, source.as_new);
+
+    assert_string_equal(destination.path.string, source.path.string);
+    assert_int_equal(destination.path.used, source.path.used);
+
+    assert_non_null(destination.groups.array);
+    assert_int_equal(destination.groups.used, source.groups.used);
+
+    assert_string_equal(destination.groups.array[0].string, source.groups.array[0].string);
+    assert_string_equal(destination.groups.array[1].string, source.groups.array[1].string);
+    assert_string_equal(destination.groups.array[2].string, source.groups.array[2].string);
+
+    assert_int_equal(destination.groups.array[0].used, source.groups.array[0].used);
+    assert_int_equal(destination.groups.array[1].used, source.groups.array[1].used);
+    assert_int_equal(destination.groups.array[2].used, source.groups.array[2].used);
+
+    macro_f_control_group_t_delete_simple(destination);
+  }
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_control_group/tests/c/test-control_group-copy.h b/level_0/f_control_group/tests/c/test-control_group-copy.h
new file mode 100644 (file)
index 0000000..eeff77a
--- /dev/null
@@ -0,0 +1,31 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Control Group
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the control group project.
+ */
+#ifndef _TEST__F_control_group_copy_h
+#define _TEST__F_control_group_copy_h
+
+// f_control_group_copy() only returns memory failures.
+
+/**
+ * Test that parameter checking works as expected.
+ *
+ * @see f_control_group_copy()
+ */
+#ifndef _di_level_0_parameter_checking_
+  extern void test__f_control_group_copy__parameter_checking(void **state);
+#endif // _di_level_0_parameter_checking_
+
+/**
+ * Test that function works.
+ *
+ * @see f_control_group_copy()
+ */
+extern void test__f_control_group_copy__works(void **state);
+
+#endif // _TEST__F_control_group_copy_h
diff --git a/level_0/f_control_group/tests/c/test-control_group.c b/level_0/f_control_group/tests/c/test-control_group.c
new file mode 100644 (file)
index 0000000..c295aa2
--- /dev/null
@@ -0,0 +1,36 @@
+#include "test-control_group.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[] = {
+
+    // f_control_group_copy() only returns memory failures.
+    cmocka_unit_test(test__f_control_group_copy__works),
+
+    #ifndef _di_level_0_parameter_checking_
+      cmocka_unit_test(test__f_control_group_copy__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_control_group/tests/c/test-control_group.h b/level_0/f_control_group/tests/c/test-control_group.h
new file mode 100644 (file)
index 0000000..dadb17e
--- /dev/null
@@ -0,0 +1,69 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Control Group
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the control group project.
+ */
+#ifndef _TEST__F_control_group_h
+#define _TEST__F_control_group_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/control_group.h>
+
+// test includes.
+#include "test-control_group-copy.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_control_group_h