summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Chan <benchan@chromium.org>2017-07-27 19:45:54 -0700
committerAleksander Morgado <aleksander@aleksander.es>2017-07-28 09:47:54 +0200
commit44c7593c716ac321d6b2640a86fce34e41d8fbb6 (patch)
tree399c467f7280ac199d53fc9e06bff37383e5996f
parent8e64510e706d7192ec9e0db6c506d05beda9820c (diff)
mbim-common,test: add unit tests for mbim_common_str_hex
-rw-r--r--configure.ac1
-rw-r--r--src/common/Makefile.am2
-rw-r--r--src/common/test/Makefile.am17
-rw-r--r--src/common/test/test-common.c54
4 files changed, 73 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index b3ecb7e..c61f67b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -173,6 +173,7 @@ AC_CONFIG_FILES([Makefile
data/pkg-config/mbim-glib.pc
src/Makefile
src/common/Makefile
+ src/common/test/Makefile
src/libmbim-glib/Makefile
src/libmbim-glib/mbim-version.h
src/libmbim-glib/generated/Makefile
diff --git a/src/common/Makefile.am b/src/common/Makefile.am
index 747d077..c5e4207 100644
--- a/src/common/Makefile.am
+++ b/src/common/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = .
+SUBDIRS = . test
# common library, built as a noinst
noinst_LTLIBRARIES = libmbim-common.la
diff --git a/src/common/test/Makefile.am b/src/common/test/Makefile.am
new file mode 100644
index 0000000..549fbb6
--- /dev/null
+++ b/src/common/test/Makefile.am
@@ -0,0 +1,17 @@
+include $(top_srcdir)/gtester.make
+
+noinst_PROGRAMS = \
+ test-common
+
+TEST_PROGS += $(noinst_PROGRAMS)
+
+test_common_SOURCES = \
+ test-common.c
+test_common_CPPFLAGS = \
+ $(MBIM_COMMON_CFLAGS) \
+ -I$(top_srcdir) \
+ -I$(top_builddir) \
+ -I$(top_srcdir)/src/common
+test_common_LDADD = \
+ $(top_builddir)/src/common/libmbim-common.la \
+ $(MBIM_COMMON_LIBS)
diff --git a/src/common/test/test-common.c b/src/common/test/test-common.c
new file mode 100644
index 0000000..6c2841c
--- /dev/null
+++ b/src/common/test/test-common.c
@@ -0,0 +1,54 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * 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 2 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:
+ *
+ * Copyright (C) 2017 Google Inc.
+ */
+
+#include <config.h>
+
+#include "mbim-common.h"
+
+static void
+test_common_str_hex (void)
+{
+ static const guint8 buffer [] = { 0x00, 0xDE, 0xAD, 0xC0, 0xDE };
+ gchar *str;
+
+ str = mbim_common_str_hex (NULL, 0, ':');
+ g_assert (str == NULL);
+
+ str = mbim_common_str_hex (buffer, 0, ':');
+ g_assert (str == NULL);
+
+ str = mbim_common_str_hex (buffer, 1, ':');
+ g_assert_cmpstr (str, ==, "00");
+ g_free (str);
+
+ str = mbim_common_str_hex (buffer, 2, '-');
+ g_assert_cmpstr (str, ==, "00-DE");
+ g_free (str);
+
+ str = mbim_common_str_hex (buffer, 5, '.');
+ g_assert_cmpstr (str, ==, "00.DE.AD.C0.DE");
+ g_free (str);
+}
+
+/*****************************************************************************/
+
+int main (int argc, char **argv)
+{
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/common/str_hex", test_common_str_hex);
+
+ return g_test_run ();
+}