Force usage of assert() condition when NDEBUG is defined
[lttng-tools.git] / tests / unit / test_string_utils.c
index 9596af83ed7bd299063714d3bfcc9d00492e2ef2..d2b0d905d4598ac030da684411be82a57983f80b 100644 (file)
@@ -1,23 +1,12 @@
 /*
- * Copyright (c) - 2017 Philippe Proulx <pproulx@efficios.com>
+ * Copyright (C) 2017 Philippe Proulx <pproulx@efficios.com>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by as
- * published by the Free Software Foundation; only version 2 of the License.
+ * SPDX-License-Identifier: GPL-2.0-only
  *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #include <stdlib.h>
 #include <stdbool.h>
-#include <assert.h>
 #include <string.h>
 #include <stdarg.h>
 #include <common/string-utils/string-utils.h>
 /* Number of TAP tests in this file */
 #define NUM_TESTS 69
 
-static void test_one_split(const char *input, char delim, bool escape_delim,
+/* For error.h */
+int lttng_opt_quiet = 1;
+int lttng_opt_verbose;
+int lttng_opt_mi;
+
+static void test_one_split(const char *input, char delim, int escape_delim,
                ...)
 {
        va_list vl;
-       char **substrings;
-       char * const *substring;
        bool all_ok = true;
+       struct lttng_dynamic_pointer_array strings;
+       int split_ret;
+       size_t i, string_count;
 
-       substrings = strutils_split(input, delim, escape_delim);
-       assert(substrings);
+       split_ret = strutils_split(input, delim, escape_delim, &strings);
+       LTTNG_ASSERT(split_ret == 0);
        va_start(vl, escape_delim);
 
-       for (substring = substrings; *substring; substring++) {
+       string_count = lttng_dynamic_pointer_array_get_count(&strings);
+
+       for (i = 0; i < string_count; i++) {
                const char *expected_substring = va_arg(vl, const char *);
+               const char *substring =
+                               lttng_dynamic_pointer_array_get_pointer(
+                                               &strings, i);
 
-               diag("  got `%s`, expecting `%s`", *substring, expected_substring);
+               diag("  got `%s`, expecting `%s`", substring, expected_substring);
 
                if (!expected_substring) {
                        all_ok = false;
                        break;
                }
 
-               if (strcmp(*substring, expected_substring) != 0) {
+               if (strcmp(substring, expected_substring) != 0) {
                        all_ok = false;
                        break;
                }
        }
 
-       strutils_free_null_terminated_array_of_strings(substrings);
+       lttng_dynamic_pointer_array_reset(&strings);
        va_end(vl);
        ok(all_ok, "strutils_split() produces the expected substrings: `%s` (delim. `%c`, escape `%d`)",
-               input, delim, escape_delim);
+                       input, delim, escape_delim);
 }
 
 static void test_split(void)
@@ -133,7 +133,7 @@ static void test_one_normalize_star_glob_pattern(const char *pattern,
 {
        char *rw_pattern = strdup(pattern);
 
-       assert(rw_pattern);
+       LTTNG_ASSERT(rw_pattern);
        strutils_normalize_star_glob_pattern(rw_pattern);
        ok(strcmp(rw_pattern, expected) == 0,
                "strutils_normalize_star_glob_pattern() produces the expected result: `%s` -> `%s`",
This page took 0.02528 seconds and 4 git commands to generate.