aboutsummaryrefslogtreecommitdiff
path: root/libqcdm/tests
diff options
context:
space:
mode:
Diffstat (limited to 'libqcdm/tests')
-rw-r--r--libqcdm/tests/Makefile.am30
-rw-r--r--libqcdm/tests/test-qcdm-com.c771
-rw-r--r--libqcdm/tests/test-qcdm-com.h41
-rw-r--r--libqcdm/tests/test-qcdm-crc.c65
-rw-r--r--libqcdm/tests/test-qcdm-crc.h25
-rw-r--r--libqcdm/tests/test-qcdm-escaping.c124
-rw-r--r--libqcdm/tests/test-qcdm-escaping.h26
-rw-r--r--libqcdm/tests/test-qcdm-result.c71
-rw-r--r--libqcdm/tests/test-qcdm-result.h26
-rw-r--r--libqcdm/tests/test-qcdm.c107
10 files changed, 1286 insertions, 0 deletions
diff --git a/libqcdm/tests/Makefile.am b/libqcdm/tests/Makefile.am
new file mode 100644
index 00000000..3d1b7ba5
--- /dev/null
+++ b/libqcdm/tests/Makefile.am
@@ -0,0 +1,30 @@
+INCLUDES = \
+ -I$(top_srcdir)/libqcdm/src
+
+noinst_PROGRAMS = test-qcdm
+
+test_qcdm_SOURCES = \
+ test-qcdm-crc.c \
+ test-qcdm-crc.h \
+ test-qcdm-escaping.c \
+ test-qcdm-escaping.h \
+ test-qcdm-com.c \
+ test-qcdm-com.h \
+ test-qcdm-result.c \
+ test-qcdm-result.h \
+ test-qcdm.c
+
+test_qcdm_CPPFLAGS = \
+ $(MM_CFLAGS)
+
+test_qcdm_LDADD = \
+ $(top_builddir)/libqcdm/src/libqcdm.la \
+ $(MM_LIBS)
+
+if WITH_TESTS
+
+check-local: test-qcdm
+ $(abs_builddir)/test-qcdm
+
+endif
+
diff --git a/libqcdm/tests/test-qcdm-com.c b/libqcdm/tests/test-qcdm-com.c
new file mode 100644
index 00000000..aeec6377
--- /dev/null
+++ b/libqcdm/tests/test-qcdm-com.c
@@ -0,0 +1,771 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Copyright (C) 2010 Red Hat, Inc.
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <termios.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include "test-qcdm-com.h"
+#include "com.h"
+#include "utils.h"
+#include "result.h"
+#include "commands.h"
+#include "error.h"
+
+typedef struct {
+ char *port;
+ int fd;
+ struct termios old_t;
+ gboolean debug;
+} TestComData;
+
+gpointer
+test_com_setup (const char *port)
+{
+ TestComData *d;
+ int ret;
+
+ d = g_malloc0 (sizeof (TestComData));
+ g_assert (d);
+
+ if (getenv ("SERIAL_DEBUG"))
+ d->debug = TRUE;
+
+ errno = 0;
+ d->fd = open (port, O_RDWR | O_EXCL | O_NONBLOCK | O_NOCTTY);
+ if (d->fd < 0)
+ g_warning ("%s: open failed: (%d) %s", port, errno, strerror (errno));
+ g_assert (d->fd >= 0);
+
+ ret = ioctl (d->fd, TIOCEXCL);
+ if (ret) {
+ g_warning ("%s: lock failed: (%d) %s", port, errno, strerror (errno));
+ close (d->fd);
+ d->fd = -1;
+ }
+ g_assert (ret == 0);
+
+ ret = ioctl (d->fd, TCGETA, &d->old_t);
+ if (ret) {
+ g_warning ("%s: old termios failed: (%d) %s", port, errno, strerror (errno));
+ close (d->fd);
+ d->fd = -1;
+ }
+ g_assert (ret == 0);
+
+ d->port = g_strdup (port);
+ return d;
+}
+
+void
+test_com_teardown (gpointer user_data)
+{
+ TestComData *d = user_data;
+
+ g_assert (d);
+
+ g_free (d->port);
+ close (d->fd);
+ g_free (d);
+}
+
+static void
+print_buf (const char *detail, const char *buf, gsize len)
+{
+ int i = 0;
+ gboolean newline = FALSE;
+
+ g_print ("%s (%zu) ", detail, len);
+ for (i = 0; i < len; i++) {
+ g_print ("0x%02x ", buf[i] & 0xFF);
+ if (((i + 1) % 12) == 0) {
+ g_print ("\n");
+ newline = TRUE;
+ } else
+ newline = FALSE;
+ }
+
+ if (!newline)
+ g_print ("\n");
+}
+
+static gboolean
+send_command (TestComData *d, char *buf, gsize len)
+{
+ int status;
+ int eagain_count = 1000;
+ gsize i = 0;
+
+ if (d->debug)
+ print_buf (">>>", buf, len);
+
+ while (i < len) {
+ errno = 0;
+ status = write (d->fd, &buf[i], 1);
+ if (status < 0) {
+ if (errno == EAGAIN) {
+ eagain_count--;
+ if (eagain_count <= 0)
+ return FALSE;
+ } else
+ g_assert (errno == 0);
+ } else
+ i++;
+
+ usleep (1000);
+ }
+
+ return TRUE;
+}
+
+static gsize
+wait_reply (TestComData *d, char *buf, gsize len)
+{
+ fd_set in;
+ int result;
+ struct timeval timeout = { 1, 0 };
+ char readbuf[1024];
+ ssize_t bytes_read;
+ int total = 0, retries = 0;
+ gsize decap_len = 0;
+
+ FD_ZERO (&in);
+ FD_SET (d->fd, &in);
+ result = select (d->fd + 1, &in, NULL, NULL, &timeout);
+ if (result != 1 || !FD_ISSET (d->fd, &in))
+ return 0;
+
+ do {
+ errno = 0;
+ bytes_read = read (d->fd, &readbuf[total], 1);
+ if ((bytes_read == 0) || (errno == EAGAIN)) {
+ /* Haven't gotten the async control char yet */
+ if (retries > 20)
+ return 0; /* 2 seconds, give up */
+
+ /* Otherwise wait a bit and try again */
+ usleep (100000);
+ retries++;
+ continue;
+ } else if (bytes_read == 1) {
+ gboolean more = FALSE, success;
+ gsize used = 0;
+
+ total++;
+ decap_len = 0;
+ success = dm_decapsulate_buffer (readbuf, total, buf, len, &decap_len, &used, &more);
+
+ /* Discard used data */
+ if (used > 0) {
+ total -= used;
+ memmove (readbuf, &readbuf[used], total);
+ }
+
+ if (success && !more) {
+ /* Success; we have a packet */
+ break;
+ }
+ } else {
+ /* Some error occurred */
+ return 0;
+ }
+ } while (total < sizeof (readbuf));
+
+ if (d->debug) {
+ print_buf ("<<<", readbuf, total);
+ print_buf ("D<<", buf, decap_len);
+ }
+
+ return decap_len;
+}
+
+void
+test_com_port_init (void *f, void *data)
+{
+ TestComData *d = data;
+ GError *error = NULL;
+ gboolean success;
+
+ success = qcdm_port_setup (d->fd, &error);
+ if (!success) {
+ g_warning ("%s: error setting up port: (%d) %s",
+ d->port,
+ error ? error->code : -1,
+ error && error->message ? error->message : "(unknown)");
+ }
+ g_assert (success);
+}
+
+void
+test_com_version_info (void *f, void *data)
+{
+ TestComData *d = data;
+ gboolean success;
+ GError *error = NULL;
+ char buf[512];
+ const char *str;
+ gint len;
+ QCDMResult *result;
+ gsize reply_len;
+
+ len = qcdm_cmd_version_info_new (buf, sizeof (buf), NULL);
+ g_assert (len == 4);
+
+ /* Send the command */
+ success = send_command (d, buf, len);
+ g_assert (success);
+
+ /* Get a response */
+ reply_len = wait_reply (d, buf, sizeof (buf));
+
+ /* Parse the response into a result structure */
+ result = qcdm_cmd_version_info_result (buf, reply_len, &error);
+ g_assert (result);
+
+ g_print ("\n");
+
+ str = NULL;
+ qcdm_result_get_string (result, QCDM_CMD_VERSION_INFO_ITEM_COMP_DATE, &str);
+ g_message ("%s: Compiled Date: %s", __func__, str);
+
+ str = NULL;
+ qcdm_result_get_string (result, QCDM_CMD_VERSION_INFO_ITEM_COMP_TIME, &str);
+ g_message ("%s: Compiled Time: %s", __func__, str);
+
+ str = NULL;
+ qcdm_result_get_string (result, QCDM_CMD_VERSION_INFO_ITEM_RELEASE_DATE, &str);
+ g_message ("%s: Release Date: %s", __func__, str);
+
+ str = NULL;
+ qcdm_result_get_string (result, QCDM_CMD_VERSION_INFO_ITEM_RELEASE_TIME, &str);
+ g_message ("%s: Release Time: %s", __func__, str);
+
+ str = NULL;
+ qcdm_result_get_string (result, QCDM_CMD_VERSION_INFO_ITEM_MODEL, &str);
+ g_message ("%s: Model: %s", __func__, str);
+
+ qcdm_result_unref (result);
+}
+
+void
+test_com_esn (void *f, void *data)
+{
+ TestComData *d = data;
+ gboolean success;
+ GError *error = NULL;
+ char buf[512];
+ const char *str;
+ gint len;
+ QCDMResult *result;
+ gsize reply_len;
+
+ len = qcdm_cmd_esn_new (buf, sizeof (buf), NULL);
+ g_assert (len == 4);
+
+ /* Send the command */
+ success = send_command (d, buf, len);
+ g_assert (success);
+
+ /* Get a response */
+ reply_len = wait_reply (d, buf, sizeof (buf));
+
+ /* Parse the response into a result structure */
+ result = qcdm_cmd_esn_result (buf, reply_len, &error);
+ g_assert (result);
+
+ g_print ("\n");
+
+ str = NULL;
+ qcdm_result_get_string (result, QCDM_CMD_ESN_ITEM_ESN, &str);
+ g_message ("%s: ESN: %s", __func__, str);
+
+ qcdm_result_unref (result);
+}
+
+void
+test_com_mdn (void *f, void *data)
+{
+ TestComData *d = data;
+ gboolean success;
+ GError *error = NULL;
+ char buf[512];
+ const char *str;
+ gint len;
+ QCDMResult *result;
+ gsize reply_len;
+
+ len = qcdm_cmd_nv_get_mdn_new (buf, sizeof (buf), 0, NULL);
+ g_assert (len > 0);
+
+ /* Send the command */
+ success = send_command (d, buf, len);
+ g_assert (success);
+
+ /* Get a response */
+ reply_len = wait_reply (d, buf, sizeof (buf));
+
+ /* Parse the response into a result structure */
+ result = qcdm_cmd_nv_get_mdn_result (buf, reply_len, &error);
+ g_assert (result);
+
+ g_print ("\n");
+
+ str = NULL;
+ qcdm_result_get_string (result, QCDM_CMD_NV_GET_MDN_ITEM_MDN, &str);
+ g_message ("%s: MDN: %s", __func__, str);
+
+ qcdm_result_unref (result);
+}
+
+void
+test_com_status (void *f, void *data)
+{
+ TestComData *d = data;
+ gboolean success;
+ GError *error = NULL;
+ char buf[100];
+ const char *str;
+ gint len;
+ QCDMResult *result;
+ gsize reply_len;
+ guint32 n32;
+ guint8 n8;
+
+ len = qcdm_cmd_cdma_status_new (buf, sizeof (buf), NULL);
+ g_assert (len == 4);
+
+ /* Send the command */
+ success = send_command (d, buf, len);
+ g_assert (success);
+
+ /* Get a response */
+ reply_len = wait_reply (d, buf, sizeof (buf));
+
+ /* Parse the response into a result structure */
+ result = qcdm_cmd_cdma_status_result (buf, reply_len, &error);
+ g_assert (result);
+
+ g_print ("\n");
+
+ str = NULL;
+ qcdm_result_get_string (result, QCDM_CMD_CDMA_STATUS_ITEM_ESN, &str);
+ g_message ("%s: ESN: %s", __func__, str);
+
+ n32 = 0;
+ qcdm_result_get_uint32 (result, QCDM_CMD_CDMA_STATUS_ITEM_RX_STATE, &n32);
+ g_message ("%s: CDMA RX State: %u", __func__, n32);
+
+ n32 = 0;
+ qcdm_result_get_uint32 (result, QCDM_CMD_CDMA_STATUS_ITEM_ENTRY_REASON, &n32);
+ g_message ("%s: Entry Reason: %u", __func__, n32);
+
+ n32 = 0;
+ qcdm_result_get_uint32 (result, QCDM_CMD_CDMA_STATUS_ITEM_CURRENT_CHANNEL, &n32);
+ g_message ("%s: Current Channel: %u", __func__, n32);
+
+ n8 = 0;
+ qcdm_result_get_uint8 (result, QCDM_CMD_CDMA_STATUS_ITEM_CODE_CHANNEL, &n8);
+ g_message ("%s: Code Channel: %u", __func__, n8);
+
+ n32 = 0;
+ qcdm_result_get_uint32 (result, QCDM_CMD_CDMA_STATUS_ITEM_PILOT_BASE, &n32);
+ g_message ("%s: Pilot Base: %u", __func__, n32);
+
+ n32 = 0;
+ qcdm_result_get_uint32 (result, QCDM_CMD_CDMA_STATUS_ITEM_SID, &n32);
+ g_message ("%s: CDMA System ID: %u", __func__, n32);
+
+ n32 = 0;
+ qcdm_result_get_uint32 (result, QCDM_CMD_CDMA_STATUS_ITEM_NID, &n32);
+ g_message ("%s: CDMA Network ID: %u", __func__, n32);
+
+ qcdm_result_unref (result);
+}
+
+void
+test_com_sw_version (void *f, void *data)
+{
+ TestComData *d = data;
+ gboolean success;
+ GError *error = NULL;
+ char buf[100];
+ gint len;
+ QCDMResult *result;
+ gsize reply_len;
+
+ len = qcdm_cmd_sw_version_new (buf, sizeof (buf), NULL);
+ g_assert (len == 4);
+
+ /* Send the command */
+ success = send_command (d, buf, len);
+ g_assert (success);
+
+ /* Get a response */
+ reply_len = wait_reply (d, buf, sizeof (buf));
+
+ /* Parse the response into a result structure */
+ result = qcdm_cmd_sw_version_result (buf, reply_len, &error);
+
+ /* Recent devices don't appear to implement this command */
+ g_assert (result == NULL);
+ g_assert_error (error, QCDM_COMMAND_ERROR, QCDM_COMMAND_BAD_COMMAND);
+
+/*
+ str = NULL;
+ qcdm_result_get_string (result, QCDM_CMD_SW_VERSION_ITEM_VERSION, &str);
+ g_message ("%s: SW Version: %s", __func__, str);
+
+ str = NULL;
+ qcdm_result_get_string (result, QCDM_CMD_SW_VERSION_ITEM_COMP_DATE, &str);
+ g_message ("%s: Compiled Date: %s", __func__, str);
+
+ str = NULL;
+ qcdm_result_get_string (result, QCDM_CMD_SW_VERSION_ITEM_COMP_TIME, &str);
+ g_message ("%s: Compiled Time: %s", __func__, str);
+
+ qcdm_result_unref (result);
+*/
+}
+
+void
+test_com_cm_subsys_state_info (void *f, void *data)
+{
+ TestComData *d = data;
+ gboolean success;
+ GError *error = NULL;
+ char buf[100];
+ gint len;
+ QCDMResult *result;
+ gsize reply_len;
+ guint32 n32;
+ const char *detail;
+
+ len = qcdm_cmd_cm_subsys_state_info_new (buf, sizeof (buf), NULL);
+ g_assert (len == 7);
+
+ /* Send the command */
+ success = send_command (d, buf, len);
+ g_assert (success);
+
+ /* Get a response */
+ reply_len = wait_reply (d, buf, sizeof (buf));
+
+ /* Parse the response into a result structure */
+ result = qcdm_cmd_cm_subsys_state_info_result (buf, reply_len, &error);
+ g_assert (result);
+
+ g_print ("\n");
+
+ n32 = 0;
+ qcdm_result_get_uint32 (result, QCDM_CMD_CM_SUBSYS_STATE_INFO_ITEM_CALL_STATE, &n32);
+ g_message ("%s: Call State: %u", __func__, n32);
+
+ n32 = 0;
+ detail = NULL;
+ qcdm_result_get_uint32 (result, QCDM_CMD_CM_SUBSYS_STATE_INFO_ITEM_OPERATING_MODE, &n32);
+ switch (n32) {
+ case QCDM_CMD_CM_SUBSYS_STATE_INFO_OPERATING_MODE_ONLINE:
+ detail = "online";
+ break;
+ default:
+ detail = "unknown";
+ break;
+ }
+ g_message ("%s: Operating Mode: %u (%s)", __func__, n32, detail);
+
+ n32 = 0;
+ detail = NULL;
+ qcdm_result_get_uint32 (result, QCDM_CMD_CM_SUBSYS_STATE_INFO_ITEM_SYSTEM_MODE, &n32);
+ switch (n32) {
+ case QCDM_CMD_CM_SUBSYS_STATE_INFO_SYSTEM_MODE_NO_SERVICE:
+ detail = "no service";
+ break;
+ case QCDM_CMD_CM_SUBSYS_STATE_INFO_SYSTEM_MODE_AMPS:
+ detail = "AMPS";
+ break;
+ case QCDM_CMD_CM_SUBSYS_STATE_INFO_SYSTEM_MODE_CDMA:
+ detail = "CDMA";
+ break;
+ case QCDM_CMD_CM_SUBSYS_STATE_INFO_SYSTEM_MODE_HDR:
+ detail = "HDR/EVDO";
+ break;
+ case QCDM_CMD_CM_SUBSYS_STATE_INFO_SYSTEM_MODE_WCDMA:
+ detail = "WCDMA";
+ break;
+ default:
+ detail = "unknown";
+ break;
+ }
+ g_message ("%s: System Mode: %u (%s)", __func__, n32, detail);
+
+ n32 = 0;
+ qcdm_result_get_uint32 (result, QCDM_CMD_CM_SUBSYS_STATE_INFO_ITEM_MODE_PREF, &n32);
+ g_message ("%s: Mode Preference: %u", __func__, n32);
+
+ n32 = 0;
+ qcdm_result_get_uint32 (result, QCDM_CMD_CM_SUBSYS_STATE_INFO_ITEM_BAND_PREF, &n32);
+ g_message ("%s: Band Preference: %u", __func__, n32);
+
+ n32 = 0;
+ qcdm_result_get_uint32 (result, QCDM_CMD_CM_SUBSYS_STATE_INFO_ITEM_ROAM_PREF, &n32);
+ g_message ("%s: Roam Preference: %u", __func__, n32);
+
+ n32 = 0;
+ qcdm_result_get_uint32 (result, QCDM_CMD_CM_SUBSYS_STATE_INFO_ITEM_SERVICE_DOMAIN_PREF, &n32);
+ g_message ("%s: Service Domain Preference: %u", __func__, n32);
+
+ n32 = 0;
+ qcdm_result_get_uint32 (result, QCDM_CMD_CM_SUBSYS_STATE_INFO_ITEM_ACQ_ORDER_PREF, &n32);
+ g_message ("%s: Acquisition Order Preference: %u", __func__, n32);
+
+ n32 = 0;
+ qcdm_result_get_uint32 (result, QCDM_CMD_CM_SUBSYS_STATE_INFO_ITEM_HYBRID_PREF, &n32);
+ g_message ("%s: Hybrid Preference: %u", __func__, n32);
+
+ n32 = 0;
+ qcdm_result_get_uint32 (result, QCDM_CMD_CM_SUBSYS_STATE_INFO_ITEM_NETWORK_SELECTION_PREF, &n32);
+ g_message ("%s: Network Selection Preference: %u", __func__, n32);
+
+ qcdm_result_unref (result);
+}
+
+void
+test_com_hdr_subsys_state_info (void *f, void *data)
+{
+ TestComData *d = data;
+ gboolean success;
+ GError *error = NULL;
+ char buf[100];
+ gint len;
+ QCDMResult *result;
+ gsize reply_len;
+ guint8 num;
+ const char *detail;
+
+ len = qcdm_cmd_hdr_subsys_state_info_new (buf, sizeof (buf), NULL);
+ g_assert (len == 7);
+
+ /* Send the command */
+ success = send_command (d, buf, len);
+ g_assert (success);
+
+ /* Get a response */
+ reply_len = wait_reply (d, buf, sizeof (buf));
+
+ /* Parse the response into a result structure */
+ result = qcdm_cmd_hdr_subsys_state_info_result (buf, reply_len, &error);
+ if (!result) {
+ /* 1x-only devices won't implement the HDR subsystem of course */
+ g_assert_error (error, QCDM_COMMAND_ERROR, QCDM_COMMAND_BAD_COMMAND);
+ g_message ("%s: device does not implement the HDR subsystem", __func__);
+ return;
+ }
+ g_assert (result);
+
+ g_print ("\n");
+
+ num = 0;
+ detail = NULL;
+ qcdm_result_get_uint8 (result, QCDM_CMD_HDR_SUBSYS_STATE_INFO_ITEM_AT_STATE, &num);
+ switch (num) {
+ case QCDM_CMD_HDR_SUBSYS_STATE_INFO_AT_STATE_INACTIVE:
+ detail = "inactive";
+ break;
+ case QCDM_CMD_HDR_SUBSYS_STATE_INFO_AT_STATE_ACQUISITION:
+ detail = "acquisition";
+ break;
+ case QCDM_CMD_HDR_SUBSYS_STATE_INFO_AT_STATE_SYNC:
+ detail = "sync";
+ break;
+ case QCDM_CMD_HDR_SUBSYS_STATE_INFO_AT_STATE_IDLE:
+ detail = "idle";
+ break;
+ case QCDM_CMD_HDR_SUBSYS_STATE_INFO_AT_STATE_ACCESS:
+ detail = "access";
+ break;
+ case QCDM_CMD_HDR_SUBSYS_STATE_INFO_AT_STATE_CONNECTED:
+ detail = "connected";
+ break;
+ default:
+ detail = "unknown";
+ break;
+ }
+ g_message ("%s: AT State: %u (%s)", __func__, num, detail);
+
+ num = 0;
+ detail = NULL;
+ qcdm_result_get_uint8 (result, QCDM_CMD_HDR_SUBSYS_STATE_INFO_ITEM_SESSION_STATE, &num);
+ switch (num) {
+ case QCDM_CMD_HDR_SUBSYS_STATE_INFO_SESSION_STATE_CLOSED:
+ detail = "closed";
+ break;
+ case QCDM_CMD_HDR_SUBSYS_STATE_INFO_SESSION_STATE_SETUP:
+ detail = "setup";
+ break;
+ case QCDM_CMD_HDR_SUBSYS_STATE_INFO_SESSION_STATE_AT_INIT:
+ detail = "AT init";
+ break;
+ case QCDM_CMD_HDR_SUBSYS_STATE_INFO_SESSION_STATE_AN_INIT:
+ detail = "AN init";
+ break;
+ case QCDM_CMD_HDR_SUBSYS_STATE_INFO_SESSION_STATE_OPEN:
+ detail = "open";
+ break;
+ case QCDM_CMD_HDR_SUBSYS_STATE_INFO_SESSION_STATE_CLOSING:
+ detail = "closing";
+ break;
+ default:
+ detail = "unknown";
+ break;
+ }
+ g_message ("%s: Session State: %u (%s)", __func__, num, detail);
+
+ num = 0;
+ detail = NULL;
+ qcdm_result_get_uint8 (result, QCDM_CMD_HDR_SUBSYS_STATE_INFO_ITEM_ALMP_STATE, &num);
+ switch (num) {
+ case QCDM_CMD_HDR_SUBSYS_STATE_INFO_ALMP_STATE_INACTIVE:
+ detail = "inactive";
+ break;
+ case QCDM_CMD_HDR_SUBSYS_STATE_INFO_ALMP_STATE_INIT:
+ detail = "init";
+ break;
+ case QCDM_CMD_HDR_SUBSYS_STATE_INFO_ALMP_STATE_IDLE:
+ detail = "idle";
+ break;
+ case QCDM_CMD_HDR_SUBSYS_STATE_INFO_ALMP_STATE_CONNECTED:
+ detail = "connected";
+ break;
+ default:
+ detail = "unknown";
+ break;
+ }
+ g_message ("%s: ALMP State: %u (%s)", __func__, num, detail);
+
+ num = 0;
+ detail = NULL;
+ qcdm_result_get_uint8 (result, QCDM_CMD_HDR_SUBSYS_STATE_INFO_ITEM_INIT_STATE, &num);
+ switch (num) {
+ case QCDM_CMD_HDR_SUBSYS_STATE_INFO_INIT_STATE_INACTIVE:
+ detail = "inactive";
+ break;
+ case QCDM_CMD_HDR_SUBSYS_STATE_INFO_INIT_STATE_NET_DETERMINE:
+ detail = "searching";
+ break;
+ case QCDM_CMD_HDR_SUBSYS_STATE_INFO_INIT_STATE_ACQUISITION:
+ detail = "acquisition";
+ break;
+ case QCDM_CMD_HDR_SUBSYS_STATE_INFO_INIT_STATE_SYNC:
+ detail = "sync";
+ break;
+ default:
+ detail = "unknown";
+ break;
+ }
+ g_message ("%s: Init State: %u (%s)", __func__, num, detail);
+
+ num = 0;
+ detail = NULL;
+ qcdm_result_get_uint8 (result, QCDM_CMD_HDR_SUBSYS_STATE_INFO_ITEM_IDLE_STATE, &num);
+ switch (num) {
+ case QCDM_CMD_HDR_SUBSYS_STATE_INFO_IDLE_STATE_INACTIVE:
+ detail = "inactive";
+ break;
+ case QCDM_CMD_HDR_SUBSYS_STATE_INFO_IDLE_STATE_SLEEP:
+ detail = "sleep";
+ break;
+ case QCDM_CMD_HDR_SUBSYS_STATE_INFO_IDLE_STATE_MONITOR:
+ detail = "monitor";
+ break;
+ case QCDM_CMD_HDR_SUBSYS_STATE_INFO_IDLE_STATE_SETUP:
+ detail = "setup";
+ break;
+ default:
+ detail = "unknown";
+ break;
+ }
+ g_message ("%s: Idle State: %u (%s)", __func__, num, detail);
+
+ num = 0;
+ detail = NULL;
+ qcdm_result_get_uint8 (result, QCDM_CMD_HDR_SUBSYS_STATE_INFO_ITEM_CONNECTED_STATE, &num);
+ switch (num) {
+ case QCDM_CMD_HDR_SUBSYS_STATE_INFO_CONNECTED_STATE_INACTIVE:
+ detail = "inactive";
+ break;
+ case QCDM_CMD_HDR_SUBSYS_STATE_INFO_CONNECTED_STATE_OPEN:
+ detail = "open";
+ break;
+ case QCDM_CMD_HDR_SUBSYS_STATE_INFO_CONNECTED_STATE_CLOSING:
+ detail = "closing";
+ break;
+ default:
+ detail = "unknown";
+ break;
+ }
+ g_message ("%s: Connected State: %u (%s)", __func__, num, detail);
+
+ num = 0;
+ detail = NULL;
+ qcdm_result_get_uint8 (result, QCDM_CMD_HDR_SUBSYS_STATE_INFO_ITEM_ROUTE_UPDATE_STATE, &num);
+ switch (num) {
+ case QCDM_CMD_HDR_SUBSYS_STATE_INFO_ROUTE_UPDATE_STATE_INACTIVE:
+ detail = "inactive";
+ break;
+ case QCDM_CMD_HDR_SUBSYS_STATE_INFO_ROUTE_UPDATE_STATE_IDLE:
+ detail = "idle";
+ break;
+ case QCDM_CMD_HDR_SUBSYS_STATE_INFO_ROUTE_UPDATE_STATE_CONNECTED:
+ detail = "connected";
+ break;
+ default:
+ detail = "unknown";
+ break;
+ }
+ g_message ("%s: Route Update State: %u (%s)", __func__, num, detail);
+
+ num = 0;
+ detail = NULL;
+ qcdm_result_get_uint8 (result, QCDM_CMD_HDR_SUBSYS_STATE_INFO_ITEM_OVERHEAD_MSG_STATE, &num);
+ switch (num) {
+ case QCDM_CMD_HDR_SUBSYS_STATE_INFO_OVERHEAD_MSG_STATE_INIT:
+ detail = "initial";
+ break;
+ case QCDM_CMD_HDR_SUBSYS_STATE_INFO_OVERHEAD_MSG_STATE_INACTIVE:
+ detail = "inactive";
+ break;
+ case QCDM_CMD_HDR_SUBSYS_STATE_INFO_OVERHEAD_MSG_STATE_ACTIVE:
+ detail = "active";
+ break;
+ default:
+ detail = "unknown";
+ break;
+ }
+ g_message ("%s: Overhead Msg State: %u (%s)", __func__, num, detail);
+
+ num = 0;
+ qcdm_result_get_uint8 (result, QCDM_CMD_HDR_SUBSYS_STATE_INFO_ITEM_HDR_HYBRID_MODE, &num);
+ g_message ("%s: HDR Hybrid Mode: %u", __func__, num);
+
+ qcdm_result_unref (result);
+}
+
diff --git a/libqcdm/tests/test-qcdm-com.h b/libqcdm/tests/test-qcdm-com.h
new file mode 100644
index 00000000..6c9b6e0a
--- /dev/null
+++ b/libqcdm/tests/test-qcdm-com.h
@@ -0,0 +1,41 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Copyright (C) 2010 Red Hat, Inc.
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef TEST_QCDM_COM_H
+#define TEST_QCDM_COM_H
+
+gpointer test_com_setup (const char *port);
+void test_com_teardown (gpointer d);
+
+void test_com_port_init (void *f, void *data);
+
+void test_com_version_info (void *f, void *data);
+
+void test_com_esn (void *f, void *data);
+
+void test_com_mdn (void *f, void *data);
+
+void test_com_status (void *f, void *data);
+
+void test_com_sw_version (void *f, void *data);
+
+void test_com_cm_subsys_state_info (void *f, void *data);
+
+void test_com_hdr_subsys_state_info (void *f, void *data);
+
+#endif /* TEST_QCDM_COM_H */
+
diff --git a/libqcdm/tests/test-qcdm-crc.c b/libqcdm/tests/test-qcdm-crc.c
new file mode 100644
index 00000000..0cb3e863
--- /dev/null
+++ b/libqcdm/tests/test-qcdm-crc.c
@@ -0,0 +1,65 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Copyright (C) 2010 Red Hat, Inc.
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib.h>
+#include <string.h>
+
+#include "test-qcdm-crc.h"
+#include "utils.h"
+
+void
+test_crc16_2 (void *f, void *data)
+{
+ static const char buf[] = {
+ 0x26, 0xb2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00
+ };
+ guint16 crc;
+ guint16 expected = 0x6D69;
+
+ /* CRC check */
+ crc = crc16 (buf, sizeof (buf));
+ g_assert (crc == expected);
+}
+
+void
+test_crc16_1 (void *f, void *data)
+{
+ static const char buf[] = {
+ 0x4b, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,
+ 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x3f,
+ 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff
+ };
+ guint16 crc;
+ guint16 expected = 0x097A;
+
+ /* CRC check */
+ crc = crc16 (buf, sizeof (buf));
+ g_assert (crc == expected);
+}
+
diff --git a/libqcdm/tests/test-qcdm-crc.h b/libqcdm/tests/test-qcdm-crc.h
new file mode 100644
index 00000000..91b95a08
--- /dev/null
+++ b/libqcdm/tests/test-qcdm-crc.h
@@ -0,0 +1,25 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Copyright (C) 2010 Red Hat, Inc.
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef TEST_QCDM_CRC_H
+#define TEST_QCDM_CRC_H
+
+void test_crc16_2 (void *f, void *data);
+void test_crc16_1 (void *f, void *data);
+
+#endif /* TEST_QCDM_CRC_H */
+
diff --git a/libqcdm/tests/test-qcdm-escaping.c b/libqcdm/tests/test-qcdm-escaping.c
new file mode 100644
index 00000000..fb5fb82a
--- /dev/null
+++ b/libqcdm/tests/test-qcdm-escaping.c
@@ -0,0 +1,124 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Copyright (C) 2010 Red Hat, Inc.
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib.h>
+#include <string.h>
+
+#include "test-qcdm-escaping.h"
+#include "utils.h"
+
+static const char data1[] = {
+ 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x66, 0x61, 0x69, 0x6c, 0x75, 0x72, 0x65,
+ 0x0a, 0x6e, 0x6f, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f,
+ 0x6e, 0x74, 0x6f, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x0a, 0x70, 0x68, 0x6f,
+ 0x6e, 0x7e, 0x7e, 0x7e, 0x7d, 0x7d, 0x7e, 0x7d, 0x7e, 0x7d, 0x7e, 0x6e,
+ 0x6b, 0x72, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x0a, 0x6f, 0x70,
+ 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x6c,
+ 0x6c, 0x6f, 0x77, 0x65, 0x64, 0x0a, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74,
+ 0x69, 0x6f, 0x6e, 0x6e, 0x6f, 0x74, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72,
+ 0x74, 0x65, 0x64, 0x0a, 0x70, 0x68, 0x73, 0x69, 0x6d, 0x70, 0x69, 0x6e,
+ 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x0a, 0x70, 0x68, 0x66,
+ 0x73, 0x69, 0x6d, 0x70, 0x69, 0x6e, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72,
+ 0x65, 0x64, 0x0a, 0x70, 0x68, 0x66, 0x73, 0x69, 0x6d, 0x70, 0x75, 0x6b,
+ 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x0a, 0x73, 0x69, 0x6d,
+ 0x6e, 0x6f, 0x74, 0x69, 0x6e, 0x73, 0x65, 0x72, 0x74, 0x65, 0x64, 0x0a,
+ 0x73, 0x69, 0x6d, 0x70, 0x69, 0x6e, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72,
+ 0x65, 0x64, 0x0a, 0x73, 0x69, 0x6d, 0x70, 0x75, 0x6b, 0x72, 0x65, 0x71,
+ 0x75, 0x69, 0x72, 0x65, 0x64, 0x0a, 0x73, 0x69, 0x6d, 0x66, 0x61, 0x69,
+ 0x6c, 0x75, 0x72, 0x65, 0x0a, 0x73, 0x69, 0x6d, 0x62, 0x75, 0x73, 0x79,
+ 0x0a, 0x73, 0x69, 0x6d, 0x77, 0x72, 0x6f, 0x6e, 0x67, 0x0a, 0x69, 0x6e,
+ 0x63, 0x6f, 0x72, 0x72, 0x65, 0x63, 0x74, 0x70, 0x61, 0x73, 0x73, 0x77,
+ 0x6f, 0x72, 0x64, 0x0a, 0x73, 0x69, 0x6d, 0x70, 0x69, 0x6e, 0x32, 0x72,
+ 0x65, 0x71, 0x75, 0x69
+};
+
+static const char expected1[] = {
+ 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x66, 0x61, 0x69, 0x6c, 0x75, 0x72, 0x65,
+ 0x0a, 0x6e, 0x6f, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f,
+ 0x6e, 0x74, 0x6f, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x0a, 0x70, 0x68, 0x6f,
+ 0x6e, 0x7d, 0x5e, 0x7d, 0x5e, 0x7d, 0x5e, 0x7d, 0x5d, 0x7d, 0x5d, 0x7d,
+ 0x5e, 0x7d, 0x5d, 0x7d, 0x5e, 0x7d, 0x5d, 0x7d, 0x5e, 0x6e, 0x6b, 0x72,
+ 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x0a, 0x6f, 0x70, 0x65, 0x72,
+ 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x6c, 0x6c, 0x6f,
+ 0x77, 0x65, 0x64, 0x0a, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f,
+ 0x6e, 0x6e, 0x6f, 0x74, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x65,
+ 0x64, 0x0a, 0x70, 0x68, 0x73, 0x69, 0x6d, 0x70, 0x69, 0x6e, 0x72, 0x65,
+ 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x0a, 0x70, 0x68, 0x66, 0x73, 0x69,
+ 0x6d, 0x70, 0x69, 0x6e, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64,
+ 0x0a, 0x70, 0x68, 0x66, 0x73, 0x69, 0x6d, 0x70, 0x75, 0x6b, 0x72, 0x65,
+ 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x0a, 0x73, 0x69, 0x6d, 0x6e, 0x6f,
+ 0x74, 0x69, 0x6e, 0x73, 0x65, 0x72, 0x74, 0x65, 0x64, 0x0a, 0x73, 0x69,
+ 0x6d, 0x70, 0x69, 0x6e, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64,
+ 0x0a, 0x73, 0x69, 0x6d, 0x70, 0x75, 0x6b, 0x72, 0x65, 0x71, 0x75, 0x69,
+ 0x72, 0x65, 0x64, 0x0a, 0x73, 0x69, 0x6d, 0x66, 0x61, 0x69, 0x6c, 0x75,
+ 0x72, 0x65, 0x0a, 0x73, 0x69, 0x6d, 0x62, 0x75, 0x73, 0x79, 0x0a, 0x73,
+ 0x69, 0x6d, 0x77, 0x72, 0x6f, 0x6e, 0x67, 0x0a, 0x69, 0x6e, 0x63, 0x6f,
+ 0x72, 0x72, 0x65, 0x63, 0x74, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72,
+ 0x64, 0x0a, 0x73, 0x69, 0x6d, 0x70, 0x69, 0x6e, 0x32, 0x72, 0x65, 0x71,
+ 0x75, 0x69
+};
+
+void
+test_escape1 (void *f, void *data)
+{
+ char escaped[1024];
+ gsize len;
+
+ /* Ensure that escaping in general works */
+ len = dm_escape (data1, sizeof (data1), escaped, sizeof (escaped));
+ g_assert (len == 266);
+ g_assert (len == sizeof (expected1));
+ g_assert (memcmp (escaped, expected1, len) == 0);
+}
+
+static const char data2[] = {
+ 0x4b, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,
+ 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x3f,
+ 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff
+};
+
+void
+test_escape2 (void *f, void *data)
+{
+ char escaped[1024];
+ gsize len;
+
+ /* Ensure that escaping data that doesn't need escaping works */
+ len = dm_escape (data2, sizeof (data2), escaped, sizeof (escaped));
+ g_assert (len == sizeof (data2));
+ g_assert (memcmp (escaped, data2, len) == 0);
+}
+
+void
+test_escape_unescape (void *f, void *data)
+{
+ char escaped[512];
+ char unescaped[512];
+ gsize len, unlen;
+ gboolean escaping = FALSE;
+
+ /* Ensure that escaping data that needs escaping, and then unescaping it,
+ * produces the exact same data as was originally escaped.
+ */
+ len = dm_escape (data1, sizeof (data1), escaped, sizeof (escaped));
+ unlen = dm_unescape (escaped, len, unescaped, sizeof (unescaped), &escaping);
+
+ g_assert (unlen == sizeof (data1));
+ g_assert (memcmp (unescaped, data1, unlen) == 0);
+}
+
diff --git a/libqcdm/tests/test-qcdm-escaping.h b/libqcdm/tests/test-qcdm-escaping.h
new file mode 100644
index 00000000..91706ee2
--- /dev/null
+++ b/libqcdm/tests/test-qcdm-escaping.h
@@ -0,0 +1,26 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Copyright (C) 2010 Red Hat, Inc.
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef TEST_QCDM_ESCAPING_H
+#define TEST_QCDM_ESCAPING_H
+
+void test_escape1 (void *f, void *data);
+void test_escape2 (void *f, void *data);
+void test_escape_unescape (void *f, void *data);
+
+#endif /* TEST_QCDM_ESCAPING_H */
+
diff --git a/libqcdm/tests/test-qcdm-result.c b/libqcdm/tests/test-qcdm-result.c
new file mode 100644
index 00000000..87f264b0
--- /dev/null
+++ b/libqcdm/tests/test-qcdm-result.c
@@ -0,0 +1,71 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Copyright (C) 2010 Red Hat, Inc.
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib.h>
+#include <string.h>
+
+#include "test-qcdm-result.h"
+#include "result.h"
+#include "result-private.h"
+
+#define TEST_TAG "test"
+
+void
+test_result_string (void *f, void *data)
+{
+ const char *str = "foobarblahblahblah";
+ const char *tmp = NULL;
+ QCDMResult *result;
+
+ result = qcdm_result_new ();
+ qcdm_result_add_string (result, TEST_TAG, str);
+
+ qcdm_result_get_string (result, TEST_TAG, &tmp);
+ g_assert (tmp);
+ g_assert (strcmp (tmp, str) == 0);
+
+ qcdm_result_unref (result);
+}
+
+void
+test_result_uint32 (void *f, void *data)
+{
+ guint32 num = 0xDEADBEEF;
+ guint32 tmp = 0;
+ QCDMResult *result;
+
+ result = qcdm_result_new ();
+ qcdm_result_add_uint32 (result, TEST_TAG, num);
+
+ qcdm_result_get_uint32 (result, TEST_TAG, &tmp);
+ g_assert (tmp == num);
+}
+
+void
+test_result_uint8 (void *f, void *data)
+{
+ guint8 num = 0x1E;
+ guint8 tmp = 0;
+ QCDMResult *result;
+
+ result = qcdm_result_new ();
+ qcdm_result_add_uint8 (result, TEST_TAG, num);
+
+ qcdm_result_get_uint8 (result, TEST_TAG, &tmp);
+ g_assert (tmp == num);
+}
+
diff --git a/libqcdm/tests/test-qcdm-result.h b/libqcdm/tests/test-qcdm-result.h
new file mode 100644
index 00000000..20d6cec0
--- /dev/null
+++ b/libqcdm/tests/test-qcdm-result.h
@@ -0,0 +1,26 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Copyright (C) 2010 Red Hat, Inc.
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef TEST_QCDM_RESULT_H
+#define TEST_QCDM_RESULT_H
+
+void test_result_string (void *f, void *data);
+void test_result_uint32 (void *f, void *data);
+void test_result_uint8 (void *f, void *data);
+
+#endif /* TEST_QCDM_RESULT_H */
+
diff --git a/libqcdm/tests/test-qcdm.c b/libqcdm/tests/test-qcdm.c
new file mode 100644
index 00000000..e5e3b42a
--- /dev/null
+++ b/libqcdm/tests/test-qcdm.c
@@ -0,0 +1,107 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Copyright (C) 2010 Red Hat, Inc.
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib.h>
+#include <string.h>
+
+#include "test-qcdm-crc.h"
+#include "test-qcdm-escaping.h"
+#include "test-qcdm-com.h"
+#include "test-qcdm-result.h"
+
+typedef struct {
+ gpointer com_data;
+} TestData;
+
+typedef void (*TCFunc)(void);
+
+#define TESTCASE(t, d) g_test_create_case (#t, 0, d, NULL, (TCFunc) t, NULL)
+
+static TestData *
+test_data_new (const char *port)
+{
+ TestData *d;
+
+ d = g_malloc0 (sizeof (TestData));
+ g_assert (d);
+
+ if (port)
+ d->com_data = test_com_setup (port);
+
+ return d;
+}
+
+static void
+test_data_free (TestData *d)
+{
+ if (d->com_data)
+ test_com_teardown (d->com_data);
+
+ g_free (d);
+}
+
+int main (int argc, char **argv)
+{
+ GTestSuite *suite;
+ TestData *data;
+ int i;
+ const char *port = NULL;
+ gint result;
+
+ g_test_init (&argc, &argv, NULL);
+
+ /* See if we got passed a serial port for live testing */
+ for (i = 0; i < argc; i++) {
+ if (!strcmp (argv[i], "--port")) {
+ /* Make sure there's actually a port in the next arg */
+ g_assert (argc > i + 1);
+ port = argv[++i];
+ }
+ }
+
+ data = test_data_new (port);
+
+ suite = g_test_get_root ();
+
+ g_test_suite_add (suite, TESTCASE (test_crc16_1, NULL));
+ g_test_suite_add (suite, TESTCASE (test_crc16_2, NULL));
+ g_test_suite_add (suite, TESTCASE (test_escape1, NULL));
+ g_test_suite_add (suite, TESTCASE (test_escape2, NULL));
+ g_test_suite_add (suite, TESTCASE (test_escape_unescape, NULL));
+ g_test_suite_add (suite, TESTCASE (test_result_string, NULL));
+ g_test_suite_add (suite, TESTCASE (test_result_uint32, NULL));
+ g_test_suite_add (suite, TESTCASE (test_result_uint8, NULL));
+
+ /* Live tests */
+ if (port) {
+ g_test_suite_add (suite, TESTCASE (test_com_port_init, data->com_data));
+ g_test_suite_add (suite, TESTCASE (test_com_version_info, data->com_data));
+ g_test_suite_add (suite, TESTCASE (test_com_esn, data->com_data));
+ g_test_suite_add (suite, TESTCASE (test_com_mdn, data->com_data));
+ g_test_suite_add (suite, TESTCASE (test_com_status, data->com_data));
+ g_test_suite_add (suite, TESTCASE (test_com_sw_version, data->com_data));
+ g_test_suite_add (suite, TESTCASE (test_com_cm_subsys_state_info, data->com_data));
+ g_test_suite_add (suite, TESTCASE (test_com_hdr_subsys_state_info, data->com_data));
+ }
+
+ result = g_test_run ();
+
+ test_data_free (data);
+
+ return result;
+}
+