[recipes] Add a few tests for strv utilities
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes] Add a few tests for strv utilities
- Date: Sun, 7 May 2017 13:24:17 +0000 (UTC)
commit 707dff4465ba1b7152e027aee8c6bd00436d1ef6
Author: Matthias Clasen <mclasen redhat com>
Date: Sun May 7 09:21:52 2017 -0400
Add a few tests for strv utilities
Evidently, without tests things don't work.
tests/meson.build | 5 +++
tests/strv.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 95 insertions(+), 0 deletions(-)
---
diff --git a/tests/meson.build b/tests/meson.build
index 4da7f76..e278ea6 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -26,3 +26,8 @@ ids = executable('ids', 'ids.c',
include_directories : tests_inc,
dependencies: deps)
test('ids', ids, env : env)
+
+strv = executable('strv', 'strv.c',
+ include_directories : tests_inc,
+ dependencies: deps)
+test('strv', strv, env : env)
diff --git a/tests/strv.c b/tests/strv.c
new file mode 100644
index 0000000..d2e7814
--- /dev/null
+++ b/tests/strv.c
@@ -0,0 +1,90 @@
+/* strv.c
+ *
+ * Copyright (C) 2017 Matthias Clasen <mclasen redhat 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include <locale.h>
+#include <stdio.h>
+#include <glib.h>
+#include "gr-utils.h"
+#include "gr-utils.c"
+
+static void
+test_strv_prepend (void)
+{
+ char **strv;
+
+ strv = g_new0 (char *, 3);
+ strv[0] = g_strdup ("b");
+ strv[1] = g_strdup ("c");
+
+ strv_prepend (&strv, "a");
+
+ g_assert (g_strv_length (strv) == 3);
+ g_assert_cmpstr (strv[0], ==, "a");
+ g_assert_cmpstr (strv[1], ==, "b");
+ g_assert_cmpstr (strv[2], ==, "c");
+
+ g_strfreev (strv);
+
+ strv = g_new0 (char *, 1);
+
+ strv_prepend (&strv, "a");
+
+ g_assert (g_strv_length (strv) == 1);
+ g_assert_cmpstr (strv[0], ==, "a");
+
+ g_strfreev (strv);
+}
+
+static void
+test_strv_remove (void)
+{
+ char **strv;
+
+ strv = g_new0 (char *, 4);
+ strv[0] = g_strdup ("b");
+ strv[1] = g_strdup ("c");
+ strv[2] = g_strdup ("b");
+
+ strv_remove (&strv, "b");
+
+ g_assert (g_strv_length (strv) == 1);
+ g_assert_cmpstr (strv[0], ==, "c");
+
+ strv_remove (&strv, "a");
+
+ g_assert (g_strv_length (strv) == 1);
+ g_assert_cmpstr (strv[0], ==, "c");
+
+ strv_remove (&strv, "c");
+
+ g_assert (g_strv_length (strv) == 0);
+
+ g_strfreev (strv);
+}
+
+int
+main (int argc, char *argv[])
+{
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/strv/prepend", test_strv_prepend);
+ g_test_add_func ("/strv/remove", test_strv_remove);
+
+ return g_test_run ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]