[ostree] tests: Add tests for ot-unix-utils
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] tests: Add tests for ot-unix-utils
- Date: Mon, 2 Feb 2015 20:02:21 +0000 (UTC)
commit cfc344fbb0fa7bf9f2726bcda112adb3cc082599
Author: Giuseppe Scrivano <gscrivan redhat com>
Date: Mon Feb 2 13:37:48 2015 +0100
tests: Add tests for ot-unix-utils
Signed-off-by: Giuseppe Scrivano <gscrivan redhat com>
Makefile-tests.am | 7 +++-
tests/test-ot-unix-utils.c | 78 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 83 insertions(+), 2 deletions(-)
---
diff --git a/Makefile-tests.am b/Makefile-tests.am
index 1ac5c5a..8571fa1 100644
--- a/Makefile-tests.am
+++ b/Makefile-tests.am
@@ -104,7 +104,10 @@ endif
endif
# "make check" do not depend from --enable-installed-tests
-check_PROGRAMS = tests/test-rollsum tests/test-varint
+check_PROGRAMS = tests/test-rollsum tests/test-varint tests/test-ot-unix-utils
+
+tests_test_ot_unix_utils_CFLAGS = $(ostree_bin_shared_cflags) $(OT_INTERNAL_GIO_UNIX_CFLAGS)
+tests_test_ot_unix_utils_LDADD = $(ostree_bin_shared_ldadd) $(OT_INTERNAL_GIO_UNIX_LIBS)
tests_test_rollsum_SOURCES = src/libostree/bupsplit.c tests/test-rollsum.c
tests_test_rollsum_CFLAGS = $(ostree_bin_shared_cflags) $(OT_INTERNAL_GIO_UNIX_CFLAGS)
@@ -114,4 +117,4 @@ tests_test_varint_SOURCES = src/libostree/ostree-varint.c tests/test-varint.c
tests_test_varint_CFLAGS = $(ostree_bin_shared_cflags) $(OT_INTERNAL_GIO_UNIX_CFLAGS)
tests_test_varint_LDADD = $(ostree_bin_shared_ldadd) $(OT_INTERNAL_GIO_UNIX_LIBS)
-TESTS = tests/test-rollsum tests/test-varint
+TESTS = tests/test-rollsum tests/test-varint tests/test-ot-unix-utils
diff --git a/tests/test-ot-unix-utils.c b/tests/test-ot-unix-utils.c
new file mode 100644
index 0000000..cd167a2
--- /dev/null
+++ b/tests/test-ot-unix-utils.c
@@ -0,0 +1,78 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2015 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include "libgsystem.h"
+#include "ot-unix-utils.h"
+#include <glib.h>
+
+static void
+test_ot_util_path_split_validate (void)
+{
+ const char *paths[] = {"foo/bar", "test", "foo/bar:", "a/b/c/d/e/f/g/h/i/l/m/n/o/p", NULL};
+ int n_components[] = {2, 1, 2, 14, 0};
+ int i;
+ for (i = 0; paths[i]; i++)
+ {
+ GError *error = NULL;
+ GPtrArray *components = NULL;
+ if (! ot_util_path_split_validate (paths[i], &components, &error))
+ {
+ int j;
+ g_assert_cmpint (components->len, ==, n_components[i]);
+ for (j = 0; j < components->len; j++)
+ {
+ g_assert (strcmp (components->pdata[i], ".."));
+ g_assert_null (strchr (components->pdata[i], '/'));
+ }
+ }
+ gs_local_ptrarray_unref (components);
+ }
+}
+
+static void
+test_ot_util_filename_validate (void)
+{
+ GError *error = NULL;
+
+ /* Check for valid inputs. */
+ g_assert (ot_util_filename_validate ("valid", &error));
+ g_assert (ot_util_filename_validate ("valid_file_name", &error));
+ g_assert (ot_util_filename_validate ("file.name", &error));
+ g_assert (ot_util_filename_validate ("foo..", &error));
+ g_assert (ot_util_filename_validate ("..bar", &error));
+ g_assert (ot_util_filename_validate ("baz:", &error));
+
+ /* Check for invalid inputs. */
+ g_assert_false (ot_util_filename_validate ("not/valid/file/name", &error));
+ error = NULL;
+ g_assert_false (ot_util_filename_validate (".", &error));
+ error = NULL;
+ g_assert_false (ot_util_filename_validate ("..", &error));
+}
+
+int main (int argc, char **argv)
+{
+ g_test_init (&argc, &argv, NULL);
+ g_test_add_func ("/ot_util_path_split_validate", test_ot_util_path_split_validate);
+ g_test_add_func ("/ot_util_filename_validate", test_ot_util_filename_validate);
+ return g_test_run();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]