]> Kevux Git Server - fll/commitdiff
Update: Implement f_capability unit tests and improve existing unit tests.
authorKevin Day <thekevinday@gmail.com>
Mon, 10 Jan 2022 03:35:03 +0000 (21:35 -0600)
committerKevin Day <thekevinday@gmail.com>
Mon, 10 Jan 2022 03:35:03 +0000 (21:35 -0600)
Add tests for f_capability functions.
This includes my first go at mocking functions using function wrapping.
It seems that the linker is limited on how it handles function wrapping.
I cannot simply wrap functions pulled in via a library.
To work around this I implemented another Fake build settings file for handling this.
This is not an ideal situation and adds a bit of extra work.

The environment variable settings for LD_LIBRARY_PATH needs to also support the work parameter.

These changes expose a logic flaw in the if/else logic of the Fake program.
That bug is not fixed in this commit, it is simply noted in this commit log.

90 files changed:
level_0/f_capability/data/build/dependencies-tests [new file with mode: 0644]
level_0/f_capability/data/build/settings-mocks [new file with mode: 0644]
level_0/f_capability/data/build/settings-tests [new file with mode: 0644]
level_0/f_capability/data/build/testfile [new file with mode: 0644]
level_0/f_capability/tests/c/mock-capability.c [new file with mode: 0644]
level_0/f_capability/tests/c/mock-capability.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-ambient_get.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-ambient_get.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-ambient_reset.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-ambient_reset.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-ambient_set.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-ambient_set.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-clear.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-clear.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-clear_flag.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-clear_flag.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-compare.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-compare.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-copy.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-copy.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-copy_external.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-copy_external.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-copy_internal.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-copy_internal.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-delete.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-delete.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-file_descriptor_get.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-file_descriptor_get.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-file_descriptor_set.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-file_descriptor_set.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-file_get.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-file_get.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-file_set.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-file_set.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-flag_get.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-flag_get.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-flag_set.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-flag_set.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-from_name.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-from_name.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-from_text.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-from_text.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-groups_set.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-groups_set.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-initialize.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-initialize.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-mode_get.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-mode_get.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-mode_get_name.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-mode_get_name.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-mode_set.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-mode_set.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-owner_get.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-owner_get.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-owner_set.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-owner_set.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-process_bound_drop.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-process_bound_drop.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-process_bound_get.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-process_bound_get.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-process_get.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-process_get.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-process_get_by_id.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-process_get_by_id.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-process_set.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-process_set.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-security_bits_get.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-security_bits_get.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-security_bits_set.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-security_bits_set.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-size.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-size.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-supported.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-supported.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-supported_ambient.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-supported_ambient.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-supported_code.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-supported_code.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-to_name.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-to_name.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-to_text.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-to_text.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-user_set.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability-user_set.h [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability.c [new file with mode: 0644]
level_0/f_capability/tests/c/test-capability.h [new file with mode: 0644]
level_0/f_memory/data/build/dependencies-tests
level_0/f_memory/data/build/testfile
level_0/f_type_array/data/build/dependencies-tests
level_0/f_type_array/data/build/testfile

diff --git a/level_0/f_capability/data/build/dependencies-tests b/level_0/f_capability/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_capability/data/build/settings-mocks b/level_0/f_capability/data/build/settings-mocks
new file mode 100644 (file)
index 0000000..650ecbd
--- /dev/null
@@ -0,0 +1,119 @@
+# fss-0001
+#
+# 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 exaclty match the "settings" file, except for the additional "-Wl,--wrap" parts and the additional mock source file.
+#
+
+project_name f_capability
+
+version_major 0
+version_minor 5
+version_micro 8
+version_file micro
+version_target minor
+
+environment
+
+process_pre
+process_post
+
+modes individual
+modes_default individual
+
+build_compiler gcc
+build_indexer ar
+build_indexer_arguments rcs
+build_language c
+build_libraries -lc -lcap
+build_libraries-individual -lf_memory -lf_string -lf_type_array
+build_libraries_shared
+build_libraries_static
+build_sources_library capability.c ../../tests/c/mock-capability.c
+build_sources_library_shared
+build_sources_library_static
+build_sources_program
+build_sources_program_shared
+build_sources_program_static
+build_sources_headers capability.h capability-common.h
+build_sources_headers_shared
+build_sources_headers_static
+build_sources_script
+build_sources_setting
+build_script yes
+build_shared yes
+build_static no
+
+path_headers fll/level_0
+path_headers_preserve no
+path_library_script script
+path_library_shared shared
+path_library_static static
+path_program_script script
+path_program_shared shared
+path_program_static static
+path_sources
+path_standard yes
+
+search_exclusive yes
+search_shared yes
+search_static yes
+
+#defines -D_di_libcap_
+defines -D_libcap_legacy_only_
+defines_library
+defines_library_shared
+defines_library_static
+defines_program
+defines_program_shared
+defines_program_static
+defines_static
+defines_shared
+
+flags -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses
+flags_library -fPIC
+flags_library_shared
+flags_library_static
+flags_program -fPIE
+flags_program_shared
+flags_program_static
+flags_shared
+flags_static
+
+# Inject mocks.
+flags -Wl,--wrap=cap_get_ambient
+flags -Wl,--wrap=cap_clear
+flags -Wl,--wrap=cap_clear_flag
+flags -Wl,--wrap=cap_compare
+flags -Wl,--wrap=cap_copy_ext
+flags -Wl,--wrap=cap_copy_int
+flags -Wl,--wrap=cap_drop_bound
+flags -Wl,--wrap=cap_dup
+flags -Wl,--wrap=cap_free
+flags -Wl,--wrap=cap_from_name
+flags -Wl,--wrap=cap_from_text
+flags -Wl,--wrap=cap_get_bound
+flags -Wl,--wrap=cap_get_fd
+flags -Wl,--wrap=cap_get_file
+flags -Wl,--wrap=cap_get_flag
+flags -Wl,--wrap=cap_get_mode
+flags -Wl,--wrap=cap_get_pid
+flags -Wl,--wrap=cap_get_proc
+flags -Wl,--wrap=cap_set_mode
+flags -Wl,--wrap=cap_get_nsowner
+flags -Wl,--wrap=cap_get_secbits
+flags -Wl,--wrap=cap_init
+flags -Wl,--wrap=cap_mode_name
+flags -Wl,--wrap=cap_reset_ambient
+flags -Wl,--wrap=cap_set_ambient
+flags -Wl,--wrap=cap_set_fd
+flags -Wl,--wrap=cap_set_file
+flags -Wl,--wrap=cap_set_flag
+flags -Wl,--wrap=cap_set_nsowner
+flags -Wl,--wrap=cap_set_proc
+flags -Wl,--wrap=cap_set_secbits
+flags -Wl,--wrap=cap_setgroups
+flags -Wl,--wrap=cap_setuid
+flags -Wl,--wrap=cap_size
+flags -Wl,--wrap=cap_to_name
+flags -Wl,--wrap=cap_to_text
diff --git a/level_0/f_capability/data/build/settings-tests b/level_0/f_capability/data/build/settings-tests
new file mode 100644 (file)
index 0000000..f826fcc
--- /dev/null
@@ -0,0 +1,47 @@
+# fss-0001
+
+project_name test-f_capability
+
+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_type_array -lf_capability
+build_libraries-level -lfll_0
+build_libraries-monolithic -lfll
+build_sources_program test-capability-ambient_get.c test-capability-ambient_reset.c test-capability-ambient_set.c test-capability-clear.c test-capability-clear_flag.c test-capability-compare.c test-capability-copy.c test-capability-copy_external.c test-capability-copy_internal.c test-capability-delete.c test-capability-file_descriptor_get.c test-capability-file_descriptor_set.c test-capability-file_get.c test-capability-file_set.c test-capability-flag_get.c test-capability-flag_set.c test-capability-from_name.c test-capability-from_text.c test-capability-groups_set.c test-capability-initialize.c test-capability-mode_get.c test-capability-mode_get_name.c test-capability-mode_set.c test-capability-owner_get.c test-capability-owner_set.c test-capability-process_bound_drop.c test-capability-process_bound_get.c test-capability-process_get_by_id.c test-capability-process_get.c test-capability-process_set.c test-capability-security_bits_get.c test-capability-security_bits_set.c test-capability-size.c test-capability-supported_ambient.c test-capability-supported.c test-capability-supported_code.c test-capability-to_name.c test-capability-to_text.c test-capability-user_set.c test-capability.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 -D_di_libcap_
+defines -D_libcap_legacy_only_
+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_capability/data/build/testfile b/level_0/f_capability/data/build/testfile
new file mode 100644 (file)
index 0000000..d2c7591
--- /dev/null
@@ -0,0 +1,45 @@
+# fss-0005 iki-0002
+
+settings:
+  load_build yes
+  fail exit
+
+  environment LD_LIBRARY_PATH
+
+main:
+  build settings-mocks
+  build settings-tests
+
+  operate ld_library_path
+
+  if exists build/programs/shared/test-f_capability
+    shell build/programs/shared/test-f_capability
+
+  if exists build/programs/static/test-f_capability
+    shell build/programs/static/test-f_capability
+
+  if not exists build/programs/shared/test-f_capability
+  and not exists build/programs/static/test-f_capability
+    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_capability/tests/c/mock-capability.c b/level_0/f_capability/tests/c/mock-capability.c
new file mode 100644 (file)
index 0000000..090d1a9
--- /dev/null
@@ -0,0 +1,477 @@
+#include "mock-capability.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int __wrap_cap_get_ambient(cap_value_t value) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    return -1;
+  }
+
+  return 1;
+}
+
+int __wrap_cap_clear(cap_t capability) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return -1;
+  }
+
+  return 1;
+}
+
+int __wrap_cap_clear_flag(cap_t capability, cap_flag_value_t flag_value) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return -1;
+  }
+
+  return 1;
+}
+
+int __wrap_cap_compare(cap_t capability_1, cap_t capability_2) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return -1;
+  }
+
+  return mock_type(int);
+}
+
+ssize_t __wrap_cap_copy_ext(void *data, cap_t capability, ssize_t size) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return -1;
+  }
+
+  return 1;
+}
+
+cap_t __wrap_cap_copy_int(void *data) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return (cap_t) 0;
+  }
+
+  return (cap_t) 1;
+}
+
+int __wrap_cap_drop_bound(cap_value_t value) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return -1;
+  }
+
+  return 1;
+}
+
+cap_t __wrap_cap_dup(cap_t capability) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return (cap_t) 0;
+  }
+
+  return (cap_t) 1;
+}
+
+int __wrap_cap_free(void *pointer) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return -1;
+  }
+
+  return 1;
+}
+
+int __wrap_cap_from_name(const char *name, cap_value_t *value) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return -1;
+  }
+
+  return 1;
+}
+
+cap_t __wrap_cap_from_text(const char *text) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return (cap_t) 0;
+  }
+
+  return (cap_t) 1;
+}
+
+int __wrap_cap_get_bound(cap_value_t value) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return -1;
+  }
+
+  return 1;
+}
+
+cap_t __wrap_cap_get_fd(int descriptor) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return (cap_t) 0;
+  }
+
+  return (cap_t) 1;
+}
+
+cap_t __wrap_cap_get_file(const char *path) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return (cap_t) 0;
+  }
+
+  return (cap_t) 1;
+}
+
+int __wrap_cap_get_flag(cap_t capability, cap_value_t value, cap_flag_t flag, cap_flag_value_t *flag_value) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return -1;
+  }
+
+  return 1;
+}
+
+cap_mode_t __wrap_cap_get_mode(void) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return (cap_mode_t) 0;
+  }
+
+  return (cap_mode_t) 1;
+}
+
+uid_t __wrap_cap_get_nsowner(cap_t) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return (uid_t) -1;
+  }
+
+  return (uid_t) 1;
+}
+
+cap_t __wrap_cap_init(void) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return (cap_t) 0;
+  }
+
+  return (cap_t) 1;
+}
+
+const char *__wrap_cap_mode_name(cap_mode_t mode) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return (char *) 0;
+  }
+
+  return (char *) 1;
+}
+
+cap_t __wrap_cap_get_pid(pid_t pid) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return (cap_t) 0;
+  }
+
+  return (cap_t) 1;
+}
+
+cap_t __wrap_cap_get_proc(void) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return (cap_t) 0;
+  }
+
+  return (cap_t) 1;
+}
+
+unsigned __wrap_cap_get_secbits(void) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return -1;
+  }
+
+  return 1;
+}
+
+int __wrap_cap_reset_ambient(void) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return -1;
+  }
+
+  return 1;
+}
+
+int __wrap_cap_set_ambient(cap_value_t value, cap_flag_value_t flag_value) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return -1;
+  }
+
+  return 1;
+}
+
+int __wrap_cap_set_fd(int descriptor, cap_t capability) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return -1;
+  }
+
+  return 1;
+}
+
+int __wrap_cap_set_file(const char *path, cap_t capability) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return -1;
+  }
+
+  return 1;
+}
+
+int __wrap_cap_set_flag(cap_t capability, cap_flag_t flag, int number, const cap_value_t *value, cap_flag_value_t flag_value) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return -1;
+  }
+
+  return 1;
+}
+
+int __wrap_cap_set_mode(cap_mode_t mode) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return -1;
+  }
+
+  return 1;
+}
+
+int __wrap_cap_set_nsowner(cap_t capability, uid_t id) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return -1;
+  }
+
+  return 1;
+}
+
+int __wrap_cap_set_proc(cap_t capability) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return -1;
+  }
+
+  return 1;
+}
+
+int __wrap_cap_set_secbits(unsigned bits) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return -1;
+  }
+
+  return 1;
+}
+
+int __wrap_cap_setgroups(gid_t gid, size_t total, const gid_t groups[]) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return -1;
+  }
+
+  return 1;
+}
+
+int __wrap_cap_setuid(uid_t uid) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return -1;
+  }
+
+  return 1;
+}
+
+ssize_t __wrap_cap_size(cap_t capability) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return -1;
+  }
+
+  return 1;
+}
+
+char * __wrap_cap_to_text(cap_t capability, ssize_t *size) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return (char *) 0;
+  }
+
+  *size = mock_type(int);
+
+  return mock_type(char *);
+}
+
+char * __wrap_cap_to_name(cap_value_t value) {
+
+  bool failure = mock_type(bool);
+
+  if (failure) {
+    errno = mock_type(int);
+
+    return (char *) 0;
+  }
+
+  return mock_type(char *);
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/mock-capability.h b/level_0/f_capability/tests/c/mock-capability.h
new file mode 100644 (file)
index 0000000..756693e
--- /dev/null
@@ -0,0 +1,72 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _MOCK__capability_h
+#define _MOCK__capability_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/capability.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+const static int mock_errno_generic = 32767;
+
+extern int __wrap_cap_get_ambient(cap_value_t value);
+extern int __wrap_cap_clear(cap_t capability);
+extern int __wrap_cap_clear_flag(cap_t capability, cap_flag_value_t flag_value);
+extern int __wrap_cap_compare(cap_t capability_1, cap_t capability_2);
+extern ssize_t __wrap_cap_copy_ext(void *data, cap_t capability, ssize_t size);
+extern cap_t __wrap_cap_copy_int(void *data);
+extern int __wrap_cap_drop_bound(cap_value_t value);
+extern cap_t __wrap_cap_dup(cap_t capability);
+extern int __wrap_cap_free(void *pointer);
+extern int __wrap_cap_from_name(const char *name, cap_value_t *value);
+extern cap_t __wrap_cap_from_text(const char *text);
+extern int __wrap_cap_get_bound(cap_value_t value);
+extern cap_t __wrap_cap_get_fd(int descriptor);
+extern cap_t __wrap_cap_get_file(const char *path);
+extern int __wrap_cap_get_flag(cap_t capability, cap_value_t value, cap_flag_t flag, cap_flag_value_t *flag_value);
+extern cap_mode_t __wrap_cap_get_mode(void);
+extern uid_t __wrap_cap_get_nsowner(cap_t capability);
+extern cap_t __wrap_cap_init(void);
+extern const char *__wrap_cap_mode_name(cap_mode_t mode);
+extern cap_t __wrap_cap_get_pid(pid_t pid);
+extern cap_t __wrap_cap_get_proc(void);
+extern unsigned __wrap_cap_get_secbits(void);
+extern int __wrap_cap_reset_ambient(void);
+extern int __wrap_cap_set_ambient(cap_value_t value, cap_flag_value_t flag_value);
+extern int __wrap_cap_set_fd(int descriptor, cap_t capability);
+extern int __wrap_cap_set_file(const char *path, cap_t capability);
+extern int __wrap_cap_set_flag(cap_t capability, cap_flag_t flag, int number, const cap_value_t *value, cap_flag_value_t flag_value);
+extern int __wrap_cap_set_mode(cap_mode_t mode);
+extern int __wrap_cap_set_nsowner(cap_t capability, uid_t id);
+extern int __wrap_cap_set_proc(cap_t capability);
+extern int __wrap_cap_set_secbits(unsigned bits);
+extern int __wrap_cap_setgroups(gid_t gid, size_t total, const gid_t groups[]);
+extern int __wrap_cap_setuid(uid_t uid);
+extern ssize_t __wrap_cap_size(cap_t capability);
+extern char * __wrap_cap_to_text(cap_t capability, ssize_t *size);
+extern char * __wrap_cap_to_name(cap_value_t value);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // _MOCK__capability_h
diff --git a/level_0/f_capability/tests/c/test-capability-ambient_get.c b/level_0/f_capability/tests/c/test-capability-ambient_get.c
new file mode 100644 (file)
index 0000000..9125894
--- /dev/null
@@ -0,0 +1,50 @@
+#include "test-capability.h"
+#include "test-capability-ambient_get.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_ambient_get__works(void **state) {
+
+  f_capability_value_t value = f_capability_value_t_initialize;
+  int ambient = 0;
+
+  #if defined(_di_libcap_) || defined(_libcap_legacy_only_)
+    printf("[  WARN    ] f_capability_ambient_get() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_get_ambient, false);
+  #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_)
+
+  {
+    const f_status_t status = f_capability_ambient_get(value, &ambient);
+
+    #if defined(_di_libcap_) || defined(_libcap_legacy_only_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_int_equal(status, F_none);
+      assert_int_equal(ambient, 1);
+    #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_)
+  }
+}
+
+void test__f_capability_ambient_get__fails(void **state) {
+
+  #if !defined(_di_libcap_) && !defined(_libcap_legacy_only_)
+    f_capability_value_t value = f_capability_value_t_initialize;
+    int ambient = 0;
+
+    {
+      will_return(__wrap_cap_get_ambient, true);
+
+      const f_status_t status = f_capability_ambient_get(value, &ambient);
+
+      assert_int_equal(F_status_set_fine(status), F_supported_not);
+      assert_int_equal(ambient, -1);
+    }
+  #endif // !defined(_di_libcap_) && !defined(_libcap_legacy_only_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-ambient_get.h b/level_0/f_capability/tests/c/test-capability-ambient_get.h
new file mode 100644 (file)
index 0000000..89bcafe
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__ambient_get
+#define _TEST__F_capability__ambient_get
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_ambient_get()
+ */
+extern void test__f_capability_ambient_get__works(void **state);
+
+/**
+ * Test that function fails.
+ *
+ * @see f_capability_ambient_get()
+ */
+extern void test__f_capability_ambient_get__fails(void **state);
+
+#endif // _TEST__F_capability__ambient_get
diff --git a/level_0/f_capability/tests/c/test-capability-ambient_reset.c b/level_0/f_capability/tests/c/test-capability-ambient_reset.c
new file mode 100644 (file)
index 0000000..c17e3ea
--- /dev/null
@@ -0,0 +1,65 @@
+#include "test-capability.h"
+#include "test-capability-ambient_reset.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_ambient_reset__works(void **state) {
+
+  #if defined(_di_libcap_) || defined(_libcap_legacy_only_)
+    printf("[  WARN    ] f_capability_ambient_reset() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_get_ambient, false);
+  #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_)
+
+  {
+    const f_status_t status = f_capability_ambient_reset();
+
+    #if defined(_di_libcap_) || defined(_libcap_legacy_only_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_int_equal(status, F_none);
+    #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_)
+  }
+}
+
+void test__f_capability_ambient_reset__fails(void **state) {
+
+  #if !defined(_di_libcap_) && !defined(_libcap_legacy_only_)
+    {
+      will_return(__wrap_cap_get_ambient, true);
+      will_return(__wrap_cap_clear, EINVAL);
+
+      const f_status_t status = f_capability_ambient_reset();
+
+      assert_int_equal(F_status_set_fine(status), F_parameter);
+    }
+
+    int errnos[] = {
+      ENOMEM,
+      EPERM,
+      mock_errno_generic,
+    };
+
+    f_status_t statuss[] = {
+      F_memory_not,
+      F_prohibited,
+      F_failure,
+    };
+
+    for (int i = 0; i < 3; ++i) {
+
+      will_return(__wrap_cap_get_ambient, true);
+      will_return(__wrap_cap_clear, errnos[i]);
+
+      const f_status_t status = f_capability_ambient_reset();
+
+      assert_int_equal(F_status_set_fine(status), statuss[i]);
+    } // for
+  #endif // !defined(_di_libcap_) && !defined(_libcap_legacy_only_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-ambient_reset.h b/level_0/f_capability/tests/c/test-capability-ambient_reset.h
new file mode 100644 (file)
index 0000000..8391ff8
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__ambient_reset
+#define _TEST__F_capability__ambient_reset
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_ambient_reset()
+ */
+extern void test__f_capability_ambient_reset__works(void **state);
+
+/**
+ * Test that function fails.
+ *
+ * @see f_capability_ambient_reset()
+ */
+extern void test__f_capability_ambient_reset__fails(void **state);
+
+#endif // _TEST__F_capability__ambient_reset
diff --git a/level_0/f_capability/tests/c/test-capability-ambient_set.c b/level_0/f_capability/tests/c/test-capability-ambient_set.c
new file mode 100644 (file)
index 0000000..db69868
--- /dev/null
@@ -0,0 +1,62 @@
+#include "test-capability.h"
+#include "test-capability-ambient_set.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_ambient_set__works(void **state) {
+
+  f_capability_value_t value = f_capability_value_t_initialize;
+  f_capability_flag_value_t flag_value = f_capability_flag_value_t_initialize;
+
+  #if defined(_di_libcap_) || defined(_libcap_legacy_only_)
+    printf("[  WARN    ] f_capability_ambient_set() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_get_ambient, false);
+  #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_)
+
+  {
+    const f_status_t status = f_capability_ambient_set(value, flag_value);
+
+    #if defined(_di_libcap_) || defined(_libcap_legacy_only_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_int_equal(status, F_none);
+    #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_)
+  }
+}
+
+void test__f_capability_ambient_set__fails(void **state) {
+
+  #if !defined(_di_libcap_) && !defined(_libcap_legacy_only_)
+    f_capability_value_t value = f_capability_value_t_initialize;
+    f_capability_flag_value_t flag_value = f_capability_flag_value_t_initialize;
+
+    int errnos[] = {
+      ENOMEM,
+      EPERM,
+      mock_errno_generic,
+    };
+
+    f_status_t statuss[] = {
+      F_memory_not,
+      F_prohibited,
+      F_failure,
+    };
+
+    for (int i = 0; i < 3; ++i) {
+
+      will_return(__wrap_cap_get_ambient, true);
+      will_return(__wrap_cap_clear, errnos[i]);
+
+      const f_status_t status = f_capability_ambient_set(value, flag_value);
+
+      assert_int_equal(F_status_set_fine(status), statuss[i]);
+    } // for
+  #endif // !defined(_di_libcap_) && !defined(_libcap_legacy_only_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-ambient_set.h b/level_0/f_capability/tests/c/test-capability-ambient_set.h
new file mode 100644 (file)
index 0000000..633fc7d
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__ambient_set
+#define _TEST__F_capability__ambient_set
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_ambient_set()
+ */
+extern void test__f_capability_ambient_set__works(void **state);
+
+/**
+ * Test that function fails.
+ *
+ * @see f_capability_ambient_set()
+ */
+extern void test__f_capability_ambient_set__fails(void **state);
+
+#endif // _TEST__F_capability__ambient_set
diff --git a/level_0/f_capability/tests/c/test-capability-clear.c b/level_0/f_capability/tests/c/test-capability-clear.c
new file mode 100644 (file)
index 0000000..bff320f
--- /dev/null
@@ -0,0 +1,62 @@
+#include "test-capability.h"
+#include "test-capability-clear.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_clear__works(void **state) {
+
+  f_capability_t capability = f_capability_t_initialize;
+
+  #if defined(_di_libcap_)
+    printf("[  WARN    ] f_capability_clear() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_clear, false);
+  #endif // defined(_di_libcap_)
+
+  {
+    const f_status_t status = f_capability_clear(&capability);
+
+    #if defined(_di_libcap_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_int_equal(status, F_none);
+    #endif // defined(_di_libcap_)
+  }
+}
+
+void test__f_capability_clear__fails(void **state) {
+
+  #if !defined(_di_libcap_)
+    f_capability_t capability = f_capability_t_initialize;
+
+    int errnos[] = {
+      EINVAL,
+      ENOMEM,
+      ERANGE,
+      mock_errno_generic,
+    };
+
+    f_status_t statuss[] = {
+      F_parameter,
+      F_memory_not,
+      F_range_not,
+      F_failure,
+    };
+
+    for (int i = 0; i < 4; ++i) {
+
+      will_return(__wrap_cap_clear, true);
+      will_return(__wrap_cap_clear, errnos[i]);
+
+      const f_status_t status = f_capability_clear(&capability);
+
+      assert_int_equal(F_status_set_fine(status), statuss[i]);
+    } // for
+  #endif // !defined(_di_libcap_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-clear.h b/level_0/f_capability/tests/c/test-capability-clear.h
new file mode 100644 (file)
index 0000000..a09104b
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__clear
+#define _TEST__F_capability__clear
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_clear()
+ */
+extern void test__f_capability_clear__works(void **state);
+
+/**
+ * Test that function fails.
+ *
+ * @see f_capability_clear()
+ */
+extern void test__f_capability_clear__fails(void **state);
+
+#endif // _TEST__F_capability__clear
diff --git a/level_0/f_capability/tests/c/test-capability-clear_flag.c b/level_0/f_capability/tests/c/test-capability-clear_flag.c
new file mode 100644 (file)
index 0000000..280024a
--- /dev/null
@@ -0,0 +1,60 @@
+#include "test-capability.h"
+#include "test-capability-clear_flag.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_clear_flag__works(void **state) {
+
+  f_capability_t capability = f_capability_t_initialize;
+  f_capability_flag_value_t flag_value = f_capability_flag_value_t_initialize;
+
+  #if defined(_di_libcap_)
+    printf("[  WARN    ] f_capability_clear_flag() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_clear_flag, false);
+  #endif // defined(_di_libcap_)
+
+  {
+    const f_status_t status = f_capability_clear_flag(flag_value, &capability);
+
+    #if defined(_di_libcap_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_int_equal(status, F_none);
+    #endif // defined(_di_libcap_)
+  }
+}
+
+void test__f_capability_clear_flag__fails(void **state) {
+
+  #if !defined(_di_libcap_)
+    f_capability_t capability = f_capability_t_initialize;
+    f_capability_flag_value_t flag_value = f_capability_flag_value_t_initialize;
+
+    int errnos[] = {
+      EINVAL,
+      mock_errno_generic,
+    };
+
+    f_status_t statuss[] = {
+      F_parameter,
+      F_failure,
+    };
+
+    for (int i = 0; i < 2; ++i) {
+
+      will_return(__wrap_cap_clear_flag, true);
+      will_return(__wrap_cap_clear_flag, errnos[i]);
+
+      const f_status_t status = f_capability_clear_flag(flag_value, &capability);
+
+      assert_int_equal(F_status_set_fine(status), statuss[i]);
+    } // for
+  #endif // !defined(_di_libcap_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-clear_flag.h b/level_0/f_capability/tests/c/test-capability-clear_flag.h
new file mode 100644 (file)
index 0000000..23a8492
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__clear_flag
+#define _TEST__F_capability__clear_flag
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_clear_flag()
+ */
+extern void test__f_capability_clear_flag__works(void **state);
+
+/**
+ * Test that function fails.
+ *
+ * @see f_capability_clear_flag()
+ */
+extern void test__f_capability_clear_flag__fails(void **state);
+
+#endif // _TEST__F_capability__clear_flag
diff --git a/level_0/f_capability/tests/c/test-capability-compare.c b/level_0/f_capability/tests/c/test-capability-compare.c
new file mode 100644 (file)
index 0000000..3762786
--- /dev/null
@@ -0,0 +1,75 @@
+#include "test-capability.h"
+#include "test-capability-compare.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_compare__works(void **state) {
+
+  f_capability_t capability_1 = f_capability_t_initialize;
+  f_capability_t capability_2 = f_capability_t_initialize;
+  int flags = 0;
+
+  #if defined(_di_libcap_)
+    printf("[  WARN    ] f_capability_compare() is not implemented and cannot be fully tested.\n");
+
+    {
+      const f_status_t status = f_capability_compare(capability_1, capability_2, &flags);
+
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    }
+  #else
+    {
+      will_return(__wrap_cap_compare, false);
+      will_return(__wrap_cap_compare, 0);
+
+      const f_status_t status = f_capability_compare(capability_1, capability_2, &flags);
+
+      assert_int_equal(status, F_equal_to);
+    }
+
+    {
+      will_return(__wrap_cap_compare, false);
+      will_return(__wrap_cap_compare, 1);
+
+      const f_status_t status = f_capability_compare(capability_1, capability_2, &flags);
+
+      assert_int_equal(status, F_equal_to_not);
+      assert_int_equal(flags, 1);
+    }
+  #endif // defined(_di_libcap_)
+}
+
+void test__f_capability_compare__fails(void **state) {
+
+  #if !defined(_di_libcap_)
+    f_capability_t capability_1 = f_capability_t_initialize;
+    f_capability_t capability_2 = f_capability_t_initialize;
+    int flags = 0;
+
+    int errnos[] = {
+      EINVAL,
+      mock_errno_generic,
+    };
+
+    f_status_t statuss[] = {
+      F_parameter,
+      F_failure,
+    };
+
+    for (int i = 0; i < 2; ++i) {
+
+      will_return(__wrap_cap_compare, true);
+      will_return(__wrap_cap_compare, errnos[i]);
+
+      const f_status_t status = f_capability_compare(capability_1, capability_2, &flags);
+
+      assert_int_equal(F_status_set_fine(status), statuss[i]);
+    } // for
+  #endif // !defined(_di_libcap_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-compare.h b/level_0/f_capability/tests/c/test-capability-compare.h
new file mode 100644 (file)
index 0000000..fd04416
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__compare
+#define _TEST__F_capability__compare
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_compare()
+ */
+extern void test__f_capability_compare__works(void **state);
+
+/**
+ * Test that function fails.
+ *
+ * @see f_capability_compare()
+ */
+extern void test__f_capability_compare__fails(void **state);
+
+#endif // _TEST__F_capability__compare
diff --git a/level_0/f_capability/tests/c/test-capability-copy.c b/level_0/f_capability/tests/c/test-capability-copy.c
new file mode 100644 (file)
index 0000000..5c5e0c3
--- /dev/null
@@ -0,0 +1,63 @@
+#include "test-capability.h"
+#include "test-capability-copy.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_copy__works(void **state) {
+
+  f_capability_t capability_1 = f_capability_t_initialize;
+  f_capability_t capability_2 = f_capability_t_initialize;
+
+  #if defined(_di_libcap_)
+    printf("[  WARN    ] f_capability_copy() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_dup, false);
+  #endif // defined(_di_libcap_)
+
+  {
+    const f_status_t status = f_capability_copy(capability_1, &capability_2);
+
+    #if defined(_di_libcap_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_int_equal(status, F_none);
+      assert_int_equal(capability_2, 1);
+    #endif // defined(_di_libcap_)
+  }
+}
+
+void test__f_capability_copy__fails(void **state) {
+
+  #if !defined(_di_libcap_)
+    f_capability_t capability_1 = f_capability_t_initialize;
+    f_capability_t capability_2 = f_capability_t_initialize;
+
+    int errnos[] = {
+      EINVAL,
+      ENOMEM,
+      mock_errno_generic,
+    };
+
+    f_status_t statuss[] = {
+      F_parameter,
+      F_memory_not,
+      F_failure,
+    };
+
+    for (int i = 0; i < 3; ++i) {
+
+      will_return(__wrap_cap_dup, true);
+      will_return(__wrap_cap_dup, EINVAL);
+
+      const f_status_t status = f_capability_copy(capability_1, &capability_2);
+
+      assert_int_equal(F_status_set_fine(status), F_parameter);
+    } // for
+  #endif // !defined(_di_libcap_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-copy.h b/level_0/f_capability/tests/c/test-capability-copy.h
new file mode 100644 (file)
index 0000000..e1bfea8
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__copy
+#define _TEST__F_capability__copy
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_copy()
+ */
+extern void test__f_capability_copy__works(void **state);
+
+/**
+ * Test that function fails.
+ *
+ * @see f_capability_copy()
+ */
+extern void test__f_capability_copy__fails(void **state);
+
+#endif // _TEST__F_capability__copy
diff --git a/level_0/f_capability/tests/c/test-capability-copy_external.c b/level_0/f_capability/tests/c/test-capability-copy_external.c
new file mode 100644 (file)
index 0000000..66b487a
--- /dev/null
@@ -0,0 +1,69 @@
+#include "test-capability.h"
+#include "test-capability-copy_external.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_copy_external__works(void **state) {
+
+  f_capability_t capability = f_capability_t_initialize;
+  ssize_t max = 0;
+  int stub = 0;
+  void *external = (void *) &stub;
+  ssize_t size = 0;
+
+  #if defined(_di_libcap_)
+    printf("[  WARN    ] f_capability_copy_external() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_copy_ext, false);
+  #endif // defined(_di_libcap_)
+
+  {
+    const f_status_t status = f_capability_copy_external(capability, max, external, &size);
+
+    #if defined(_di_libcap_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_int_equal(status, F_none);
+      assert_int_equal(size, 1);
+    #endif // defined(_di_libcap_)
+  }
+}
+
+void test__f_capability_copy_external__fails(void **state) {
+
+  #if !defined(_di_libcap_)
+    f_capability_t capability = f_capability_t_initialize;
+    ssize_t max = 0;
+    int stub = 0;
+    void *external = (void *) &stub;
+    ssize_t size = 0;
+
+    int errnos[] = {
+      EINVAL,
+      ERANGE,
+      mock_errno_generic,
+    };
+
+    f_status_t statuss[] = {
+      F_parameter,
+      F_range_not,
+      F_failure,
+    };
+
+    for (int i = 0; i < 3; ++i) {
+
+      will_return(__wrap_cap_copy_ext, true);
+      will_return(__wrap_cap_copy_ext, errnos[i]);
+
+      const f_status_t status = f_capability_copy_external(capability, max, external, &size);
+
+      assert_int_equal(F_status_set_fine(status), statuss[i]);
+    } // for
+  #endif // !defined(_di_libcap_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-copy_external.h b/level_0/f_capability/tests/c/test-capability-copy_external.h
new file mode 100644 (file)
index 0000000..32c23ee
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__copy_external
+#define _TEST__F_capability__copy_external
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_copy_external()
+ */
+extern void test__f_capability_copy_external__works(void **state);
+
+/**
+ * Test that function fails.
+ *
+ * @see f_capability_copy_external()
+ */
+extern void test__f_capability_copy_external__fails(void **state);
+
+#endif // _TEST__F_capability__copy_external
diff --git a/level_0/f_capability/tests/c/test-capability-copy_internal.c b/level_0/f_capability/tests/c/test-capability-copy_internal.c
new file mode 100644 (file)
index 0000000..8aad5f3
--- /dev/null
@@ -0,0 +1,65 @@
+#include "test-capability.h"
+#include "test-capability-copy_internal.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_copy_internal__works(void **state) {
+
+  f_capability_t capability = f_capability_t_initialize;
+  int stub = 0;
+  void *external = (void *) &stub;
+
+  #if defined(_di_libcap_)
+    printf("[  WARN    ] f_capability_copy_internal() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_copy_int, false);
+  #endif // defined(_di_libcap_)
+
+  {
+    const f_status_t status = f_capability_copy_internal(external, &capability);
+
+    #if defined(_di_libcap_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_int_equal(status, F_none);
+      assert_int_equal(capability, 1);
+    #endif // defined(_di_libcap_)
+  }
+}
+
+void test__f_capability_copy_internal__fails(void **state) {
+
+  #if !defined(_di_libcap_)
+    f_capability_t capability = f_capability_t_initialize;
+    int stub = 0;
+    void *external = (void *) &stub;
+
+    int errnos[] = {
+      EINVAL,
+      ERANGE,
+      mock_errno_generic,
+    };
+
+    f_status_t statuss[] = {
+      F_parameter,
+      F_range_not,
+      F_failure,
+    };
+
+    for (int i = 0; i < 3; ++i) {
+
+      will_return(__wrap_cap_copy_int, true);
+      will_return(__wrap_cap_copy_int, errnos[i]);
+
+      const f_status_t status = f_capability_copy_internal(external, &capability);
+
+      assert_int_equal(F_status_set_fine(status), statuss[i]);
+    } // for
+  #endif // !defined(_di_libcap_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-copy_internal.h b/level_0/f_capability/tests/c/test-capability-copy_internal.h
new file mode 100644 (file)
index 0000000..078a939
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__copy_internal
+#define _TEST__F_capability__copy_internal
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_copy_internal()
+ */
+extern void test__f_capability_copy_internal__works(void **state);
+
+/**
+ * Test that function fails.
+ *
+ * @see f_capability_copy_internal()
+ */
+extern void test__f_capability_copy_internal__fails(void **state);
+
+#endif // _TEST__F_capability__copy_internal
diff --git a/level_0/f_capability/tests/c/test-capability-delete.c b/level_0/f_capability/tests/c/test-capability-delete.c
new file mode 100644 (file)
index 0000000..1b46878
--- /dev/null
@@ -0,0 +1,61 @@
+#include "test-capability.h"
+#include "test-capability-delete.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_delete__works(void **state) {
+
+  f_capability_t capability = f_capability_t_initialize;
+
+  #if defined(_di_libcap_)
+    printf("[  WARN    ] f_capability_delete() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_free, false);
+  #endif // defined(_di_libcap_)
+
+  {
+    const f_status_t status = f_capability_delete(&capability);
+
+    #if defined(_di_libcap_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_int_equal(status, F_none);
+      assert_int_equal(capability, 0);
+    #endif // defined(_di_libcap_)
+  }
+}
+
+void test__f_capability_delete__fails(void **state) {
+
+  #if !defined(_di_libcap_)
+    f_capability_t capability = f_capability_t_initialize;
+
+    int errnos[] = {
+      EINVAL,
+      ENOMEM,
+      mock_errno_generic,
+    };
+
+    f_status_t statuss[] = {
+      F_parameter,
+      F_memory_not,
+      F_failure,
+    };
+
+    for (int i = 0; i < 3; ++i) {
+
+      will_return(__wrap_cap_free, true);
+      will_return(__wrap_cap_free, errnos[i]);
+
+      const f_status_t status = f_capability_delete(&capability);
+
+      assert_int_equal(F_status_set_fine(status), statuss[i]);
+    } // for
+  #endif // !defined(_di_libcap_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-delete.h b/level_0/f_capability/tests/c/test-capability-delete.h
new file mode 100644 (file)
index 0000000..6018b2a
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__delete
+#define _TEST__F_capability__delete
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_delete()
+ */
+extern void test__f_capability_delete__works(void **state);
+
+/**
+ * Test that function fails.
+ *
+ * @see f_capability_delete()
+ */
+extern void test__f_capability_delete__fails(void **state);
+
+#endif // _TEST__F_capability__delete
diff --git a/level_0/f_capability/tests/c/test-capability-file_descriptor_get.c b/level_0/f_capability/tests/c/test-capability-file_descriptor_get.c
new file mode 100644 (file)
index 0000000..0d1f3ff
--- /dev/null
@@ -0,0 +1,74 @@
+#include "test-capability.h"
+#include "test-capability-file_descriptor_get.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_file_descriptor_get__works(void **state) {
+
+  int descriptor = 0;
+  f_capability_t capability = f_capability_t_initialize;
+
+  #if defined(_di_libcap_)
+    printf("[  WARN    ] f_capability_file_descriptor_get() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_get_fd, false);
+  #endif // defined(_di_libcap_)
+
+  {
+    const f_status_t status = f_capability_file_descriptor_get(descriptor, &capability);
+
+    #if defined(_di_libcap_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_int_equal(status, F_none);
+    #endif // defined(_di_libcap_)
+  }
+}
+
+void test__f_capability_file_descriptor_get__fails(void **state) {
+
+  #if !defined(_di_libcap_)
+    int descriptor = 0;
+    f_capability_t capability = f_capability_t_initialize;
+
+    int errnos[] = {
+      EACCES,
+      EBADFD,
+      ENAMETOOLONG,
+      ENOENT,
+      ENOMEM,
+      ENOTDIR,
+      EPERM,
+      EROFS,
+      mock_errno_generic,
+    };
+
+    f_status_t statuss[] = {
+      F_access_denied,
+      F_descriptor_not,
+      F_name_not,
+      F_file_found_not,
+      F_memory_not,
+      F_directory_not,
+      F_prohibited,
+      F_supported_not,
+      F_failure,
+    };
+
+    for (int i = 0; i < 9; ++i) {
+
+      will_return(__wrap_cap_get_fd, true);
+      will_return(__wrap_cap_get_fd, errnos[i]);
+
+      const f_status_t status = f_capability_file_descriptor_get(descriptor, &capability);
+
+      assert_int_equal(F_status_set_fine(status), statuss[i]);
+    } // for
+  #endif // !defined(_di_libcap_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-file_descriptor_get.h b/level_0/f_capability/tests/c/test-capability-file_descriptor_get.h
new file mode 100644 (file)
index 0000000..b436024
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__file_descriptor_get
+#define _TEST__F_capability__file_descriptor_get
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_file_descriptor_get()
+ */
+extern void test__f_capability_file_descriptor_get__works(void **state);
+
+/**
+ * Test that function fails.
+ *
+ * @see f_capability_file_descriptor_get()
+ */
+extern void test__f_capability_file_descriptor_get__fails(void **state);
+
+#endif // _TEST__F_capability__file_descriptor_get
diff --git a/level_0/f_capability/tests/c/test-capability-file_descriptor_set.c b/level_0/f_capability/tests/c/test-capability-file_descriptor_set.c
new file mode 100644 (file)
index 0000000..89dccfe
--- /dev/null
@@ -0,0 +1,74 @@
+#include "test-capability.h"
+#include "test-capability-file_descriptor_set.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_file_descriptor_set__works(void **state) {
+
+  int descriptor = 0;
+  f_capability_t capability = f_capability_t_initialize;
+
+  #if defined(_di_libcap_)
+    printf("[  WARN    ] f_capability_file_descriptor_set() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_set_fd, false);
+  #endif // defined(_di_libcap_)
+
+  {
+    const f_status_t status = f_capability_file_descriptor_set(descriptor, capability);
+
+    #if defined(_di_libcap_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_int_equal(status, F_none);
+    #endif // defined(_di_libcap_)
+  }
+}
+
+void test__f_capability_file_descriptor_set__fails(void **state) {
+
+  #if !defined(_di_libcap_)
+    int descriptor = 0;
+    f_capability_t capability = f_capability_t_initialize;
+
+    int errnos[] = {
+      EACCES,
+      EBADFD,
+      ENAMETOOLONG,
+      ENOENT,
+      ENOMEM,
+      ENOTDIR,
+      EPERM,
+      EROFS,
+      mock_errno_generic,
+    };
+
+    f_status_t statuss[] = {
+      F_access_denied,
+      F_descriptor_not,
+      F_name_not,
+      F_file_found_not,
+      F_memory_not,
+      F_directory_not,
+      F_prohibited,
+      F_supported_not,
+      F_failure,
+    };
+
+    for (int i = 0; i < 9; ++i) {
+
+      will_return(__wrap_cap_set_fd, true);
+      will_return(__wrap_cap_set_fd, errnos[i]);
+
+      const f_status_t status = f_capability_file_descriptor_set(descriptor, capability);
+
+      assert_int_equal(F_status_set_fine(status), statuss[i]);
+    } // for
+  #endif // !defined(_di_libcap_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-file_descriptor_set.h b/level_0/f_capability/tests/c/test-capability-file_descriptor_set.h
new file mode 100644 (file)
index 0000000..13e7623
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__file_descriptor_set
+#define _TEST__F_capability__file_descriptor_set
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_file_descriptor_set()
+ */
+extern void test__f_capability_file_descriptor_set__works(void **state);
+
+/**
+ * Test that function fails.
+ *
+ * @see f_capability_file_descriptor_set()
+ */
+extern void test__f_capability_file_descriptor_set__fails(void **state);
+
+#endif // _TEST__F_capability__file_descriptor_set
diff --git a/level_0/f_capability/tests/c/test-capability-file_get.c b/level_0/f_capability/tests/c/test-capability-file_get.c
new file mode 100644 (file)
index 0000000..31dbb46
--- /dev/null
@@ -0,0 +1,74 @@
+#include "test-capability.h"
+#include "test-capability-file_get.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_file_get__works(void **state) {
+
+  f_string_t path = f_string_t_initialize;
+  f_capability_t capability = f_capability_t_initialize;
+
+  #if defined(_di_libcap_)
+    printf("[  WARN    ] f_capability_file_get() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_get_file, false);
+  #endif // defined(_di_libcap_)
+
+  {
+    const f_status_t status = f_capability_file_get(path, &capability);
+
+    #if defined(_di_libcap_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_int_equal(status, F_none);
+    #endif // defined(_di_libcap_)
+  }
+}
+
+void test__f_capability_file_get__fails(void **state) {
+
+  #if !defined(_di_libcap_)
+    f_string_t path = f_string_t_initialize;
+    f_capability_t capability = f_capability_t_initialize;
+
+    int errnos[] = {
+      EACCES,
+      EBADFD,
+      ENAMETOOLONG,
+      ENOENT,
+      ENOMEM,
+      ENOTDIR,
+      EPERM,
+      EROFS,
+      mock_errno_generic,
+    };
+
+    f_status_t statuss[] = {
+      F_access_denied,
+      F_descriptor_not,
+      F_name_not,
+      F_file_found_not,
+      F_memory_not,
+      F_directory_not,
+      F_prohibited,
+      F_supported_not,
+      F_failure,
+    };
+
+    for (int i = 0; i < 9; ++i) {
+
+      will_return(__wrap_cap_get_file, true);
+      will_return(__wrap_cap_get_file, errnos[i]);
+
+      const f_status_t status = f_capability_file_get(path, &capability);
+
+      assert_int_equal(F_status_set_fine(status), statuss[i]);
+    } // for
+  #endif // !defined(_di_libcap_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-file_get.h b/level_0/f_capability/tests/c/test-capability-file_get.h
new file mode 100644 (file)
index 0000000..55afbce
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__file_get
+#define _TEST__F_capability__file_get
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_file_get()
+ */
+extern void test__f_capability_file_get__works(void **state);
+
+/**
+ * Test that function fails.
+ *
+ * @see f_capability_file_get()
+ */
+extern void test__f_capability_file_get__fails(void **state);
+
+#endif // _TEST__F_capability__file_get
diff --git a/level_0/f_capability/tests/c/test-capability-file_set.c b/level_0/f_capability/tests/c/test-capability-file_set.c
new file mode 100644 (file)
index 0000000..6ccf929
--- /dev/null
@@ -0,0 +1,74 @@
+#include "test-capability.h"
+#include "test-capability-file_set.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_file_set__works(void **state) {
+
+  f_string_t path = f_string_t_initialize;
+  f_capability_t capability = f_capability_t_initialize;
+
+  #if defined(_di_libcap_)
+    printf("[  WARN    ] f_capability_file_set() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_set_file, false);
+  #endif // defined(_di_libcap_)
+
+  {
+    const f_status_t status = f_capability_file_set(path, capability);
+
+    #if defined(_di_libcap_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_int_equal(status, F_none);
+    #endif // defined(_di_libcap_)
+  }
+}
+
+void test__f_capability_file_set__fails(void **state) {
+
+  #if !defined(_di_libcap_)
+    f_string_t path = f_string_t_initialize;
+    f_capability_t capability = f_capability_t_initialize;
+
+    int errnos[] = {
+      EACCES,
+      EBADFD,
+      ENAMETOOLONG,
+      ENOENT,
+      ENOMEM,
+      ENOTDIR,
+      EPERM,
+      EROFS,
+      mock_errno_generic,
+    };
+
+    f_status_t statuss[] = {
+      F_access_denied,
+      F_descriptor_not,
+      F_name_not,
+      F_file_found_not,
+      F_memory_not,
+      F_directory_not,
+      F_prohibited,
+      F_supported_not,
+      F_failure,
+    };
+
+    for (int i = 0; i < 9; ++i) {
+
+      will_return(__wrap_cap_set_file, true);
+      will_return(__wrap_cap_set_file, errnos[i]);
+
+      const f_status_t status = f_capability_file_set(path, capability);
+
+      assert_int_equal(F_status_set_fine(status), statuss[i]);
+    } // for
+  #endif // !defined(_di_libcap_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-file_set.h b/level_0/f_capability/tests/c/test-capability-file_set.h
new file mode 100644 (file)
index 0000000..dd54e2e
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__file_set
+#define _TEST__F_capability__file_set
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_file_set()
+ */
+extern void test__f_capability_file_set__works(void **state);
+
+/**
+ * Test that function fails.
+ *
+ * @see f_capability_file_set()
+ */
+extern void test__f_capability_file_set__fails(void **state);
+
+#endif // _TEST__F_capability__file_set
diff --git a/level_0/f_capability/tests/c/test-capability-flag_get.c b/level_0/f_capability/tests/c/test-capability-flag_get.c
new file mode 100644 (file)
index 0000000..5910951
--- /dev/null
@@ -0,0 +1,64 @@
+#include "test-capability.h"
+#include "test-capability-flag_get.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_flag_get__works(void **state) {
+
+  f_capability_flag_t flag = f_capability_flag_t_initialize;
+  f_capability_flag_value_t value = f_capability_flag_value_t_initialize;
+  f_capability_t capability = f_capability_t_initialize;
+  f_capability_value_t capability_value = f_capability_value_t_initialize;
+
+  #if defined(_di_libcap_)
+    printf("[  WARN    ] f_capability_flag_get() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_get_flag, false);
+  #endif // defined(_di_libcap_)
+
+  {
+    const f_status_t status = f_capability_flag_get(capability, capability_value, flag, &value);
+
+    #if defined(_di_libcap_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_int_equal(status, F_none);
+    #endif // defined(_di_libcap_)
+  }
+}
+
+void test__f_capability_flag_get__fails(void **state) {
+
+  #if !defined(_di_libcap_)
+    f_capability_flag_t flag = f_capability_flag_t_initialize;
+    f_capability_flag_value_t value = f_capability_flag_value_t_initialize;
+    f_capability_t capability = f_capability_t_initialize;
+    f_capability_value_t capability_value = f_capability_value_t_initialize;
+
+    int errnos[] = {
+      EINVAL,
+      mock_errno_generic,
+    };
+
+    f_status_t statuss[] = {
+      F_parameter,
+      F_failure,
+    };
+
+    for (int i = 0; i < 2; ++i) {
+
+      will_return(__wrap_cap_get_flag, true);
+      will_return(__wrap_cap_get_flag, errnos[i]);
+
+      const f_status_t status = f_capability_flag_get(capability, capability_value, flag, &value);
+
+      assert_int_equal(F_status_set_fine(status), statuss[i]);
+    } // for
+  #endif // !defined(_di_libcap_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-flag_get.h b/level_0/f_capability/tests/c/test-capability-flag_get.h
new file mode 100644 (file)
index 0000000..eb1b5f9
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__flag_get
+#define _TEST__F_capability__flag_get
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_flag_get()
+ */
+extern void test__f_capability_flag_get__works(void **state);
+
+/**
+ * Test that function fails.
+ *
+ * @see f_capability_flag_get()
+ */
+extern void test__f_capability_flag_get__fails(void **state);
+
+#endif // _TEST__F_capability__flag_get
diff --git a/level_0/f_capability/tests/c/test-capability-flag_set.c b/level_0/f_capability/tests/c/test-capability-flag_set.c
new file mode 100644 (file)
index 0000000..fd0f430
--- /dev/null
@@ -0,0 +1,64 @@
+#include "test-capability.h"
+#include "test-capability-flag_set.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_flag_set__works(void **state) {
+
+  f_capability_flag_t flag = f_capability_flag_t_initialize;
+  f_capability_flag_value_t value = f_capability_flag_value_t_initialize;
+  f_int32s_t codes = f_int32s_t_initialize;
+  f_capability_t capability = f_capability_t_initialize;
+
+  #if defined(_di_libcap_)
+    printf("[  WARN    ] f_capability_flag_set() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_set_flag, false);
+  #endif // defined(_di_libcap_)
+
+  {
+    const f_status_t status = f_capability_flag_set(flag, value, codes, &capability);
+
+    #if defined(_di_libcap_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_int_equal(status, F_none);
+    #endif // defined(_di_libcap_)
+  }
+}
+
+void test__f_capability_flag_set__fails(void **state) {
+
+  #if !defined(_di_libcap_)
+    f_capability_flag_t flag = f_capability_flag_t_initialize;
+    f_capability_flag_value_t value = f_capability_flag_value_t_initialize;
+    f_int32s_t codes = f_int32s_t_initialize;
+    f_capability_t capability = f_capability_t_initialize;
+
+    int errnos[] = {
+      EINVAL,
+      mock_errno_generic,
+    };
+
+    f_status_t statuss[] = {
+      F_parameter,
+      F_failure,
+    };
+
+    for (int i = 0; i < 2; ++i) {
+
+      will_return(__wrap_cap_set_flag, true);
+      will_return(__wrap_cap_set_flag, errnos[i]);
+
+      const f_status_t status = f_capability_flag_set(flag, value, codes, &capability);
+
+      assert_int_equal(F_status_set_fine(status), statuss[i]);
+    } // for
+  #endif // !defined(_di_libcap_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-flag_set.h b/level_0/f_capability/tests/c/test-capability-flag_set.h
new file mode 100644 (file)
index 0000000..623594b
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__flag_set
+#define _TEST__F_capability__flag_set
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_flag_set()
+ */
+extern void test__f_capability_flag_set__works(void **state);
+
+/**
+ * Test that function fails.
+ *
+ * @see f_capability_flag_set()
+ */
+extern void test__f_capability_flag_set__fails(void **state);
+
+#endif // _TEST__F_capability__flag_set
diff --git a/level_0/f_capability/tests/c/test-capability-from_name.c b/level_0/f_capability/tests/c/test-capability-from_name.c
new file mode 100644 (file)
index 0000000..e1327e8
--- /dev/null
@@ -0,0 +1,62 @@
+#include "test-capability.h"
+#include "test-capability-from_name.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_from_name__works(void **state) {
+
+  f_string_t name = f_string_t_initialize;
+  f_capability_value_t capability_value = f_capability_value_t_initialize;
+
+  #if defined(_di_libcap_)
+    printf("[  WARN    ] f_capability_from_name() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_from_name, false);
+  #endif // defined(_di_libcap_)
+
+  {
+    const f_status_t status = f_capability_from_name(name, &capability_value);
+
+    #if defined(_di_libcap_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_int_equal(status, F_none);
+    #endif // defined(_di_libcap_)
+  }
+}
+
+void test__f_capability_from_name__fails(void **state) {
+
+  #if !defined(_di_libcap_)
+    f_string_t name = f_string_t_initialize;
+    f_capability_value_t capability_value = f_capability_value_t_initialize;
+
+    int errnos[] = {
+      EINVAL,
+      ENOMEM,
+      mock_errno_generic,
+    };
+
+    f_status_t statuss[] = {
+      F_parameter,
+      F_memory_not,
+      F_failure,
+    };
+
+    for (int i = 0; i < 3; ++i) {
+
+      will_return(__wrap_cap_from_name, true);
+      will_return(__wrap_cap_from_name, errnos[i]);
+
+      const f_status_t status = f_capability_from_name(name, &capability_value);
+
+      assert_int_equal(F_status_set_fine(status), statuss[i]);
+    } // for
+  #endif // !defined(_di_libcap_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-from_name.h b/level_0/f_capability/tests/c/test-capability-from_name.h
new file mode 100644 (file)
index 0000000..c33ea13
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__from_name
+#define _TEST__F_capability__from_name
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_from_name()
+ */
+extern void test__f_capability_from_name__works(void **state);
+
+/**
+ * Test that function fails.
+ *
+ * @see f_capability_from_name()
+ */
+extern void test__f_capability_from_name__fails(void **state);
+
+#endif // _TEST__F_capability__from_name
diff --git a/level_0/f_capability/tests/c/test-capability-from_text.c b/level_0/f_capability/tests/c/test-capability-from_text.c
new file mode 100644 (file)
index 0000000..2dd90c7
--- /dev/null
@@ -0,0 +1,62 @@
+#include "test-capability.h"
+#include "test-capability-from_text.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_from_text__works(void **state) {
+
+  f_string_t text = f_string_t_initialize;
+  f_capability_t capability = f_capability_t_initialize;
+
+  #if defined(_di_libcap_)
+    printf("[  WARN    ] f_capability_from_text() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_from_text, false);
+  #endif // defined(_di_libcap_)
+
+  {
+    const f_status_t status = f_capability_from_text(text, &capability);
+
+    #if defined(_di_libcap_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_int_equal(status, F_none);
+    #endif // defined(_di_libcap_)
+  }
+}
+
+void test__f_capability_from_text__fails(void **state) {
+
+  #if !defined(_di_libcap_)
+    f_string_t text = f_string_t_initialize;
+    f_capability_t capability = f_capability_t_initialize;
+
+    int errnos[] = {
+      EINVAL,
+      ENOMEM,
+      mock_errno_generic,
+    };
+
+    f_status_t statuss[] = {
+      F_parameter,
+      F_memory_not,
+      F_failure,
+    };
+
+    for (int i = 0; i < 3; ++i) {
+
+      will_return(__wrap_cap_from_text, true);
+      will_return(__wrap_cap_from_text, errnos[i]);
+
+      const f_status_t status = f_capability_from_text(text, &capability);
+
+      assert_int_equal(F_status_set_fine(status), statuss[i]);
+    } // for
+  #endif // !defined(_di_libcap_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-from_text.h b/level_0/f_capability/tests/c/test-capability-from_text.h
new file mode 100644 (file)
index 0000000..8c54a0c
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__from_text
+#define _TEST__F_capability__from_text
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_from_text()
+ */
+extern void test__f_capability_from_text__works(void **state);
+
+/**
+ * Test that function fails.
+ *
+ * @see f_capability_from_text()
+ */
+extern void test__f_capability_from_text__fails(void **state);
+
+#endif // _TEST__F_capability__from_text
diff --git a/level_0/f_capability/tests/c/test-capability-groups_set.c b/level_0/f_capability/tests/c/test-capability-groups_set.c
new file mode 100644 (file)
index 0000000..ac3f3a0
--- /dev/null
@@ -0,0 +1,66 @@
+#include "test-capability.h"
+#include "test-capability-groups_set.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_groups_set__works(void **state) {
+
+  gid_t group;
+  size_t total = 2;
+  gid_t groups[total];
+
+  #if defined(_di_libcap_) || defined(_libcap_legacy_only_)
+    printf("[  WARN    ] f_capability_groups_set() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_setgroups, false);
+  #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_)
+
+  {
+    const f_status_t status = f_capability_groups_set(group, total, groups);
+
+    #if defined(_di_libcap_) || defined(_libcap_legacy_only_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_int_equal(status, F_none);
+    #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_)
+  }
+}
+
+void test__f_capability_groups_set__fails(void **state) {
+
+  #if !defined(_di_libcap_) && !defined(_libcap_legacy_only_)
+    gid_t group;
+    size_t total = 2;
+    gid_t groups[total];
+
+    int errnos[] = {
+      EINVAL,
+      ENOMEM,
+      ERANGE,
+      mock_errno_generic,
+    };
+
+    f_status_t statuss[] = {
+      F_parameter,
+      F_memory_not,
+      F_range_not,
+      F_failure,
+    };
+
+    for (int i = 0; i < 4; ++i) {
+
+      will_return(__wrap_cap_setgroups, true);
+      will_return(__wrap_cap_setgroups, errnos[i]);
+
+      const f_status_t status = f_capability_groups_set(group, total, groups);
+
+      assert_int_equal(F_status_set_fine(status), statuss[i]);
+    } // for
+  #endif // !defined(_di_libcap_) && !defined(_libcap_legacy_only_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-groups_set.h b/level_0/f_capability/tests/c/test-capability-groups_set.h
new file mode 100644 (file)
index 0000000..afb8fdd
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__groups_set
+#define _TEST__F_capability__groups_set
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_groups_set()
+ */
+extern void test__f_capability_groups_set__works(void **state);
+
+/**
+ * Test that function fails.
+ *
+ * @see f_capability_groups_set()
+ */
+extern void test__f_capability_groups_set__fails(void **state);
+
+#endif // _TEST__F_capability__groups_set
diff --git a/level_0/f_capability/tests/c/test-capability-initialize.c b/level_0/f_capability/tests/c/test-capability-initialize.c
new file mode 100644 (file)
index 0000000..665e41e
--- /dev/null
@@ -0,0 +1,60 @@
+#include "test-capability.h"
+#include "test-capability-initialize.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_initialize__works(void **state) {
+
+  f_capability_t capability = f_capability_t_initialize;
+
+  #if defined(_di_libcap_)
+    printf("[  WARN    ] f_capability_initialize() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_init, false);
+  #endif // defined(_di_libcap_)
+
+  {
+    const f_status_t status = f_capability_initialize(&capability);
+
+    #if defined(_di_libcap_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_int_equal(status, F_none);
+    #endif // defined(_di_libcap_)
+  }
+}
+
+void test__f_capability_initialize__fails(void **state) {
+
+  #if !defined(_di_libcap_)
+    f_capability_t capability = f_capability_t_initialize;
+
+    int errnos[] = {
+      EINVAL,
+      ENOMEM,
+      mock_errno_generic,
+    };
+
+    f_status_t statuss[] = {
+      F_parameter,
+      F_memory_not,
+      F_failure,
+    };
+
+    for (int i = 0; i < 3; ++i) {
+
+      will_return(__wrap_cap_init, true);
+      will_return(__wrap_cap_init, errnos[i]);
+
+      const f_status_t status = f_capability_initialize(&capability);
+
+      assert_int_equal(F_status_set_fine(status), statuss[i]);
+    } // for
+  #endif // !defined(_di_libcap_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-initialize.h b/level_0/f_capability/tests/c/test-capability-initialize.h
new file mode 100644 (file)
index 0000000..3f436b4
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__initialize
+#define _TEST__F_capability__initialize
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_initialize()
+ */
+extern void test__f_capability_initialize__works(void **state);
+
+/**
+ * Test that function fails.
+ *
+ * @see f_capability_initialize()
+ */
+extern void test__f_capability_initialize__fails(void **state);
+
+#endif // _TEST__F_capability__initialize
diff --git a/level_0/f_capability/tests/c/test-capability-mode_get.c b/level_0/f_capability/tests/c/test-capability-mode_get.c
new file mode 100644 (file)
index 0000000..7733a60
--- /dev/null
@@ -0,0 +1,31 @@
+#include "test-capability.h"
+#include "test-capability-mode_get.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_mode_get__works(void **state) {
+
+  f_capability_mode_t mode = f_capability_mode_t_initialize;
+
+  #if defined(_di_libcap_) || defined(_libcap_legacy_only_)
+    printf("[  WARN    ] f_capability_mode_get() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_mode_get, false);
+  #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_)
+
+  {
+    const f_status_t status = f_capability_mode_get(&mode);
+
+    #if defined(_di_libcap_) || defined(_libcap_legacy_only_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_int_equal(status, F_none);
+    #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_)
+  }
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-mode_get.h b/level_0/f_capability/tests/c/test-capability-mode_get.h
new file mode 100644 (file)
index 0000000..d30dded
--- /dev/null
@@ -0,0 +1,22 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__mode_get
+#define _TEST__F_capability__mode_get
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_mode_get()
+ */
+extern void test__f_capability_mode_get__works(void **state);
+
+// cap_get_mode() doesn't return failure.
+
+#endif // _TEST__F_capability__mode_get
diff --git a/level_0/f_capability/tests/c/test-capability-mode_get_name.c b/level_0/f_capability/tests/c/test-capability-mode_get_name.c
new file mode 100644 (file)
index 0000000..71b324b
--- /dev/null
@@ -0,0 +1,32 @@
+#include "test-capability.h"
+#include "test-capability-mode_get_name.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_mode_get_name__works(void **state) {
+
+  f_capability_mode_t mode = f_capability_mode_t_initialize;
+  f_string_constant_t constant = f_string_constant_t_initialize;
+
+  #if defined(_di_libcap_) || defined(_libcap_legacy_only_)
+    printf("[  WARN    ] f_capability_mode_get_name() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_mode_get_name, false);
+  #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_)
+
+  {
+    const f_status_t status = f_capability_mode_get_name(mode, &constant);
+
+    #if defined(_di_libcap_) || defined(_libcap_legacy_only_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_int_equal(status, F_none);
+    #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_)
+  }
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-mode_get_name.h b/level_0/f_capability/tests/c/test-capability-mode_get_name.h
new file mode 100644 (file)
index 0000000..f36776a
--- /dev/null
@@ -0,0 +1,22 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__mode_get_name
+#define _TEST__F_capability__mode_get_name
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_mode_get_name()
+ */
+extern void test__f_capability_mode_get_name__works(void **state);
+
+// cap_mode_name() doesn't return failure.
+
+#endif // _TEST__F_capability__mode_get_name
diff --git a/level_0/f_capability/tests/c/test-capability-mode_set.c b/level_0/f_capability/tests/c/test-capability-mode_set.c
new file mode 100644 (file)
index 0000000..32f56ce
--- /dev/null
@@ -0,0 +1,62 @@
+#include "test-capability.h"
+#include "test-capability-mode_set.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_mode_set__works(void **state) {
+
+  f_capability_mode_t mode = f_capability_mode_t_initialize;
+
+  #if defined(_di_libcap_) || defined(_libcap_legacy_only_)
+    printf("[  WARN    ] f_capability_mode_set() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_mode_set, false);
+  #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_)
+
+  {
+    const f_status_t status = f_capability_mode_set(mode);
+
+    #if defined(_di_libcap_) || defined(_libcap_legacy_only_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_int_equal(status, F_none);
+    #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_)
+  }
+}
+
+void test__f_capability_mode_set__fails(void **state) {
+
+  #if !defined(_di_libcap_) && !defined(_libcap_legacy_only_)
+    f_capability_mode_t mode = f_capability_mode_t_initialize;
+
+    int errnos[] = {
+      EINVAL,
+      ENOMEM,
+      EPERM,
+      mock_errno_generic,
+    };
+
+    f_status_t statuss[] = {
+      F_parameter,
+      F_memory_not,
+      F_prohibited,
+      F_failure,
+    };
+
+    for (int i = 0; i < 4; ++i) {
+
+      will_return(__wrap_cap_mode_set, true);
+      will_return(__wrap_cap_mode_set, errnos[i]);
+
+      const f_status_t status = f_capability_mode_set(mode);
+
+      assert_int_equal(F_status_set_fine(status), statuss[i]);
+    } // for
+  #endif // !defined(_di_libcap_) && !defined(_libcap_legacy_only_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-mode_set.h b/level_0/f_capability/tests/c/test-capability-mode_set.h
new file mode 100644 (file)
index 0000000..d1c8753
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__mode_set
+#define _TEST__F_capability__mode_set
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_mode_set()
+ */
+extern void test__f_capability_mode_set__works(void **state);
+
+/**
+ * Test that function fails.
+ *
+ * @see f_capability_mode_set()
+ */
+extern void test__f_capability_mode_set__fails(void **state);
+
+#endif // _TEST__F_capability__mode_set
diff --git a/level_0/f_capability/tests/c/test-capability-owner_get.c b/level_0/f_capability/tests/c/test-capability-owner_get.c
new file mode 100644 (file)
index 0000000..51f0081
--- /dev/null
@@ -0,0 +1,33 @@
+#include "test-capability.h"
+#include "test-capability-owner_get.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_owner_get__works(void **state) {
+
+  f_capability_t capability = f_capability_t_initialize;
+  uid_t id;
+
+  #if defined(_di_libcap_) || defined(_libcap_legacy_only_)
+    printf("[  WARN    ] f_capability_owner_get() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_get_nsowner, false);
+  #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_)
+
+  {
+    const f_status_t status = f_capability_owner_get(capability, &id);
+
+    #if defined(_di_libcap_) || defined(_libcap_legacy_only_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_int_equal(status, F_none);
+      assert_int_equal(id, 1);
+    #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_)
+  }
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-owner_get.h b/level_0/f_capability/tests/c/test-capability-owner_get.h
new file mode 100644 (file)
index 0000000..04991c9
--- /dev/null
@@ -0,0 +1,22 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__owner_get
+#define _TEST__F_capability__owner_get
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_owner_get()
+ */
+extern void test__f_capability_owner_get__works(void **state);
+
+// cap_mode_name() doesn't return failure.
+
+#endif // _TEST__F_capability__owner_get
diff --git a/level_0/f_capability/tests/c/test-capability-owner_set.c b/level_0/f_capability/tests/c/test-capability-owner_set.c
new file mode 100644 (file)
index 0000000..02da076
--- /dev/null
@@ -0,0 +1,74 @@
+#include "test-capability.h"
+#include "test-capability-owner_set.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_owner_set__works(void **state) {
+
+  f_capability_t capability = f_capability_t_initialize;
+  uid_t id;
+
+  #if defined(_di_libcap_) || defined(_libcap_legacy_only_)
+    printf("[  WARN    ] f_capability_owner_set() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_set_nsowner, false);
+  #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_)
+
+  {
+    const f_status_t status = f_capability_owner_set(capability, id);
+
+    #if defined(_di_libcap_) || defined(_libcap_legacy_only_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_int_equal(status, F_none);
+    #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_)
+  }
+}
+
+void test__f_capability_owner_set__fails(void **state) {
+
+  #if !defined(_di_libcap_) && !defined(_libcap_legacy_only_)
+    f_capability_t capability = f_capability_t_initialize;
+    uid_t id;
+
+    int errnos[] = {
+      EACCES,
+      EBADFD,
+      ENAMETOOLONG,
+      ENOENT,
+      ENOMEM,
+      ENOTDIR,
+      EPERM,
+      EROFS,
+      mock_errno_generic,
+    };
+
+    f_status_t statuss[] = {
+      F_access_denied,
+      F_descriptor_not,
+      F_name_not,
+      F_file_found_not,
+      F_memory_not,
+      F_directory_not,
+      F_prohibited,
+      F_supported_not,
+      F_failure,
+    };
+
+    for (int i = 0; i < 9; ++i) {
+
+      will_return(__wrap_cap_owner_set, true);
+      will_return(__wrap_cap_owner_set, errnos[i]);
+
+      const f_status_t status = f_capability_owner_set(capability, id);
+
+      assert_int_equal(F_status_set_fine(status), statuss[i]);
+    } // for
+  #endif // !defined(_di_libcap_) && !defined(_libcap_legacy_only_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-owner_set.h b/level_0/f_capability/tests/c/test-capability-owner_set.h
new file mode 100644 (file)
index 0000000..b2687fd
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__owner_set
+#define _TEST__F_capability__owner_set
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_owner_set()
+ */
+extern void test__f_capability_owner_set__works(void **state);
+
+/**
+ * Test that function fails.
+ *
+ * @see f_capability_owner_set()
+ */
+extern void test__f_capability_owner_set__fails(void **state);
+
+#endif // _TEST__F_capability__owner_set
diff --git a/level_0/f_capability/tests/c/test-capability-process_bound_drop.c b/level_0/f_capability/tests/c/test-capability-process_bound_drop.c
new file mode 100644 (file)
index 0000000..a6bb5ab
--- /dev/null
@@ -0,0 +1,65 @@
+#include "test-capability.h"
+#include "test-capability-process_bound_drop.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_process_bound_drop__works(void **state) {
+
+  f_capability_value_t value = f_capability_value_t_initialize;
+  int bound = 0;
+
+  #if defined(_di_libcap_)
+    printf("[  WARN    ] f_capability_process_bound_drop() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_drop_bound, false);
+  #endif // defined(_di_libcap_)
+
+  {
+    const f_status_t status = f_capability_process_bound_drop(value, &bound);
+
+    #if defined(_di_libcap_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_int_equal(status, F_none);
+      assert_int_equal(bound, 1);
+    #endif // defined(_di_libcap_)
+  }
+}
+
+void test__f_capability_process_bound_drop__fails(void **state) {
+
+  #if !defined(_di_libcap_)
+    f_capability_value_t value = f_capability_value_t_initialize;
+    int bound = 0;
+
+    int errnos[] = {
+      EINVAL,
+      ENOMEM,
+      EPERM,
+      mock_errno_generic,
+    };
+
+    f_status_t statuss[] = {
+      F_parameter,
+      F_memory_not,
+      F_prohibited,
+      F_failure,
+    };
+
+    for (int i = 0; i < 4; ++i) {
+
+      will_return(__wrap_cap_drop_bound, true);
+      will_return(__wrap_cap_drop_bound, errnos[i]);
+
+      const f_status_t status = f_capability_process_bound_drop(value, &bound);
+
+      assert_int_equal(F_status_set_fine(status), statuss[i]);
+    } // for
+  #endif // !defined(_di_libcap_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-process_bound_drop.h b/level_0/f_capability/tests/c/test-capability-process_bound_drop.h
new file mode 100644 (file)
index 0000000..4143d90
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__process_bound_drop
+#define _TEST__F_capability__process_bound_drop
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_process_bound_drop()
+ */
+extern void test__f_capability_process_bound_drop__works(void **state);
+
+/**
+ * Test that function fails.
+ *
+ * @see f_capability_process_bound_drop()
+ */
+extern void test__f_capability_process_bound_drop__fails(void **state);
+
+#endif // _TEST__F_capability__process_bound_drop
diff --git a/level_0/f_capability/tests/c/test-capability-process_bound_get.c b/level_0/f_capability/tests/c/test-capability-process_bound_get.c
new file mode 100644 (file)
index 0000000..409d541
--- /dev/null
@@ -0,0 +1,59 @@
+#include "test-capability.h"
+#include "test-capability-process_bound_get.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_process_bound_get__works(void **state) {
+
+  f_capability_value_t value = f_capability_value_t_initialize;
+  int bound = 0;
+
+  #if defined(_di_libcap_)
+    printf("[  WARN    ] f_capability_process_bound_get() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_get_bound, false);
+  #endif // defined(_di_libcap_)
+
+  {
+    const f_status_t status = f_capability_process_bound_get(value, &bound);
+
+    #if defined(_di_libcap_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_int_equal(status, F_none);
+      assert_int_equal(bound, 1);
+    #endif // defined(_di_libcap_)
+  }
+}
+
+void test__f_capability_process_bound_get__fails(void **state) {
+
+  #if !defined(_di_libcap_)
+    f_capability_value_t value = f_capability_value_t_initialize;
+    int bound = 0;
+
+    int errnos[] = {
+      mock_errno_generic,
+    };
+
+    f_status_t statuss[] = {
+      F_known_not,
+    };
+
+    for (int i = 0; i < 1; ++i) {
+
+      will_return(__wrap_cap_get_bound, true);
+      will_return(__wrap_cap_get_bound, errnos[i]);
+
+      const f_status_t status = f_capability_process_bound_get(value, &bound);
+
+      assert_int_equal(F_status_set_fine(status), statuss[i]);
+    } // for
+  #endif // !defined(_di_libcap_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-process_bound_get.h b/level_0/f_capability/tests/c/test-capability-process_bound_get.h
new file mode 100644 (file)
index 0000000..cfa3f9b
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__process_bound_get
+#define _TEST__F_capability__process_bound_get
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_process_bound_get()
+ */
+extern void test__f_capability_process_bound_get__works(void **state);
+
+/**
+ * Test that function fails.
+ *
+ * @see f_capability_process_bound_get()
+ */
+extern void test__f_capability_process_bound_get__fails(void **state);
+
+#endif // _TEST__F_capability__process_bound_get
diff --git a/level_0/f_capability/tests/c/test-capability-process_get.c b/level_0/f_capability/tests/c/test-capability-process_get.c
new file mode 100644 (file)
index 0000000..60aded0
--- /dev/null
@@ -0,0 +1,60 @@
+#include "test-capability.h"
+#include "test-capability-process_get.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_process_get__works(void **state) {
+
+  f_capability_t capability = f_capability_t_initialize;
+
+  #if defined(_di_libcap_)
+    printf("[  WARN    ] f_capability_process_get() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_get_proc, false);
+  #endif // defined(_di_libcap_)
+
+  {
+    const f_status_t status = f_capability_process_get(&capability);
+
+    #if defined(_di_libcap_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_int_equal(status, F_none);
+    #endif // defined(_di_libcap_)
+  }
+}
+
+void test__f_capability_process_get__fails(void **state) {
+
+  #if !defined(_di_libcap_)
+    f_capability_t capability = f_capability_t_initialize;
+
+    int errnos[] = {
+      EINVAL,
+      ENOMEM,
+      mock_errno_generic,
+    };
+
+    f_status_t statuss[] = {
+      F_parameter,
+      F_memory_not,
+      F_failure,
+    };
+
+    for (int i = 0; i < 3; ++i) {
+
+      will_return(__wrap_cap_get_proc, true);
+      will_return(__wrap_cap_get_proc, errnos[i]);
+
+      const f_status_t status = f_capability_process_get(&capability);
+
+      assert_int_equal(F_status_set_fine(status), statuss[i]);
+    } // for
+  #endif // !defined(_di_libcap_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-process_get.h b/level_0/f_capability/tests/c/test-capability-process_get.h
new file mode 100644 (file)
index 0000000..2397ab2
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__process_get
+#define _TEST__F_capability__process_get
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_process_get()
+ */
+extern void test__f_capability_process_get__works(void **state);
+
+/**
+ * Test that function fails.
+ *
+ * @see f_capability_process_get()
+ */
+extern void test__f_capability_process_get__fails(void **state);
+
+#endif // _TEST__F_capability__process_get
diff --git a/level_0/f_capability/tests/c/test-capability-process_get_by_id.c b/level_0/f_capability/tests/c/test-capability-process_get_by_id.c
new file mode 100644 (file)
index 0000000..7087f20
--- /dev/null
@@ -0,0 +1,59 @@
+#include "test-capability.h"
+#include "test-capability-process_get_by_id.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_process_get_by_id__works(void **state) {
+
+  f_capability_t capability = f_capability_t_initialize;
+  pid_t pid;
+
+  #if defined(_di_libcap_)
+    printf("[  WARN    ] f_capability_process_get_by_id() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_get_pid, false);
+  #endif // defined(_di_libcap_)
+
+  {
+    const f_status_t status = f_capability_process_get_by_id(pid, &capability);
+
+    #if defined(_di_libcap_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_int_equal(status, F_none);
+      assert_int_equal(capability, 1);
+    #endif // defined(_di_libcap_)
+  }
+}
+
+void test__f_capability_process_get_by_id__fails(void **state) {
+
+  #if !defined(_di_libcap_)
+    f_capability_t capability = f_capability_t_initialize;
+    pid_t pid;
+
+    int errnos[] = {
+      mock_errno_generic,
+    };
+
+    f_status_t statuss[] = {
+      F_failure,
+    };
+
+    for (int i = 0; i < 1; ++i) {
+
+      will_return(__wrap_cap_get_pid, true);
+      will_return(__wrap_cap_get_pid, errnos[i]);
+
+      const f_status_t status = f_capability_process_get_by_id(pid, &capability);
+
+      assert_int_equal(F_status_set_fine(status), statuss[i]);
+    } // for
+  #endif // !defined(_di_libcap_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-process_get_by_id.h b/level_0/f_capability/tests/c/test-capability-process_get_by_id.h
new file mode 100644 (file)
index 0000000..d5c9357
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__process_get_by_id
+#define _TEST__F_capability__process_get_by_id
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_process_get_by_id()
+ */
+extern void test__f_capability_process_get_by_id__works(void **state);
+
+/**
+ * Test that function fails.
+ *
+ * @see f_capability_process_get_by_id()
+ */
+extern void test__f_capability_process_get_by_id__fails(void **state);
+
+#endif // _TEST__F_capability__process_get_by_id
diff --git a/level_0/f_capability/tests/c/test-capability-process_set.c b/level_0/f_capability/tests/c/test-capability-process_set.c
new file mode 100644 (file)
index 0000000..00b26cd
--- /dev/null
@@ -0,0 +1,62 @@
+#include "test-capability.h"
+#include "test-capability-process_set.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_process_set__works(void **state) {
+
+  f_capability_t capability = f_capability_t_initialize;
+
+  #if defined(_di_libcap_)
+    printf("[  WARN    ] f_capability_process_set() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_set_proc, false);
+  #endif // defined(_di_libcap_)
+
+  {
+    const f_status_t status = f_capability_process_set(capability);
+
+    #if defined(_di_libcap_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_int_equal(status, F_none);
+    #endif // defined(_di_libcap_)
+  }
+}
+
+void test__f_capability_process_set__fails(void **state) {
+
+  #if !defined(_di_libcap_)
+    f_capability_t capability = f_capability_t_initialize;
+
+    int errnos[] = {
+      EINVAL,
+      ENOMEM,
+      EPERM,
+      mock_errno_generic,
+    };
+
+    f_status_t statuss[] = {
+      F_parameter,
+      F_memory_not,
+      F_prohibited,
+      F_failure,
+    };
+
+    for (int i = 0; i < 4; ++i) {
+
+      will_return(__wrap_cap_set_proc, true);
+      will_return(__wrap_cap_set_proc, errnos[i]);
+
+      const f_status_t status = f_capability_process_set(capability);
+
+      assert_int_equal(F_status_set_fine(status), statuss[i]);
+    } // for
+  #endif // !defined(_di_libcap_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-process_set.h b/level_0/f_capability/tests/c/test-capability-process_set.h
new file mode 100644 (file)
index 0000000..dccdc6d
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__process_set
+#define _TEST__F_capability__process_set
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_process_set()
+ */
+extern void test__f_capability_process_set__works(void **state);
+
+/**
+ * Test that function fails.
+ *
+ * @see f_capability_process_set()
+ */
+extern void test__f_capability_process_set__fails(void **state);
+
+#endif // _TEST__F_capability__process_set
diff --git a/level_0/f_capability/tests/c/test-capability-security_bits_get.c b/level_0/f_capability/tests/c/test-capability-security_bits_get.c
new file mode 100644 (file)
index 0000000..d2bb8af
--- /dev/null
@@ -0,0 +1,62 @@
+#include "test-capability.h"
+#include "test-capability-security_bits_get.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_security_bits_get__works(void **state) {
+
+  f_capability_bits_t bits = f_capability_bits_t_initialize;
+
+  #if defined(_di_libcap_) || defined(_libcap_legacy_only_)
+    printf("[  WARN    ] f_capability_security_bits_get() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_get_secbits, false);
+  #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_)
+
+  {
+    const f_status_t status = f_capability_security_bits_get(&bits);
+
+    #if defined(_di_libcap_) || defined(_libcap_legacy_only_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_int_equal(status, F_none);
+    #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_)
+  }
+}
+
+void test__f_capability_security_bits_get__fails(void **state) {
+
+  #if !defined(_di_libcap_) && !defined(_libcap_legacy_only_)
+    f_capability_bits_t bits = f_capability_bits_t_initialize;
+
+    int errnos[] = {
+      EINVAL,
+      ENOMEM,
+      EPERM,
+      mock_errno_generic,
+    };
+
+    f_status_t statuss[] = {
+      F_parameter,
+      F_memory_not,
+      F_prohibited,
+      F_failure,
+    };
+
+    for (int i = 0; i < 4; ++i) {
+
+      will_return(__wrap_cap_get_secbits, true);
+      will_return(__wrap_cap_get_secbits, errnos[i]);
+
+      const f_status_t status = f_capability_security_bits_get(&bits);
+
+      assert_int_equal(F_status_set_fine(status), statuss[i]);
+    } // for
+  #endif // !defined(_di_libcap_) && !defined(_libcap_legacy_only_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-security_bits_get.h b/level_0/f_capability/tests/c/test-capability-security_bits_get.h
new file mode 100644 (file)
index 0000000..c1ae696
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__security_bits_get
+#define _TEST__F_capability__security_bits_get
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_security_bits_get()
+ */
+extern void test__f_capability_security_bits_get__works(void **state);
+
+/**
+ * Test that function fails.
+ *
+ * @see f_capability_security_bits_get()
+ */
+extern void test__f_capability_security_bits_get__fails(void **state);
+
+#endif // _TEST__F_capability__security_bits_get
diff --git a/level_0/f_capability/tests/c/test-capability-security_bits_set.c b/level_0/f_capability/tests/c/test-capability-security_bits_set.c
new file mode 100644 (file)
index 0000000..55e2621
--- /dev/null
@@ -0,0 +1,72 @@
+#include "test-capability.h"
+#include "test-capability-security_bits_set.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_security_bits_set__works(void **state) {
+
+  f_capability_bits_t bits = f_capability_bits_t_initialize;
+
+  #if defined(_di_libcap_) || defined(_libcap_legacy_only_)
+    printf("[  WARN    ] f_capability_security_bits_set() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_set_secbits, false);
+  #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_)
+
+  {
+    const f_status_t status = f_capability_security_bits_set(bits);
+
+    #if defined(_di_libcap_) || defined(_libcap_legacy_only_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_int_equal(status, F_none);
+    #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_)
+  }
+}
+
+void test__f_capability_security_bits_set__fails(void **state) {
+
+  #if !defined(_di_libcap_) && !defined(_libcap_legacy_only_)
+    f_capability_bits_t bits = f_capability_bits_t_initialize;
+
+    int errnos[] = {
+      EACCES,
+      EBADFD,
+      ENAMETOOLONG,
+      ENOENT,
+      ENOMEM,
+      ENOTDIR,
+      EPERM,
+      EROFS,
+      mock_errno_generic,
+    };
+
+    f_status_t statuss[] = {
+      F_access_denied,
+      F_descriptor_not,
+      F_name_not,
+      F_file_found_not,
+      F_memory_not,
+      F_directory_not,
+      F_prohibited,
+      F_supported_not,
+      F_failure,
+    };
+
+    for (int i = 0; i < 9; ++i) {
+
+      will_return(__wrap_cap_set_secbits, true);
+      will_return(__wrap_cap_set_secbits, errnos[i]);
+
+      const f_status_t status = f_capability_security_bits_set(bits);
+
+      assert_int_equal(F_status_set_fine(status), statuss[i]);
+    } // for
+  #endif // !defined(_di_libcap_) && !defined(_libcap_legacy_only_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-security_bits_set.h b/level_0/f_capability/tests/c/test-capability-security_bits_set.h
new file mode 100644 (file)
index 0000000..ec29fa3
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__security_bits_set
+#define _TEST__F_capability__security_bits_set
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_security_bits_set()
+ */
+extern void test__f_capability_security_bits_set__works(void **state);
+
+/**
+ * Test that function fails.
+ *
+ * @see f_capability_security_bits_set()
+ */
+extern void test__f_capability_security_bits_set__fails(void **state);
+
+#endif // _TEST__F_capability__security_bits_set
diff --git a/level_0/f_capability/tests/c/test-capability-size.c b/level_0/f_capability/tests/c/test-capability-size.c
new file mode 100644 (file)
index 0000000..10378c3
--- /dev/null
@@ -0,0 +1,65 @@
+#include "test-capability.h"
+#include "test-capability-size.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_size__works(void **state) {
+
+  f_capability_t capability = f_capability_t_initialize;
+  ssize_t size = 0;
+
+  #if defined(_di_libcap_)
+    printf("[  WARN    ] f_capability_size() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_size, false);
+  #endif // defined(_di_libcap_)
+
+  {
+    const f_status_t status = f_capability_size(capability, &size);
+
+    #if defined(_di_libcap_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_int_equal(status, F_none);
+      assert_int_equal(size, 1);
+    #endif // defined(_di_libcap_)
+  }
+}
+
+void test__f_capability_size__fails(void **state) {
+
+  #if !defined(_di_libcap_)
+    f_capability_t capability = f_capability_t_initialize;
+    ssize_t size = 0;
+
+    int errnos[] = {
+      EINVAL,
+      ENOMEM,
+      EPERM,
+      mock_errno_generic,
+    };
+
+    f_status_t statuss[] = {
+      F_parameter,
+      F_memory_not,
+      F_prohibited,
+      F_failure,
+    };
+
+    for (int i = 0; i < 4; ++i) {
+
+      will_return(__wrap_cap_size, true);
+      will_return(__wrap_cap_size, errnos[i]);
+
+      const f_status_t status = f_capability_size(capability, &size);
+
+      assert_int_equal(F_status_set_fine(status), statuss[i]);
+    } // for
+  #endif // !defined(_di_libcap_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-size.h b/level_0/f_capability/tests/c/test-capability-size.h
new file mode 100644 (file)
index 0000000..5115f29
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__size
+#define _TEST__F_capability__size
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_size()
+ */
+extern void test__f_capability_size__works(void **state);
+
+/**
+ * Test that function fails.
+ *
+ * @see f_capability_size()
+ */
+extern void test__f_capability_size__fails(void **state);
+
+#endif // _TEST__F_capability__size
diff --git a/level_0/f_capability/tests/c/test-capability-supported.c b/level_0/f_capability/tests/c/test-capability-supported.c
new file mode 100644 (file)
index 0000000..d01f370
--- /dev/null
@@ -0,0 +1,23 @@
+#include "test-capability.h"
+#include "test-capability-supported.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_supported__works(void **state) {
+
+  {
+    const f_status_t status = f_capability_supported();
+
+    #if defined(_di_libcap_)
+      assert_int_equal(status, F_false);
+    #else
+      assert_int_equal(status, F_true);
+    #endif // defined(_di_libcap_)
+  }
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-supported.h b/level_0/f_capability/tests/c/test-capability-supported.h
new file mode 100644 (file)
index 0000000..8cb9925
--- /dev/null
@@ -0,0 +1,22 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__supported
+#define _TEST__F_capability__supported
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_supported()
+ */
+extern void test__f_capability_supported__works(void **state);
+
+// f_capability_supported() doesn't return failure.
+
+#endif // _TEST__F_capability__supported
diff --git a/level_0/f_capability/tests/c/test-capability-supported_ambient.c b/level_0/f_capability/tests/c/test-capability-supported_ambient.c
new file mode 100644 (file)
index 0000000..0ca5d7b
--- /dev/null
@@ -0,0 +1,38 @@
+#include "test-capability.h"
+#include "test-capability-supported_ambient.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_supported_ambient__works(void **state) {
+
+  #if defined(_di_libcap_) || defined(_libcap_legacy_only_)
+    {
+      const f_status_t status = f_capability_supported_ambient();
+
+      assert_int_equal(status, F_false);
+    }
+  #else
+    {
+      const f_status_t status = f_capability_supported_ambient();
+
+      will_return(__wrap_cap_get_ambient, false);
+
+      assert_int_equal(status, F_true);
+    }
+
+    {
+      const f_status_t status = f_capability_supported_ambient();
+
+      will_return(__wrap_cap_get_ambient, true);
+      will_return(__wrap_cap_get_ambient, mock_errno_generic);
+
+      assert_int_equal(status, F_false);
+    }
+  #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-supported_ambient.h b/level_0/f_capability/tests/c/test-capability-supported_ambient.h
new file mode 100644 (file)
index 0000000..66bd54c
--- /dev/null
@@ -0,0 +1,22 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__supported_ambient
+#define _TEST__F_capability__supported_ambient
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_supported_ambient()
+ */
+extern void test__f_capability_supported_ambient__works(void **state);
+
+// f_capability_supported_ambient() doesn't return failure.
+
+#endif // _TEST__F_capability__supported_ambient
diff --git a/level_0/f_capability/tests/c/test-capability-supported_code.c b/level_0/f_capability/tests/c/test-capability-supported_code.c
new file mode 100644 (file)
index 0000000..c1b54f2
--- /dev/null
@@ -0,0 +1,40 @@
+#include "test-capability.h"
+#include "test-capability-supported_code.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_supported_code__works(void **state) {
+
+  f_capability_value_t value = f_capability_value_t_initialize;
+
+  #if defined(_di_libcap_)
+    {
+      const f_status_t status = f_capability_supported_code(value);
+
+      assert_int_equal(status, F_false);
+    }
+  #else
+    {
+      will_return(__wrap_cap_get_bound, false);
+
+      const f_status_t status = f_capability_supported_code(value);
+
+      assert_int_equal(status, F_true);
+    }
+
+    {
+      will_return(__wrap_cap_get_bound, F_true);
+      will_return(__wrap_cap_get_bound, mock_errno_generic);
+
+      const f_status_t status = f_capability_supported_code(value);
+
+      assert_int_equal(status, F_false);
+    }
+  #endif // defined(_di_libcap_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-supported_code.h b/level_0/f_capability/tests/c/test-capability-supported_code.h
new file mode 100644 (file)
index 0000000..7ec5a84
--- /dev/null
@@ -0,0 +1,22 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__supported_code
+#define _TEST__F_capability__supported_code
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_supported_code()
+ */
+extern void test__f_capability_supported_code__works(void **state);
+
+// f_capability_supported_code() doesn't return failure.
+
+#endif // _TEST__F_capability__supported_code
diff --git a/level_0/f_capability/tests/c/test-capability-to_name.c b/level_0/f_capability/tests/c/test-capability-to_name.c
new file mode 100644 (file)
index 0000000..1d122f7
--- /dev/null
@@ -0,0 +1,69 @@
+#include "test-capability.h"
+#include "test-capability-to_name.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_to_name__works(void **state) {
+
+  int code = CAP_CHOWN;
+  char string[] = "CAP_CHOWN";
+  f_string_dynamic_t name = f_string_dynamic_t_initialize;
+
+  #if defined(_di_libcap_)
+    printf("[  WARN    ] f_capability_to_name() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_to_name, false);
+    will_return(__wrap_cap_to_name, string);
+    will_return(__wrap_cap_free, false);
+  #endif // defined(_di_libcap_)
+
+  {
+    const f_status_t status = f_capability_to_name(code, &name);
+
+    #if defined(_di_libcap_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_string_equal(name.string, string);
+      assert_int_equal(name.used, 9);
+    #endif // defined(_di_libcap_)
+  }
+
+  f_string_dynamic_resize(0, &name);
+}
+
+void test__f_capability_to_name__fails(void **state) {
+
+  #if !defined(_di_libcap_)
+    int code = CAP_CHOWN;
+    f_string_dynamic_t name = f_string_dynamic_t_initialize;
+
+    int errnos[] = {
+      EINVAL,
+      ENOMEM,
+      mock_errno_generic,
+    };
+
+    f_status_t statuss[] = {
+      F_parameter,
+      F_memory_not,
+      F_failure,
+    };
+
+    for (int i = 0; i < 3; ++i) {
+
+      will_return(__wrap_cap_to_name, true);
+      will_return(__wrap_cap_to_name, errnos[i]);
+
+      const f_status_t status = f_capability_to_name(code, &name);
+
+      assert_int_equal(F_status_set_fine(status), statuss[i]);
+      assert_int_equal(name.used, 0);
+    } // for
+  #endif // !defined(_di_libcap_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-to_name.h b/level_0/f_capability/tests/c/test-capability-to_name.h
new file mode 100644 (file)
index 0000000..c02cfb2
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__to_name
+#define _TEST__F_capability__to_name
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_to_name()
+ */
+extern void test__f_capability_to_name__works(void **state);
+
+/**
+ * Test that function fails.
+ *
+ * @see f_capability_to_name()
+ */
+extern void test__f_capability_to_name__fails(void **state);
+
+#endif // _TEST__F_capability__to_name
diff --git a/level_0/f_capability/tests/c/test-capability-to_text.c b/level_0/f_capability/tests/c/test-capability-to_text.c
new file mode 100644 (file)
index 0000000..e10069a
--- /dev/null
@@ -0,0 +1,70 @@
+#include "test-capability.h"
+#include "test-capability-to_text.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_to_text__works(void **state) {
+
+  f_capability_t capability = f_capability_t_initialize;
+  char string[] = "CAP_CHOWN";
+  f_string_dynamic_t text = f_string_dynamic_t_initialize;
+
+  #if defined(_di_libcap_)
+    printf("[  WARN    ] f_capability_to_text() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_to_text, false);
+    will_return(__wrap_cap_to_text, 9);
+    will_return(__wrap_cap_to_text, string);
+    will_return(__wrap_cap_free, false);
+  #endif // defined(_di_libcap_)
+
+  {
+    const f_status_t status = f_capability_to_text(capability, &text);
+
+    #if defined(_di_libcap_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_string_equal(text.string, string);
+      assert_int_equal(text.used, 9);
+    #endif // defined(_di_libcap_)
+  }
+
+  f_string_dynamic_resize(0, &text);
+}
+
+void test__f_capability_to_text__fails(void **state) {
+
+  #if !defined(_di_libcap_)
+    f_capability_t capability = f_capability_t_initialize;
+    f_string_dynamic_t text = f_string_dynamic_t_initialize;
+
+    int errnos[] = {
+      EINVAL,
+      ENOMEM,
+      mock_errno_generic,
+    };
+
+    f_status_t statuss[] = {
+      F_parameter,
+      F_memory_not,
+      F_failure,
+    };
+
+    for (int i = 0; i < 3; ++i) {
+
+      will_return(__wrap_cap_to_text, true);
+      will_return(__wrap_cap_to_text, errnos[i]);
+
+      const f_status_t status = f_capability_to_text(capability, &text);
+
+      assert_int_equal(F_status_set_fine(status), statuss[i]);
+      assert_int_equal(text.used, 0);
+    } // for
+  #endif // !defined(_di_libcap_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-to_text.h b/level_0/f_capability/tests/c/test-capability-to_text.h
new file mode 100644 (file)
index 0000000..4612b2c
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__to_text
+#define _TEST__F_capability__to_text
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_to_text()
+ */
+extern void test__f_capability_to_text__works(void **state);
+
+/**
+ * Test that function fails.
+ *
+ * @see f_capability_to_text()
+ */
+extern void test__f_capability_to_text__fails(void **state);
+
+#endif // _TEST__F_capability__to_text
diff --git a/level_0/f_capability/tests/c/test-capability-user_set.c b/level_0/f_capability/tests/c/test-capability-user_set.c
new file mode 100644 (file)
index 0000000..20e4d02
--- /dev/null
@@ -0,0 +1,62 @@
+#include "test-capability.h"
+#include "test-capability-user_set.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_capability_user_set__works(void **state) {
+
+  uid_t uid;
+
+  #if defined(_di_libcap_) || defined(_libcap_legacy_only_)
+    printf("[  WARN    ] f_capability_user_set() is not implemented and cannot be fully tested.\n");
+  #else
+    will_return(__wrap_cap_setuid, false);
+  #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_)
+
+  {
+    const f_status_t status = f_capability_user_set(uid);
+
+    #if defined(_di_libcap_) || defined(_libcap_legacy_only_)
+      assert_int_equal(F_status_set_fine(status), F_implemented_not);
+    #else
+      assert_int_equal(status, F_none);
+    #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_)
+  }
+}
+
+void test__f_capability_user_set__fails(void **state) {
+
+  #if !defined(_di_libcap_) && !defined(_libcap_legacy_only_)
+    uid_t uid;
+
+    int errnos[] = {
+      EINVAL,
+      ENOMEM,
+      EPERM,
+      mock_errno_generic,
+    };
+
+    f_status_t statuss[] = {
+      F_parameter,
+      F_memory_not,
+      F_prohibited,
+      F_failure,
+    };
+
+    for (int i = 0; i < 4; ++i) {
+
+      will_return(__wrap_cap_setuid, true);
+      will_return(__wrap_cap_setuid, errnos[i]);
+
+      const f_status_t status = f_capability_user_set(uid);
+
+      assert_int_equal(F_status_set_fine(status), statuss[i]);
+    } // for
+  #endif // !defined(_di_libcap_) && !defined(_libcap_legacy_only_)
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability-user_set.h b/level_0/f_capability/tests/c/test-capability-user_set.h
new file mode 100644 (file)
index 0000000..44b9b6d
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability__user_set
+#define _TEST__F_capability__user_set
+
+/**
+ * Test that function works.
+ *
+ * @see f_capability_user_set()
+ */
+extern void test__f_capability_user_set__works(void **state);
+
+/**
+ * Test that function fails.
+ *
+ * @see f_capability_user_set()
+ */
+extern void test__f_capability_user_set__fails(void **state);
+
+#endif // _TEST__F_capability__user_set
diff --git a/level_0/f_capability/tests/c/test-capability.c b/level_0/f_capability/tests/c/test-capability.c
new file mode 100644 (file)
index 0000000..96d9e27
--- /dev/null
@@ -0,0 +1,145 @@
+#include "test-capability.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_capability_ambient_get__works),
+    cmocka_unit_test(test__f_capability_ambient_get__fails),
+
+    cmocka_unit_test(test__f_capability_ambient_reset__works),
+    cmocka_unit_test(test__f_capability_ambient_reset__fails),
+
+    cmocka_unit_test(test__f_capability_ambient_set__works),
+    cmocka_unit_test(test__f_capability_ambient_set__fails),
+
+    cmocka_unit_test(test__f_capability_clear__works),
+    cmocka_unit_test(test__f_capability_clear__fails),
+
+    cmocka_unit_test(test__f_capability_clear_flag__works),
+    cmocka_unit_test(test__f_capability_clear_flag__fails),
+
+    cmocka_unit_test(test__f_capability_compare__works),
+    cmocka_unit_test(test__f_capability_compare__fails),
+
+    cmocka_unit_test(test__f_capability_copy__works),
+    cmocka_unit_test(test__f_capability_copy__fails),
+
+    cmocka_unit_test(test__f_capability_copy_external__works),
+    cmocka_unit_test(test__f_capability_copy_external__fails),
+
+    cmocka_unit_test(test__f_capability_copy_internal__works),
+    cmocka_unit_test(test__f_capability_copy_internal__fails),
+
+    cmocka_unit_test(test__f_capability_delete__works),
+    cmocka_unit_test(test__f_capability_delete__fails),
+
+    cmocka_unit_test(test__f_capability_file_descriptor_get__works),
+    cmocka_unit_test(test__f_capability_file_descriptor_get__fails),
+
+    cmocka_unit_test(test__f_capability_file_descriptor_set__works),
+    cmocka_unit_test(test__f_capability_file_descriptor_set__fails),
+
+    cmocka_unit_test(test__f_capability_file_get__works),
+    cmocka_unit_test(test__f_capability_file_get__fails),
+
+    cmocka_unit_test(test__f_capability_file_set__works),
+    cmocka_unit_test(test__f_capability_file_set__fails),
+
+    cmocka_unit_test(test__f_capability_flag_get__works),
+    cmocka_unit_test(test__f_capability_flag_get__fails),
+
+    cmocka_unit_test(test__f_capability_flag_set__works),
+    cmocka_unit_test(test__f_capability_flag_set__fails),
+
+    cmocka_unit_test(test__f_capability_from_name__works),
+    cmocka_unit_test(test__f_capability_from_name__fails),
+
+    cmocka_unit_test(test__f_capability_from_text__works),
+    cmocka_unit_test(test__f_capability_from_text__fails),
+
+    cmocka_unit_test(test__f_capability_groups_set__works),
+    cmocka_unit_test(test__f_capability_groups_set__fails),
+
+    cmocka_unit_test(test__f_capability_initialize__works),
+    cmocka_unit_test(test__f_capability_initialize__fails),
+
+    cmocka_unit_test(test__f_capability_mode_get__works),
+    // cap_get_mode() doesn't return failure.
+
+    cmocka_unit_test(test__f_capability_mode_get_name__works),
+    // cap_mode_name() doesn't return failure.
+
+    cmocka_unit_test(test__f_capability_mode_set__works),
+    cmocka_unit_test(test__f_capability_mode_set__fails),
+
+    cmocka_unit_test(test__f_capability_owner_get__works),
+    // cap_get_nsowner() doesn't return failure.
+
+    cmocka_unit_test(test__f_capability_owner_set__works),
+    cmocka_unit_test(test__f_capability_owner_set__fails),
+
+    cmocka_unit_test(test__f_capability_process_bound_drop__works),
+    cmocka_unit_test(test__f_capability_process_bound_drop__fails),
+
+    cmocka_unit_test(test__f_capability_process_bound_get__works),
+    cmocka_unit_test(test__f_capability_process_bound_get__fails),
+
+    cmocka_unit_test(test__f_capability_process_get_by_id__works),
+    cmocka_unit_test(test__f_capability_process_get_by_id__fails),
+
+    cmocka_unit_test(test__f_capability_process_get__works),
+    cmocka_unit_test(test__f_capability_process_get__fails),
+
+    cmocka_unit_test(test__f_capability_process_set__works),
+    cmocka_unit_test(test__f_capability_process_set__fails),
+
+    cmocka_unit_test(test__f_capability_security_bits_get__works),
+    cmocka_unit_test(test__f_capability_security_bits_get__fails),
+
+    cmocka_unit_test(test__f_capability_security_bits_set__works),
+    cmocka_unit_test(test__f_capability_security_bits_set__fails),
+
+    cmocka_unit_test(test__f_capability_size__works),
+    cmocka_unit_test(test__f_capability_size__fails),
+
+    cmocka_unit_test(test__f_capability_supported__works),
+    // f_capability_supported() doesn't return failure.
+
+    cmocka_unit_test(test__f_capability_supported_ambient__works),
+    // f_capability_supported_ambient() doesn't return failure.
+
+    cmocka_unit_test(test__f_capability_supported_code__works),
+    // f_capability_supported_code() doesn't return failure.
+
+    cmocka_unit_test(test__f_capability_to_name__works),
+    cmocka_unit_test(test__f_capability_to_name__fails),
+
+    cmocka_unit_test(test__f_capability_to_text__works),
+    cmocka_unit_test(test__f_capability_to_text__fails),
+
+    cmocka_unit_test(test__f_capability_user_set__works),
+    cmocka_unit_test(test__f_capability_user_set__fails),
+  };
+
+  return cmocka_run_group_tests(tests, setup, setdown);
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_capability/tests/c/test-capability.h b/level_0/f_capability/tests/c/test-capability.h
new file mode 100644 (file)
index 0000000..7362238
--- /dev/null
@@ -0,0 +1,110 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Capability
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the capability project.
+ */
+#ifndef _TEST__F_capability_h
+#define _TEST__F_capability_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/capability.h>
+
+// mock includes.
+#include "mock-capability.h"
+
+// test includes.
+#include "test-capability-ambient_get.h"
+#include "test-capability-ambient_reset.h"
+#include "test-capability-ambient_set.h"
+#include "test-capability-clear.h"
+#include "test-capability-clear_flag.h"
+#include "test-capability-compare.h"
+#include "test-capability-copy.h"
+#include "test-capability-copy_external.h"
+#include "test-capability-copy_internal.h"
+#include "test-capability-delete.h"
+#include "test-capability-file_descriptor_get.h"
+#include "test-capability-file_descriptor_set.h"
+#include "test-capability-file_get.h"
+#include "test-capability-file_set.h"
+#include "test-capability-flag_get.h"
+#include "test-capability-flag_set.h"
+#include "test-capability-from_name.h"
+#include "test-capability-from_text.h"
+#include "test-capability-groups_set.h"
+#include "test-capability-initialize.h"
+#include "test-capability-mode_get.h"
+#include "test-capability-mode_get_name.h"
+#include "test-capability-mode_set.h"
+#include "test-capability-owner_get.h"
+#include "test-capability-owner_set.h"
+#include "test-capability-process_bound_drop.h"
+#include "test-capability-process_bound_get.h"
+#include "test-capability-process_get_by_id.h"
+#include "test-capability-process_get.h"
+#include "test-capability-process_set.h"
+#include "test-capability-security_bits_get.h"
+#include "test-capability-security_bits_set.h"
+#include "test-capability-size.h"
+#include "test-capability-supported_ambient.h"
+#include "test-capability-supported.h"
+#include "test-capability-supported_code.h"
+#include "test-capability-to_name.h"
+#include "test-capability-to_text.h"
+#include "test-capability-user_set.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_capability_h
index ef33c6ae9d5f289b8f91502b4f3fa09aadaf2984..dea3179c38af2975f53f753a1311be4aa158be6a 100644 (file)
@@ -1,3 +1,3 @@
-# fss-0000
+# fss-0001
 
 cmocka 1.*
index 81aa652b22f71850ea58b8c446bc9c950e55e021..da9e230b54b12c6a59dc3e324f8e06dcd8eb0c28 100644 (file)
@@ -10,10 +10,7 @@ main:
   build settings
   build settings-tests
 
-  if defined environment LD_LIBRARY_PATH
-    define LD_LIBRARY_PATH build/libraries/shared:define:"LD_LIBRARY_PATH"
-  else
-    define LD_LIBRARY_PATH build/libraries/shared
+  operate ld_library_path
 
   if exists build/programs/shared/test-f_memory
     shell build/programs/shared/test-f_memory
@@ -30,3 +27,19 @@ not_created:
   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
index ef33c6ae9d5f289b8f91502b4f3fa09aadaf2984..dea3179c38af2975f53f753a1311be4aa158be6a 100644 (file)
@@ -1,3 +1,3 @@
-# fss-0000
+# fss-0001
 
 cmocka 1.*
index 44898dda84ac217f29f71fc38114a6932ea5288d..e2264ee1515a0ca9826bbe717936d45e965c9064 100644 (file)
@@ -10,10 +10,7 @@ main:
   build settings
   build settings-tests
 
-  if defined environment LD_LIBRARY_PATH
-    define LD_LIBRARY_PATH build/libraries/shared:define:"LD_LIBRARY_PATH"
-  else
-    define LD_LIBRARY_PATH build/libraries/shared
+  operate ld_library_path
 
   if exists build/programs/shared/test-f_type_array
     shell build/programs/shared/test-f_type_array
@@ -30,3 +27,19 @@ not_created:
   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