[PATCH 2/3] libmbim-glib,test: add unit tests for mbim_utils_str_hex

Ben Chan benchan at chromium.org
Thu Jul 27 06:30:24 UTC 2017


---
 src/libmbim-glib/test/Makefile.am  | 19 +++++++++++++-
 src/libmbim-glib/test/test-utils.c | 54 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+), 1 deletion(-)
 create mode 100644 src/libmbim-glib/test/test-utils.c

diff --git a/src/libmbim-glib/test/Makefile.am b/src/libmbim-glib/test/Makefile.am
index cddfb26..5cf2220 100644
--- a/src/libmbim-glib/test/Makefile.am
+++ b/src/libmbim-glib/test/Makefile.am
@@ -7,7 +7,8 @@ noinst_PROGRAMS = \
 	test-fragment \
 	test-message-parser \
 	test-message-builder \
-	test-proxy-helpers
+	test-proxy-helpers \
+	test-utils
 
 TEST_PROGS += $(noinst_PROGRAMS)
 
@@ -107,3 +108,19 @@ test_proxy_helpers_LDADD = \
 	$(top_builddir)/src/libmbim-glib/libmbim-glib-core.la \
 	$(top_builddir)/src/libmbim-glib/generated/libmbim-glib-generated.la \
 	$(LIBMBIM_GLIB_LIBS)
+
+test_utils_SOURCES = \
+	test-utils.c \
+	$(top_srcdir)/src/libmbim-glib/mbim-utils.h \
+	$(top_srcdir)/src/libmbim-glib/mbim-utils.c
+test_utils_CPPFLAGS = \
+	$(LIBMBIM_GLIB_CFLAGS) \
+	-I$(top_srcdir) \
+	-I$(top_srcdir)/src/libmbim-glib \
+	-I$(top_builddir)/src/libmbim-glib \
+	-I$(top_builddir)/src/libmbim-glib/generated \
+	-DLIBMBIM_GLIB_COMPILATION
+test_utils_LDADD = \
+	$(top_builddir)/src/libmbim-glib/libmbim-glib-core.la \
+	$(top_builddir)/src/libmbim-glib/generated/libmbim-glib-generated.la \
+	$(LIBMBIM_GLIB_LIBS)
diff --git a/src/libmbim-glib/test/test-utils.c b/src/libmbim-glib/test/test-utils.c
new file mode 100644
index 0000000..7e79706
--- /dev/null
+++ b/src/libmbim-glib/test/test-utils.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-utils.h"
+
+static void
+test_utils_str_hex (void)
+{
+    static const guint8 buffer [] = { 0x00, 0xDE, 0xAD, 0xC0, 0xDE };
+    gchar *str;
+
+    str = mbim_utils_str_hex (NULL, 0, ':');
+    g_assert (str == NULL);
+
+    str = mbim_utils_str_hex (buffer, 0, ':');
+    g_assert (str == NULL);
+
+    str = mbim_utils_str_hex (buffer, 1, ':');
+    g_assert_cmpstr (str, ==, "00");
+    g_free (str);
+
+    str = mbim_utils_str_hex (buffer, 2, '-');
+    g_assert_cmpstr (str, ==, "00-DE");
+    g_free (str);
+
+    str = mbim_utils_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 ("/libmbim-glib/utils/str_hex", test_utils_str_hex);
+
+    return g_test_run ();
+}
-- 
2.14.0.rc0.400.g1c36432dff-goog



More information about the libmbim-devel mailing list