aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2012-07-04 13:00:52 +0200
committerAleksander Morgado <aleksander@lanedo.com>2012-07-04 16:00:39 +0200
commit8b1edc1038883541b8fdfd7265d5b2771d168f96 (patch)
tree3c8978c12e14651fa71dc1dccb6943c58f6382f8
parent03aa6bc53c7873633be7f52669636004c4cf0373 (diff)
downloadexternal_libqmi-8b1edc1038883541b8fdfd7265d5b2771d168f96.zip
external_libqmi-8b1edc1038883541b8fdfd7265d5b2771d168f96.tar.gz
external_libqmi-8b1edc1038883541b8fdfd7265d5b2771d168f96.tar.bz2
libqmi-glib,test: new unit tests for the integer read/write operations
-rw-r--r--.gitignore6
-rw-r--r--configure.ac14
-rw-r--r--libqmi-glib/Makefile.am2
-rw-r--r--libqmi-glib/test/Makefile.am23
-rw-r--r--libqmi-glib/test/test-utils.c315
5 files changed, 360 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 1c7f91e..2f0e464 100644
--- a/.gitignore
+++ b/.gitignore
@@ -48,6 +48,12 @@ libqmi-glib/qmi-wds.h
libqmi-glib/qmi-wds.c
libqmi-glib/*.stamp
+libqmi-glib/test/.libs
+libqmi-glib/test/.deps
+libqmi-glib/test/Makefile
+libqmi-glib/test/Makefile.in
+libqmi-glib/test/test-utils
+
cli/.deps
cli/.libs
cli/qmicli
diff --git a/configure.ac b/configure.ac
index 6406b3e..bcc7699 100644
--- a/configure.ac
+++ b/configure.ac
@@ -45,6 +45,18 @@ AC_SUBST(QMICLI_LIBS)
GLIB_MKENUMS=`pkg-config --variable=glib_mkenums glib-2.0`
AC_SUBST(GLIB_MKENUMS)
+dnl Tests
+AC_ARG_WITH(tests, AS_HELP_STRING([--with-tests], [Build libqmi tests]))
+AM_CONDITIONAL(WITH_TESTS, test "x$with_tests" = "xyes")
+case $with_tests in
+ yes)
+ with_tests=yes
+ ;;
+ *)
+ with_tests=no
+ ;;
+esac
+
AC_CONFIG_FILES([Makefile
data/Makefile
data/pkg-config/Makefile
@@ -53,6 +65,7 @@ AC_CONFIG_FILES([Makefile
build-aux/templates/Makefile
build-aux/qmi-codegen/Makefile
libqmi-glib/Makefile
+ libqmi-glib/test/Makefile
cli/Makefile
utils/Makefile])
AC_OUTPUT
@@ -64,4 +77,5 @@ echo "
compiler: ${CC}
cflags: ${CFLAGS}
Maintainer mode: ${USE_MAINTAINER_MODE}
+ Tests: ${with_tests}
"
diff --git a/libqmi-glib/Makefile.am b/libqmi-glib/Makefile.am
index 71d85c3..7af62bc 100644
--- a/libqmi-glib/Makefile.am
+++ b/libqmi-glib/Makefile.am
@@ -1,4 +1,6 @@
+SUBDIRS = . test
+
lib_LTLIBRARIES = libqmi-glib.la
libqmi_glib_la_CPPFLAGS = \
diff --git a/libqmi-glib/test/Makefile.am b/libqmi-glib/test/Makefile.am
new file mode 100644
index 0000000..fa95310
--- /dev/null
+++ b/libqmi-glib/test/Makefile.am
@@ -0,0 +1,23 @@
+
+noinst_PROGRAMS = \
+ test-utils
+
+test_utils_SOURCES = \
+ test-utils.c
+
+test_utils_CPPFLAGS = \
+ $(LIBQMI_GLIB_CFLAGS) \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/libqmi-glib \
+ -I$(top_builddir)/libqmi-glib
+
+test_utils_LDADD = \
+ $(top_builddir)/libqmi-glib/libqmi-glib.la \
+ $(LIBQMI_GLIB_LIBS)
+
+if WITH_TESTS
+
+check-local: test-utils
+ $(abs_builddir)/test-utils
+
+endif
diff --git a/libqmi-glib/test/test-utils.c b/libqmi-glib/test/test-utils.c
new file mode 100644
index 0000000..290b48d
--- /dev/null
+++ b/libqmi-glib/test/test-utils.c
@@ -0,0 +1,315 @@
+/* -*- 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) 2012 Aleksander Morgado <aleksander@gnu.org>
+ */
+
+#include <glib-object.h>
+#include <string.h>
+#include "qmi-utils.h"
+
+static void
+test_utils_uint8 (void)
+{
+ static guint8 in_buffer[8] = {
+ 0x0F, 0x50, 0xEB, 0xE2, 0xB6, 0x00, 0x00, 0x00
+ };
+ guint8 out_buffer[8] = { 0 };
+
+ guint16 in_buffer_size;
+ guint8 *in_buffer_walker;
+ guint16 out_buffer_size;
+ guint8 *out_buffer_walker;
+
+ in_buffer_size = sizeof (in_buffer);
+ in_buffer_walker = &in_buffer[0];
+ out_buffer_size = sizeof (out_buffer);
+ out_buffer_walker = &out_buffer[0];
+
+ while (in_buffer_size) {
+ guint8 tmp;
+
+ qmi_utils_read_guint8_from_buffer (&in_buffer_walker, &in_buffer_size, &tmp);
+ qmi_utils_write_guint8_to_buffer (&out_buffer_walker, &out_buffer_size, &tmp);
+ }
+
+ g_assert_cmpuint (out_buffer_size, ==, 0);
+ g_assert (memcmp (in_buffer, out_buffer, sizeof (in_buffer)) == 0);
+}
+
+static void
+test_utils_int8 (void)
+{
+ static guint8 in_buffer[8] = {
+ 0x0F, 0x50, 0xEB, 0xE2, 0xB6, 0x00, 0x00, 0x00
+ };
+ guint8 out_buffer[8] = { 0 };
+
+ guint16 in_buffer_size;
+ guint8 *in_buffer_walker;
+ guint16 out_buffer_size;
+ guint8 *out_buffer_walker;
+
+ in_buffer_size = sizeof (in_buffer);
+ in_buffer_walker = &in_buffer[0];
+ out_buffer_size = sizeof (out_buffer);
+ out_buffer_walker = &out_buffer[0];
+
+ while (in_buffer_size) {
+ gint8 tmp;
+
+ qmi_utils_read_gint8_from_buffer (&in_buffer_walker, &in_buffer_size, &tmp);
+ qmi_utils_write_gint8_to_buffer (&out_buffer_walker, &out_buffer_size, &tmp);
+ }
+
+ g_assert_cmpuint (out_buffer_size, ==, 0);
+ g_assert (memcmp (in_buffer, out_buffer, sizeof (in_buffer)) == 0);
+}
+
+static void
+test_utils_uint16 (void)
+{
+ static guint8 in_buffer[8] = {
+ 0x0F, 0x50, 0xEB, 0xE2, 0xB6, 0x00, 0x00, 0x00
+ };
+ static guint16 values[4] = {
+ 0x500F, 0xE2EB, 0x00B6, 0x0000
+ };
+ guint8 out_buffer[8] = { 0 };
+
+ guint i;
+ guint16 in_buffer_size;
+ guint8 *in_buffer_walker;
+ guint16 out_buffer_size;
+ guint8 *out_buffer_walker;
+
+ in_buffer_size = sizeof (in_buffer);
+ in_buffer_walker = &in_buffer[0];
+ out_buffer_size = sizeof (out_buffer);
+ out_buffer_walker = &out_buffer[0];
+ i = 0;
+
+ while (in_buffer_size) {
+ guint16 tmp;
+
+ qmi_utils_read_guint16_from_buffer (&in_buffer_walker, &in_buffer_size, &tmp);
+
+ g_assert (tmp == values[i++]);
+
+ qmi_utils_write_guint16_to_buffer (&out_buffer_walker, &out_buffer_size, &tmp);
+ }
+
+ g_assert_cmpuint (out_buffer_size, ==, 0);
+ g_assert (memcmp (in_buffer, out_buffer, sizeof (in_buffer)) == 0);
+}
+
+static void
+test_utils_int16 (void)
+{
+ static guint8 in_buffer[8] = {
+ 0x0F, 0x50, 0xEB, 0xE2, 0xB6, 0x00, 0x00, 0x00
+ };
+ static gint16 values[4] = {
+ 0x500F, 0xE2EB, 0x00B6, 0x0000
+ };
+ guint8 out_buffer[8] = { 0 };
+
+ guint i;
+ guint16 in_buffer_size;
+ guint8 *in_buffer_walker;
+ guint16 out_buffer_size;
+ guint8 *out_buffer_walker;
+
+ in_buffer_size = sizeof (in_buffer);
+ in_buffer_walker = &in_buffer[0];
+ out_buffer_size = sizeof (out_buffer);
+ out_buffer_walker = &out_buffer[0];
+ i = 0;
+
+ while (in_buffer_size) {
+ gint16 tmp;
+
+ qmi_utils_read_gint16_from_buffer (&in_buffer_walker, &in_buffer_size, &tmp);
+
+ g_assert (tmp == values[i++]);
+
+ qmi_utils_write_gint16_to_buffer (&out_buffer_walker, &out_buffer_size, &tmp);
+ }
+
+ g_assert_cmpuint (out_buffer_size, ==, 0);
+ g_assert (memcmp (in_buffer, out_buffer, sizeof (in_buffer)) == 0);
+}
+
+static void
+test_utils_uint32 (void)
+{
+ static guint8 in_buffer[8] = {
+ 0x0F, 0x50, 0xEB, 0xE2, 0xB6, 0x00, 0x00, 0x00
+ };
+ static guint32 values[2] = {
+ 0xE2EB500F, 0x000000B6
+ };
+ guint8 out_buffer[8] = { 0 };
+
+ guint i;
+ guint16 in_buffer_size;
+ guint8 *in_buffer_walker;
+ guint16 out_buffer_size;
+ guint8 *out_buffer_walker;
+
+ in_buffer_size = sizeof (in_buffer);
+ in_buffer_walker = &in_buffer[0];
+ out_buffer_size = sizeof (out_buffer);
+ out_buffer_walker = &out_buffer[0];
+ i = 0;
+
+ while (in_buffer_size) {
+ guint32 tmp;
+
+ qmi_utils_read_guint32_from_buffer (&in_buffer_walker, &in_buffer_size, &tmp);
+
+ g_assert (tmp == values[i++]);
+
+ qmi_utils_write_guint32_to_buffer (&out_buffer_walker, &out_buffer_size, &tmp);
+ }
+
+ g_assert_cmpuint (out_buffer_size, ==, 0);
+ g_assert (memcmp (in_buffer, out_buffer, sizeof (in_buffer)) == 0);
+}
+
+static void
+test_utils_int32 (void)
+{
+ static guint8 in_buffer[8] = {
+ 0x0F, 0x50, 0xEB, 0xE2, 0xB6, 0x00, 0x00, 0x00
+ };
+ static gint32 values[2] = {
+ 0xE2EB500F, 0x000000B6
+ };
+ guint8 out_buffer[8] = { 0 };
+
+ guint i;
+ guint16 in_buffer_size;
+ guint8 *in_buffer_walker;
+ guint16 out_buffer_size;
+ guint8 *out_buffer_walker;
+
+ in_buffer_size = sizeof (in_buffer);
+ in_buffer_walker = &in_buffer[0];
+ out_buffer_size = sizeof (out_buffer);
+ out_buffer_walker = &out_buffer[0];
+ i = 0;
+
+ while (in_buffer_size) {
+ gint32 tmp;
+
+ qmi_utils_read_gint32_from_buffer (&in_buffer_walker, &in_buffer_size, &tmp);
+
+ g_assert (tmp == values[i++]);
+
+ qmi_utils_write_gint32_to_buffer (&out_buffer_walker, &out_buffer_size, &tmp);
+ }
+
+ g_assert_cmpuint (out_buffer_size, ==, 0);
+ g_assert (memcmp (in_buffer, out_buffer, sizeof (in_buffer)) == 0);
+}
+
+static void
+test_utils_uint64 (void)
+{
+ static guint8 in_buffer[8] = {
+ 0x0F, 0x50, 0xEB, 0xE2, 0xB6, 0x00, 0x00, 0x00
+ };
+ static guint64 values[1] = {
+ 0x000000B6E2EB500F
+ };
+ guint8 out_buffer[8] = { 0 };
+
+ guint i;
+ guint16 in_buffer_size;
+ guint8 *in_buffer_walker;
+ guint16 out_buffer_size;
+ guint8 *out_buffer_walker;
+
+ in_buffer_size = sizeof (in_buffer);
+ in_buffer_walker = &in_buffer[0];
+ out_buffer_size = sizeof (out_buffer);
+ out_buffer_walker = &out_buffer[0];
+ i = 0;
+
+ while (in_buffer_size) {
+ guint64 tmp;
+
+ qmi_utils_read_guint64_from_buffer (&in_buffer_walker, &in_buffer_size, &tmp);
+
+ g_assert (tmp == values[i++]);
+
+ qmi_utils_write_guint64_to_buffer (&out_buffer_walker, &out_buffer_size, &tmp);
+ }
+
+ g_assert_cmpuint (out_buffer_size, ==, 0);
+ g_assert (memcmp (in_buffer, out_buffer, sizeof (in_buffer)) == 0);
+}
+
+static void
+test_utils_int64 (void)
+{
+ static guint8 in_buffer[8] = {
+ 0x0F, 0x50, 0xEB, 0xE2, 0xB6, 0x00, 0x00, 0x00
+ };
+ static gint64 values[1] = {
+ 0x000000B6E2EB500F
+ };
+ guint8 out_buffer[8] = { 0 };
+
+ guint i;
+ guint16 in_buffer_size;
+ guint8 *in_buffer_walker;
+ guint16 out_buffer_size;
+ guint8 *out_buffer_walker;
+
+ in_buffer_size = sizeof (in_buffer);
+ in_buffer_walker = &in_buffer[0];
+ out_buffer_size = sizeof (out_buffer);
+ out_buffer_walker = &out_buffer[0];
+ i = 0;
+
+ while (in_buffer_size) {
+ gint64 tmp;
+
+ qmi_utils_read_gint64_from_buffer (&in_buffer_walker, &in_buffer_size, &tmp);
+
+ g_assert (tmp == values[i++]);
+
+ qmi_utils_write_gint64_to_buffer (&out_buffer_walker, &out_buffer_size, &tmp);
+ }
+
+ g_assert_cmpuint (out_buffer_size, ==, 0);
+ g_assert (memcmp (in_buffer, out_buffer, sizeof (in_buffer)) == 0);
+}
+
+int main (int argc, char **argv)
+{
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/libqmi-glib/utils/uint8", test_utils_uint8);
+ g_test_add_func ("/libqmi-glib/utils/int8", test_utils_int8);
+ g_test_add_func ("/libqmi-glib/utils/uint16", test_utils_uint16);
+ g_test_add_func ("/libqmi-glib/utils/int16", test_utils_int16);
+ g_test_add_func ("/libqmi-glib/utils/uint32", test_utils_uint32);
+ g_test_add_func ("/libqmi-glib/utils/int32", test_utils_int32);
+ g_test_add_func ("/libqmi-glib/utils/uint64", test_utils_uint64);
+ g_test_add_func ("/libqmi-glib/utils/int64", test_utils_int64);
+
+ return g_test_run ();
+}