[PATCH v2 2/3] mbim-common, test: add unit tests for mbim_common_str_hex

Ben Chan benchan at chromium.org
Fri Jul 28 02:45:54 UTC 2017


---
 configure.ac                  |  1 +
 src/common/Makefile.am        |  2 +-
 src/common/test/Makefile.am   | 17 ++++++++++++++
 src/common/test/test-common.c | 54 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 73 insertions(+), 1 deletion(-)
 create mode 100644 src/common/test/Makefile.am
 create mode 100644 src/common/test/test-common.c

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 ();
+}
-- 
2.14.0.rc0.400.g1c36432dff-goog



More information about the libmbim-devel mailing list