aboutsummaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/Makefile.am16
-rw-r--r--src/tests/Makefile.in63
-rw-r--r--src/tests/test-at-serial-port.c86
-rw-r--r--src/tests/test-charsets.c45
-rw-r--r--src/tests/test-modem-helpers.c14
-rw-r--r--src/tests/test-qcdm-serial-port.c20
-rw-r--r--src/tests/test-sms.c289
7 files changed, 495 insertions, 38 deletions
diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am
index cc47e66..43b3eb1 100644
--- a/src/tests/Makefile.am
+++ b/src/tests/Makefile.am
@@ -5,6 +5,7 @@ noinst_PROGRAMS = \
test-modem-helpers \
test-charsets \
test-qcdm-serial-port \
+ test-at-serial-port \
test-sms
test_modem_helpers_SOURCES = \
@@ -41,6 +42,20 @@ test_qcdm_serial_port_LDADD = \
$(top_builddir)/libqcdm/src/libqcdm.la \
-lutil
+test_at_serial_port_SOURCES = \
+ test-at-serial-port.c
+
+test_at_serial_port_CPPFLAGS = \
+ $(MM_CFLAGS) \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/src
+
+test_at_serial_port_LDADD = \
+ $(MM_LIBS) \
+ $(top_builddir)/src/libserial.la \
+ $(top_builddir)/src/libmodem-helpers.la \
+ -lutil
+
test_sms_SOURCES = \
test-sms.c
@@ -60,4 +75,3 @@ check-local: test-modem-helpers
$(abs_builddir)/test-sms
endif
-
diff --git a/src/tests/Makefile.in b/src/tests/Makefile.in
index 94793ef..d6c4d1a 100644
--- a/src/tests/Makefile.in
+++ b/src/tests/Makefile.in
@@ -35,7 +35,8 @@ POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
noinst_PROGRAMS = test-modem-helpers$(EXEEXT) test-charsets$(EXEEXT) \
- test-qcdm-serial-port$(EXEEXT) test-sms$(EXEEXT)
+ test-qcdm-serial-port$(EXEEXT) test-at-serial-port$(EXEEXT) \
+ test-sms$(EXEEXT)
subdir = src/tests
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@@ -43,7 +44,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/compiler_warnings.m4 \
$(top_srcdir)/m4/intltool.m4 $(top_srcdir)/m4/libtool.m4 \
$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
- $(top_srcdir)/configure.ac
+ $(top_srcdir)/m4/nls.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
@@ -51,14 +52,20 @@ CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
PROGRAMS = $(noinst_PROGRAMS)
-am_test_charsets_OBJECTS = test_charsets-test-charsets.$(OBJEXT)
-test_charsets_OBJECTS = $(am_test_charsets_OBJECTS)
+am_test_at_serial_port_OBJECTS = \
+ test_at_serial_port-test-at-serial-port.$(OBJEXT)
+test_at_serial_port_OBJECTS = $(am_test_at_serial_port_OBJECTS)
am__DEPENDENCIES_1 =
-test_charsets_DEPENDENCIES = $(top_builddir)/src/libmodem-helpers.la \
- $(am__DEPENDENCIES_1)
+test_at_serial_port_DEPENDENCIES = $(am__DEPENDENCIES_1) \
+ $(top_builddir)/src/libserial.la \
+ $(top_builddir)/src/libmodem-helpers.la
AM_V_lt = $(am__v_lt_$(V))
am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY))
am__v_lt_0 = --silent
+am_test_charsets_OBJECTS = test_charsets-test-charsets.$(OBJEXT)
+test_charsets_OBJECTS = $(am_test_charsets_OBJECTS)
+test_charsets_DEPENDENCIES = $(top_builddir)/src/libmodem-helpers.la \
+ $(am__DEPENDENCIES_1)
am_test_modem_helpers_OBJECTS = \
test_modem_helpers-test-modem-helpers.$(OBJEXT)
test_modem_helpers_OBJECTS = $(am_test_modem_helpers_OBJECTS)
@@ -104,10 +111,12 @@ am__v_CCLD_0 = @echo " CCLD " $@;
AM_V_GEN = $(am__v_GEN_$(V))
am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY))
am__v_GEN_0 = @echo " GEN " $@;
-SOURCES = $(test_charsets_SOURCES) $(test_modem_helpers_SOURCES) \
- $(test_qcdm_serial_port_SOURCES) $(test_sms_SOURCES)
-DIST_SOURCES = $(test_charsets_SOURCES) $(test_modem_helpers_SOURCES) \
- $(test_qcdm_serial_port_SOURCES) $(test_sms_SOURCES)
+SOURCES = $(test_at_serial_port_SOURCES) $(test_charsets_SOURCES) \
+ $(test_modem_helpers_SOURCES) $(test_qcdm_serial_port_SOURCES) \
+ $(test_sms_SOURCES)
+DIST_SOURCES = $(test_at_serial_port_SOURCES) $(test_charsets_SOURCES) \
+ $(test_modem_helpers_SOURCES) $(test_qcdm_serial_port_SOURCES) \
+ $(test_sms_SOURCES)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
@@ -299,6 +308,20 @@ test_qcdm_serial_port_LDADD = \
$(top_builddir)/libqcdm/src/libqcdm.la \
-lutil
+test_at_serial_port_SOURCES = \
+ test-at-serial-port.c
+
+test_at_serial_port_CPPFLAGS = \
+ $(MM_CFLAGS) \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/src
+
+test_at_serial_port_LDADD = \
+ $(MM_LIBS) \
+ $(top_builddir)/src/libserial.la \
+ $(top_builddir)/src/libmodem-helpers.la \
+ -lutil
+
test_sms_SOURCES = \
test-sms.c
@@ -352,6 +375,9 @@ clean-noinstPROGRAMS:
list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
echo " rm -f" $$list; \
rm -f $$list
+test-at-serial-port$(EXEEXT): $(test_at_serial_port_OBJECTS) $(test_at_serial_port_DEPENDENCIES)
+ @rm -f test-at-serial-port$(EXEEXT)
+ $(AM_V_CCLD)$(LINK) $(test_at_serial_port_OBJECTS) $(test_at_serial_port_LDADD) $(LIBS)
test-charsets$(EXEEXT): $(test_charsets_OBJECTS) $(test_charsets_DEPENDENCIES)
@rm -f test-charsets$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(test_charsets_OBJECTS) $(test_charsets_LDADD) $(LIBS)
@@ -371,6 +397,7 @@ mostlyclean-compile:
distclean-compile:
-rm -f *.tab.c
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_at_serial_port-test-at-serial-port.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_charsets-test-charsets.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_modem_helpers-test-modem-helpers.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_qcdm_serial_port-test-qcdm-serial-port.Po@am__quote@
@@ -403,6 +430,22 @@ distclean-compile:
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
+test_at_serial_port-test-at-serial-port.o: test-at-serial-port.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_at_serial_port_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_at_serial_port-test-at-serial-port.o -MD -MP -MF $(DEPDIR)/test_at_serial_port-test-at-serial-port.Tpo -c -o test_at_serial_port-test-at-serial-port.o `test -f 'test-at-serial-port.c' || echo '$(srcdir)/'`test-at-serial-port.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_at_serial_port-test-at-serial-port.Tpo $(DEPDIR)/test_at_serial_port-test-at-serial-port.Po
+@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='test-at-serial-port.c' object='test_at_serial_port-test-at-serial-port.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_at_serial_port_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_at_serial_port-test-at-serial-port.o `test -f 'test-at-serial-port.c' || echo '$(srcdir)/'`test-at-serial-port.c
+
+test_at_serial_port-test-at-serial-port.obj: test-at-serial-port.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_at_serial_port_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_at_serial_port-test-at-serial-port.obj -MD -MP -MF $(DEPDIR)/test_at_serial_port-test-at-serial-port.Tpo -c -o test_at_serial_port-test-at-serial-port.obj `if test -f 'test-at-serial-port.c'; then $(CYGPATH_W) 'test-at-serial-port.c'; else $(CYGPATH_W) '$(srcdir)/test-at-serial-port.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_at_serial_port-test-at-serial-port.Tpo $(DEPDIR)/test_at_serial_port-test-at-serial-port.Po
+@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='test-at-serial-port.c' object='test_at_serial_port-test-at-serial-port.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_at_serial_port_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_at_serial_port-test-at-serial-port.obj `if test -f 'test-at-serial-port.c'; then $(CYGPATH_W) 'test-at-serial-port.c'; else $(CYGPATH_W) '$(srcdir)/test-at-serial-port.c'; fi`
+
test_charsets-test-charsets.o: test-charsets.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_charsets_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_charsets-test-charsets.o -MD -MP -MF $(DEPDIR)/test_charsets-test-charsets.Tpo -c -o test_charsets-test-charsets.o `test -f 'test-charsets.c' || echo '$(srcdir)/'`test-charsets.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_charsets-test-charsets.Tpo $(DEPDIR)/test_charsets-test-charsets.Po
diff --git a/src/tests/test-at-serial-port.c b/src/tests/test-at-serial-port.c
new file mode 100644
index 0000000..c46fa88
--- /dev/null
+++ b/src/tests/test-at-serial-port.c
@@ -0,0 +1,86 @@
+/* -*- 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 <config.h>
+#include <string.h>
+#include <glib.h>
+
+#include "mm-errors.h"
+#include "mm-at-serial-port.h"
+#include "mm-log.h"
+
+typedef struct {
+ gchar *original;
+ gchar *without_echo;
+} EchoRemovalTest;
+
+static const EchoRemovalTest echo_removal_tests[] = {
+ { "\r\n", "\r\n" },
+ { "\r", "\r" },
+ { "\n", "\n" },
+ { "this is a string that ends just with <CR>\r", "this is a string that ends just with <CR>\r" },
+ { "this is a string that ends just with <CR>\n", "this is a string that ends just with <CR>\n" },
+ { "\r\nthis is valid", "\r\nthis is valid" },
+ { "a\r\nthis is valid", "\r\nthis is valid" },
+ { "a\r\n", "\r\n" },
+ { "all this string is to be considered echo\r\n", "\r\n" },
+ { "all this string is to be considered echo\r\nthis is valid", "\r\nthis is valid" },
+ { "echo echo\r\nthis is valid\r\nand so is this", "\r\nthis is valid\r\nand so is this" },
+ { "\r\nthis is valid\r\nand so is this", "\r\nthis is valid\r\nand so is this" },
+ { "\r\nthis is valid\r\nand so is this\r\n", "\r\nthis is valid\r\nand so is this\r\n" },
+};
+
+static void
+at_serial_echo_removal (void)
+{
+ guint i;
+
+ for (i = 0; i < G_N_ELEMENTS (echo_removal_tests); i++) {
+ GByteArray *ba;
+
+ /* Note that we add last NUL also to the byte array, so that we can compare
+ * C strings later on */
+ ba = g_byte_array_sized_new (strlen (echo_removal_tests[i].original) + 1);
+ g_byte_array_prepend (ba,
+ (guint8 *)echo_removal_tests[i].original,
+ strlen (echo_removal_tests[i].original) + 1);
+
+ mm_at_serial_port_remove_echo (ba);
+
+ g_assert_cmpstr ((gchar *)ba->data, ==, echo_removal_tests[i].without_echo);
+
+ g_byte_array_unref (ba);
+ }
+}
+
+void
+_mm_log (const char *loc,
+ const char *func,
+ guint32 level,
+ const char *fmt,
+ ...)
+{
+ /* Dummy log function */
+}
+
+int main (int argc, char **argv)
+{
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/ModemManager/AT-serial/echo-removal", at_serial_echo_removal);
+
+ return g_test_run ();
+}
diff --git a/src/tests/test-charsets.c b/src/tests/test-charsets.c
index 70c796a..f954d93 100644
--- a/src/tests/test-charsets.c
+++ b/src/tests/test-charsets.c
@@ -284,6 +284,48 @@ test_pack_gsm7_24_chars (void *f, gpointer d)
g_free (packed);
}
+static void
+test_pack_gsm7_last_septet_alone (void *f, gpointer d)
+{
+ static const guint8 unpacked[] = {
+ 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x72, 0x65, 0x61, 0x6C,
+ 0x6C, 0x79, 0x20, 0x63, 0x6F, 0x6F, 0x6C, 0x20, 0x10, 0x10, 0x10, 0x10,
+ 0x10
+ };
+ static const guint8 expected[] = {
+ 0x54, 0x74, 0x7A, 0x0E, 0x4A, 0xCF, 0x41, 0xF2, 0x72, 0x98, 0xCD, 0xCE,
+ 0x83, 0xC6, 0xEF, 0x37, 0x1B, 0x04, 0x81, 0x40, 0x20, 0x10
+ };
+ guint8 *packed;
+ guint32 packed_len = 0;
+
+ /* Tests that a 25-character unpacked string (where, when packed, the last
+ * septet will be in an octet by itself) packs correctly.
+ */
+
+ packed = gsm_pack (unpacked, sizeof (unpacked), 0, &packed_len);
+ g_assert (packed);
+ g_assert_cmpint (packed_len, ==, sizeof (expected));
+
+ g_free (packed);
+}
+
+static void
+test_pack_gsm7_7_chars_offset (void *f, gpointer d)
+{
+ static const guint8 unpacked[] = { 0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x10, 0x2F };
+ static const guint8 expected[] = { 0x00, 0x5D, 0x66, 0xB3, 0xDF, 0x90, 0x17 };
+ guint8 *packed;
+ guint32 packed_len = 0;
+
+ packed = gsm_pack (unpacked, sizeof (unpacked), 5, &packed_len);
+ g_assert (packed);
+ g_assert_cmpint (packed_len, ==, sizeof (expected));
+ g_assert_cmpint (memcmp (packed, expected, packed_len), ==, 0);
+
+ g_free (packed);
+}
+
#if GLIB_CHECK_VERSION(2,25,12)
typedef GTestFixtureFunc TCFunc;
@@ -314,6 +356,9 @@ int main (int argc, char **argv)
g_test_suite_add (suite, TESTCASE (test_pack_gsm7_7_chars, NULL));
g_test_suite_add (suite, TESTCASE (test_pack_gsm7_all_chars, NULL));
g_test_suite_add (suite, TESTCASE (test_pack_gsm7_24_chars, NULL));
+ g_test_suite_add (suite, TESTCASE (test_pack_gsm7_last_septet_alone, NULL));
+
+ g_test_suite_add (suite, TESTCASE (test_pack_gsm7_7_chars_offset, NULL));
result = g_test_run ();
diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c
index d07f0d4..3b8e2e2 100644
--- a/src/tests/test-modem-helpers.c
+++ b/src/tests/test-modem-helpers.c
@@ -491,8 +491,9 @@ test_creg_match (const char *test,
g_assert (data);
g_assert (result);
- g_print ("\nTesting %s +CREG %s response...\n",
+ g_print ("\nTesting %s +C%sREG %s response...\n",
test,
+ result->cgreg ? "G" : "",
solicited ? "solicited" : "unsolicited");
array = solicited ? data->solicited_creg : data->unsolicited_creg;
@@ -743,6 +744,16 @@ test_creg2_gobi_weird_solicited (void *f, gpointer d)
}
static void
+test_cgreg2_unsolicited_with_rac (void *f, gpointer d)
+{
+ TestData *data = (TestData *) d;
+ const char *reply = "\r\n+CGREG: 1,\"1422\",\"00000142\",3,\"00\"\r\n";
+ const CregResult result = { 1, 0x1422, 0x0142, 3, 8, TRUE };
+
+ test_creg_match ("CGREG=2 with RAC", FALSE, reply, data, &result);
+}
+
+static void
test_cscs_icon225_support_response (void *f, gpointer d)
{
const char *reply = "\r\n+CSCS: (\"IRA\",\"GSM\",\"UCS2\")\r\n";
@@ -1269,6 +1280,7 @@ int main (int argc, char **argv)
g_test_suite_add (suite, TESTCASE (test_cgreg2_f3607gw_unsolicited, data));
g_test_suite_add (suite, TESTCASE (test_cgreg2_md400_unsolicited, data));
g_test_suite_add (suite, TESTCASE (test_cgreg2_x220_unsolicited, data));
+ g_test_suite_add (suite, TESTCASE (test_cgreg2_unsolicited_with_rac, data));
g_test_suite_add (suite, TESTCASE (test_creg_cgreg_multi_unsolicited, data));
g_test_suite_add (suite, TESTCASE (test_creg_cgreg_multi2_unsolicited, data));
diff --git a/src/tests/test-qcdm-serial-port.c b/src/tests/test-qcdm-serial-port.c
index 3aeed6a..c31011b 100644
--- a/src/tests/test-qcdm-serial-port.c
+++ b/src/tests/test-qcdm-serial-port.c
@@ -31,6 +31,7 @@
#include "libqcdm/src/commands.h"
#include "libqcdm/src/utils.h"
#include "libqcdm/src/com.h"
+#include "libqcdm/src/errors.h"
#include "mm-log.h"
typedef struct {
@@ -135,8 +136,9 @@ server_wait_request (int fd, char *buf, gsize len)
retries++;
continue;
} else if (bytes_read == 1) {
- gboolean more = FALSE, success;
+ gboolean success;
gsize used = 0;
+ qcdmbool more = FALSE;
total++;
decap_len = 0;
@@ -187,17 +189,14 @@ qcdm_verinfo_expect_success_cb (MMQcdmSerialPort *port,
static void
qcdm_request_verinfo (MMQcdmSerialPort *port, VerInfoCb cb, GMainLoop *loop)
{
- GError *error = NULL;
GByteArray *verinfo;
gint len;
/* Build up the probe command */
verinfo = g_byte_array_sized_new (50);
- len = qcdm_cmd_version_info_new ((char *) verinfo->data, 50, &error);
- if (len <= 0) {
+ len = qcdm_cmd_version_info_new ((char *) verinfo->data, 50);
+ if (len <= 0)
g_byte_array_free (verinfo, TRUE);
- g_assert_no_error (error);
- }
verinfo->len = len;
mm_qcdm_serial_port_queue_command (port, verinfo, 3, cb, loop);
@@ -400,9 +399,7 @@ test_pty_create (gpointer user_data)
{
TestData *d = user_data;
struct termios stbuf;
- int ret;
- GError *error = NULL;
- gboolean success;
+ int ret, err;
ret = openpty (&d->master, &d->slave, NULL, NULL, NULL);
g_assert (ret == 0);
@@ -417,9 +414,8 @@ test_pty_create (gpointer user_data)
fcntl (d->slave, F_SETFL, O_NONBLOCK);
fcntl (d->master, F_SETFL, O_NONBLOCK);
- success = qcdm_port_setup (d->master, &error);
- g_assert_no_error (error);
- g_assert (success);
+ err = qcdm_port_setup (d->master);
+ g_assert_cmpint (err, ==, QCDM_SUCCESS);
}
static void
diff --git a/src/tests/test-sms.c b/src/tests/test-sms.c
index bd18c0b..5c32ad1 100644
--- a/src/tests/test-sms.c
+++ b/src/tests/test-sms.c
@@ -20,6 +20,7 @@
#include "mm-sms-utils.h"
#include "mm-utils.h"
+#include "dbus/dbus-glib.h"
#define TEST_ENTRY_EQ(hash, key, expectvalue) do { \
@@ -30,6 +31,27 @@
g_assert_cmpstr(g_value_get_string(value), ==, (expectvalue)); \
} while (0)
+#define TEST_UINT_ENTRY_EQ(hash, key, expectvalue) do { \
+ GValue *value; \
+ value = g_hash_table_lookup((hash), (key)); \
+ g_assert(value); \
+ g_assert(G_VALUE_HOLDS_UINT(value)); \
+ g_assert_cmpint(g_value_get_uint(value), ==, (expectvalue)); \
+ } while (0)
+
+#define TEST_ARRAY_ENTRY_EQ(hash, key, expectvalue) do { \
+ GValue *value; \
+ GByteArray *tmp; \
+ guint32 i; \
+ value = g_hash_table_lookup((hash), (key)); \
+ g_assert(value); \
+ g_assert(G_VALUE_HOLDS(value, DBUS_TYPE_G_UCHAR_ARRAY)); \
+ tmp = g_value_get_boxed (value); \
+ g_assert_cmpint (tmp->len, ==, sizeof (expectvalue)); \
+ for (i = 0; i < tmp->len; i++) \
+ g_assert_cmpint (tmp->data[i], ==, expectvalue[i]); \
+ } while (0)
+
static void
test_pdu1 (void *f, gpointer d)
{
@@ -52,7 +74,7 @@ test_pdu1 (void *f, gpointer d)
0x28, 0xec, 0x26, 0x83, 0xbe, 0x60, 0x50, 0x78,
0x0e, 0xba, 0x97, 0xd9, 0x6c, 0x17};
GHashTable *sms;
- GError *error;
+ GError *error = NULL;
char *hexpdu;
hexpdu = utils_bin2hexstr (pdu, sizeof(pdu));
@@ -80,7 +102,7 @@ test_pdu2 (void *f, gpointer d)
0x30, 0x92, 0x91, 0x02, 0x40, 0x61, 0x08, 0x04,
0x42, 0x04, 0x35, 0x04, 0x41, 0x04, 0x42};
GHashTable *sms;
- GError *error;
+ GError *error = NULL;
char *hexpdu;
hexpdu = utils_bin2hexstr (pdu, sizeof(pdu));
@@ -106,7 +128,7 @@ test_pdu3 (void *f, gpointer d)
0x65, 0x00, 0x0a, 0xe8, 0x32, 0x9b, 0xfd, 0x46,
0x97, 0xd9, 0xec, 0x37};
GHashTable *sms;
- GError *error;
+ GError *error = NULL;
char *hexpdu;
hexpdu = utils_bin2hexstr (pdu, sizeof(pdu));
@@ -134,7 +156,7 @@ test_pdu3_nzpid (void *f, gpointer d)
0x65, 0x00, 0x0a, 0xe8, 0x32, 0x9b, 0xfd, 0x46,
0x97, 0xd9, 0xec, 0x37};
GHashTable *sms;
- GError *error;
+ GError *error = NULL;
char *hexpdu;
hexpdu = utils_bin2hexstr (pdu, sizeof(pdu));
@@ -163,7 +185,7 @@ test_pdu3_mms (void *f, gpointer d)
0x65, 0x00, 0x0a, 0xe8, 0x32, 0x9b, 0xfd, 0x46,
0x97, 0xd9, 0xec, 0x37};
GHashTable *sms;
- GError *error;
+ GError *error = NULL;
char *hexpdu;
hexpdu = utils_bin2hexstr (pdu, sizeof(pdu));
@@ -191,7 +213,7 @@ test_pdu3_natl (void *f, gpointer d)
0x65, 0x00, 0x0a, 0xe8, 0x32, 0x9b, 0xfd, 0x46,
0x97, 0xd9, 0xec, 0x37};
GHashTable *sms;
- GError *error;
+ GError *error = NULL;
char *hexpdu;
hexpdu = utils_bin2hexstr (pdu, sizeof(pdu));
@@ -217,8 +239,10 @@ test_pdu3_8bit (void *f, gpointer d)
0xf2, 0x00, 0x04, 0x11, 0x10, 0x10, 0x21, 0x43,
0x65, 0x00, 0x0a, 0xe8, 0x32, 0x9b, 0xfd, 0x46,
0x97, 0xd9, 0xec, 0x37, 0xde};
+ static const guint8 expected_data[] = {
+ 0xe8, 0x32, 0x9b, 0xfd, 0x46, 0x97, 0xd9, 0xec, 0x37, 0xde };
GHashTable *sms;
- GError *error;
+ GError *error = NULL;
char *hexpdu;
hexpdu = utils_bin2hexstr (pdu, sizeof(pdu));
@@ -228,7 +252,9 @@ test_pdu3_8bit (void *f, gpointer d)
TEST_ENTRY_EQ (sms, "smsc", "+12345678901");
TEST_ENTRY_EQ (sms, "number", "+18005551212");
TEST_ENTRY_EQ (sms, "timestamp", "110101123456+00");
- TEST_ENTRY_EQ (sms, "text", "\xe8\x32\x9b\xfd\x46\x97\xd9\xec\x37\xde");
+ TEST_ENTRY_EQ (sms, "text", "");
+ TEST_UINT_ENTRY_EQ (sms, "data-coding-scheme", 0x04);
+ TEST_ARRAY_ENTRY_EQ (sms, "data", expected_data);
g_free (hexpdu);
g_hash_table_unref (sms);
@@ -272,7 +298,7 @@ test_pdu_dcsf1 (void *f, gpointer d)
0x00, 0x47, 0xBF, 0xDD, 0x65, 0x50, 0xB8, 0x0E,
0xCA, 0xD9, 0x66};
GHashTable *sms;
- GError *error;
+ GError *error = NULL;
char *hexpdu;
hexpdu = utils_bin2hexstr (pdu, sizeof(pdu));
@@ -301,8 +327,10 @@ test_pdu_dcsf_8bit (void *f, gpointer d)
0xf2, 0x00, 0xf4, 0x11, 0x10, 0x10, 0x21, 0x43,
0x65, 0x00, 0x0a, 0xe8, 0x32, 0x9b, 0xfd, 0x46,
0x97, 0xd9, 0xec, 0x37, 0xde};
+ static const guint8 expected_data[] = {
+ 0xe8, 0x32, 0x9b, 0xfd, 0x46, 0x97, 0xd9, 0xec, 0x37, 0xde };
GHashTable *sms;
- GError *error;
+ GError *error = NULL;
char *hexpdu;
hexpdu = utils_bin2hexstr (pdu, sizeof(pdu));
@@ -312,7 +340,9 @@ test_pdu_dcsf_8bit (void *f, gpointer d)
TEST_ENTRY_EQ (sms, "smsc", "+12345678901");
TEST_ENTRY_EQ (sms, "number", "+18005551212");
TEST_ENTRY_EQ (sms, "timestamp", "110101123456+00");
- TEST_ENTRY_EQ (sms, "text", "\xe8\x32\x9b\xfd\x46\x97\xd9\xec\x37\xde");
+ TEST_ENTRY_EQ (sms, "text", "");
+ TEST_UINT_ENTRY_EQ (sms, "data-coding-scheme", 0xF4);
+ TEST_ARRAY_ENTRY_EQ (sms, "data", expected_data);
g_free (hexpdu);
g_hash_table_unref (sms);
@@ -329,7 +359,7 @@ test_pdu_insufficient_data (void *f, gpointer d)
0x97, 0xd9, 0xec, 0x37
};
GHashTable *sms;
- GError *error;
+ GError *error = NULL;
char *hexpdu;
hexpdu = utils_bin2hexstr (pdu, sizeof(pdu));
@@ -351,7 +381,7 @@ test_pdu_udhi (void *f, gpointer d)
"5C7683D27350984D4FABC9A0B33C4C4FCF5D20EBFB2D079DCB62793DBD06D9C36E50FB2D4E97D9"
"A0B49B5E96BBCB";
GHashTable *sms;
- GError *error;
+ GError *error = NULL;
sms = sms_parse_pdu (hexpdu, &error);
g_assert (sms);
@@ -372,7 +402,7 @@ static void
test_pduX (void *f, gpointer d)
{
GHashTable *sms;
- GError *error;
+ GError *error = NULL;
char *hexpdu;
hexpdu = utils_bin2hexstr (pdu1, sizeof(pdu1));
@@ -390,7 +420,225 @@ test_pduX (void *f, gpointer d)
}
#endif
+static void
+test_encode_sms_addr_encode_smsc_intl (void *f, gpointer d)
+{
+ static const char *addr = "+19037029920";
+ static const guint8 expected[] = { 0x07, 0x91, 0x91, 0x30, 0x07, 0x92, 0x29, 0xF0 };
+ guint enclen;
+ guint8 buf[20];
+
+ enclen = sms_encode_address (addr, buf, sizeof (buf), TRUE);
+ g_assert_cmpint (enclen, ==, sizeof (expected));
+ g_assert_cmpint (memcmp (buf, expected, sizeof (expected)), ==, 0);
+}
+
+static void
+test_encode_sms_addr_encode_smsc_unknown (void *f, gpointer d)
+{
+ static const char *addr = "9037029920";
+ static const guint8 expected[] = { 0x06, 0x81, 0x09, 0x73, 0x20, 0x99, 0x02 };
+ guint enclen;
+ guint8 buf[20];
+
+ enclen = sms_encode_address (addr, buf, sizeof (buf), TRUE);
+ g_assert_cmpint (enclen, ==, sizeof (expected));
+ g_assert_cmpint (memcmp (buf, expected, sizeof (expected)), ==, 0);
+}
+
+static void
+test_encode_sms_addr_encode_intl (void *f, gpointer d)
+{
+ static const char *addr = "+19037029920";
+ static const guint8 expected[] = { 0x0B, 0x91, 0x91, 0x30, 0x07, 0x92, 0x29, 0xF0 };
+ guint enclen;
+ guint8 buf[20];
+
+ enclen = sms_encode_address (addr, buf, sizeof (buf), FALSE);
+ g_assert_cmpint (enclen, ==, sizeof (expected));
+ g_assert_cmpint (memcmp (buf, expected, sizeof (expected)), ==, 0);
+}
+
+static void
+test_encode_sms_addr_encode_unknown (void *f, gpointer d)
+{
+ static const char *addr = "9037029920";
+ static const guint8 expected[] = { 0x0A, 0x81, 0x09, 0x73, 0x20, 0x99, 0x02 };
+ guint enclen;
+ guint8 buf[20];
+
+ enclen = sms_encode_address (addr, buf, sizeof (buf), FALSE);
+ g_assert_cmpint (enclen, ==, sizeof (expected));
+ g_assert_cmpint (memcmp (buf, expected, sizeof (expected)), ==, 0);
+}
+
+static void
+test_create_pdu_ucs2_with_smsc (void *f, gpointer d)
+{
+ static const char *smsc = "+19037029920";
+ static const char *number = "+15555551234";
+ static const char *text = "Да здравствует король, детка!";
+ static const guint8 expected[] = {
+ 0x07, 0x91, 0x91, 0x30, 0x07, 0x92, 0x29, 0xF0, 0x11, 0x00, 0x0B, 0x91,
+ 0x51, 0x55, 0x55, 0x15, 0x32, 0xF4, 0x00, 0x08, 0x00, 0x3A, 0x04, 0x14,
+ 0x04, 0x30, 0x00, 0x20, 0x04, 0x37, 0x04, 0x34, 0x04, 0x40, 0x04, 0x30,
+ 0x04, 0x32, 0x04, 0x41, 0x04, 0x42, 0x04, 0x32, 0x04, 0x43, 0x04, 0x35,
+ 0x04, 0x42, 0x00, 0x20, 0x04, 0x3A, 0x04, 0x3E, 0x04, 0x40, 0x04, 0x3E,
+ 0x04, 0x3B, 0x04, 0x4C, 0x00, 0x2C, 0x00, 0x20, 0x04, 0x34, 0x04, 0x35,
+ 0x04, 0x42, 0x04, 0x3A, 0x04, 0x30, 0x00, 0x21
+ };
+ guint8 *pdu;
+ guint len = 0, msgstart = 0;
+ GError *error = NULL;
+
+ pdu = sms_create_submit_pdu (number, text, smsc, 5, 0, &len, &msgstart, &error);
+ g_assert_no_error (error);
+ g_assert (pdu);
+ g_assert_cmpint (len, ==, sizeof (expected));
+ g_assert_cmpint (memcmp (pdu, expected, len), ==, 0);
+ g_assert_cmpint (msgstart, ==, 8);
+}
+
+static void
+test_create_pdu_ucs2_no_smsc (void *f, gpointer d)
+{
+ static const char *number = "+15555551234";
+ static const char *text = "Да здравствует король, детка!";
+ static const guint8 expected[] = {
+ 0x00, 0x11, 0x00, 0x0B, 0x91, 0x51, 0x55, 0x55, 0x15, 0x32, 0xF4, 0x00,
+ 0x08, 0x00, 0x3A, 0x04, 0x14, 0x04, 0x30, 0x00, 0x20, 0x04, 0x37, 0x04,
+ 0x34, 0x04, 0x40, 0x04, 0x30, 0x04, 0x32, 0x04, 0x41, 0x04, 0x42, 0x04,
+ 0x32, 0x04, 0x43, 0x04, 0x35, 0x04, 0x42, 0x00, 0x20, 0x04, 0x3A, 0x04,
+ 0x3E, 0x04, 0x40, 0x04, 0x3E, 0x04, 0x3B, 0x04, 0x4C, 0x00, 0x2C, 0x00,
+ 0x20, 0x04, 0x34, 0x04, 0x35, 0x04, 0x42, 0x04, 0x3A, 0x04, 0x30, 0x00,
+ 0x21
+ };
+ guint8 *pdu;
+ guint len = 0, msgstart = 0;
+ GError *error = NULL;
+
+ pdu = sms_create_submit_pdu (number, text, NULL, 5, 0, &len, &msgstart, &error);
+ g_assert_no_error (error);
+ g_assert (pdu);
+ g_assert_cmpint (len, ==, sizeof (expected));
+ g_assert_cmpint (memcmp (pdu, expected, len), ==, 0);
+ g_assert_cmpint (msgstart, ==, 1);
+}
+
+static void
+test_create_pdu_gsm_with_smsc (void *f, gpointer d)
+{
+ static const char *smsc = "+19037029920";
+ static const char *number = "+15555551234";
+ static const char *text = "Hi there...Tue 17th Jan 2012 05:30.18 pm (GMT+1) ΔΔΔΔΔ";
+ static const guint8 expected[] = {
+ 0x07, 0x91, 0x91, 0x30, 0x07, 0x92, 0x29, 0xF0, 0x11, 0x00, 0x0B, 0x91,
+ 0x51, 0x55, 0x55, 0x15, 0x32, 0xF4, 0x00, 0x00, 0x00, 0x36, 0xC8, 0x34,
+ 0x88, 0x8E, 0x2E, 0xCB, 0xCB, 0x2E, 0x97, 0x8B, 0x5A, 0x2F, 0x83, 0x62,
+ 0x37, 0x3A, 0x1A, 0xA4, 0x0C, 0xBB, 0x41, 0x32, 0x58, 0x4C, 0x06, 0x82,
+ 0xD5, 0x74, 0x33, 0x98, 0x2B, 0x86, 0x03, 0xC1, 0xDB, 0x20, 0xD4, 0xB1,
+ 0x49, 0x5D, 0xC5, 0x52, 0x20, 0x08, 0x04, 0x02, 0x81, 0x00
+ };
+ guint8 *pdu;
+ guint len = 0, msgstart = 0;
+ GError *error = NULL;
+
+ pdu = sms_create_submit_pdu (number, text, smsc, 5, 0, &len, &msgstart, &error);
+ g_assert_no_error (error);
+ g_assert (pdu);
+ g_assert_cmpint (len, ==, sizeof (expected));
+ g_assert_cmpint (memcmp (pdu, expected, len), ==, 0);
+ g_assert_cmpint (msgstart, ==, 8);
+}
+
+static void
+test_create_pdu_gsm_no_smsc (void *f, gpointer d)
+{
+ static const char *number = "+15555551234";
+ static const char *text = "Hi there...Tue 17th Jan 2012 05:30.18 pm (GMT+1) ΔΔΔΔΔ";
+ static const guint8 expected[] = {
+ 0x00, 0x11, 0x00, 0x0B, 0x91, 0x51, 0x55, 0x55, 0x15, 0x32, 0xF4, 0x00,
+ 0x00, 0x00, 0x36, 0xC8, 0x34, 0x88, 0x8E, 0x2E, 0xCB, 0xCB, 0x2E, 0x97,
+ 0x8B, 0x5A, 0x2F, 0x83, 0x62, 0x37, 0x3A, 0x1A, 0xA4, 0x0C, 0xBB, 0x41,
+ 0x32, 0x58, 0x4C, 0x06, 0x82, 0xD5, 0x74, 0x33, 0x98, 0x2B, 0x86, 0x03,
+ 0xC1, 0xDB, 0x20, 0xD4, 0xB1, 0x49, 0x5D, 0xC5, 0x52, 0x20, 0x08, 0x04,
+ 0x02, 0x81, 0x00
+ };
+ guint8 *pdu;
+ guint len = 0, msgstart = 0;
+ GError *error = NULL;
+
+ pdu = sms_create_submit_pdu (number, text, NULL, 5, 0, &len, &msgstart, &error);
+ g_assert_no_error (error);
+ g_assert (pdu);
+ g_assert_cmpint (len, ==, sizeof (expected));
+ g_assert_cmpint (memcmp (pdu, expected, len), ==, 0);
+ g_assert_cmpint (msgstart, ==, 1);
+}
+
+static void
+test_create_pdu_gsm_3 (void *f, gpointer d)
+{
+ static const char *number = "+15556661234";
+ static const char *text = "This is really cool ΔΔΔΔΔ";
+ static const guint8 expected[] = {
+ 0x00, 0x11, 0x00, 0x0B, 0x91, 0x51, 0x55, 0x66, 0x16, 0x32, 0xF4, 0x00,
+ 0x00, 0x00, 0x19, 0x54, 0x74, 0x7A, 0x0E, 0x4A, 0xCF, 0x41, 0xF2, 0x72,
+ 0x98, 0xCD, 0xCE, 0x83, 0xC6, 0xEF, 0x37, 0x1B, 0x04, 0x81, 0x40, 0x20,
+ 0x10
+ };
+ guint8 *pdu;
+ guint len = 0, msgstart = 0;
+ GError *error = NULL;
+
+ /* Tests that a 25-character message (where the last septet is packed into
+ * an octet by itself) is created correctly. Previous to
+ * "core: fix some bugs in GSM7 packing code" the GSM packing code would
+ * leave off the last octet.
+ */
+
+ pdu = sms_create_submit_pdu (number, text, NULL, 5, 0, &len, &msgstart, &error);
+ g_assert_no_error (error);
+ g_assert (pdu);
+ g_assert_cmpint (len, ==, sizeof (expected));
+ g_assert_cmpint (memcmp (pdu, expected, len), ==, 0);
+ g_assert_cmpint (msgstart, ==, 1);
+}
+
+static void
+test_create_pdu_gsm_no_validity (void *f, gpointer d)
+{
+ static const char *number = "+15556661234";
+ static const char *text = "This is really cool ΔΔΔΔΔ";
+ static const guint8 expected[] = {
+ 0x00, 0x01, 0x00, 0x0B, 0x91, 0x51, 0x55, 0x66, 0x16, 0x32, 0xF4, 0x00,
+ 0x00, 0x19, 0x54, 0x74, 0x7A, 0x0E, 0x4A, 0xCF, 0x41, 0xF2, 0x72, 0x98,
+ 0xCD, 0xCE, 0x83, 0xC6, 0xEF, 0x37, 0x1B, 0x04, 0x81, 0x40, 0x20, 0x10
+ };
+ guint8 *pdu;
+ guint len = 0, msgstart = 0;
+ GError *error = NULL;
+
+ pdu = sms_create_submit_pdu (number, text, NULL, 0, 0, &len, &msgstart, &error);
+ g_assert_no_error (error);
+ g_assert (pdu);
+ g_assert_cmpint (len, ==, sizeof (expected));
+ g_assert_cmpint (memcmp (pdu, expected, len), ==, 0);
+ g_assert_cmpint (msgstart, ==, 1);
+}
+#if 0
+{
+int i;
+g_print ("\n ");
+for (i = 0; i < len; i++) {
+ g_print (" 0x%02X", pdu[i]);
+ if (((i + 1) % 12) == 0)
+ g_print ("\n ");
+}
+g_print ("\n");
+}
+#endif
#if GLIB_CHECK_VERSION(2,25,12)
typedef GTestFixtureFunc TCFunc;
@@ -423,6 +671,19 @@ int main (int argc, char **argv)
g_test_suite_add (suite, TESTCASE (test_pdu_insufficient_data, NULL));
g_test_suite_add (suite, TESTCASE (test_pdu_udhi, NULL));
+ g_test_suite_add (suite, TESTCASE (test_encode_sms_addr_encode_smsc_intl, NULL));
+ g_test_suite_add (suite, TESTCASE (test_encode_sms_addr_encode_smsc_unknown, NULL));
+ g_test_suite_add (suite, TESTCASE (test_encode_sms_addr_encode_intl, NULL));
+ g_test_suite_add (suite, TESTCASE (test_encode_sms_addr_encode_unknown, NULL));
+
+ g_test_suite_add (suite, TESTCASE (test_create_pdu_ucs2_with_smsc, NULL));
+ g_test_suite_add (suite, TESTCASE (test_create_pdu_ucs2_no_smsc, NULL));
+ g_test_suite_add (suite, TESTCASE (test_create_pdu_gsm_with_smsc, NULL));
+ g_test_suite_add (suite, TESTCASE (test_create_pdu_gsm_no_smsc, NULL));
+
+ g_test_suite_add (suite, TESTCASE (test_create_pdu_gsm_3, NULL));
+ g_test_suite_add (suite, TESTCASE (test_create_pdu_gsm_no_validity, NULL));
+
result = g_test_run ();
return result;