]> Kevux Git Server - fll/commitdiff
Update: Add missing structures to f_account_t and implement allocation functions.
authorKevin Day <thekevinday@gmail.com>
Fri, 5 Aug 2022 02:33:42 +0000 (21:33 -0500)
committerKevin Day <thekevinday@gmail.com>
Fri, 5 Aug 2022 02:33:42 +0000 (21:33 -0500)
I failed to notice that f_account is incomplete and this failed to make the 0.6 release window.
This is an API change and will only be applied to the 0.7 development releases as a result.

Provide real functions rather than macros for allocation and deallocation of the f_account_t structure.
Make sure both f_accounts_t and f_acountss_t exist for standard consistency.
Add unit tests.

48 files changed:
build/level_0/settings
build/monolithic/settings
level_0/f_account/c/account.c
level_0/f_account/c/account.h
level_0/f_account/c/account/accounts.c [new file with mode: 0644]
level_0/f_account/c/account/accounts.h [new file with mode: 0644]
level_0/f_account/c/account/common.h
level_0/f_account/c/account/private-accounts.c [new file with mode: 0644]
level_0/f_account/c/account/private-accounts.h [new file with mode: 0644]
level_0/f_account/c/private-account.c
level_0/f_account/c/private-account.h
level_0/f_account/data/build/settings
level_0/f_account/data/build/settings-mocks
level_0/f_account/data/build/settings-tests
level_0/f_account/tests/unit/c/test-account-s_adjust.c [new file with mode: 0644]
level_0/f_account/tests/unit/c/test-account-s_adjust.h [new file with mode: 0644]
level_0/f_account/tests/unit/c/test-account-s_append.c [new file with mode: 0644]
level_0/f_account/tests/unit/c/test-account-s_append.h [new file with mode: 0644]
level_0/f_account/tests/unit/c/test-account-s_append_all.c [new file with mode: 0644]
level_0/f_account/tests/unit/c/test-account-s_append_all.h [new file with mode: 0644]
level_0/f_account/tests/unit/c/test-account-s_decimate_by.c [new file with mode: 0644]
level_0/f_account/tests/unit/c/test-account-s_decimate_by.h [new file with mode: 0644]
level_0/f_account/tests/unit/c/test-account-s_decrease_by.c [new file with mode: 0644]
level_0/f_account/tests/unit/c/test-account-s_decrease_by.h [new file with mode: 0644]
level_0/f_account/tests/unit/c/test-account-s_increase.c [new file with mode: 0644]
level_0/f_account/tests/unit/c/test-account-s_increase.h [new file with mode: 0644]
level_0/f_account/tests/unit/c/test-account-s_increase_by.c [new file with mode: 0644]
level_0/f_account/tests/unit/c/test-account-s_increase_by.h [new file with mode: 0644]
level_0/f_account/tests/unit/c/test-account-s_resize.c [new file with mode: 0644]
level_0/f_account/tests/unit/c/test-account-s_resize.h [new file with mode: 0644]
level_0/f_account/tests/unit/c/test-account-ss_adjust.c [new file with mode: 0644]
level_0/f_account/tests/unit/c/test-account-ss_adjust.h [new file with mode: 0644]
level_0/f_account/tests/unit/c/test-account-ss_append.c [new file with mode: 0644]
level_0/f_account/tests/unit/c/test-account-ss_append.h [new file with mode: 0644]
level_0/f_account/tests/unit/c/test-account-ss_append_all.c [new file with mode: 0644]
level_0/f_account/tests/unit/c/test-account-ss_append_all.h [new file with mode: 0644]
level_0/f_account/tests/unit/c/test-account-ss_decimate_by.c [new file with mode: 0644]
level_0/f_account/tests/unit/c/test-account-ss_decimate_by.h [new file with mode: 0644]
level_0/f_account/tests/unit/c/test-account-ss_decrease_by.c [new file with mode: 0644]
level_0/f_account/tests/unit/c/test-account-ss_decrease_by.h [new file with mode: 0644]
level_0/f_account/tests/unit/c/test-account-ss_increase.c [new file with mode: 0644]
level_0/f_account/tests/unit/c/test-account-ss_increase.h [new file with mode: 0644]
level_0/f_account/tests/unit/c/test-account-ss_increase_by.c [new file with mode: 0644]
level_0/f_account/tests/unit/c/test-account-ss_increase_by.h [new file with mode: 0644]
level_0/f_account/tests/unit/c/test-account-ss_resize.c [new file with mode: 0644]
level_0/f_account/tests/unit/c/test-account-ss_resize.h [new file with mode: 0644]
level_0/f_account/tests/unit/c/test-account.c
level_0/f_account/tests/unit/c/test-account.h

index f6166ee9593137cf30abf8a9b6ab617017c9e16c..034494de8a6d579cab740e94a99e1f8cca7a1e80 100644 (file)
@@ -19,7 +19,7 @@ build_language c
 
 build_libraries -lc -lcap
 
-build_sources_library account.c private-account.c
+build_sources_library account.c private-account.c account/private-accounts.c
 build_sources_library capability.c
 build_sources_library color.c private-color.c color/common.c
 build_sources_library console.c console/common.c
@@ -48,7 +48,7 @@ build_sources_library utf/common.c utf/convert.c utf/dynamic.c utf/is.c utf/is_c
 
 build_sources_library-level thread.c private-thread.c thread/attribute.c thread/barrier.c thread/barrier_attribute.c thread/condition.c thread/condition_attribute.c thread/id.c thread/key.c thread/lock.c thread/lock_attribute.c thread/mutex.c thread/mutex_attribute.c thread/once.c thread/semaphore.c thread/set.c thread/spin.c
 
-build_sources_headers account.h account/common.h
+build_sources_headers account.h account/accounts.h account/common.h
 build_sources_headers capability.h capability/common.h
 build_sources_headers color.h color/common.h
 build_sources_headers console.h console/common.h
index e1efa995ab3b3b80e527498bbfbdcd364b8e140d..3b6b5a8b197602c3b79e26a7c8a17066830bfbd7 100644 (file)
@@ -19,7 +19,7 @@ build_language c
 
 build_libraries -lc -lcap
 
-build_sources_library level_0/account.c level_0/private-account.c
+build_sources_library
 build_sources_library level_0/capability.c
 build_sources_library level_0/color.c level_0/private-color.c level_0/color/common.c
 build_sources_library level_0/console.c level_0/console/common.c
@@ -72,7 +72,7 @@ build_sources_library level_2/status_string.c
 
 build_sources_library-monolithic level_0/thread.c level_0/private-thread.c level_0/thread/attribute.c level_0/thread/barrier.c level_0/thread/barrier_attribute.c level_0/thread/condition.c level_0/thread/condition_attribute.c level_0/thread/id.c level_0/thread/key.c level_0/thread/lock.c level_0/thread/lock_attribute.c level_0/thread/mutex.c level_0/thread/mutex_attribute.c level_0/thread/once.c level_0/thread/semaphore.c level_0/thread/set.c level_0/thread/spin.c
 
-build_sources_headers level_0/account.h level_0/account/common.h
+build_sources_headers level_0/account.h level_0/account/accounts.h level_0/account/common.h
 build_sources_headers level_0/capability.h level_0/capability/common.h
 build_sources_headers level_0/color.h level_0/color/common.h
 build_sources_headers level_0/console.h level_0/console/common.h
index 3e4a1ae4f5fa4e591a099dff66fbce25a067e481..43a79f33fd8ca4169ccabdd28bebfb6ccf3940b9 100644 (file)
@@ -53,9 +53,7 @@ extern "C" {
         }
       }
       else {
-        if (!pointer) {
-          return F_exist_not;
-        }
+        if (!pointer) return F_exist_not;
 
         return private_f_account_from_passwd(password, length, account);
       }
@@ -78,9 +76,7 @@ extern "C" {
       return F_status_set_error(F_failure);
     }
 
-    if (!pointer) {
-      return F_exist_not;
-    }
+    if (!pointer) return F_exist_not;
 
     return private_f_account_from_passwd(password, length, account);
   }
@@ -117,6 +113,7 @@ extern "C" {
       errno = 0;
 
       char buffer[length];
+
       const int result = getpwnam_r(name.string, &password, buffer, length, &pointer);
 
       if (result) {
@@ -134,9 +131,7 @@ extern "C" {
         }
       }
       else {
-        if (!pointer) {
-          return F_exist_not;
-        }
+        if (!pointer) return F_exist_not;
 
         return private_f_account_from_passwd(password, length, account);
       }
@@ -159,9 +154,7 @@ extern "C" {
       return F_status_set_error(F_failure);
     }
 
-    if (!pointer) {
-      return F_exist_not;
-    }
+    if (!pointer) return F_exist_not;
 
     return private_f_account_from_passwd(password, length, account);
   }
