summaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
authorPetr Cech <pcech@redhat.com>2015-11-10 06:04:45 -0500
committerJakub Hrozek <jhrozek@redhat.com>2015-11-14 13:08:04 +0100
commit6ae53d7b54ec2ece9fb51ed92c097f5ba8f9d849 (patch)
tree61c4c55045ce92a50b65fe93c9329bc6b4a9fd93 /src/tests
parentc4d4fe1603420fe8f3d256a3a446974699563ff3 (diff)
downloadsssd-6ae53d7b54ec2ece9fb51ed92c097f5ba8f9d849.tar.gz
sssd-6ae53d7b54ec2ece9fb51ed92c097f5ba8f9d849.tar.xz
sssd-6ae53d7b54ec2ece9fb51ed92c097f5ba8f9d849.zip
TEST: Add common function are_values_in_array()
This patch adds function are_values_in_array() to common test code. And there is tc_are_values_in_array macro defined which is usefull for talloc allocated values and arrays. Resolves: https://fedorahosted.org/sssd/ticket/2730 Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/common.c21
-rw-r--r--src/tests/common.h8
2 files changed, 29 insertions, 0 deletions
diff --git a/src/tests/common.c b/src/tests/common.c
index 9655cd3ce..8ba73a2ef 100644
--- a/src/tests/common.c
+++ b/src/tests/common.c
@@ -118,3 +118,24 @@ bool ldb_modules_path_is_set(void)
return false;
}
+
+/* Returns true if all values are in array (else returns false) */
+bool are_values_in_array(const char **values, size_t values_len,
+ const char **array, size_t array_len)
+{
+ bool is_value_in_element = false;
+ bool is_value_in_array = false;
+ bool ret = true;
+
+ for (size_t i = 0; i < values_len; i++) {
+ is_value_in_array = false;
+ for (size_t j = 0; j < array_len; j++) {
+ is_value_in_element = strcmp(values[i], array[j]) == 0 ? \
+ true : false;
+ is_value_in_array = is_value_in_array || is_value_in_element;
+ }
+ ret = ret && is_value_in_array;
+ }
+
+ return ret;
+}
diff --git a/src/tests/common.h b/src/tests/common.h
index 794218c5b..c9b3815cd 100644
--- a/src/tests/common.h
+++ b/src/tests/common.h
@@ -143,4 +143,12 @@ struct sss_domain_info *named_domain(TALLOC_CTX *mem_ctx,
const char *name,
struct sss_domain_info *parent);
+/* Returns true if all values are in array (else returns false) */
+bool are_values_in_array(const char **values, size_t values_len,
+ const char **array, size_t array_len);
+
+#define tc_are_values_in_array(values, array) \
+ are_values_in_array(values, talloc_array_length(values), \
+ array, talloc_array_length(array))
+
#endif /* !__TESTS_COMMON_H__ */