return EXIT_FAILURE;
}
+static int test_string_join(const struct test* t) {
+ char* s = NULL;
+
+ // Some test elements
+ char* elements1[] = {
+ "A",
+ "B",
+ "C",
+ NULL,
+ };
+
+ // Join with newline
+ s = pakfire_string_join(elements1, "\n");
+ ASSERT_STRING_EQUALS(s, "A\nB\nC");
+
+ if (s) {
+ free(s);
+ s = NULL;
+ }
+
+ // Join with empty delimiter
+ s = pakfire_string_join(elements1, "");
+ ASSERT_STRING_EQUALS(s, "ABC");
+
+ if (s) {
+ free(s);
+ s = NULL;
+ }
+
+ char* elements2[] = {
+ "",
+ "",
+ "",
+ NULL,
+ };
+
+ // Join list with empty elements
+ s = pakfire_string_join(elements2, "X");
+ ASSERT_STRING_EQUALS(s, "XX");
+
+ if (s) {
+ free(s);
+ s = NULL;
+ }
+
+ // Invalid inputs
+ s = pakfire_string_join(NULL, NULL);
+ ASSERT_ERRNO(!s, EINVAL);
+
+ s = pakfire_string_join(elements1, NULL);
+ ASSERT_ERRNO(!s, EINVAL);
+
+ s = pakfire_string_join(NULL, "\n");
+ ASSERT_ERRNO(!s, EINVAL);
+
+ char* elements3[] = {
+ NULL,
+ };
+
+ // Join empty elements
+ ASSERT_NULL(pakfire_string_join(elements3, "\n"));
+
+ return EXIT_SUCCESS;
+
+FAIL:
+ if (s)
+ free(s);
+
+ return EXIT_FAILURE;
+}
+
int main(int argc, char** argv) {
testsuite_add_test(test_basename);
testsuite_add_test(test_dirname);
testsuite_add_test(test_string_partition);
testsuite_add_test(test_string_replace);
testsuite_add_test(test_string_split);
+ testsuite_add_test(test_string_join);
return testsuite_run();
}