@@ -190,6 +183,7 @@ extern "C" {
       errno = 0;
 
       char buffer[length];
+
       int result = getgrnam_r(name.string, &group_data, buffer, length, &pointer);
 
       if (result) {
@@ -207,9 +201,7 @@ extern "C" {
         }
       }
       else {
-        if (!pointer) {
-          return F_exist_not;
-        }
+        if (!pointer) return F_exist_not;
 
         *id = group_data.gr_gid;
 
@@ -234,9 +226,7 @@ extern "C" {
       return F_status_set_error(F_failure);
     }
 
-    if (!pointer) {
-      return F_exist_not;
-    }
+    if (!pointer) return F_exist_not;
 
     *id = group_data.gr_gid;
 
@@ -271,6 +261,7 @@ extern "C" {
       errno = 0;
 
       char buffer[length];
+
       const int result = getgrgid_r(id, &group_data, buffer, length, &pointer);
 
       if (result) {
@@ -288,13 +279,13 @@ extern "C" {
         }
       }
       else {
-        if (!pointer) {
-          return F_exist_not;
-        }
+        if (!pointer) return F_exist_not;
 
         const f_array_length_t name_length = strnlen(group_data.gr_name, length);
 
-        status = f_string_dynamic_resize(name_length + 1, name);
+        name->used = 0;
+
+        status = f_string_dynamic_increase_by(name_length + 1, name);
         if (F_status_is_error(status)) return status;
 
         memcpy(name->string, group_data.gr_name, sizeof(f_char_t) * name_length);
@@ -323,13 +314,13 @@ extern "C" {
       return F_status_set_error(F_failure);
     }
 
-    if (!pointer) {
-      return F_exist_not;
-    }
+    if (!pointer) return F_exist_not;
 
     const f_array_length_t name_length = strnlen(group_data.gr_name, length);
 
-    status = f_string_dynamic_resize(name_length + 1, name);
+    name->used = 0;
+
+    status = f_string_dynamic_increase_by(name_length + 1, name);
     if (F_status_is_error(status)) return status;
 
     memcpy(name->string, group_data.gr_name, sizeof(f_char_t) * name_length);
@@ -364,6 +355,7 @@ extern "C" {
       errno = 0;
 
       char buffer[length];
+
       const int result = getpwnam_r(name.string, &password, buffer, length, &pointer);
 
       if (result) {
@@ -381,9 +373,7 @@ extern "C" {
         }
       }
       else {
-        if (!pointer) {
-          return F_exist_not;
-        }
+        if (!pointer) return F_exist_not;
 
         *id = password.pw_uid;
 
@@ -408,9 +398,7 @@ extern "C" {
       return F_status_set_error(F_failure);
     }
 
-    if (!pointer) {
-      return F_exist_not;
-    }
+    if (!pointer) return F_exist_not;
 
     *id = password.pw_uid;
 
@@ -445,6 +433,7 @@ extern "C" {
       errno = 0;
 
       char buffer[length];
+
       const int result = getpwuid_r(id, &password, buffer, length, &pointer);
 
       if (result) {
@@ -462,13 +451,13 @@ extern "C" {
         }
       }
       else {
-        if (!pointer) {
-          return F_exist_not;
-        }
+        if (!pointer) return F_exist_not;
 
         const f_array_length_t name_length = strnlen(password.pw_name, length);
 
-        status = f_string_dynamic_resize(name_length + 1, name);
+        name->used = 0;
+
+        status = f_string_dynamic_increase_by(name_length + 1, name);
         if (F_status_is_error(status)) return status;
 
         memcpy(name->string, password.pw_name, sizeof(f_char_t) * name_length);
@@ -497,13 +486,13 @@ extern "C" {
       return F_status_set_error(F_failure);
     }
 
-    if (!pointer) {
-      return F_exist_not;
-    }
+    if (!pointer) return F_exist_not;
 
     const f_array_length_t name_length = strnlen(password.pw_name, length);
 
-    status = f_string_dynamic_resize(name_length + 1, name);
+    name->used = 0;
+
+    status = f_string_dynamic_increase_by(name_length + 1, name);
     if (F_status_is_error(status)) return status;
 
     memcpy(name->string, password.pw_name, sizeof(f_char_t) * name_length);
index a73903806ab630aef41b873d3ddc056dbb54d425..4a39dbb175c69c9255496f31e4b193b32fb62ecf 100644 (file)
@@ -27,6 +27,7 @@
 
 // FLL-0 account includes.
 #include <fll/level_0/account/common.h>
+#include <fll/level_0/account/accounts.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -53,7 +54,12 @@ extern "C" {
  *   F_parameter (with error bit) if a parameter is invalid.
  *   F_failure (with error bit) on any other error.
  *
+ *   Errors (with error bit) from f_string_dynamic_increase_by().
+ *
  * @see getpwuid_r()
+ * @see sysconf()
+ *
+ * @see f_string_dynamic_increase_by()
  */
 #ifndef _di_f_account_by_id_
   extern f_status_t f_account_by_id(const uid_t id, f_account_t * const account);
@@ -81,7 +87,11 @@ extern "C" {
  *   F_parameter (with error bit) if a parameter is invalid.
  *   F_failure (with error bit) on any other error.
  *
+ *   Errors (with error bit) from f_string_dynamic_increase_by().
+ *
  * @see getpwnam_r()
+ *
+ * @see f_string_dynamic_increase_by()
  */
 #ifndef _di_f_account_by_name_
   extern f_status_t f_account_by_name(const f_string_static_t name, f_account_t * const account);
@@ -135,7 +145,11 @@ extern "C" {
  *   F_parameter (with error bit) if a parameter is invalid.
  *   F_failure (with error bit) on any other error.
  *
+ *   Errors (with error bit) from f_string_dynamic_increase_by().
+ *
  * @see getgrgid_r()
+ *
+ * @see f_string_dynamic_increase_by()
  */
 #ifndef _di_f_account_group_name_by_id_
   extern f_status_t f_account_group_name_by_id(const gid_t id, f_string_dynamic_t * const name);
@@ -189,7 +203,11 @@ extern "C" {
  *   F_parameter (with error bit) if a parameter is invalid.
  *   F_failure (with error bit) on any other error.
  *
+ *   Errors (with error bit) from f_string_dynamic_increase_by().
+ *
  * @see getpwuid_r()
+ *
+ * @see f_string_dynamic_increase_by()
  */
 #ifndef _di_f_account_name_by_id_
   extern f_status_t f_account_name_by_id(const uid_t id, f_string_dynamic_t * const name);
diff --git a/level_0/f_account/c/account/accounts.c b/level_0/f_account/c/account/accounts.c
new file mode 100644 (file)
index 0000000..c821044
--- /dev/null
@@ -0,0 +1,298 @@
+#include "../account.h"
+#include "accounts.h"
+#include "private-accounts.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef _di_f_account_delete_
+  f_status_t f_account_delete(f_account_t *account) {
+    #ifndef _di_level_0_parameter_checking_
+      if (!account) return F_status_set_error(F_parameter);
+    #endif // _di_level_0_parameter_checking_
+
+    return private_f_account_delete(account);
+  }
+#endif // _di_f_account_delete_
+
+#ifndef _di_f_account_destroy_
+  f_status_t f_account_destroy(f_account_t *account) {
+    #ifndef _di_level_0_parameter_checking_
+      if (!account) return F_status_set_error(F_parameter);
+    #endif // _di_level_0_parameter_checking_
+
+    return private_f_account_destroy(account);
+  }
+#endif // _di_f_account_destroy_
+
+#ifndef _di_f_accounts_adjust_
+  f_status_t f_accounts_adjust(const f_array_length_t length, f_accounts_t *accounts) {
+    #ifndef _di_level_0_parameter_checking_
+      if (!accounts) return F_status_set_error(F_parameter);
+    #endif // _di_level_0_parameter_checking_
+
+    return private_f_accounts_adjust(length, accounts);
+  }
+#endif // _di_f_accounts_adjust_
+
+#ifndef _di_f_accounts_append_
+  f_status_t f_accounts_append(const f_account_t source, f_accounts_t *destination) {
+    #ifndef _di_level_0_parameter_checking_
+      if (!destination) return F_status_set_error(F_parameter);
+    #endif // _di_level_0_parameter_checking_
+
+    return private_f_accounts_append(source, destination);
+  }
+#endif // _di_f_accounts_append_
+
+#ifndef _di_f_accounts_append_all_
+  f_status_t f_accounts_append_all(const f_accounts_t source, f_accounts_t *destination) {
+    #ifndef _di_level_0_parameter_checking_
+      if (!destination) return F_status_set_error(F_parameter);
+    #endif // _di_level_0_parameter_checking_
+
+    if (!source.used) return F_data_not;
+
+    return private_f_accounts_append_all(source, destination);
+  }
+#endif // _di_f_accounts_append_all_
+
+#ifndef _di_f_accounts_decimate_by_
+  f_status_t f_accounts_decimate_by(const f_array_length_t amount, f_accounts_t *accounts) {
+    #ifndef _di_level_0_parameter_checking_
+      if (!accounts) return F_status_set_error(F_parameter);
+    #endif // _di_level_0_parameter_checking_
+
+    if (!amount) return F_data_not;
+
+    if (accounts->size - amount > 0) {
+      return private_f_accounts_adjust(accounts->size - amount, accounts);
+    }
+
+    return private_f_accounts_adjust(0, accounts);
+  }
+#endif // _di_f_accounts_decimate_by_
+
+#ifndef _di_f_accounts_decrease_by_
+  f_status_t f_accounts_decrease_by(const f_array_length_t amount, f_accounts_t *accounts) {
+    #ifndef _di_level_0_parameter_checking_
+      if (!accounts) return F_status_set_error(F_parameter);
+    #endif // _di_level_0_parameter_checking_
+
+    if (!amount) return F_data_not;
+
+    if (accounts->size - amount > 0) {
+      return private_f_accounts_resize(accounts->size - amount, accounts);
+    }
+
+    return private_f_accounts_resize(0, accounts);
+  }
+#endif // _di_f_accounts_decrease_by_
+
+#ifndef _di_f_accounts_increase_
+  f_status_t f_accounts_increase(const f_array_length_t step, f_accounts_t *accounts) {
+    #ifndef _di_level_0_parameter_checking_
+      if (!accounts) return F_status_set_error(F_parameter);
+    #endif // _di_level_0_parameter_checking_
+
+    if (step && accounts->used + 1 > accounts->size) {
+      f_array_length_t size = accounts->used + step;
+
+      if (size > F_array_length_t_size_d) {
+        if (accounts->used + 1 > F_array_length_t_size_d) {
+          return F_status_set_error(F_array_too_large);
+        }
+
+        size = F_array_length_t_size_d;
+      }
+
+      return private_f_accounts_resize(size, accounts);
+    }
+
+    return F_data_not;
+  }
+#endif // _di_f_accounts_increase_
+
+#ifndef _di_f_accounts_increase_by_
+  f_status_t f_accounts_increase_by(const f_array_length_t amount, f_accounts_t *accounts) {
+    #ifndef _di_level_0_parameter_checking_
+      if (!accounts) return F_status_set_error(F_parameter);
+    #endif // _di_level_0_parameter_checking_
+
+    if (!amount) return F_data_not;
+
+    if (accounts->used + amount > accounts->size) {
+      if (accounts->used + amount > F_array_length_t_size_d) {
+        return F_status_set_error(F_array_too_large);
+      }
+
+      return private_f_accounts_resize(accounts->used + amount, accounts);
+    }
+
+    return F_data_not;
+  }
+#endif // _di_f_accounts_increase_by_
+
+#ifndef _di_f_accounts_resize_
+  f_status_t f_accounts_resize(const f_array_length_t length, f_accounts_t *accounts) {
+    #ifndef _di_level_0_parameter_checking_
+      if (!accounts) return F_status_set_error(F_parameter);
+    #endif // _di_level_0_parameter_checking_
+
+    return private_f_accounts_resize(length, accounts);
+  }
+#endif // _di_f_accounts_resize_
+
+#ifndef _di_f_accountss_adjust_
+  f_status_t f_accountss_adjust(const f_array_length_t length, f_accountss_t *accountss) {
+    #ifndef _di_level_0_parameter_checking_
+      if (!accountss) return F_status_set_error(F_parameter);
+    #endif // _di_level_0_parameter_checking_
+
+    return private_f_accountss_adjust(length, accountss);
+  }
+#endif // _di_f_accountss_adjust_
+
+#ifndef _di_f_accountss_append_
+  f_status_t f_accountss_append(const f_accounts_t source, f_accountss_t *destination) {
+    #ifndef _di_level_0_parameter_checking_
+      if (!destination) return F_status_set_error(F_parameter);
+    #endif // _di_level_0_parameter_checking_
+
+    if (!source.used) return F_data_not;
+
+    f_status_t status = F_none;
+
+    if (destination->used + 1 > destination->size) {
+      status = private_f_accountss_resize(destination->used + F_memory_default_allocation_small_d, destination);
+      if (F_status_is_error(status)) return status;
+    }
+
+    status = private_f_accounts_append_all(source, &destination->array[destination->used]);
+    if (F_status_is_error(status)) return status;
+
+    ++destination->used;
+
+    return F_none;
+  }
+#endif // _di_f_accountss_append_
+
+#ifndef _di_f_accountss_append_all_
+  f_status_t f_accountss_append_all(const f_accountss_t source, f_accountss_t *destination) {
+    #ifndef _di_level_0_parameter_checking_
+      if (!destination) return F_status_set_error(F_parameter);
+    #endif // _di_level_0_parameter_checking_
+
+    if (!source.used) return F_data_not;
+
+    f_status_t status = F_none;
+
+    if (destination->used + source.used > destination->size) {
+      status = private_f_accountss_resize(destination->used + source.used, destination);
+      if (F_status_is_error(status)) return status;
+    }
+
+    for (f_array_length_t i = 0; i < source.used; ++i, ++destination->used) {
+
+      destination->array[destination->used].used = 0;
+
+      if (source.array[i].used) {
+        status = private_f_accounts_append_all(source.array[i], &destination->array[destination->used]);
+        if (F_status_is_error(status)) return status;
+      }
+    } // for
+
+    return F_none;
+  }
+#endif // _di_f_accountss_append_all_
+
+#ifndef _di_f_accountss_decimate_by_
+  f_status_t f_accountss_decimate_by(const f_array_length_t amount, f_accountss_t *accountss) {
+    #ifndef _di_level_0_parameter_checking_
+      if (!accountss) return F_status_set_error(F_parameter);
+    #endif // _di_level_0_parameter_checking_
+
+    if (!amount) return F_data_not;
+
+    if (accountss->size - amount > 0) {
+      return private_f_accountss_adjust(accountss->size - amount, accountss);
+    }
+
+    return private_f_accountss_adjust(0, accountss);
+  }
+#endif // _di_f_accountss_decimate_by_
+
+#ifndef _di_f_accountss_decrease_by_
+  f_status_t f_accountss_decrease_by(const f_array_length_t amount, f_accountss_t *accountss) {
+    #ifndef _di_level_0_parameter_checking_
+      if (!accountss) return F_status_set_error(F_parameter);
+    #endif // _di_level_0_parameter_checking_
+
+    if (!amount) return F_data_not;
+
+    if (accountss->size - amount > 0) {
+      return private_f_accountss_resize(accountss->size - amount, accountss);
+    }
+
+    return private_f_accountss_resize(0, accountss);
+  }
+#endif // _di_f_accountss_decrease_by_
+
+#ifndef _di_f_accountss_increase_
+  f_status_t f_accountss_increase(const f_array_length_t step, f_accountss_t *accountss) {
+    #ifndef _di_level_0_parameter_checking_
+      if (!accountss) return F_status_set_error(F_parameter);
+    #endif // _di_level_0_parameter_checking_
+
+    if (step && accountss->used + 1 > accountss->size) {
+      f_array_length_t size = accountss->used + step;
+
+      if (size > F_array_length_t_size_d) {
+        if (accountss->used + 1 > F_array_length_t_size_d) {
+          return F_status_set_error(F_array_too_large);
+        }
+
+        size = F_array_length_t_size_d;
+      }
+
+      return private_f_accountss_resize(size, accountss);
+    }
+
+    return F_data_not;
+  }
+#endif // _di_f_accountss_increase_
+
+#ifndef _di_f_accountss_increase_by_
+  f_status_t f_accountss_increase_by(const f_array_length_t amount, f_accountss_t *accountss) {
+    #ifndef _di_level_0_parameter_checking_
+      if (!accountss) return F_status_set_error(F_parameter);
+    #endif // _di_level_0_parameter_checking_
+
+    if (!amount) return F_data_not;
+
+    if (accountss->used + amount > accountss->size) {
+      if (accountss->used + amount > F_array_length_t_size_d) {
+        return F_status_set_error(F_array_too_large);
+      }
+
+      return private_f_accountss_resize(accountss->used + amount, accountss);
+    }
+
+    return F_data_not;
+  }
+#endif // _di_f_accountss_increase_by_
+
+#ifndef _di_f_accountss_resize_
+  f_status_t f_accountss_resize(const f_array_length_t length, f_accountss_t *accountss) {
+    #ifndef _di_level_0_parameter_checking_
+      if (!accountss) return F_status_set_error(F_parameter);
+    #endif // _di_level_0_parameter_checking_
+
+    return private_f_accountss_resize(length, accountss);
+  }
+#endif // _di_f_accountss_resize_
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_account/c/account/accounts.h b/level_0/f_account/c/account/accounts.h
new file mode 100644 (file)
index 0000000..4e98120
--- /dev/null
@@ -0,0 +1,475 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Account
+ * API Version: 0.7
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Defines data to be used for/by account (array) related functionality.
+ *
+ * This is auto-included by account.h and should not need to be explicitly included.
+ */
+#ifndef _F_accounts_h
+#define _F_accounts_h
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Delete the account.
+ *
+ * @param account
+ *   The account to delete.
+ *
+ * @return
+ *   F_none on success.
+ *
+ *   F_parameter (with error bit) if a parameter is invalid.
+ *
+ *   Errors (with error bit) from: f_string_dynamic_resize().
+ *
+ * @see f_string_dynamic_resize()
+ */
+#ifndef _di_f_account_delete_
+  extern f_status_t f_account_delete(f_account_t *account);
+#endif // _di_f_account_delete_
+
+/**
+ * Destroy the account.
+ *
+ * @param account
+ *   The account to delete.
+ *
+ * @return
+ *   F_none on success.
+ *
+ *   F_parameter (with error bit) if a parameter is invalid.
+ *
+ *   Errors (with error bit) from: f_string_dynamic_adjust().
+ *
+ * @see f_string_dynamic_adjust()
+ */
+#ifndef _di_f_account_destroy_
+  extern f_status_t f_account_destroy(f_account_t *account);
+#endif // _di_f_account_destroy_
+
+/**
+ * Resize the accounts array.
+ *
+ * @param length
+ *   The new size to use.
+ * @param accounts
+ *   The accounts array to resize.
+ *
+ * @return
+ *   F_none on success.
+ *
+ *   F_parameter (with error bit) if a parameter is invalid.
+ *
+ *   Errors (with error bit) from: f_memory_adjust().
+ *   Errors (with error bit) from: f_string_dynamic_adjust().
+ *
+ * @see f_memory_adjust()
+ * @see f_string_dynamic_adjust()
+ */
+#ifndef _di_f_accounts_adjust_
+  extern f_status_t f_accounts_adjust(const f_array_length_t length, f_accounts_t *accounts);
+#endif // _di_f_accounts_adjust_
+
+/**
+ * Append the single source account onto the destination.
+ *
+ * @param source
+ *   The source account to append.
+ * @param destination
+ *   The destination accounts the source is appended onto.
+ *
+ * @return
+ *   F_none on success.
+ *   F_data_not on success, but there is nothing to append (size == 0).
+ *
+ *   F_parameter (with error bit) if a parameter is invalid.
+ *
+ *   Errors (with error bit) from: f_memory_resize().
+ *   Errors (with error bit) from: f_string_dynamic_append().
+ *
+ * @see f_memory_resize()
+ * @see f_string_dynamic_append()
+ */
+#ifndef _di_f_accounts_append_
+  extern f_status_t f_accounts_append(const f_account_t source, f_accounts_t *destination);
+#endif // _di_f_accounts_append_
+
+/**
+ * Append the source accounts onto the destination.
+ *
+ * @param source
+ *   The source accounts to append.
+ * @param destination
+ *   The destination accounts the source is appended onto.
+ *
+ * @return
+ *   F_none on success.
+ *   F_data_not on success, but there is nothing to append (size == 0).
+ *
+ *   F_parameter (with error bit) if a parameter is invalid.
+ *
+ *   Errors (with error bit) from: f_memory_resize().
+ *   Errors (with error bit) from: f_string_dynamic_append().
+ *
+ * @see f_memory_resize()
+ * @see f_string_dynamic_append()
+ */
+#ifndef _di_f_accounts_append_all_
+  extern f_status_t f_accounts_append_all(const f_accounts_t source, f_accounts_t *destination);
+#endif // _di_f_accounts_append_all_
+
+/**
+ * Resize the accounts array to a smaller size.
+ *
+ * This will resize making the array smaller based on (size - given length).
+ * If the given length is too small, then the resize will fail.
+ * This will not shrink the size to les than 0.
+ *
+ * @param amount
+ *   A positive number representing how much to decimate the size by.
+ * @param accounts
+ *   The accounts array to resize.
+ *
+ * @return
+ *   F_none on success.
+ *   F_data_not if amount is 0.
+ *
+ *   F_parameter (with error bit) if a parameter is invalid.
+ *
+ *   Errors (with error bit) from: f_memory_adjust().
+ *   Errors (with error bit) from: f_string_dynamic_adjust().
+ *
+ * @see f_memory_adjust()
+ * @see f_string_dynamic_adjust()
+ */
+#ifndef _di_f_accounts_decimate_by_
+  extern f_status_t f_accounts_decimate_by(const f_array_length_t amount, f_accounts_t *accounts);
+#endif // _di_f_accounts_decimate_by_
+
+/**
+ * Resize the accounts array to a smaller size.
+ *
+ * This will resize making the array smaller based on (size - given length).
+ * If the given length is too small, then the resize will fail.
+ * This will not shrink the size to les than 0.
+ *
+ * @param amount
+ *   A positive number representing how much to decrease the size by.
+ * @param accounts
+ *   The accounts array to resize.
+ *
+ * @return
+ *   F_none on success.
+ *   F_data_not if amount is 0.
+ *
+ *   F_parameter (with error bit) if a parameter is invalid.
+ *
+ *   Errors (with error bit) from: f_memory_resize().
+ *   Errors (with error bit) from: f_string_dynamic_resize().
+ *
+ * @see f_memory_resize()
+ * @see f_string_dynamic_resize()
+ */
+#ifndef _di_f_accounts_decrease_by_
+  extern f_status_t f_accounts_decrease_by(const f_array_length_t amount, f_accounts_t *accounts);
+#endif // _di_f_accounts_decrease_by_
+
+/**
+ * Increase the size of the accounts array, but only if necesary.
+ *
+ * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d).
+ * If already set to the maximum buffer size, then the resize will fail.
+ *
+ * @param step
+ *   The allocation step to use.
+ *   Must be greater than 0.
+ * @param accounts
+ *   The accounts array to resize.
+ *
+ * @return
+ *   F_none on success.
+ *   F_data_not on success, but there is no reason to increase size (used + 1 <= size).
+ *
+ *   F_array_too_large (with error bit) if the new array length is too large.
+ *   F_parameter (with error bit) if a parameter is invalid.
+ *
+ *   Errors (with error bit) from: f_memory_resize().
+ *   Errors (with error bit) from: f_string_dynamic_resize().
+ *
+ * @see f_memory_resize()
+ * @see f_string_dynamic_resize()
+ */
+#ifndef _di_f_accounts_increase_
+  extern f_status_t f_accounts_increase(const f_array_length_t step, f_accounts_t *accounts);
+#endif // _di_f_accounts_increase_
+
+/**
+ * Resize the accounts array to a larger size.
+ *
+ * This will resize making the string larger based on the given length.
+ * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d).
+ * If already set to the maximum buffer size, then the resize will fail.
+ *
+ * @param amount
+ *   A positive number representing how much to increase the size by.
+ * @param accounts
+ *   The accounts array to resize.
+ *
+ * @return
+ *   F_none on success.
+ *   F_data_not on success, but there is no reason to increase size (used + amount <= size).
+ *
+ *   F_array_too_large (with error bit) if the new array length is too large.
+ *   F_parameter (with error bit) if a parameter is invalid.
+ *
+ *   Errors (with error bit) from: f_memory_resize().
+ *   Errors (with error bit) from: f_string_dynamic_resize().
+ *
+ * @see f_memory_resize()
+ * @see f_string_dynamic_resize()
+ */
+#ifndef _di_f_accounts_increase_by_
+  extern f_status_t f_accounts_increase_by(const f_array_length_t amount, f_accounts_t *accounts);
+#endif // _di_f_accounts_increase_by_
+
+/**
+ * Resize the accounts array.
+ *
+ * @param length
+ *   The new size to use.
+ * @param accounts
+ *   The accounts array to adjust.
+ *
+ * @return
+ *   F_none on success.
+ *
+ *   F_parameter (with error bit) if a parameter is invalid.
+ *
+ *   Errors (with error bit) from: f_memory_resize().
+ *   Errors (with error bit) from: f_string_dynamic_resize().
+ *
+ * @see f_memory_resize()
+ * @see f_string_dynamic_resize()
+ */
+#ifndef _di_f_accounts_resize_
+  extern f_status_t f_accounts_resize(const f_array_length_t length, f_accounts_t *accounts);
+#endif // _di_f_accounts_resize_
+
+/**
+ * Resize the string accountss array.
+ *
+ * @param length
+ *   The new size to use.
+ * @param accountss
+ *   The string accountss array to resize.
+ *
+ * @return
+ *   F_none on success.
+ *
+ *   F_parameter (with error bit) if a parameter is invalid.
+ *
+ *   Errors (with error bit) from: f_memory_adjust().
+ *   Errors (with error bit) from: f_string_dynamic_adjust().
+ *
+ * @see f_memory_adjust()
+ * @see f_string_dynamic_adjust()
+ */
+#ifndef _di_f_accountss_adjust_
+  extern f_status_t f_accountss_adjust(const f_array_length_t length, f_accountss_t *accountss);
+#endif // _di_f_accountss_adjust_
+
+/**
+ * Append the single source accounts onto the destination.
+ *
+ * @param source
+ *   The source accounts to append.
+ * @param destination
+ *   The destination ranges the source is appended onto.
+ *
+ * @return
+ *   F_none on success.
+ *   F_data_not on success, but there is nothing to append (size == 0).
+ *
+ *   F_parameter (with error bit) if a parameter is invalid.
+ *
+ *   Errors (with error bit) from: f_memory_resize().
+ *   Errors (with error bit) from: f_string_dynamic_resize().
+ *
+ * @see f_memory_resize()
+ * @see f_string_dynamic_resize()
+ */
+#ifndef _di_f_accountss_append_
+  extern f_status_t f_accountss_append(const f_accounts_t source, f_accountss_t *destination);
+#endif // _di_f_accountss_append_
+
+/**
+ * Append the source accountss onto the destination.
+ *
+ * @param source
+ *   The source accountss to append.
+ * @param destination
+ *   The destination ranges the source is appended onto.
+ *
+ * @return
+ *   F_none on success.
+ *   F_data_not on success, but there is nothing to append (size == 0).
+ *
+ *   F_parameter (with error bit) if a parameter is invalid.
+ *
+ *   Errors (with error bit) from: f_memory_resize().
+ *   Errors (with error bit) from: f_string_dynamic_resize().
+ *
+ * @see f_memory_resize()
+ * @see f_string_dynamic_resize()
+ */
+#ifndef _di_f_accountss_append_all_
+  extern f_status_t f_accountss_append_all(const f_accountss_t source, f_accountss_t *destination);
+#endif // _di_f_accountss_append_all_
+
+/**
+ * Resize the string accountss array to a smaller size.
+ *
+ * This will resize making the array smaller based on (size - given length).
+ * If the given length is too small, then the resize will fail.
+ * This will not shrink the size to less than 0.
+ *
+ * @param amount
+ *   A positive number representing how much to decimate the size by.
+ * @param accountss
+ *   The string accountss array to resize.
+ *
+ * @return
+ *   F_none on success.
+ *
+ *   F_parameter (with error bit) if a parameter is invalid.
+ *
+ *   Errors (with error bit) from: f_memory_adjust().
+ *   Errors (with error bit) from: f_string_dynamic_adjust().
+ *
+ * @see f_memory_adjust()
+ * @see f_string_dynamic_adjust()
+ */
+#ifndef _di_f_accountss_decimate_by_
+  extern f_status_t f_accountss_decimate_by(const f_array_length_t amount, f_accountss_t *accountss);
+#endif // _di_f_accountss_decimate_by_
+
+/**
+ * Resize the string accountss array to a smaller size.
+ *
+ * This will resize making the array smaller based on (size - given length).
+ * If the given length is too small, then the resize will fail.
+ * This will not shrink the size to less than 0.
+ *
+ * @param amount
+ *   A positive number representing how much to decrease the size by.
+ * @param accountss
+ *   The string accountss array to resize.
+ *
+ * @return
+ *   F_none on success.
+ *
+ *   F_parameter (with error bit) if a parameter is invalid.
+ *
+ *   Errors (with error bit) from: f_memory_resize().
+ *   Errors (with error bit) from: f_string_dynamic_resize().
+ *
+ * @see f_memory_resize()
+ * @see f_string_dynamic_resize()
+ */
+#ifndef _di_f_accountss_decrease_by_
+  extern f_status_t f_accountss_decrease_by(const f_array_length_t amount, f_accountss_t *accountss);
+#endif // _di_f_accountss_decrease_by_
+
+/**
+ * Increase the size of the string accountss array, but only if necessary.
+ *
+ * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d).
+ * If already set to the maximum buffer size, then the resize will fail.
+ *
+ * @param step
+ *   The allocation step to use.
+ *   Must be greater than 0.
+ * @param accountss
+ *   The string accountss array to resize.
+ *
+ * @return
+ *   F_none on success.
+ *   F_data_not on success, but there is no reason to increase size (used + 1 <= size).
+ *
+ *   F_array_too_large (with error bit) if the new array length is too large.
+ *   F_parameter (with error bit) if a parameter is invalid.
+ *
+ *   Errors (with error bit) from: f_memory_resize().
+ *   Errors (with error bit) from: f_string_dynamic_resize().
+ *
+ * @see f_memory_resize()
+ * @see f_string_dynamic_resize()
+ */
+#ifndef _di_f_accountss_increase_
+  extern f_status_t f_accountss_increase(const f_array_length_t step, f_accountss_t *accountss);
+#endif // _di_f_accountss_increase_
+
+/**
+ * Resize the string accountss array to a larger size.
+ *
+ * This will resize making the string larger based on the given length.
+ * If the given length is too large for the buffer, then attempt to set max buffer size (F_array_length_t_size_d).
+ * If already set to the maximum buffer size, then the resize will fail.
+ *
+ * @param amount
+ *   A positive number representing how much to increase the size by.
+ * @param accountss
+ *   The string accountss array to resize.
+ *
+ * @return
+ *   F_none on success.
+ *   F_data_not on success, but there is no reason to increase size (used + amount <= size).
+ *
+ *   F_array_too_large (with error bit) if the new array length is too large.
+ *   F_parameter (with error bit) if a parameter is invalid.
+ *
+ *   Errors (with error bit) from: f_memory_resize().
+ *   Errors (with error bit) from: f_string_dynamic_resize().
+ *
+ * @see f_memory_resize()
+ * @see f_string_dynamic_resize()
+ */
+#ifndef _di_f_accountss_increase_by_
+  extern f_status_t f_accountss_increase_by(const f_array_length_t amount, f_accountss_t *accountss);
+#endif // _di_f_accountss_increase_by_
+
+/**
+ * Resize the string accountss array.
+ *
+ * @param length
+ *   The new size to use.
+ * @param accountss
+ *   The accounts array to adjust.
+ *
+ * @return
+ *   F_none on success.
+ *
+ *   F_parameter (with error bit) if a parameter is invalid.
+ *
+ *   Errors (with error bit) from: f_memory_resize().
+ *   Errors (with error bit) from: f_string_dynamic_resize().
+ *
+ * @see f_memory_resize()
+ * @see f_string_dynamic_resize()
+ */
+#ifndef _di_f_accountss_resize_
+  extern f_status_t f_accountss_resize(const f_array_length_t length, f_accountss_t *accountss);
+#endif // _di_f_accountss_resize_
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // _F_accounts_h
index 00bd9abfb1af5469f163f31d507e9db07d7b773f..c90adf9265aea3f435d7d61c7b66f2d795d5d11d 100644 (file)
@@ -70,19 +70,8 @@ extern "C" {
     macro_f_account_t_clear(account.password); \
     macro_f_account_t_clear(account.shell);
 
-  #define macro_f_account_t_delete_simple(account) \
-    macro_f_string_dynamic_t_delete_simple(account.home); \
-    macro_f_string_dynamic_t_delete_simple(account.label); \
-    macro_f_string_dynamic_t_delete_simple(account.name); \
-    macro_f_string_dynamic_t_delete_simple(account.password); \
-    macro_f_string_dynamic_t_delete_simple(account.shell);
-
-  #define macro_f_account_t_destroy_simple(account) \
-    macro_f_string_dynamic_t_destroy_simple(account.home); \
-    macro_f_string_dynamic_t_destroy_simple(account.label); \
-    macro_f_string_dynamic_t_destroy_simple(account.name); \
-    macro_f_string_dynamic_t_destroy_simple(account.password); \
-    macro_f_string_dynamic_t_destroy_simple(account.shell);
+  #define macro_f_account_t_delete_simple(accounts)  f_account_delete(&accounts);
+  #define macro_f_account_t_destroy_simple(accounts) f_account_destroy(&accounts);
 #endif // _di_f_account_t_
 
 /**
@@ -102,23 +91,57 @@ extern "C" {
 
   #define f_accounts_t_initialize { 0, 0, 0 }
 
-  #define macro_f_accounts_t_initialize(content, size, used) { array, size, used }
+  #define macro_f_accounts_t_initialize(array, size, used) { array, size, used }
   #define macro_f_accounts_t_initialize2(array, length) { array, length, length }
 
-  #define macro_f_accounts_t_clear(accounts) macro_f_memory_structure_clear(accounts)
+  #define macro_f_accounts_t_clear(accounts) macro_f_memory_structures_clear(accounts)
 
-  #define macro_f_string_accounts_t_resize(status, accounts, length) macro_f_memory_structure_resize(status, values, sizeof(f_account_t), length)
-  #define macro_f_string_accounts_t_adjust(status, accounts, length) macro_f_memory_structure_adjust(status, values, sizeof(f_account_t), length)
+  #define macro_f_accounts_t_resize(status, accounts, length) status = f_accounts_resize(length, &accounts);
+  #define macro_f_accounts_t_adjust(status, accounts, length) status = f_accounts_adjust(length, &accounts);
 
-  #define macro_f_string_accounts_t_delete_simple(accounts)  macro_f_memory_structure_delete_simple(values, sizeof(f_account_t), 0)
-  #define macro_f_string_accounts_t_destroy_simple(accounts) macro_f_memory_structure_destroy_simple(values, sizeof(f_account_t), 0)
+  #define macro_f_accounts_t_delete_simple(accounts)  f_accounts_resize(0, &accounts);
+  #define macro_f_accounts_t_destroy_simple(accounts) f_accounts_adjust(0, &accounts);
 
-  #define macro_f_string_accounts_t_increase(status, step, values)      macro_f_memory_structure_increase(status, step, values, f_account_t)
-  #define macro_f_string_accounts_t_increase_by(status, values, amount) macro_f_memory_structure_increase_by(status, values, f_account_t, amount)
-  #define macro_f_string_accounts_t_decrease_by(status, values, amount) macro_f_memory_structure_decrease_by(status, values, f_account_t, amount)
-  #define macro_f_string_accounts_t_decimate_by(status, values, amount) macro_f_memory_structure_decimate_by(status, values, f_account_t, amount)
+  #define macro_f_accounts_t_increase(status, step, accounts)      status = f_accounts_increase(step, &accounts);
+  #define macro_f_accounts_t_increase_by(status, accounts, amount) status = f_accounts_increase_by(amount, &accounts);
+  #define macro_f_accounts_t_decrease_by(status, accounts, amount) status = f_accounts_decrease_by(amount, &accounts);
+  #define macro_f_accounts_t_decimate_by(status, accounts, amount) status = f_accounts_decimate_by(amount, &accounts);
 #endif // _di_f_accounts_t_
 
+/**
+ * An array of f_accounts_t.
+ *
+ * array: The array of f_accounts_t.
+ * size:  Total amount of allocated space.
+ * used:  Total number of allocated spaces used.
+ */
+#ifndef _di_f_accounts_t_
+  typedef struct {
+    f_accounts_t *array;
+
+    f_array_length_t size;
+    f_array_length_t used;
+  } f_accountss_t;
+
+  #define f_accountss_t_initialize { 0, 0, 0 }
+
+  #define macro_f_accountss_t_initialize(array, size, used) { array, size, used }
+  #define macro_f_accountss_t_initialize2(array, length) { array, length, length }
+
+  #define macro_f_accountss_t_clear(accountss) macro_f_memory_structures_clear(accountss)
+
+  #define macro_f_accountss_t_resize(status, accountss, length) status = f_accountss_resize(length, &accountss);
+  #define macro_f_accountss_t_adjust(status, accountss, length) status = f_accountss_adjust(length, &accountss);
+
+  #define macro_f_accountss_t_delete_simple(accountss)  f_accountss_resize(0, &accountss);
+  #define macro_f_accountss_t_destroy_simple(accountss) f_accountss_adjust(0, &accountss);
+
+  #define macro_f_accountss_t_increase(status, step, accountss)      status = f_accountss_increase(step, &accountss);
+  #define macro_f_accountss_t_increase_by(status, accountss, amount) status = f_accountss_increase_by(amount, &accountss);
+  #define macro_f_accountss_t_decrease_by(status, accountss, amount) status = f_accountss_decrease_by(amount, &accountss);
+  #define macro_f_accountss_t_decimate_by(status, accountss, amount) status = f_accountss_decimate_by(amount, &accountss);
+#endif // _di_f_accountss_t_
+
 #ifdef __cplusplus
 } // extern "C"
 #endif
diff --git a/level_0/f_account/c/account/private-accounts.c b/level_0/f_account/c/account/private-accounts.c
new file mode 100644 (file)
index 0000000..a9ba955
--- /dev/null
@@ -0,0 +1,247 @@
+#include "../account.h"
+#include "private-accounts.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if !defined(_di_f_account_delete_) || !defined(_di_f_accounts_resize_) || !defined(_di_f_accounts_append_) || !defined(_di_f_accounts_decimate_by_) || !defined(_di_f_accountss_append_) || !defined(_di_f_accountss_decrease_by_) || !defined(_di_f_accountss_increase_) || !defined(_di_f_accountss_increase_by_) || !defined(_di_f_accountss_resize_)
+  f_status_t private_f_account_delete(f_account_t *account) {
+
+    f_status_t status = f_string_dynamic_resize(0, &account->home);
+    if (F_status_is_error(status)) return status;
+
+    status = f_string_dynamic_resize(0, &account->label);
+    if (F_status_is_error(status)) return status;
+
+    status = f_string_dynamic_resize(0, &account->name);
+    if (F_status_is_error(status)) return status;
+
+    status = f_string_dynamic_resize(0, &account->password);
+    if (F_status_is_error(status)) return status;
+
+    status = f_string_dynamic_resize(0, &account->shell);
+    if (F_status_is_error(status)) return status;
+
+    return F_none;
+  }
+#endif // !defined(_di_f_account_delete_) || !defined(_di_f_accounts_resize_) || !defined(_di_f_accounts_append_) || !defined(_di_f_accounts_decimate_by_) || !defined(_di_f_accountss_append_) || !defined(_di_f_accountss_decrease_by_) || !defined(_di_f_accountss_increase_) || !defined(_di_f_accountss_increase_by_) || !defined(_di_f_accountss_resize_)
+
+#if !defined(_di_f_account_destroy_) || !defined(_di_f_accounts_adjust_) || !defined(_di_f_accounts_decimate_by_) || !defined(_di_f_accountss_adjust_) || !defined(_di_f_accountss_decimate_by_)
+  f_status_t private_f_account_destroy(f_account_t *account) {
+
+    f_status_t status = f_string_dynamic_adjust(0, &account->home);
+    if (F_status_is_error(status)) return status;
+
+    status = f_string_dynamic_adjust(0, &account->label);
+    if (F_status_is_error(status)) return status;
+
+    status = f_string_dynamic_adjust(0, &account->name);
+    if (F_status_is_error(status)) return status;
+
+    status = f_string_dynamic_adjust(0, &account->password);
+    if (F_status_is_error(status)) return status;
+
+    status = f_string_dynamic_adjust(0, &account->shell);
+    if (F_status_is_error(status)) return status;
+
+    return F_none;
+  }
+#endif // !defined(_di_f_account_destroy_) || !defined(_di_f_accounts_adjust_) || !defined(_di_f_accounts_decimate_by_) || !defined(_di_f_accountss_adjust_) || !defined(_di_f_accountss_decimate_by_)
+
+#if !defined(_di_f_accounts_adjust_) || !defined(_di_f_accounts_decimate_by_) || !defined(_di_f_accountss_adjust_) || !defined(_di_f_accountss_decimate_by_)
+  f_status_t private_f_accounts_adjust(const f_array_length_t length, f_accounts_t *accounts) {
+
+    f_status_t status = F_none;
+
+    if (length < accounts->size) {
+      for (f_array_length_t i = length; i < accounts->size; ++i) {
+
+        status = private_f_account_destroy(&accounts->array[i]);
+        if (F_status_is_error(status)) return status;
+      } // for
+    }
+
+    status = f_memory_adjust(accounts->size, length, sizeof(f_account_t), (void **) & accounts->array);
+    if (F_status_is_error(status)) return status;
+
+    accounts->size = length;
+
+    if (accounts->used > accounts->size) {
+      accounts->used = length;
+    }
+
+    return F_none;
+  }
+#endif // !defined(_di_f_accounts_adjust_) || !defined(_di_f_accounts_decimate_by_) || !defined(_di_f_accountss_adjust_) || !defined(_di_f_accountss_decimate_by_)
+
+#if !defined(_di_f_accounts_append_) || !defined(_di_f_accountss_append_)
+  extern f_status_t private_f_accounts_append(const f_account_t source, f_accounts_t *destination) {
+
+    f_status_t status = F_none;
+
+    if (destination->used + 1 > destination->size) {
+      status = private_f_accounts_resize(destination->used + F_memory_default_allocation_small_d, destination);
+      if (F_status_is_error(status)) return status;
+    }
+
+    destination->array[destination->used].home.used = 0;
+    destination->array[destination->used].label.used = 0;
+    destination->array[destination->used].name.used = 0;
+    destination->array[destination->used].password.used = 0;
+    destination->array[destination->used].shell.used = 0;
+
+    status = f_string_dynamic_append(source.home, &destination->array[destination->used].home);
+    if (F_status_is_error(status)) return status;
+
+    status = f_string_dynamic_append(source.label, &destination->array[destination->used].label);
+    if (F_status_is_error(status)) return status;
+
+    status = f_string_dynamic_append(source.name, &destination->array[destination->used].name);
+    if (F_status_is_error(status)) return status;
+
+    status = f_string_dynamic_append(source.password, &destination->array[destination->used].password);
+    if (F_status_is_error(status)) return status;
+
+    status = f_string_dynamic_append(source.shell, &destination->array[destination->used].shell);
+    if (F_status_is_error(status)) return status;
+
+    ++destination->used;
+
+    return F_none;
+  }
+#endif // !defined(_di_f_accounts_append_) || !defined(_di_f_accountss_append_)
+
+#if !defined(_di_f_accounts_append_) || !defined(_di_f_accounts_append_all_) || !defined(_di_f_accountss_append_all_)
+  extern f_status_t private_f_accounts_append_all(const f_accounts_t source, f_accounts_t *destination) {
+
+    f_status_t status = F_none;
+
+    if (destination->used + source.used > destination->size) {
+      status = private_f_accounts_resize(destination->used + source.used, destination);
+      if (F_status_is_error(status)) return status;
+    }
+
+    for (f_array_length_t i = 0; i < source.used; ++i, ++destination->used) {
+
+      destination->array[destination->used].home.used = 0;
+      destination->array[destination->used].label.used = 0;
+      destination->array[destination->used].name.used = 0;
+      destination->array[destination->used].password.used = 0;
+      destination->array[destination->used].shell.used = 0;
+
+      status = f_string_dynamic_append(source.array[i].home, &destination->array[destination->used].home);
+      if (F_status_is_error(status)) return status;
+
+      status = f_string_dynamic_append(source.array[i].label, &destination->array[destination->used].label);
+      if (F_status_is_error(status)) return status;
+
+      status = f_string_dynamic_append(source.array[i].name, &destination->array[destination->used].name);
+      if (F_status_is_error(status)) return status;
+
+      status = f_string_dynamic_append(source.array[i].password, &destination->array[destination->used].password);
+      if (F_status_is_error(status)) return status;
+
+      status = f_string_dynamic_append(source.array[i].shell, &destination->array[destination->used].shell);
+      if (F_status_is_error(status)) return status;
+    } // for
+
+    return F_none;
+  }
+#endif // !defined(_di_f_accounts_append_) || !defined(_di_f_accounts_append_all_) || !defined(_di_f_accountss_append_all_)
+
+#if !defined(_di_f_accounts_resize_) || !defined(_di_f_accounts_append_) || !defined(_di_f_accounts_decimate_by_) || !defined(_di_f_accountss_append_) || !defined(_di_f_accountss_decrease_by_) || !defined(_di_f_accountss_increase_) || !defined(_di_f_accountss_increase_by_) || !defined(_di_f_accountss_resize_)
+  f_status_t private_f_accounts_resize(const f_array_length_t length, f_accounts_t *accounts) {
+
+    f_status_t status = F_none;
+
+    if (length < accounts->size) {
+      for (f_array_length_t i = length; i < accounts->size; ++i) {
+
+        status = f_string_dynamic_resize(0, &accounts->array[i].home);
+        if (F_status_is_error(status)) return status;
+
+        status = f_string_dynamic_resize(0, &accounts->array[i].label);
+        if (F_status_is_error(status)) return status;
+
+        status = f_string_dynamic_resize(0, &accounts->array[i].name);
+        if (F_status_is_error(status)) return status;
+
+        status = f_string_dynamic_resize(0, &accounts->array[i].password);
+        if (F_status_is_error(status)) return status;
+
+        status = f_string_dynamic_resize(0, &accounts->array[i].shell);
+        if (F_status_is_error(status)) return status;
+      } // for
+    }
+
+    status = f_memory_resize(accounts->size, length, sizeof(f_account_t), (void **) & accounts->array);
+    if (F_status_is_error(status)) return status;
+
+    accounts->size = length;
+
+    if (accounts->used > accounts->size) {
+      accounts->used = length;
+    }
+
+    return F_none;
+  }
+#endif // !defined(_di_f_accounts_resize_) || !defined(_di_f_accounts_append_) || !defined(_di_f_accounts_decimate_by_) || !defined(_di_f_accountss_append_) || !defined(_di_f_accountss_decrease_by_) || !defined(_di_f_accountss_increase_) || !defined(_di_f_accountss_increase_by_) || !defined(_di_f_accountss_resize_)
+
+#if !defined(_di_f_accountss_adjust_) || !defined(_di_f_accountss_decimate_by_)
+  f_status_t private_f_accountss_adjust(const f_array_length_t length, f_accountss_t *accountss) {
+
+    f_status_t status = F_none;
+
+    for (f_array_length_t i = length; i < accountss->size; ++i) {
+
+      status = private_f_accounts_adjust(0, &accountss->array[i]);
+      if (F_status_is_error(status)) return status;
+
+      accountss->array[i].size = 0;
+      accountss->array[i].used = 0;
+    } // for
+
+    status = f_memory_adjust(accountss->size, length, sizeof(f_accounts_t), (void **) & accountss->array);
+    if (F_status_is_error(status)) return status;
+
+    accountss->size = length;
+
+    if (accountss->used > accountss->size) {
+      accountss->used = length;
+    }
+
+    return F_none;
+  }
+#endif // !defined(_di_f_accountss_adjust_) || !defined(_di_f_accountss_decimate_by_)
+
+#if !defined(_di_f_accountss_decrease_by_) || !defined(_di_f_accountss_increase_) || !defined(_di_f_accountss_increase_by_) || !defined(_di_f_accountss_resize_)
+  f_status_t private_f_accountss_resize(const f_array_length_t length, f_accountss_t *accountss) {
+
+    f_status_t status = F_none;
+
+    for (f_array_length_t i = length; i < accountss->size; ++i) {
+
+      status = private_f_accounts_resize(0, &accountss->array[i]);
+      if (F_status_is_error(status)) return status;
+
+      accountss->array[i].size = 0;
+      accountss->array[i].used = 0;
+    } // for
+
+    status = f_memory_resize(accountss->size, length, sizeof(f_accounts_t), (void **) & accountss->array);
+    if (F_status_is_error(status)) return status;
+
+    accountss->size = length;
+
+    if (accountss->used > accountss->size) {
+      accountss->used = length;
+    }
+
+    return F_none;
+  }
+#endif // !defined(_di_f_accountss_decrease_by_) || !defined(_di_f_accountss_increase_) || !defined(_di_f_accountss_increase_by_) || !defined(_di_f_accountss_resize_)
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_account/c/account/private-accounts.h b/level_0/f_account/c/account/private-accounts.h
new file mode 100644 (file)
index 0000000..9b624b6
--- /dev/null
@@ -0,0 +1,252 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Account
+ * API Version: 0.7
+ * Licenses: lgpl-2.1-or-later
+ *
+ * These are provided for internal reduction in redundant code.
+ * These should not be exposed/used outside of this project.
+ */
+#ifndef _PRIVATE_F_accounts_h
+#define _PRIVATE_F_accounts_h
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Private implementation for resizing the account.
+ *
+ * Intended to be shared to each of the different implementation variations.
+ *
+ * @param account
+ *   The account to delete.
+ *
+ * @return
+ *   F_none on success.
+ *
+ *   Errors (with error bit) from: f_string_dynamic_resize().
+ *
+ * @see f_string_dynamic_resize()
+ *
+ * @see f_account_delete()
+ * @see f_accounts_append()
+ * @see f_accounts_decimate_by()
+ * @see f_accounts_resize()
+ * @see f_accountss_append()
+ * @see f_accountss_decrease_by()
+ * @see f_accountss_increase()
+ * @see f_accountss_increase_by()
+ * @see f_accountss_resize()
+ */
+#if !defined(_di_f_account_delete_) || !defined(_di_f_accounts_resize_) || !defined(_di_f_accounts_append_) || !defined(_di_f_accounts_decimate_by_) || !defined(_di_f_accountss_append_) || !defined(_di_f_accountss_decrease_by_) || !defined(_di_f_accountss_increase_) || !defined(_di_f_accountss_increase_by_) || !defined(_di_f_accountss_resize_)
+  extern f_status_t private_f_account_delete(f_account_t *account) F_attribute_visibility_internal_d;
+#endif // !defined(_di_f_account_delete_) || !defined(_di_f_accounts_resize_) || !defined(_di_f_accounts_append_) || !defined(_di_f_accounts_decimate_by_) || !defined(_di_f_accountss_append_) || !defined(_di_f_accountss_decrease_by_) || !defined(_di_f_accountss_increase_) || !defined(_di_f_accountss_increase_by_) || !defined(_di_f_accountss_resize_)
+
+/**
+ * Private implementation for resizing the account.
+ *
+ * Intended to be shared to each of the different implementation variations.
+ *
+ * @param account
+ *   The account to delete.
+ *
+ * @return
+ *   F_none on success.
+ *
+ *   Errors (with error bit) from: f_string_dynamic_adjust().
+ *
+ * @see f_string_dynamic_adjust()
+ *
+ * @see f_account_destroy()
+ * @see f_accounts_adjust()
+ * @see f_accounts_decimate_by()
+ * @see f_accountss_adjust()
+ * @see f_accountss_decimate_by()
+ */
+#if !defined(_di_f_account_destroy_) || !defined(_di_f_accounts_adjust_) || !defined(_di_f_accounts_decimate_by_) || !defined(_di_f_accountss_adjust_) || !defined(_di_f_accountss_decimate_by_)
+  extern f_status_t private_f_account_destroy(f_account_t *account) F_attribute_visibility_internal_d;
+#endif // !defined(_di_f_account_destroy_) || !defined(_di_f_accounts_adjust_) || !defined(_di_f_accounts_decimate_by_) || !defined(_di_f_accountss_adjust_) || !defined(_di_f_accountss_decimate_by_)
+
+/**
+ * Private implementation for resizing the accounts array.
+ *
+ * Intended to be shared to each of the different implementation variations.
+ *
+ * @param length
+ *   The length to adjust to.
+ * @param accounts
+ *   The accounts array to adjust.
+ *
+ * @return
+ *   F_none on success.
+ *   F_data_not on success, but there is no reason to increase size (used + 1 <= size).
+ *
+ *   Errors (with error bit) from: f_memory_adjust().
+ *   Errors (with error bit) from: f_string_dynamic_adjust().
+ *
+ * @see f_memory_adjust()
+ * @see f_string_dynamic_adjust()
+ *
+ * @see f_accounts_adjust()
+ * @see f_accounts_decimate_by()
+ * @see f_accountss_adjust()
+ * @see f_accountss_decimate_by()
+ */
+#if !defined(_di_f_accounts_adjust_) || !defined(_di_f_accounts_decimate_by_) || !defined(_di_f_accountss_adjust_) || !defined(_di_f_accountss_decimate_by_)
+  extern f_status_t private_f_accounts_adjust(const f_array_length_t length, f_accounts_t *accounts) F_attribute_visibility_internal_d;
+#endif // !defined(_di_f_accounts_adjust_) || !defined(_di_f_accounts_decimate_by_) || !defined(_di_f_accountss_adjust_) || !defined(_di_f_accountss_decimate_by_)
+
+/**
+ * Private implementation for appending the account array.
+ *
+ * Intended to be shared to each of the different implementation variations.
+ *
+ * @param source
+ *   The source account to append.
+ * @param destination
+ *   The destination lengths the source is appended onto.
+ *
+ * @return
+ *   F_none on success.
+ *
+ *   Errors (with error bit) from: f_memory_resize().
+ *   Errors (with error bit) from: f_string_dynamic_append().
+ *
+ * @see f_memory_resize()
+ * @see f_string_dynamic_append()
+ *
+ * @see f_accounts_append()
+ * @see f_accountss_append()
+ */
+#if !defined(_di_f_accounts_append_) || !defined(_di_f_accountss_append_)
+  extern f_status_t private_f_accounts_append(const f_account_t source, f_accounts_t *destination) F_attribute_visibility_internal_d;
+#endif // !defined(_di_f_accounts_append_) || !defined(_di_f_accountss_append_)
+
+/**
+ * Private implementation for appending the account array.
+ *
+ * Intended to be shared to each of the different implementation variations.
+ *
+ * @param source
+ *   The source accounts to append.
+ * @param destination
+ *   The destination lengths the source is appended onto.
+ *
+ * @return
+ *   F_none on success.
+ *
+ *   Errors (with error bit) from: f_memory_resize().
+ *   Errors (with error bit) from: f_string_dynamic_append().
+ *
+ * @see f_memory_resize()
+ * @see f_string_dynamic_append()
+ *
+ * @see f_accounts_append_all()
+ * @see f_accountss_append()
+ * @see f_accountss_append_all()
+ */
+#if !defined(_di_f_accounts_append_) || !defined(_di_f_accounts_append_all_) || !defined(_di_f_accountss_append_all_)
+  extern f_status_t private_f_accounts_append_all(const f_accounts_t source, f_accounts_t *destination) F_attribute_visibility_internal_d;
+#endif // !defined(_di_f_accounts_append_) || !defined(_di_f_accounts_append_all_) || !defined(_di_f_accountss_append_all_)
+
+/**
+ * Private implementation for resizing the accounts array.
+ *
+ * Intended to be shared to each of the different implementation variations.
+ *
+ * @param length
+ *   The length to adjust to.
+ * @param accounts
+ *   The accounts array to adjust.
+ *
+ * @return
+ *   F_none on success.
+ *   F_data_not on success, but there is no reason to increase size (used + 1 <= size).
+ *
+ *   Errors (with error bit) from: f_memory_resize().
+ *   Errors (with error bit) from: f_string_dynamic_resize().
+ *
+ * @see f_memory_resize()
+ * @see f_string_dynamic_resize()
+ *
+ * @see f_accounts_append()
+ * @see f_accounts_decimate_by()
+ * @see f_accounts_resize()
+ * @see f_accountss_append()
+ * @see f_accountss_decrease_by()
+ * @see f_accountss_increase()
+ * @see f_accountss_increase_by()
+ * @see f_accountss_resize()
+ */
+#if !defined(_di_f_accounts_resize_) || !defined(_di_f_accounts_append_) || !defined(_di_f_accounts_decimate_by_) || !defined(_di_f_accountss_append_) || !defined(_di_f_accountss_decrease_by_) || !defined(_di_f_accountss_increase_) || !defined(_di_f_accountss_increase_by_) || !defined(_di_f_accountss_resize_)
+  extern f_status_t private_f_accounts_resize(const f_array_length_t length, f_accounts_t *accounts) F_attribute_visibility_internal_d;
+#endif // !defined(_di_f_accounts_resize_) || !defined(_di_f_accounts_append_) || !defined(_di_f_accounts_decimate_by_) || !defined(_di_f_accountss_append_) || !defined(_di_f_accountss_decrease_by_) || !defined(_di_f_accountss_increase_) || !defined(_di_f_accountss_increase_by_) || !defined(_di_f_accountss_resize_)
+
+/**
+ * Private implementation for resizing the accountss array.
+ *
+ * Intended to be shared to each of the different implementation variations.
+ *
+ * @param length
+ *   The length to adjust to.
+ * @param accountss
+ *   The accountss array to adjust.
+ *
+ * @return
+ *   F_none on success.
+ *   F_data_not on success, but there is no reason to increase size (used + 1 <= size).
+ *
+ *   F_array_too_large (with error bit) if new length is larger than max array length.
+ *   F_memory_not (with error bit) on out of memory.
+ *   F_parameter (with error bit) if a parameter is invalid.
+ *
+ *   Errors (with error bit) from: f_memory_adjust().
+ *   Errors (with error bit) from: f_string_dynamic_adjust().
+ *
+ * @see f_memory_adjust()
+ * @see f_string_dynamic_adjust()
+ *
+ * @see f_accountss_adjust()
+ * @see f_accountss_decimate_by()
+ */
+#if !defined(_di_f_accountss_adjust_) || !defined(_di_f_accountss_decimate_by_)
+  extern f_status_t private_f_accountss_adjust(const f_array_length_t length, f_accountss_t *accountss) F_attribute_visibility_internal_d;
+#endif // !defined(_di_f_accountss_adjust_) || !defined(_di_f_accountss_decimate_by_)
+
+/**
+ * Private implementation for resizing the accountss array.
+ *
+ * Intended to be shared to each of the different implementation variations.
+ *
+ * @param length
+ *   The length to resize to.
+ * @param accountss
+ *   The accountss array to resize.
+ *
+ * @return
+ *   F_none on success.
+ *   F_data_not on success, but there is no reason to increase size (used + 1 <= size).
+ *
+ *   F_array_too_large (with error bit) if new length is larger than max array length.
+ *   F_memory_not (with error bit) on out of memory.
+ *   F_parameter (with error bit) if a parameter is invalid.
+ *
+ *   Errors (with error bit) from: f_memory_delete().
+ *   Errors (with error bit) from: f_memory_resize().
+ *
+ * @see f_accountss_decrease_by()
+ * @see f_accountss_increase()
+ * @see f_accountss_increase_by()
+ * @see f_accountss_resize()
+ */
+#if !defined(_di_f_accountss_decrease_by_) || !defined(_di_f_accountss_increase_) || !defined(_di_f_accountss_increase_by_) || !defined(_di_f_accountss_resize_)
+  extern f_status_t private_f_accountss_resize(const f_array_length_t length, f_accountss_t *accountss) F_attribute_visibility_internal_d;
+#endif // !defined(_di_f_accountss_decrease_by_) || !defined(_di_f_accountss_increase_) || !defined(_di_f_accountss_increase_by_) || !defined(_di_f_accountss_resize_)
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // _PRIVATE_F_accounts_h
index ff65362cba225bc35e09ae7f67e0307dbdec1b6f..64b0ef3a211413efb2725290ef6cc22c02699da7 100644 (file)
@@ -17,7 +17,9 @@ extern "C" {
     // Account home directory.
     f_array_length_t string_length = strnlen(password.pw_dir, password_length);
 
-    status = f_string_dynamic_resize(string_length + 1, &account->home);
+    account->home.used = 0;
+
+    status = f_string_dynamic_increase_by(string_length + 1, &account->home);
     if (F_status_is_error(status)) return status;
 
     memcpy(account->home.string, password.pw_dir, sizeof(f_char_t) * string_length);
@@ -28,7 +30,9 @@ extern "C" {
     // Account label (gecos).
     string_length = strnlen(password.pw_gecos, password_length);
 
-    status = f_string_dynamic_resize(string_length + 1, &account->label);
+    account->label.used = 0;
+
+    status = f_string_dynamic_increase_by(string_length + 1, &account->label);
     if (F_status_is_error(status)) return status;
 
     memcpy(account->label.string, password.pw_gecos, sizeof(f_char_t) * string_length);
@@ -39,7 +43,9 @@ extern "C" {
     // Account name.
     string_length = strnlen(password.pw_name, password_length);
 
-    status = f_string_dynamic_resize(string_length + 1, &account->name);
+    account->name.used = 0;
+
+    status = f_string_dynamic_increase_by(string_length + 1, &account->name);
     if (F_status_is_error(status)) return status;
 
     memcpy(account->name.string, password.pw_name, sizeof(f_char_t) * string_length);
@@ -50,7 +56,9 @@ extern "C" {
     // Account password directory.
     string_length = strnlen(password.pw_passwd, password_length);
 
-    status = f_string_dynamic_resize(string_length + 1, &account->password);
+    account->password.used = 0;
+
+    status = f_string_dynamic_increase_by(string_length + 1, &account->password);
     if (F_status_is_error(status)) return status;
 
     memcpy(account->password.string, password.pw_passwd, sizeof(f_char_t) * string_length);
@@ -61,7 +69,9 @@ extern "C" {
     // Account shell directory.
     string_length = strnlen(password.pw_shell, password_length);
 
-    status = f_string_dynamic_resize(string_length + 1, &account->shell);
+    account->shell.used = 0;
+
+    status = f_string_dynamic_increase_by(string_length + 1, &account->shell);
     if (F_status_is_error(status)) return status;
 
     memcpy(account->shell.string, password.pw_shell, sizeof(f_char_t) * string_length);
index 30adce143c2f21591c2d5d0cbb0f403530515b60..799fae628416f4d25dc5d654c42ca6aff404d5a4 100644 (file)
@@ -32,9 +32,9 @@ extern "C" {
  * @return
  *   F_none on success.
  *
- *   Errors (with error bit) from f_string_dynamic_resize().
+ *   Errors (with error bit) from f_string_dynamic_increase_by().
  *
- * @see f_string_dynamic_resize()
+ * @see f_string_dynamic_increase_by()
  */
 #if !defined(_di_f_account_by_name_) || !defined(_di_f_account_by_id_)
   extern f_status_t private_f_account_from_passwd(const struct passwd password, const f_array_length_t password_length, f_account_t * const account) F_attribute_visibility_internal_d;
index 985612755919cbfb90703260479d834806e0c567..e510c61f4646abd57bb1ed9ef8127696b76cdc55 100644 (file)
@@ -20,9 +20,9 @@ build_language c
 build_libraries -lc
 build_libraries-individual -lf_memory -lf_string
 
-build_sources_library account.c private-account.c
+build_sources_library account.c private-account.c account/accounts.c account/private-accounts.c
 
-build_sources_headers account.h account/common.h
+build_sources_headers account.h account/accounts.h account/common.h
 
 build_script yes
 build_shared yes
index 066bd5702c7c1207b789a6eefa97f7dce21ba143..c1967b3e632a8ad8df4cb4977017a8e2f2a09aaa 100644 (file)
@@ -30,9 +30,9 @@ build_language c
 build_libraries -lc
 build_libraries-individual -lf_memory -lf_string
 
-build_sources_library account.c private-account.c ../../tests/unit/c/mock-account.c
+build_sources_library account.c private-account.c account/accounts.c account/private-accounts.c ../../tests/unit/c/mock-account.c
 
-build_sources_headers account.h account/common.h
+build_sources_headers account.h account/accounts.h account/common.h
 
 build_script yes
 build_shared yes
index ac55716afc17446a136c4407c38e80584a490183..b76b858736e2ae6ad9de667ec65ca063dd4818c5 100644 (file)
@@ -25,7 +25,10 @@ build_language c
 build_libraries -lc -lcmocka
 build_libraries-individual -lf_memory -lf_string -lf_type_array -lf_account
 
-build_sources_program test-account-by_id.c test-account-by_name.c test-account-group_name_by_id.c test-account-group_id_by_name.c test-account-id_by_name.c test-account-name_by_id.c test-account.c
+build_sources_program test-account-by_id.c test-account-by_name.c test-account-group_name_by_id.c test-account-group_id_by_name.c test-account-id_by_name.c test-account-name_by_id.c
+build_sources_program test-account-s_adjust.c test-account-s_append.c test-account-s_append_all.c test-account-s_decimate_by.c test-account-s_decrease_by.c test-account-s_increase.c test-account-s_increase_by.c test-account-s_resize.c
+build_sources_program test-account-ss_adjust.c test-account-ss_append.c test-account-ss_append_all.c test-account-ss_decimate_by.c test-account-ss_decrease_by.c test-account-ss_increase.c test-account-ss_increase_by.c test-account-ss_resize.c
+build_sources_program test-account.c
 
 build_script no
 build_shared yes
diff --git a/level_0/f_account/tests/unit/c/test-account-s_adjust.c b/level_0/f_account/tests/unit/c/test-account-s_adjust.c
new file mode 100644 (file)
index 0000000..52bbd86
--- /dev/null
@@ -0,0 +1,42 @@
+#include "test-account.h"
+#include "test-account-s_adjust.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_accounts_adjust__parameter_checking(void **state) {
+
+  const int length = 5;
+  f_accounts_t data = f_accounts_t_initialize;
+
+  {
+    const f_status_t status = f_accounts_adjust(length, 0);
+
+    assert_int_equal(status, F_status_set_error(F_parameter));
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, 0);
+  }
+
+  assert_null(data.array);
+}
+
+void test__f_accounts_adjust__works(void **state) {
+
+  const int length = 5;
+  f_accounts_t data = f_accounts_t_initialize;
+
+  {
+    const f_status_t status = f_accounts_adjust(length, &data);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, length);
+  }
+
+  free((void *) data.array);
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_account/tests/unit/c/test-account-s_adjust.h b/level_0/f_account/tests/unit/c/test-account-s_adjust.h
new file mode 100644 (file)
index 0000000..0cf011e
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Type
+ * API Version: 0.7
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the array types in the type project.
+ */
+#ifndef _TEST__F_account_s_adjust
+#define _TEST__F_account_s_adjust
+
+/**
+ * Test that the function correctly fails on invalid parameter.
+ *
+ * @see f_accounts_adjust()
+ */
+extern void test__f_accounts_adjust__parameter_checking(void **state);
+
+/**
+ * Test that the function works.
+ *
+ * @see f_accounts_adjust()
+ */
+extern void test__f_accounts_adjust__works(void **state);
+
+#endif // _TEST__F_account_s_adjust
diff --git a/level_0/f_account/tests/unit/c/test-account-s_append.c b/level_0/f_account/tests/unit/c/test-account-s_append.c
new file mode 100644 (file)
index 0000000..7ce1ba7
--- /dev/null
@@ -0,0 +1,54 @@
+#include "test-account.h"
+#include "test-account-s_append.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_accounts_append__parameter_checking(void **state) {
+
+  const f_account_t data = f_account_t_initialize;
+
+  {
+    const f_status_t status = f_accounts_append(data, 0);
+
+    assert_int_equal(status, F_status_set_error(F_parameter));
+  }
+}
+
+void test__f_accounts_append__works(void **state) {
+
+  f_string_static_t home = macro_f_string_static_t_initialize("home", 0, 4);
+  f_string_static_t label = macro_f_string_static_t_initialize("label", 0, 5);
+  f_string_static_t name = macro_f_string_static_t_initialize("name", 0, 4);
+  f_string_static_t password = macro_f_string_static_t_initialize("password", 0, 8);
+  f_string_static_t shell = macro_f_string_static_t_initialize("shell", 0, 5);
+
+  const f_account_t source = { .home = home, .label = label, .name = name, .password = password, .shell = shell };
+  f_accounts_t destination = f_accounts_t_initialize;
+
+  {
+    const f_status_t status = f_accounts_append(source, &destination);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(destination.used, 1);
+
+    assert_string_equal(destination.array[0].home.string, source.home.string);
+    assert_string_equal(destination.array[0].label.string, source.label.string);
+    assert_string_equal(destination.array[0].name.string, source.name.string);
+    assert_string_equal(destination.array[0].password.string, source.password.string);
+    assert_string_equal(destination.array[0].shell.string, source.shell.string);
+
+    assert_int_equal(destination.array[0].home.used, source.home.used);
+    assert_int_equal(destination.array[0].label.used, source.label.used);
+    assert_int_equal(destination.array[0].name.used, source.name.used);
+    assert_int_equal(destination.array[0].password.used, source.password.used);
+    assert_int_equal(destination.array[0].shell.used, source.shell.used);
+  }
+
+  free((void *) destination.array);
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_account/tests/unit/c/test-account-s_append.h b/level_0/f_account/tests/unit/c/test-account-s_append.h
new file mode 100644 (file)
index 0000000..87ad93e
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Type
+ * API Version: 0.7
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the array types in the type project.
+ */
+#ifndef _TEST__F_account_s_append
+#define _TEST__F_account_s_append
+
+/**
+ * Test that the function correctly fails on invalid parameter.
+ *
+ * @see f_accounts_append()
+ */
+extern void test__f_accounts_append__parameter_checking(void **state);
+
+/**
+ * Test that the function works.
+ *
+ * @see f_accounts_append()
+ */
+extern void test__f_accounts_append__works(void **state);
+
+#endif // _TEST__F_account_s_append
diff --git a/level_0/f_account/tests/unit/c/test-account-s_append_all.c b/level_0/f_account/tests/unit/c/test-account-s_append_all.c
new file mode 100644 (file)
index 0000000..7973b57
--- /dev/null
@@ -0,0 +1,103 @@
+#include "test-account.h"
+#include "test-account-s_append_all.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_accounts_append_all__parameter_checking(void **state) {
+
+  const f_accounts_t data = f_accounts_t_initialize;
+
+  {
+    const f_status_t status = f_accounts_append_all(data, 0);
+
+    assert_int_equal(status, F_status_set_error(F_parameter));
+  }
+}
+
+void test__f_accounts_append_all__returns_data_not(void **state) {
+
+  const int length = 5;
+  f_accounts_t source = f_accounts_t_initialize;
+  f_accounts_t destination = f_accounts_t_initialize;
+
+  {
+    const f_status_t status = f_accounts_resize(length, &source);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(source.used, 0);
+    assert_int_equal(source.size, length);
+  }
+
+  {
+    const f_status_t status = f_accounts_append_all(source, &destination);
+
+    assert_int_equal(status, F_data_not);
+    assert_int_equal(destination.used, 0);
+    assert_int_equal(destination.size, 0);
+    assert_null(destination.array);
+  }
+
+  free((void *) source.array);
+}
+
+void test__f_accounts_append_all__works(void **state) {
+
+  const int length = 5;
+  f_accounts_t source = f_accounts_t_initialize;
+  f_accounts_t destination = f_accounts_t_initialize;
+
+  f_string_static_t home_0 = macro_f_string_static_t_initialize("home_0", 0, 6);
+  f_string_static_t label_0 = macro_f_string_static_t_initialize("label_0", 0, 7);
+  f_string_static_t name_0 = macro_f_string_static_t_initialize("name_0", 0, 6);
+  f_string_static_t password_0 = macro_f_string_static_t_initialize("password_0", 0, 10);
+  f_string_static_t shell_0 = macro_f_string_static_t_initialize("shell_0", 0, 7);
+
+  f_string_static_t home_1 = macro_f_string_static_t_initialize("home_1", 0, 6);
+  f_string_static_t label_1 = macro_f_string_static_t_initialize("label_1", 0, 7);
+  f_string_static_t name_1 = macro_f_string_static_t_initialize("name_1", 0, 6);
+  f_string_static_t password_1 = macro_f_string_static_t_initialize("password_1", 0, 10);
+  f_string_static_t shell_1 = macro_f_string_static_t_initialize("shell_1", 0, 7);
+
+  const f_account_t account_0 = { .home = home_0, .label = label_0, .name = name_0, .password = password_0, .shell = shell_0 };
+  const f_account_t account_1 = { .home = home_1, .label = label_1, .name = name_1, .password = password_1, .shell = shell_1 };
+
+  {
+    const f_status_t status = f_accounts_resize(length, &source);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(source.used, 0);
+    assert_int_equal(source.size, length);
+  }
+
+  memcpy(&source.array[source.used++], (void *) &account_0, sizeof(f_account_t));
+  memcpy(&source.array[source.used++], (void *) &account_1, sizeof(f_account_t));
+
+  {
+    const f_status_t status = f_accounts_append_all(source, &destination);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(destination.used, source.used);
+    assert_int_equal(destination.size, source.used);
+
+    assert_string_equal(destination.array[0].home.string, account_0.home.string);
+    assert_string_equal(destination.array[0].label.string, account_0.label.string);
+    assert_string_equal(destination.array[0].name.string, account_0.name.string);
+    assert_string_equal(destination.array[0].password.string, account_0.password.string);
+    assert_string_equal(destination.array[0].shell.string, account_0.shell.string);
+
+    assert_string_equal(destination.array[1].home.string, account_1.home.string);
+    assert_string_equal(destination.array[1].label.string, account_1.label.string);
+    assert_string_equal(destination.array[1].name.string, account_1.name.string);
+    assert_string_equal(destination.array[1].password.string, account_1.password.string);
+    assert_string_equal(destination.array[1].shell.string, account_1.shell.string);
+  }
+
+  free((void *) source.array);
+  free((void *) destination.array);
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_account/tests/unit/c/test-account-s_append_all.h b/level_0/f_account/tests/unit/c/test-account-s_append_all.h
new file mode 100644 (file)
index 0000000..056fa31
--- /dev/null
@@ -0,0 +1,34 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Type
+ * API Version: 0.7
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the array types in the type project.
+ */
+#ifndef _TEST__F_account_s_append_all
+#define _TEST__F_account_s_append_all
+
+/**
+ * Test that the function correctly fails on invalid parameter.
+ *
+ * @see f_accounts_append_all()
+ */
+extern void test__f_accounts_append_all__parameter_checking(void **state);
+
+/**
+ * Test that the function returns F_data_not.
+ *
+ * @see f_accounts_append_all()
+ */
+extern void test__f_accounts_append_all__returns_data_not(void **state);
+
+/**
+ * Test that the function works.
+ *
+ * @see f_accounts_append_all()
+ */
+extern void test__f_accounts_append_all__works(void **state);
+
+#endif // _TEST__F_account_s_append_all
diff --git a/level_0/f_account/tests/unit/c/test-account-s_decimate_by.c b/level_0/f_account/tests/unit/c/test-account-s_decimate_by.c
new file mode 100644 (file)
index 0000000..063d1f0
--- /dev/null
@@ -0,0 +1,74 @@
+#include "test-account.h"
+#include "test-account-s_decimate_by.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_accounts_decimate_by__parameter_checking(void **state) {
+
+  const int length = 5;
+  f_accounts_t data = f_accounts_t_initialize;
+
+  {
+    const f_status_t status = f_accounts_decimate_by(length, 0);
+
+    assert_int_equal(status, F_status_set_error(F_parameter));
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, 0);
+  }
+
+  assert_null(data.array);
+}
+
+void test__f_accounts_decimate_by__returns_data_not(void **state) {
+
+  const int length = 5;
+  f_accounts_t data = f_accounts_t_initialize;
+
+  {
+    const f_status_t status = f_accounts_resize(length, &data);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, length);
+  }
+
+  {
+    const f_status_t status = f_accounts_decimate_by(0, &data);
+
+    assert_int_equal(status, F_data_not);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, length);
+  }
+
+  free((void *) data.array);
+}
+
+void test__f_accounts_decimate_by__works(void **state) {
+
+  const int length = 5;
+  f_accounts_t data = f_accounts_t_initialize;
+
+  {
+    const f_status_t status = f_accounts_resize(length, &data);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, length);
+  }
+
+  {
+    const f_status_t status = f_accounts_decimate_by(length, &data);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, 0);
+  }
+
+  assert_null(data.array);
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_account/tests/unit/c/test-account-s_decimate_by.h b/level_0/f_account/tests/unit/c/test-account-s_decimate_by.h
new file mode 100644 (file)
index 0000000..2c13180
--- /dev/null
@@ -0,0 +1,34 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Type
+ * API Version: 0.7
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the array types in the type project.
+ */
+#ifndef _TEST__F_account_s_decimate_by
+#define _TEST__F_account_s_decimate_by
+
+/**
+ * Test that the function correctly fails on invalid parameter.
+ *
+ * @see f_accounts_decimate_by()
+ */
+extern void test__f_accounts_decimate_by__parameter_checking(void **state);
+
+/**
+ * Test that the function returns F_data_not.
+ *
+ * @see f_accounts_decimate_by()
+ */
+extern void test__f_accounts_decimate_by__returns_data_not(void **state);
+
+/**
+ * Test that the function works.
+ *
+ * @see f_accounts_decimate_by()
+ */
+extern void test__f_accounts_decimate_by__works(void **state);
+
+#endif // _TEST__F_account_s_decimate_by
diff --git a/level_0/f_account/tests/unit/c/test-account-s_decrease_by.c b/level_0/f_account/tests/unit/c/test-account-s_decrease_by.c
new file mode 100644 (file)
index 0000000..7ad19a4
--- /dev/null
@@ -0,0 +1,74 @@
+#include "test-account.h"
+#include "test-account-s_decrease_by.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_accounts_decrease_by__parameter_checking(void **state) {
+
+  const int length = 5;
+  f_accounts_t data = f_accounts_t_initialize;
+
+  {
+    const f_status_t status = f_accounts_decrease_by(length, 0);
+
+    assert_int_equal(status, F_status_set_error(F_parameter));
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, 0);
+  }
+
+  assert_null(data.array);
+}
+
+void test__f_accounts_decrease_by__returns_data_not(void **state) {
+
+  const int length = 5;
+  f_accounts_t data = f_accounts_t_initialize;
+
+  {
+    const f_status_t status = f_accounts_resize(length, &data);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, length);
+  }
+
+  {
+    const f_status_t status = f_accounts_decrease_by(0, &data);
+
+    assert_int_equal(status, F_data_not);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, length);
+  }
+
+  free((void *) data.array);
+}
+
+void test__f_accounts_decrease_by__works(void **state) {
+
+  const int length = 5;
+  f_accounts_t data = f_accounts_t_initialize;
+
+  {
+    const f_status_t status = f_accounts_resize(length, &data);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, length);
+  }
+
+  {
+    const f_status_t status = f_accounts_decrease_by(length, &data);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, 0);
+  }
+
+  assert_null(data.array);
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_account/tests/unit/c/test-account-s_decrease_by.h b/level_0/f_account/tests/unit/c/test-account-s_decrease_by.h
new file mode 100644 (file)
index 0000000..bd6394c
--- /dev/null
@@ -0,0 +1,34 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Type
+ * API Version: 0.7
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the array types in the type project.
+ */
+#ifndef _TEST__F_account_s_decrease_by
+#define _TEST__F_account_s_decrease_by
+
+/**
+ * Test that the function correctly fails on invalid parameter.
+ *
+ * @see f_accounts_decrease_by()
+ */
+extern void test__f_accounts_decrease_by__parameter_checking(void **state);
+
+/**
+ * Test that the function returns F_data_not.
+ *
+ * @see f_accounts_decrease_by()
+ */
+extern void test__f_accounts_decrease_by__returns_data_not(void **state);
+
+/**
+ * Test that the function works.
+ *
+ * @see f_accounts_decrease_by()
+ */
+extern void test__f_accounts_decrease_by__works(void **state);
+
+#endif // _TEST__F_account_s_decrease_by
diff --git a/level_0/f_account/tests/unit/c/test-account-s_increase.c b/level_0/f_account/tests/unit/c/test-account-s_increase.c
new file mode 100644 (file)
index 0000000..e528c88
--- /dev/null
@@ -0,0 +1,76 @@
+#include "test-account.h"
+#include "test-account-s_increase.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_accounts_increase__parameter_checking(void **state) {
+
+  const int length = 5;
+  f_accounts_t data = f_accounts_t_initialize;
+
+  {
+    const f_status_t status = f_accounts_increase(length, 0);
+
+    assert_int_equal(status, F_status_set_error(F_parameter));
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, 0);
+  }
+
+  free((void *) data.array);
+}
+
+void test__f_accounts_increase__returns_data_not(void **state) {
+
+  const int length = 5;
+  f_accounts_t data = f_accounts_t_initialize;
+
+  {
+    const f_status_t status = f_accounts_resize(length, &data);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, length);
+  }
+
+  {
+    const f_status_t status = f_accounts_increase(length, &data);
+
+    assert_int_equal(status, F_data_not);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, length);
+  }
+
+  free((void *) data.array);
+}
+
+void test__f_accounts_increase__works(void **state) {
+
+  const int length = 5;
+  f_accounts_t data = f_accounts_t_initialize;
+
+  {
+    const f_status_t status = f_accounts_resize(length, &data);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, length);
+  }
+
+  {
+    data.used = length;
+
+    const f_status_t status = f_accounts_increase(length, &data);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(data.used, length);
+    assert_in_range(data.size, length + 1, length + 1 + F_memory_default_allocation_small_d);
+  }
+
+  free((void *) data.array);
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_account/tests/unit/c/test-account-s_increase.h b/level_0/f_account/tests/unit/c/test-account-s_increase.h
new file mode 100644 (file)
index 0000000..a953829
--- /dev/null
@@ -0,0 +1,34 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Type
+ * API Version: 0.7
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the array types in the type project.
+ */
+#ifndef _TEST__F_account_s_increase
+#define _TEST__F_account_s_increase
+
+/**
+ * Test that the function correctly fails on invalid parameter.
+ *
+ * @see f_accounts_increase()
+ */
+extern void test__f_accounts_increase__parameter_checking(void **state);
+
+/**
+ * Test that the function returns F_data_not.
+ *
+ * @see f_accounts_increase()
+ */
+extern void test__f_accounts_increase__returns_data_not(void **state);
+
+/**
+ * Test that the function works.
+ *
+ * @see f_accounts_increase()
+ */
+extern void test__f_accounts_increase__works(void **state);
+
+#endif // _TEST__F_account_s_increase
diff --git a/level_0/f_account/tests/unit/c/test-account-s_increase_by.c b/level_0/f_account/tests/unit/c/test-account-s_increase_by.c
new file mode 100644 (file)
index 0000000..c551006
--- /dev/null
@@ -0,0 +1,76 @@
+#include "test-account.h"
+#include "test-account-s_increase_by.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_accounts_increase_by__parameter_checking(void **state) {
+
+  const int length = 5;
+  f_accounts_t data = f_accounts_t_initialize;
+
+  {
+    const f_status_t status = f_accounts_increase_by(length, 0);
+
+    assert_int_equal(status, F_status_set_error(F_parameter));
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, 0);
+  }
+
+  assert_null(data.array);
+}
+
+void test__f_accounts_increase_by__returns_data_not(void **state) {
+
+  const int length = 5;
+  f_accounts_t data = f_accounts_t_initialize;
+
+  {
+    const f_status_t status = f_accounts_resize(length, &data);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, length);
+  }
+
+  {
+    const f_status_t status = f_accounts_increase_by(0, &data);
+
+    assert_int_equal(status, F_data_not);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, length);
+  }
+
+  free((void *) data.array);
+}
+
+void test__f_accounts_increase_by__works(void **state) {
+
+  const int length = 5;
+  f_accounts_t data = f_accounts_t_initialize;
+
+  {
+    const f_status_t status = f_accounts_resize(length, &data);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, length);
+  }
+
+  {
+    data.used = length;
+
+    const f_status_t status = f_accounts_increase_by(length, &data);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(data.used, length);
+    assert_int_equal(data.size, length * 2);
+  }
+
+  free((void *) data.array);
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_account/tests/unit/c/test-account-s_increase_by.h b/level_0/f_account/tests/unit/c/test-account-s_increase_by.h
new file mode 100644 (file)
index 0000000..fc386c4
--- /dev/null
@@ -0,0 +1,34 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Type
+ * API Version: 0.7
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the array types in the type project.
+ */
+#ifndef _TEST__F_account_s_increase_by
+#define _TEST__F_account_s_increase_by
+
+/**
+ * Test that the function correctly fails on invalid parameter.
+ *
+ * @see f_accounts_increase_by()
+ */
+extern void test__f_accounts_increase_by__parameter_checking(void **state);
+
+/**
+ * Test that the function returns F_data_not.
+ *
+ * @see f_accounts_increase_by()
+ */
+extern void test__f_accounts_increase_by__returns_data_not(void **state);
+
+/**
+ * Test that the function works.
+ *
+ * @see f_accounts_increase_by()
+ */
+extern void test__f_accounts_increase_by__works(void **state);
+
+#endif // _TEST__F_account_s_increase_by
diff --git a/level_0/f_account/tests/unit/c/test-account-s_resize.c b/level_0/f_account/tests/unit/c/test-account-s_resize.c
new file mode 100644 (file)
index 0000000..b67cbab
--- /dev/null
@@ -0,0 +1,42 @@
+#include "test-account.h"
+#include "test-account-s_resize.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_accounts_resize__parameter_checking(void **state) {
+
+  const int length = 5;
+  f_accounts_t data = f_accounts_t_initialize;
+
+  {
+    const f_status_t status = f_accounts_resize(length, 0);
+
+    assert_int_equal(status, F_status_set_error(F_parameter));
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, 0);
+  }
+
+  assert_null(data.array);
+}
+
+void test__f_accounts_resize__works(void **state) {
+
+  const int length = 5;
+  f_accounts_t data = f_accounts_t_initialize;
+
+  {
+    const f_status_t status = f_accounts_resize(length, &data);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, length);
+  }
+
+  free((void *) data.array);
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_account/tests/unit/c/test-account-s_resize.h b/level_0/f_account/tests/unit/c/test-account-s_resize.h
new file mode 100644 (file)
index 0000000..9cb047d
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Type
+ * API Version: 0.7
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the array types in the type project.
+ */
+#ifndef _TEST__F_account_s_resize
+#define _TEST__F_account_s_resize
+
+/**
+ * Test that the function correctly fails on invalid parameter.
+ *
+ * @see f_accounts_resize()
+ */
+extern void test__f_accounts_resize__parameter_checking(void **state);
+
+/**
+ * Test that the function works.
+ *
+ * @see f_accounts_resize()
+ */
+extern void test__f_accounts_resize__works(void **state);
+
+#endif // _TEST__F_account_s_resize
diff --git a/level_0/f_account/tests/unit/c/test-account-ss_adjust.c b/level_0/f_account/tests/unit/c/test-account-ss_adjust.c
new file mode 100644 (file)
index 0000000..66360a1
--- /dev/null
@@ -0,0 +1,42 @@
+#include "test-account.h"
+#include "test-account-ss_adjust.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_accountss_adjust__parameter_checking(void **state) {
+
+  const int length = 5;
+  f_accountss_t data = f_accountss_t_initialize;
+
+  {
+    const f_status_t status = f_accountss_adjust(length, 0);
+
+    assert_int_equal(status, F_status_set_error(F_parameter));
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, 0);
+  }
+
+  assert_null(data.array);
+}
+
+void test__f_accountss_adjust__works(void **state) {
+
+  const int length = 5;
+  f_accountss_t data = f_accountss_t_initialize;
+
+  {
+    const f_status_t status = f_accountss_adjust(length, &data);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, length);
+  }
+
+  free((void *) data.array);
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_account/tests/unit/c/test-account-ss_adjust.h b/level_0/f_account/tests/unit/c/test-account-ss_adjust.h
new file mode 100644 (file)
index 0000000..ae4a766
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Type
+ * API Version: 0.7
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the array types in the type project.
+ */
+#ifndef _TEST__F_account_ss_adjust
+#define _TEST__F_account_ss_adjust
+
+/**
+ * Test that the function correctly fails on invalid parameter.
+ *
+ * @see f_accountss_adjust()
+ */
+extern void test__f_accountss_adjust__parameter_checking(void **state);
+
+/**
+ * Test that the function works.
+ *
+ * @see f_accountss_adjust()
+ */
+extern void test__f_accountss_adjust__works(void **state);
+
+#endif // _TEST__F_account_ss_adjust
diff --git a/level_0/f_account/tests/unit/c/test-account-ss_append.c b/level_0/f_account/tests/unit/c/test-account-ss_append.c
new file mode 100644 (file)
index 0000000..f0a0487
--- /dev/null
@@ -0,0 +1,105 @@
+#include "test-account.h"
+#include "test-account-ss_append.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_accountss_append__parameter_checking(void **state) {
+
+  f_accounts_t data = f_accounts_t_initialize;
+
+  {
+    const f_status_t status = f_accountss_append(data, 0);
+
+    assert_int_equal(status, F_status_set_error(F_parameter));
+  }
+}
+
+void test__f_accountss_append__returns_data_not(void **state) {
+
+  const int length = 5;
+  f_accounts_t source = f_accountss_t_initialize;
+  f_accountss_t destination = f_accountss_t_initialize;
+
+  {
+    const f_status_t status = f_accounts_resize(length, &source);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(source.used, 0);
+    assert_int_equal(source.size, length);
+  }
+
+  {
+    const f_status_t status = f_accountss_append(source, &destination);
+
+    assert_int_equal(status, F_data_not);
+    assert_int_equal(destination.used, 0);
+    assert_int_equal(destination.size, 0);
+    assert_null(destination.array);
+  }
+
+  free((void *) source.array);
+}
+
+void test__f_accountss_append__works(void **state) {
+
+  const int length = 5;
+  f_accounts_t sources = f_accounts_t_initialize;
+  f_accountss_t destination = f_accountss_t_initialize;
+
+  f_string_static_t home = macro_f_string_static_t_initialize("home", 0, 4);
+  f_string_static_t label = macro_f_string_static_t_initialize("label", 0, 5);
+  f_string_static_t name = macro_f_string_static_t_initialize("name", 0, 4);
+  f_string_static_t password = macro_f_string_static_t_initialize("password", 0, 8);
+  f_string_static_t shell = macro_f_string_static_t_initialize("shell", 0, 5);
+
+  const f_account_t source = { .home = home, .label = label, .name = name, .password = password, .shell = shell };
+
+  {
+    const f_status_t status = f_accounts_resize(length, &sources);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(sources.used, 0);
+    assert_int_equal(sources.size, length);
+  }
+
+  while (sources.used < length) {
+    memcpy(&sources.array[sources.used++], (void *) &source, sizeof(f_account_t));
+  } // while
+
+  {
+    const f_status_t status = f_accountss_append(sources, &destination);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(destination.used, 1);
+    assert_int_equal(destination.array[0].used, sources.used);
+    assert_int_equal(destination.array[0].size, sources.used);
+
+    for (f_array_length_t i = 0; i < destination.array[0].used; ++i) {
+
+      assert_string_equal(destination.array[0].array[i].home.string, source.home.string);
+      assert_string_equal(destination.array[0].array[i].label.string, source.label.string);
+      assert_string_equal(destination.array[0].array[i].name.string, source.name.string);
+      assert_string_equal(destination.array[0].array[i].password.string, source.password.string);
+      assert_string_equal(destination.array[0].array[i].shell.string, source.shell.string);
+
+      assert_int_equal(destination.array[0].array[i].home.used, source.home.used);
+      assert_int_equal(destination.array[0].array[i].label.used, source.label.used);
+      assert_int_equal(destination.array[0].array[i].name.used, source.name.used);
+      assert_int_equal(destination.array[0].array[i].password.used, source.password.used);
+      assert_int_equal(destination.array[0].array[i].shell.used, source.shell.used);
+    } // for
+  }
+
+  for (f_array_length_t i = 0; i < destination.used; ++i) {
+    free((void *) destination.array[i].array);
+  } // for
+
+  free((void *) sources.array);
+  free((void *) destination.array);
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_account/tests/unit/c/test-account-ss_append.h b/level_0/f_account/tests/unit/c/test-account-ss_append.h
new file mode 100644 (file)
index 0000000..a45dd70
--- /dev/null
@@ -0,0 +1,34 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Type
+ * API Version: 0.7
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the array types in the type project.
+ */
+#ifndef _TEST__F_account_ss_append
+#define _TEST__F_account_ss_append
+
+/**
+ * Test that the function correctly fails on invalid parameter.
+ *
+ * @see f_accountss_append()
+ */
+extern void test__f_accountss_append__parameter_checking(void **state);
+
+/**
+ * Test that the function returns F_data_not.
+ *
+ * @see f_accountss_append()
+ */
+extern void test__f_accountss_append__returns_data_not(void **state);
+
+/**
+ * Test that the function works.
+ *
+ * @see f_accountss_append()
+ */
+extern void test__f_accountss_append__works(void **state);
+
+#endif // _TEST__F_account_ss_append
diff --git a/level_0/f_account/tests/unit/c/test-account-ss_append_all.c b/level_0/f_account/tests/unit/c/test-account-ss_append_all.c
new file mode 100644 (file)
index 0000000..541e0eb
--- /dev/null
@@ -0,0 +1,127 @@
+#include "test-account.h"
+#include "test-account-ss_append_all.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_accountss_append_all__parameter_checking(void **state) {
+
+  const f_accountss_t data = f_accountss_t_initialize;
+
+  {
+    const f_status_t status = f_accountss_append_all(data, 0);
+
+    assert_int_equal(status, F_status_set_error(F_parameter));
+  }
+}
+
+void test__f_accountss_append_all__returns_data_not(void **state) {
+
+  const int length = 5;
+  f_accountss_t source = f_accountss_t_initialize;
+  f_accountss_t destination = f_accountss_t_initialize;
+
+  {
+    const f_status_t status = f_accountss_resize(length, &source);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(source.used, 0);
+    assert_int_equal(source.size, length);
+  }
+
+  {
+    const f_status_t status = f_accountss_append_all(source, &destination);
+
+    assert_int_equal(status, F_data_not);
+    assert_int_equal(destination.used, 0);
+    assert_int_equal(destination.size, 0);
+    assert_null(destination.array);
+  }
+
+  free((void *) source.array);
+}
+
+void test__f_accountss_append_all__works(void **state) {
+
+  const int length = 5;
+  const int length_inner = 2;
+  f_accountss_t source = f_accountss_t_initialize;
+  f_accountss_t destination = f_accountss_t_initialize;
+
+  f_string_static_t home_0 = macro_f_string_static_t_initialize("home_0", 0, 6);
+  f_string_static_t label_0 = macro_f_string_static_t_initialize("label_0", 0, 7);
+  f_string_static_t name_0 = macro_f_string_static_t_initialize("name_0", 0, 6);
+  f_string_static_t password_0 = macro_f_string_static_t_initialize("password_0", 0, 10);
+  f_string_static_t shell_0 = macro_f_string_static_t_initialize("shell_0", 0, 7);
+
+  f_string_static_t home_1 = macro_f_string_static_t_initialize("home_1", 0, 6);
+  f_string_static_t label_1 = macro_f_string_static_t_initialize("label_1", 0, 7);
+  f_string_static_t name_1 = macro_f_string_static_t_initialize("name_1", 0, 6);
+  f_string_static_t password_1 = macro_f_string_static_t_initialize("password_1", 0, 10);
+  f_string_static_t shell_1 = macro_f_string_static_t_initialize("shell_1", 0, 7);
+
+  const f_account_t account_0 = { .home = home_0, .label = label_0, .name = name_0, .password = password_0, .shell = shell_0 };
+  const f_account_t account_1 = { .home = home_1, .label = label_1, .name = name_1, .password = password_1, .shell = shell_1 };
+
+  {
+    const f_status_t status = f_accountss_resize(length, &source);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(source.used, 0);
+    assert_int_equal(source.size, length);
+  }
+
+  {
+    for (; source.used < length; ++source.used) {
+
+      const f_status_t status = f_accounts_resize(length_inner, &source.array[source.used]);
+
+      assert_int_equal(status, F_none);
+
+      memcpy(&source.array[source.used].array[source.array[source.used].used++], (void *) &account_0, sizeof(f_account_t));
+      memcpy(&source.array[source.used].array[source.array[source.used].used++], (void *) &account_1, sizeof(f_account_t));
+    } // for
+  }
+
+  {
+    const f_status_t status = f_accountss_append_all(source, &destination);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(destination.used, source.used);
+    assert_int_equal(destination.size, source.used);
+
+    for (f_array_length_t i = 0; i < destination.used; ++i) {
+
+      assert_int_equal(destination.array[i].used, length_inner);
+        assert_int_equal(destination.array[i].size, length_inner);
+
+      assert_string_equal(destination.array[i].array[0].home.string, account_0.home.string);
+      assert_string_equal(destination.array[i].array[0].label.string, account_0.label.string);
+      assert_string_equal(destination.array[i].array[0].name.string, account_0.name.string);
+      assert_string_equal(destination.array[i].array[0].password.string, account_0.password.string);
+      assert_string_equal(destination.array[i].array[0].shell.string, account_0.shell.string);
+
+      assert_string_equal(destination.array[i].array[1].home.string, account_1.home.string);
+      assert_string_equal(destination.array[i].array[1].label.string, account_1.label.string);
+      assert_string_equal(destination.array[i].array[1].name.string, account_1.name.string);
+      assert_string_equal(destination.array[i].array[1].password.string, account_1.password.string);
+      assert_string_equal(destination.array[i].array[1].shell.string, account_1.shell.string);
+    } // for
+  }
+
+  for (f_array_length_t i = 0; i < source.used; ++i) {
+    free((void *) source.array[i].array);
+  } // for
+
+  for (f_array_length_t i = 0; i < destination.used; ++i) {
+    free((void *) destination.array[i].array);
+  } // for
+
+  free((void *) source.array);
+  free((void *) destination.array);
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_account/tests/unit/c/test-account-ss_append_all.h b/level_0/f_account/tests/unit/c/test-account-ss_append_all.h
new file mode 100644 (file)
index 0000000..a728832
--- /dev/null
@@ -0,0 +1,34 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Type
+ * API Version: 0.7
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the array types in the type project.
+ */
+#ifndef _TEST__F_account_ss_append_all
+#define _TEST__F_account_ss_append_all
+
+/**
+ * Test that the function correctly fails on invalid parameter.
+ *
+ * @see f_accountss_append_all()
+ */
+extern void test__f_accountss_append_all__parameter_checking(void **state);
+
+/**
+ * Test that the function returns F_data_not.
+ *
+ * @see f_accountss_append_all()
+ */
+extern void test__f_accountss_append_all__returns_data_not(void **state);
+
+/**
+ * Test that the function works.
+ *
+ * @see f_accountss_append_all()
+ */
+extern void test__f_accountss_append_all__works(void **state);
+
+#endif // _TEST__F_account_ss_append_all
diff --git a/level_0/f_account/tests/unit/c/test-account-ss_decimate_by.c b/level_0/f_account/tests/unit/c/test-account-ss_decimate_by.c
new file mode 100644 (file)
index 0000000..e9af665
--- /dev/null
@@ -0,0 +1,74 @@
+#include "test-account.h"
+#include "test-account-ss_decimate_by.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_accountss_decimate_by__parameter_checking(void **state) {
+
+  const int length = 5;
+  f_accountss_t data = f_accounts_t_initialize;
+
+  {
+    const f_status_t status = f_accountss_decimate_by(length, 0);
+
+    assert_int_equal(status, F_status_set_error(F_parameter));
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, 0);
+  }
+
+  assert_null(data.array);
+}
+
+void test__f_accountss_decimate_by__returns_data_not(void **state) {
+
+  const int length = 5;
+  f_accountss_t data = f_accountss_t_initialize;
+
+  {
+    const f_status_t status = f_accountss_resize(length, &data);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, length);
+  }
+
+  {
+    const f_status_t status = f_accountss_decimate_by(0, &data);
+
+    assert_int_equal(status, F_data_not);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, length);
+  }
+
+  free((void *) data.array);
+}
+
+void test__f_accountss_decimate_by__works(void **state) {
+
+  const int length = 5;
+  f_accountss_t data = f_accounts_t_initialize;
+
+  {
+    const f_status_t status = f_accountss_resize(length, &data);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, length);
+  }
+
+  {
+    const f_status_t status = f_accountss_decimate_by(length, &data);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, 0);
+  }
+
+  assert_null(data.array);
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_account/tests/unit/c/test-account-ss_decimate_by.h b/level_0/f_account/tests/unit/c/test-account-ss_decimate_by.h
new file mode 100644 (file)
index 0000000..4ac5cc2
--- /dev/null
@@ -0,0 +1,34 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Type
+ * API Version: 0.7
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the array types in the type project.
+ */
+#ifndef _TEST__F_account_ss_decimate_by
+#define _TEST__F_account_ss_decimate_by
+
+/**
+ * Test that the function correctly fails on invalid parameter.
+ *
+ * @see f_accountss_decimate_by()
+ */
+extern void test__f_accountss_decimate_by__parameter_checking(void **state);
+
+/**
+ * Test that the function returns F_data_not.
+ *
+ * @see f_accountss_decimate_by()
+ */
+extern void test__f_accountss_decimate_by__returns_data_not(void **state);
+
+/**
+ * Test that the function works.
+ *
+ * @see f_accountss_decimate_by()
+ */
+extern void test__f_accountss_decimate_by__works(void **state);
+
+#endif // _TEST__F_account_ss_decimate_by
diff --git a/level_0/f_account/tests/unit/c/test-account-ss_decrease_by.c b/level_0/f_account/tests/unit/c/test-account-ss_decrease_by.c
new file mode 100644 (file)
index 0000000..34fc020
--- /dev/null
@@ -0,0 +1,74 @@
+#include "test-account.h"
+#include "test-account-ss_decrease_by.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_accountss_decrease_by__parameter_checking(void **state) {
+
+  const int length = 5;
+  f_accountss_t data = f_accounts_t_initialize;
+
+  {
+    const f_status_t status = f_accountss_decrease_by(length, 0);
+
+    assert_int_equal(status, F_status_set_error(F_parameter));
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, 0);
+  }
+
+  assert_null(data.array);
+}
+
+void test__f_accountss_decrease_by__returns_data_not(void **state) {
+
+  const int length = 5;
+  f_accountss_t data = f_accountss_t_initialize;
+
+  {
+    const f_status_t status = f_accountss_resize(length, &data);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, length);
+  }
+
+  {
+    const f_status_t status = f_accountss_decrease_by(0, &data);
+
+    assert_int_equal(status, F_data_not);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, length);
+  }
+
+  free((void *) data.array);
+}
+
+void test__f_accountss_decrease_by__works(void **state) {
+
+  const int length = 5;
+  f_accountss_t data = f_accounts_t_initialize;
+
+  {
+    const f_status_t status = f_accountss_resize(length, &data);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, length);
+  }
+
+  {
+    const f_status_t status = f_accountss_decrease_by(length, &data);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, 0);
+  }
+
+  assert_null(data.array);
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_account/tests/unit/c/test-account-ss_decrease_by.h b/level_0/f_account/tests/unit/c/test-account-ss_decrease_by.h
new file mode 100644 (file)
index 0000000..cdf0b2c
--- /dev/null
@@ -0,0 +1,34 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Type
+ * API Version: 0.7
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the array types in the type project.
+ */
+#ifndef _TEST__F_account_ss_decrease_by
+#define _TEST__F_account_ss_decrease_by
+
+/**
+ * Test that the function correctly fails on invalid parameter.
+ *
+ * @see f_accountss_decrease_by()
+ */
+extern void test__f_accountss_decrease_by__parameter_checking(void **state);
+
+/**
+ * Test that the function returns F_data_not.
+ *
+ * @see f_accountss_decrease_by()
+ */
+extern void test__f_accountss_decrease_by__returns_data_not(void **state);
+
+/**
+ * Test that the function works.
+ *
+ * @see f_accountss_decrease_by()
+ */
+extern void test__f_accountss_decrease_by__works(void **state);
+
+#endif // _TEST__F_account_ss_decrease_by
diff --git a/level_0/f_account/tests/unit/c/test-account-ss_increase.c b/level_0/f_account/tests/unit/c/test-account-ss_increase.c
new file mode 100644 (file)
index 0000000..710c2e2
--- /dev/null
@@ -0,0 +1,76 @@
+#include "test-account.h"
+#include "test-account-ss_increase.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_accountss_increase__parameter_checking(void **state) {
+
+  const int length = 5;
+  f_accountss_t data = f_accounts_t_initialize;
+
+  {
+    const f_status_t status = f_accountss_increase(length, 0);
+
+    assert_int_equal(status, F_status_set_error(F_parameter));
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, 0);
+  }
+
+  free((void *) data.array);
+}
+
+void test__f_accountss_increase__returns_data_not(void **state) {
+
+  const int length = 5;
+  f_accountss_t data = f_accounts_t_initialize;
+
+  {
+    const f_status_t status = f_accountss_resize(length, &data);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, length);
+  }
+
+  {
+    const f_status_t status = f_accountss_increase(length, &data);
+
+    assert_int_equal(status, F_data_not);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, length);
+  }
+
+  free((void *) data.array);
+}
+
+void test__f_accountss_increase__works(void **state) {
+
+  const int length = 5;
+  f_accountss_t data = f_accounts_t_initialize;
+
+  {
+    const f_status_t status = f_accountss_resize(length, &data);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, length);
+  }
+
+  {
+    data.used = length;
+
+    const f_status_t status = f_accountss_increase(length, &data);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(data.used, length);
+    assert_in_range(data.size, length + 1, length + 1 + F_memory_default_allocation_small_d);
+  }
+
+  free((void *) data.array);
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_account/tests/unit/c/test-account-ss_increase.h b/level_0/f_account/tests/unit/c/test-account-ss_increase.h
new file mode 100644 (file)
index 0000000..67326d0
--- /dev/null
@@ -0,0 +1,34 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Type
+ * API Version: 0.7
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the array types in the type project.
+ */
+#ifndef _TEST__F_account_ss_increase
+#define _TEST__F_account_ss_increase
+
+/**
+ * Test that the function correctly fails on invalid parameter.
+ *
+ * @see f_accountss_increase()
+ */
+extern void test__f_accountss_increase__parameter_checking(void **state);
+
+/**
+ * Test that the function returns F_data_not.
+ *
+ * @see f_accountss_increase()
+ */
+extern void test__f_accountss_increase__returns_data_not(void **state);
+
+/**
+ * Test that the function works.
+ *
+ * @see f_accountss_increase()
+ */
+extern void test__f_accountss_increase__works(void **state);
+
+#endif // _TEST__F_account_ss_increase
diff --git a/level_0/f_account/tests/unit/c/test-account-ss_increase_by.c b/level_0/f_account/tests/unit/c/test-account-ss_increase_by.c
new file mode 100644 (file)
index 0000000..0398ccf
--- /dev/null
@@ -0,0 +1,108 @@
+#include "test-account.h"
+#include "test-account-ss_increase_by.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_accountss_increase_by__parameter_checking(void **state) {
+
+  const int length = 5;
+  f_accountss_t data = f_accounts_t_initialize;
+
+  {
+    const f_status_t status = f_accountss_increase_by(length, 0);
+
+    assert_int_equal(status, F_status_set_error(F_parameter));
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, 0);
+  }
+
+  assert_null(data.array);
+}
+
+void test__f_accountss_increase_by__returns_data_not(void **state) {
+
+  const int length = 5;
+  f_accountss_t data = f_accountss_t_initialize;
+
+  {
+    const f_status_t status = f_accountss_resize(length, &data);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, length);
+  }
+
+  {
+    const f_status_t status = f_accountss_increase_by(0, &data);
+
+    assert_int_equal(status, F_data_not);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, length);
+  }
+
+  {
+    const f_status_t status = f_accountss_increase_by(length, &data);
+
+    assert_int_equal(status, F_data_not);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, length);
+  }
+
+  free((void *) data.array);
+}
+
+void test__f_account_decrease_by__returns_data_not(void **state) {
+
+  const int length = 5;
+  f_accountss_t data = f_accountss_t_initialize;
+
+  {
+    const f_status_t status = f_accountss_resize(length, &data);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, length);
+  }
+
+  {
+    const f_status_t status = f_accountss_decrease_by(0, &data);
+
+    assert_int_equal(status, F_data_not);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, length);
+  }
+
+  free((void *) data.array);
+}
+
+void test__f_accountss_increase_by__works(void **state) {
+
+  const int length = 5;
+  f_accountss_t data = f_accounts_t_initialize;
+
+  {
+    const f_status_t status = f_accountss_resize(length, &data);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, length);
+  }
+
+  {
+    data.used = length;
+
+    const f_status_t status = f_accountss_increase_by(length, &data);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(data.used, length);
+    assert_int_equal(data.size, length * 2);
+  }
+
+  free((void *) data.array);
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_account/tests/unit/c/test-account-ss_increase_by.h b/level_0/f_account/tests/unit/c/test-account-ss_increase_by.h
new file mode 100644 (file)
index 0000000..20d99fa
--- /dev/null
@@ -0,0 +1,34 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Type
+ * API Version: 0.7
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the array types in the type project.
+ */
+#ifndef _TEST__F_account_ss_increase_by
+#define _TEST__F_account_ss_increase_by
+
+/**
+ * Test that the function correctly fails on invalid parameter.
+ *
+ * @see f_accountss_increase_by()
+ */
+extern void test__f_accountss_increase_by__parameter_checking(void **state);
+
+/**
+ * Test that the function returns F_data_not.
+ *
+ * @see f_accountss_increase_by()
+ */
+extern void test__f_accountss_increase_by__returns_data_not(void **state);
+
+/**
+ * Test that the function works.
+ *
+ * @see f_accountss_increase_by()
+ */
+extern void test__f_accountss_increase_by__works(void **state);
+
+#endif // _TEST__F_account_ss_increase_by
diff --git a/level_0/f_account/tests/unit/c/test-account-ss_resize.c b/level_0/f_account/tests/unit/c/test-account-ss_resize.c
new file mode 100644 (file)
index 0000000..d37cd77
--- /dev/null
@@ -0,0 +1,42 @@
+#include "test-account.h"
+#include "test-account-ss_resize.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__f_accountss_resize__parameter_checking(void **state) {
+
+  const int length = 5;
+  f_accountss_t data = f_accountss_t_initialize;
+
+  {
+    const f_status_t status = f_accountss_resize(length, 0);
+
+    assert_int_equal(status, F_status_set_error(F_parameter));
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, 0);
+  }
+
+  assert_null(data.array);
+}
+
+void test__f_accountss_resize__works(void **state) {
+
+  const int length = 5;
+  f_accountss_t data = f_accountss_t_initialize;
+
+  {
+    const f_status_t status = f_accountss_resize(length, &data);
+
+    assert_int_equal(status, F_none);
+    assert_int_equal(data.used, 0);
+    assert_int_equal(data.size, length);
+  }
+
+  free((void *) data.array);
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_account/tests/unit/c/test-account-ss_resize.h b/level_0/f_account/tests/unit/c/test-account-ss_resize.h
new file mode 100644 (file)
index 0000000..1df4e83
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Type
+ * API Version: 0.7
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the array types in the type project.
+ */
+#ifndef _TEST__F_account_ss_resize
+#define _TEST__F_account_ss_resize
+
+/**
+ * Test that the function correctly fails on invalid parameter.
+ *
+ * @see f_accountss_resize()
+ */
+extern void test__f_accountss_resize__parameter_checking(void **state);
+
+/**
+ * Test that the function works.
+ *
+ * @see f_accountss_resize()
+ */
+extern void test__f_accountss_resize__works(void **state);
+
+#endif // _TEST__F_account_ss_resize
index 88ba73dddedd5e3508ce22d1dd86cbb5afafedfd..3eef52c9cd2e60efb0fc95a70b1e02e70ebd7740 100644 (file)
@@ -43,6 +43,37 @@ int main(void) {
     cmocka_unit_test(test__f_account_name_by_id__not_found),
     cmocka_unit_test(test__f_account_name_by_id__works),
 
+    cmocka_unit_test(test__f_accounts_append_all__returns_data_not),
+    cmocka_unit_test(test__f_accounts_decimate_by__returns_data_not),
+    cmocka_unit_test(test__f_accounts_decrease_by__returns_data_not),
+    cmocka_unit_test(test__f_accounts_increase__returns_data_not),
+    cmocka_unit_test(test__f_accounts_increase_by__returns_data_not),
+
+    cmocka_unit_test(test__f_accounts_adjust__works),
+    cmocka_unit_test(test__f_accounts_append__works),
+    cmocka_unit_test(test__f_accounts_append_all__works),
+    cmocka_unit_test(test__f_accounts_decimate_by__works),
+    cmocka_unit_test(test__f_accounts_decrease_by__works),
+    cmocka_unit_test(test__f_accounts_increase__works),
+    cmocka_unit_test(test__f_accounts_increase_by__works),
+    cmocka_unit_test(test__f_accounts_resize__works),
+
+    cmocka_unit_test(test__f_accountss_append__returns_data_not),
+    cmocka_unit_test(test__f_accountss_append_all__returns_data_not),
+    cmocka_unit_test(test__f_accountss_decimate_by__returns_data_not),
+    cmocka_unit_test(test__f_accountss_decrease_by__returns_data_not),
+    cmocka_unit_test(test__f_accountss_increase__returns_data_not),
+    cmocka_unit_test(test__f_accountss_increase_by__returns_data_not),
+
+    cmocka_unit_test(test__f_accountss_adjust__works),
+    cmocka_unit_test(test__f_accountss_append__works),
+    cmocka_unit_test(test__f_accountss_append_all__works),
+    cmocka_unit_test(test__f_accountss_decimate_by__works),
+    cmocka_unit_test(test__f_accountss_decrease_by__works),
+    cmocka_unit_test(test__f_accountss_increase__works),
+    cmocka_unit_test(test__f_accountss_increase_by__works),
+    cmocka_unit_test(test__f_accountss_resize__works),
+
     #ifndef _di_level_0_parameter_checking_
       cmocka_unit_test(test__f_account_by_id__parameter_checking),
       cmocka_unit_test(test__f_account_by_name__parameter_checking),
@@ -50,6 +81,24 @@ int main(void) {
       cmocka_unit_test(test__f_account_group_name_by_id__parameter_checking),
       cmocka_unit_test(test__f_account_id_by_name__parameter_checking),
       cmocka_unit_test(test__f_account_name_by_id__parameter_checking),
+
+      cmocka_unit_test(test__f_accounts_adjust__parameter_checking),
+      cmocka_unit_test(test__f_accounts_append__parameter_checking),
+      cmocka_unit_test(test__f_accounts_append_all__parameter_checking),
+      cmocka_unit_test(test__f_accounts_decimate_by__parameter_checking),
+      cmocka_unit_test(test__f_accounts_decrease_by__parameter_checking),
+      cmocka_unit_test(test__f_accounts_increase__parameter_checking),
+      cmocka_unit_test(test__f_accounts_increase_by__parameter_checking),
+      cmocka_unit_test(test__f_accounts_resize__parameter_checking),
+
+      cmocka_unit_test(test__f_accountss_adjust__parameter_checking),
+      cmocka_unit_test(test__f_accountss_append__parameter_checking),
+      cmocka_unit_test(test__f_accountss_append_all__parameter_checking),
+      cmocka_unit_test(test__f_accountss_decimate_by__parameter_checking),
+      cmocka_unit_test(test__f_accountss_decrease_by__parameter_checking),
+      cmocka_unit_test(test__f_accountss_increase__parameter_checking),
+      cmocka_unit_test(test__f_accountss_increase_by__parameter_checking),
+      cmocka_unit_test(test__f_accountss_resize__parameter_checking),
     #endif // _di_level_0_parameter_checking_
   };
 
index ac704a82ba354ef7ded8e4c72bc69bea9b3df796..89f1b8ca4e99ac3d53f71bbe89358934f5d0b79e 100644 (file)
 #include "test-account-group_name_by_id.h"
 #include "test-account-id_by_name.h"
 #include "test-account-name_by_id.h"
+#include "test-account-s_adjust.h"
+#include "test-account-s_append.h"
+#include "test-account-s_append_all.h"
+#include "test-account-s_decimate_by.h"
+#include "test-account-s_decrease_by.h"
+#include "test-account-s_increase.h"
+#include "test-account-s_increase_by.h"
+#include "test-account-s_resize.h"
+#include "test-account-ss_adjust.h"
+#include "test-account-ss_append.h"
+#include "test-account-ss_append_all.h"
+#include "test-account-ss_decimate_by.h"
+#include "test-account-ss_decrease_by.h"
+#include "test-account-ss_increase.h"
+#include "test-account-ss_increase_by.h"
+#include "test-account-ss_resize.h"
 
 #ifdef __cplusplus
 extern "C" {