diff options
author | Dan Williams <dcbw@redhat.com> | 2019-04-02 11:17:21 -0500 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2019-04-02 11:20:11 -0500 |
commit | 1c14ca7262403ef6dc30319e3dc2aaa3ba47a225 (patch) | |
tree | f0274e750829c32609fe431e3b7916154bf31a05 /libwmc/tests | |
parent | 88fac7f14a8898a7856a6868bbd94d4cf576723a (diff) |
libwmc: remove it
The WMC protocol was only present on older Panasonic/Verizon devices
from the 2006 - 2011 timeframe. The last device to support WMC was
the UML290 which also supported QMI (which is much more functional).
ModemManager also never used WMC support and it was never significantly
reverse engineered.
So remove WMC code from git; it'll still be in the history if anyone
cares in the future.
Diffstat (limited to 'libwmc/tests')
-rw-r--r-- | libwmc/tests/Makefile.am | 31 | ||||
-rw-r--r-- | libwmc/tests/test-wmc-com.c | 504 | ||||
-rw-r--r-- | libwmc/tests/test-wmc-com.h | 37 | ||||
-rw-r--r-- | libwmc/tests/test-wmc-crc.c | 65 | ||||
-rw-r--r-- | libwmc/tests/test-wmc-crc.h | 25 | ||||
-rw-r--r-- | libwmc/tests/test-wmc-escaping.c | 165 | ||||
-rw-r--r-- | libwmc/tests/test-wmc-escaping.h | 28 | ||||
-rw-r--r-- | libwmc/tests/test-wmc-utils.c | 223 | ||||
-rw-r--r-- | libwmc/tests/test-wmc-utils.h | 34 | ||||
-rw-r--r-- | libwmc/tests/test-wmc.c | 110 |
10 files changed, 0 insertions, 1222 deletions
diff --git a/libwmc/tests/Makefile.am b/libwmc/tests/Makefile.am deleted file mode 100644 index 4622fbcf..00000000 --- a/libwmc/tests/Makefile.am +++ /dev/null @@ -1,31 +0,0 @@ -include $(top_srcdir)/gtester.make - -AM_CFLAGS = $(CODE_COVERAGE_CFLAGS) -AM_LDFLAGS = $(CODE_COVERAGE_LDFLAGS) - -noinst_PROGRAMS = test-wmc -TEST_PROGS += $(noinst_PROGRAMS) - -test_wmc_SOURCES = \ - test-wmc-crc.c \ - test-wmc-crc.h \ - test-wmc-escaping.c \ - test-wmc-escaping.h \ - test-wmc-utils.c \ - test-wmc-utils.h \ - test-wmc-com.c \ - test-wmc-com.h \ - test-wmc.c - -test_wmc_CPPFLAGS = \ - $(MM_CFLAGS) \ - -I$(top_srcdir)/libwmc/src \ - -I$(top_srcdir)/src - -test_wmc_LDADD = $(MM_LIBS) - -if WMC_STANDALONE -test_wmc_LDADD += $(top_builddir)/src/libwmc.la -else -test_wmc_LDADD += $(top_builddir)/libwmc/src/libwmc.la -endif diff --git a/libwmc/tests/test-wmc-com.c b/libwmc/tests/test-wmc-com.c deleted file mode 100644 index 2c100579..00000000 --- a/libwmc/tests/test-wmc-com.c +++ /dev/null @@ -1,504 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * Copyright (C) 2011 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-wmc-com.h" -#include "com.h" -#include "utils.h" -#include "errors.h" -#include "commands.h" - -/************************************************************/ - -typedef struct { - char *port; - int fd; - struct termios old_t; - wmcbool debug; - wmcbool uml290; -} TestComData; - -gpointer -test_com_setup (const char *port, wmcbool uml290, wmcbool debug) -{ - TestComData *d; - int ret; - - d = g_malloc0 (sizeof (TestComData)); - g_assert (d); - d->uml290 = uml290; - d->debug = debug; - - 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", port, errno); - g_assert (d->fd >= 0); - - ret = ioctl (d->fd, TIOCEXCL); - if (ret) { - g_warning ("%s: lock failed: %d", port, 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, size_t len) -{ - int i = 0, z; - wmcbool newline = FALSE; - char *f; - guint flen; - - f = g_strdup_printf ("%s (%zu) ", detail, len); - flen = strlen (f); - g_print ("%s", f); - for (i = 0; i < len; i++) { - g_print ("%02x ", buf[i] & 0xFF); - if (((i + 1) % 16) == 0) { - g_print ("\n"); - z = flen; - while (z--) - g_print (" "); - newline = TRUE; - } else - newline = FALSE; - } - - if (!newline) - g_print ("\n"); -} - -static wmcbool -send_command (TestComData *d, - char *inbuf, - size_t inbuf_len, - size_t cmd_len) -{ - int status; - int eagain_count = 1000; - size_t i = 0, sendlen; - char sendbuf[600]; - - if (d->debug) - print_buf ("\nRAW>>>", inbuf, cmd_len); - - /* Encapsulate the data for the device */ - sendlen = wmc_encapsulate (inbuf, cmd_len, inbuf_len, sendbuf, sizeof (sendbuf), d->uml290); - if (sendlen <= 0) { - g_warning ("Failed to encapsulate WMC command"); - return FALSE; - } - - if (d->debug) - print_buf ("ENC>>>", sendbuf, sendlen); - - while (i < sendlen) { - errno = 0; - status = write (d->fd, &sendbuf[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 size_t -wait_reply (TestComData *d, char *buf, size_t len) -{ - fd_set in; - int result; - struct timeval timeout = { 1, 0 }; - char readbuf[2048]; - ssize_t bytes_read; - int total = 0, retries = 0; - size_t 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) { - wmcbool more = FALSE, success; - size_t used = 0; - - total++; - decap_len = 0; - success = wmc_decapsulate (readbuf, total, buf, len, &decap_len, &used, &more, d->uml290); - - if (success && !more && d->debug) - print_buf ("RAW<<<", readbuf, total); - - /* 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 ("DCP<<<", buf, decap_len); - - return decap_len; -} - -void -test_com_port_init (void *f, void *data) -{ - TestComData *d = data; - int ret; - - ret = wmc_port_setup (d->fd); - if (ret < 0) - g_warning ("%s: error setting up serial port: (%d)", d->port, ret); - g_assert_cmpint (ret, ==, 0); -} - -void -test_com_init (void *f, void *data) -{ - TestComData *d = data; - wmcbool success; - char buf[512]; - gint len; - WmcResult *result; - size_t reply_len; - - len = wmc_cmd_init_new (buf, sizeof (buf), d->uml290); - g_assert (len); - - /* Send the command */ - success = send_command (d, buf, sizeof (buf), len); - g_assert (success); - - /* Get a response */ - reply_len = wait_reply (d, buf, sizeof (buf)); - - /* Parse the response into a result structure */ - result = wmc_cmd_init_result (buf, reply_len, d->uml290); - g_assert (result); - - wmc_result_unref (result); -} - -void -test_com_device_info (void *f, void *data) -{ - TestComData *d = data; - wmcbool success; - char buf[2048]; - const char *str, *str2; - gint len; - WmcResult *result; - size_t reply_len; - guint32 u32; - - len = wmc_cmd_device_info_new (buf, sizeof (buf)); - g_assert (len == 2); - - /* Send the command */ - success = send_command (d, buf, sizeof (buf), len); - g_assert (success); - - /* Get a response */ - reply_len = wait_reply (d, buf, sizeof (buf)); - - /* Parse the response into a result structure */ - result = wmc_cmd_device_info_result (buf, reply_len); - g_assert (result); - - g_print ("\n"); - - str = NULL; - wmc_result_get_string (result, WMC_CMD_DEVICE_INFO_ITEM_MANUFACTURER, &str); - g_message ("%s: Manuf: %s", __func__, str); - - str = NULL; - wmc_result_get_string (result, WMC_CMD_DEVICE_INFO_ITEM_MODEL, &str); - g_message ("%s: Model: %s", __func__, str); - - str = NULL; - wmc_result_get_string (result, WMC_CMD_DEVICE_INFO_ITEM_FW_REVISION, &str); - g_message ("%s: FW Rev: %s", __func__, str); - - str = NULL; - wmc_result_get_string (result, WMC_CMD_DEVICE_INFO_ITEM_HW_REVISION, &str); - g_message ("%s: HW Rev: %s", __func__, str); - - str = NULL; - wmc_result_get_string (result, WMC_CMD_DEVICE_INFO_ITEM_CDMA_MIN, &str); - g_message ("%s: CDMA MIN: %s", __func__, str); - - u32 = 0; - wmc_result_get_u32 (result, WMC_CMD_DEVICE_INFO_ITEM_HOME_SID, &u32); - g_message ("%s: Home SID: %d", __func__, u32); - - u32 = 0; - wmc_result_get_u32 (result, WMC_CMD_DEVICE_INFO_ITEM_PRL_VERSION, &u32); - g_message ("%s: PRL Ver: %d", __func__, u32); - - u32 = 0; - wmc_result_get_u32 (result, WMC_CMD_DEVICE_INFO_ITEM_ERI_VERSION, &u32); - g_message ("%s: ERI Ver: %d", __func__, u32); - - str = NULL; - wmc_result_get_string (result, WMC_CMD_DEVICE_INFO_ITEM_MEID, &str); - g_message ("%s: MEID: %s", __func__, str ? str : "(none)"); - - str = NULL; - wmc_result_get_string (result, WMC_CMD_DEVICE_INFO_ITEM_IMEI, &str); - g_message ("%s: IMEI: %s", __func__, str ? str : "(none)"); - - str = NULL; - wmc_result_get_string (result, WMC_CMD_DEVICE_INFO_ITEM_ICCID, &str); - g_message ("%s: ICCID: %s", __func__, str ? str : "(none)"); - - str = NULL; - wmc_result_get_string (result, WMC_CMD_DEVICE_INFO_ITEM_MCC, &str); - str2 = NULL; - wmc_result_get_string (result, WMC_CMD_DEVICE_INFO_ITEM_MNC, &str2); - g_message ("%s: MCC/MNC: %s %s", __func__, - str ? str : "(none)", - str2 ? str2 : "(none)"); - - wmc_result_unref (result); -} - -static const char * -service_to_string (uint8_t service) -{ - switch (service) { - case WMC_NETWORK_SERVICE_NONE: - return "none"; - case WMC_NETWORK_SERVICE_AMPS: - return "AMPS"; - case WMC_NETWORK_SERVICE_IS95A: - return "IS95-A"; - case WMC_NETWORK_SERVICE_IS95B: - return "IS95-B"; - case WMC_NETWORK_SERVICE_GSM: - return "GSM"; - case WMC_NETWORK_SERVICE_GPRS: - return "GPRS"; - case WMC_NETWORK_SERVICE_1XRTT: - return "1xRTT"; - case WMC_NETWORK_SERVICE_EVDO_0: - return "EVDO r0"; - case WMC_NETWORK_SERVICE_UMTS: - return "UMTS"; - case WMC_NETWORK_SERVICE_EVDO_A: - return "EVDO rA"; - case WMC_NETWORK_SERVICE_EDGE: - return "EDGE"; - case WMC_NETWORK_SERVICE_HSDPA: - return "HSDPA"; - case WMC_NETWORK_SERVICE_HSUPA: - return "HSUPA"; - case WMC_NETWORK_SERVICE_HSPA: - return "HSPA"; - case WMC_NETWORK_SERVICE_LTE: - return "LTE"; - default: - return "unknown"; - } -} - -void -test_com_network_info (void *f, void *data) -{ - TestComData *d = data; - wmcbool success; - char buf[1024]; - const char *str; - uint8_t dbm, service; - gint len; - WmcResult *result; - size_t reply_len; - - len = wmc_cmd_network_info_new (buf, sizeof (buf)); - g_assert (len == 2); - - /* Send the command */ - success = send_command (d, buf, sizeof (buf), len); - g_assert (success); - - /* Get a response */ - reply_len = wait_reply (d, buf, sizeof (buf)); - - /* Parse the response into a result structure */ - result = wmc_cmd_network_info_result (buf, reply_len); - g_assert (result); - - g_print ("\n"); - - service = 0; - wmc_result_get_u8 (result, WMC_CMD_NETWORK_INFO_ITEM_SERVICE, &service); - g_message ("%s: Service: %d (%s)", __func__, service, service_to_string (service)); - - dbm = 0; - wmc_result_get_u8 (result, WMC_CMD_NETWORK_INFO_ITEM_2G_DBM, &dbm); - g_message ("%s: 2G dBm: -%d", __func__, dbm); - - dbm = 0; - wmc_result_get_u8 (result, WMC_CMD_NETWORK_INFO_ITEM_3G_DBM, &dbm); - g_message ("%s: 3G dBm: -%d", __func__, dbm); - - dbm = 0; - wmc_result_get_u8 (result, WMC_CMD_NETWORK_INFO_ITEM_LTE_DBM, &dbm); - g_message ("%s: LTE dBm: -%d", __func__, dbm); - - str = NULL; - wmc_result_get_string (result, WMC_CMD_NETWORK_INFO_ITEM_OPNAME, &str); - g_message ("%s: Operator Name: %s", __func__, str ? str : "(none)"); - - str = NULL; - wmc_result_get_string (result, WMC_CMD_NETWORK_INFO_ITEM_MCC, &str); - g_message ("%s: MCC: %s", __func__, str ? str : "(none)"); - - str = NULL; - wmc_result_get_string (result, WMC_CMD_NETWORK_INFO_ITEM_MNC, &str); - g_message ("%s: MNC: %s", __func__, str ? str : "(none)"); - - wmc_result_unref (result); -} - -static const char * -mode_to_string (uint8_t service) -{ - switch (service) { - case WMC_NETWORK_MODE_AUTO_CDMA: - return "CDMA/EVDO"; - case WMC_NETWORK_MODE_CDMA_ONLY: - return "CDMA only"; - case WMC_NETWORK_MODE_EVDO_ONLY: - return "EVDO only"; - case WMC_NETWORK_MODE_AUTO_GSM: - return "GSM/UMTS"; - case WMC_NETWORK_MODE_GPRS_ONLY: - return "GSM/GPRS/EDGE only"; - case WMC_NETWORK_MODE_UMTS_ONLY: - return "UMTS/HSPA only"; - case WMC_NETWORK_MODE_AUTO: - return "Auto"; - case WMC_NETWORK_MODE_LTE_ONLY: - return "LTE only"; - default: - return "unknown"; - } -} - -void -test_com_get_global_mode (void *f, void *data) -{ - TestComData *d = data; - wmcbool success; - char buf[1024]; - uint8_t mode; - gint len; - WmcResult *result; - size_t reply_len; - - len = wmc_cmd_get_global_mode_new (buf, sizeof (buf)); - g_assert (len == 3); - - /* Send the command */ - success = send_command (d, buf, sizeof (buf), len); - g_assert (success); - - /* Get a response */ - reply_len = wait_reply (d, buf, sizeof (buf)); - - /* Parse the response into a result structure */ - result = wmc_cmd_get_global_mode_result (buf, reply_len); - g_assert (result); - - g_print ("\n"); - - mode = 0; - wmc_result_get_u8 (result, WMC_CMD_GET_GLOBAL_MODE_ITEM_MODE, &mode); - g_message ("%s: Mode: %d (%s)", __func__, mode, mode_to_string (mode)); - - wmc_result_unref (result); -} diff --git a/libwmc/tests/test-wmc-com.h b/libwmc/tests/test-wmc-com.h deleted file mode 100644 index 3dc0a0dd..00000000 --- a/libwmc/tests/test-wmc-com.h +++ /dev/null @@ -1,37 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * Copyright (C) 2011 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_WMC_COM_H -#define TEST_WMC_COM_H - -#include "utils.h" - -gpointer test_com_setup (const char *port, wmcbool uml290, wmcbool debug); -void test_com_teardown (gpointer d); - -void test_com_port_init (void *f, void *data); - -void test_com_init (void *f, void *data); - -void test_com_device_info (void *f, void *data); - -void test_com_network_info (void *f, void *data); - -void test_com_get_global_mode (void *f, void *data); - -#endif /* TEST_WMC_COM_H */ - diff --git a/libwmc/tests/test-wmc-crc.c b/libwmc/tests/test-wmc-crc.c deleted file mode 100644 index 29650113..00000000 --- a/libwmc/tests/test-wmc-crc.c +++ /dev/null @@ -1,65 +0,0 @@ -/* -*- 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-wmc-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 = wmc_crc16 (buf, sizeof (buf), 0); - 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 = wmc_crc16 (buf, sizeof (buf), 0); - g_assert (crc == expected); -} - diff --git a/libwmc/tests/test-wmc-crc.h b/libwmc/tests/test-wmc-crc.h deleted file mode 100644 index 4ce2871b..00000000 --- a/libwmc/tests/test-wmc-crc.h +++ /dev/null @@ -1,25 +0,0 @@ -/* -*- 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_WMC_CRC_H -#define TEST_WMC_CRC_H - -void test_crc16_2 (void *f, void *data); -void test_crc16_1 (void *f, void *data); - -#endif /* TEST_WMC_CRC_H */ - diff --git a/libwmc/tests/test-wmc-escaping.c b/libwmc/tests/test-wmc-escaping.c deleted file mode 100644 index 3c4cd21f..00000000 --- a/libwmc/tests/test-wmc-escaping.c +++ /dev/null @@ -1,165 +0,0 @@ -/* -*- 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-wmc-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]; - size_t len; - - /* Ensure that escaping in general works */ - len = hdlc_escape (data1, sizeof (data1), FALSE, 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]; - size_t len; - - /* Ensure that escaping data that doesn't need escaping works */ - len = hdlc_escape (data2, sizeof (data2), FALSE, escaped, sizeof (escaped)); - g_assert (len == sizeof (data2)); - g_assert (memcmp (escaped, data2, len) == 0); -} - -static const char data_ctrl_src[] = { - 0xc8, 0x0d, 0xda, 0x07, 0x0c, 0x00, 0x14, 0x00, 0x10, 0x00, 0x19, 0x00, - 0x04, 0x00, 0x01, 0x00, 0x07, 0x88 -}; - -static const char data_ctrl_expected[] = { - 0xc8, 0x7d, 0x2d, 0xda, 0x7d, 0x27, 0x7d, 0x2c, 0x7d, 0x20, 0x7d, 0x34, - 0x7d, 0x20, 0x7d, 0x30, 0x7d, 0x20, 0x7d, 0x39, 0x7d, 0x20, 0x7d, 0x24, - 0x7d, 0x20, 0x7d, 0x21, 0x7d, 0x20, 0x7d, 0x27, 0x88 -}; - -void -test_escape_ctrl (void *f, void *data) -{ - char escaped[1024]; - size_t len; - - len = hdlc_escape (data_ctrl_src, sizeof (data_ctrl_src), TRUE, escaped, sizeof (escaped)); - g_assert (len == sizeof (data_ctrl_expected)); - g_assert (memcmp (escaped, data_ctrl_expected, len) == 0); -} - -void -test_escape_unescape (void *f, void *data) -{ - char escaped[512]; - char unescaped[512]; - size_t len, unlen; - wmcbool escaping = FALSE; - - /* Ensure that escaping data that needs escaping, and then unescaping it, - * produces the exact same data as was originally escaped. - */ - len = hdlc_escape (data1, sizeof (data1), FALSE, escaped, sizeof (escaped)); - unlen = hdlc_unescape (escaped, len, unescaped, sizeof (unescaped), &escaping); - - g_assert (unlen == sizeof (data1)); - g_assert (memcmp (unescaped, data1, unlen) == 0); -} - -void -test_escape_unescape_ctrl (void *f, void *data) -{ - char escaped[512]; - char unescaped[512]; - size_t len, unlen; - wmcbool escaping = FALSE; - - /* Ensure that escaping data that needs escaping, and then unescaping it, - * produces the exact same data as was originally escaped. - */ - len = hdlc_escape (data_ctrl_src, sizeof (data_ctrl_src), TRUE, escaped, sizeof (escaped)); - g_assert (memcmp (escaped, data_ctrl_expected, len) == 0); - - unlen = hdlc_unescape (escaped, len, unescaped, sizeof (unescaped), &escaping); - g_assert (unlen == sizeof (data_ctrl_src)); - g_assert (memcmp (unescaped, data_ctrl_src, unlen) == 0); -} - diff --git a/libwmc/tests/test-wmc-escaping.h b/libwmc/tests/test-wmc-escaping.h deleted file mode 100644 index 144c37bf..00000000 --- a/libwmc/tests/test-wmc-escaping.h +++ /dev/null @@ -1,28 +0,0 @@ -/* -*- 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_WMC_ESCAPING_H -#define TEST_WMC_ESCAPING_H - -void test_escape1 (void *f, void *data); -void test_escape2 (void *f, void *data); -void test_escape_ctrl (void *f, void *data); -void test_escape_unescape (void *f, void *data); -void test_escape_unescape_ctrl (void *f, void *data); - -#endif /* TEST_WMC_ESCAPING_H */ - diff --git a/libwmc/tests/test-wmc-utils.c b/libwmc/tests/test-wmc-utils.c deleted file mode 100644 index 93c2a6a6..00000000 --- a/libwmc/tests/test-wmc-utils.c +++ /dev/null @@ -1,223 +0,0 @@ -/* -*- 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-wmc-utils.h" -#include "utils.h" - -static const char decap_inbuf[] = { - 0x40, 0x03, 0x00, 0x01, 0x00, 0x19, 0xf0, 0x00, 0x16, 0x00, 0x21, 0x00, - 0x1c, 0x00, 0xd8, 0x00, 0x3f, 0x00, 0x56, 0x01, 0x3f, 0x00, 0x15, 0x00, - 0x1a, 0x00, 0x11, 0x01, 0x3f, 0x00, 0x92, 0x01, 0x3f, 0x00, 0x39, 0x00, - 0x3f, 0x00, 0x95, 0x01, 0x3f, 0x00, 0x12, 0x00, 0x3f, 0x00, 0x23, 0x01, - 0x3f, 0x00, 0x66, 0x00, 0x3f, 0x00, 0x0b, 0x01, 0x3f, 0x00, 0xae, 0x00, - 0x3f, 0x00, 0x02, 0x01, 0x3f, 0x00, 0xa8, 0x00, 0x3f, 0x00, 0x50, 0x01, - 0x3f, 0x00, 0xf8, 0x01, 0x3f, 0x00, 0x57, 0x00, 0x3f, 0x00, 0x7d, 0x5e, - 0x00, 0x3f, 0x00, 0x93, 0x00, 0x3f, 0x00, 0xbd, 0x00, 0x3f, 0x00, 0x77, - 0x01, 0x3f, 0x00, 0xb7, 0x00, 0x3f, 0x00, 0xab, 0x00, 0x3f, 0x00, 0x33, - 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0xad, 0xde, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, - 0x13, 0x50, 0x1f, 0x00, 0x00, 0xff, 0xff, 0x00, 0xaa, 0x19, 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, 0xb1, 0xc4, 0x7d, 0x5e, - 0x7d, 0x5e, 0x7d, 0x5d, 0x5d, 0x04, 0x58, 0x1b, 0x5b, 0x1b, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x65, 0x69, 0x7e -}; - -void -test_utils_decapsulate_basic_buffer (void *f, void *data) -{ - wmcbool success; - char outbuf[512]; - size_t decap_len = 0; - size_t used = 0; - wmcbool more = FALSE; - - success = hdlc_decapsulate_buffer (decap_inbuf, sizeof (decap_inbuf), - FALSE, 0, outbuf, sizeof (outbuf), - &decap_len, &used, &more); - g_assert (success); - g_assert (decap_len == 214); - g_assert (used == 221); - g_assert (more == FALSE); -} - - -static const char encap_outbuf[] = { - 0x4b, 0x05, 0x08, 0x00, 0x01, 0xdd, 0x7e -}; - -void -test_utils_encapsulate_basic_buffer (void *f, void *data) -{ - char cmdbuf[10]; - char outbuf[512]; - size_t encap_len = 0; - - cmdbuf[0] = 0x4B; /* DIAG_CMD_SUBSYS */ - cmdbuf[1] = 0x05; /* DIAG_SUBSYS_HDR */ - cmdbuf[2] = 0x08; /* first byte of DIAG_SUBSYS_HDR_STATE_INFO in LE */ - cmdbuf[3] = 0x00; /* second byte of DIAG_SUBSYS_HDR_STATE_INFO in LE */ - - encap_len = hdlc_encapsulate_buffer (cmdbuf, 4, sizeof (cmdbuf), - 0, TRUE, FALSE, - &outbuf[0], sizeof (outbuf)); - g_assert (encap_len == sizeof (encap_outbuf)); - g_assert (memcmp (outbuf, encap_outbuf, encap_len) == 0); -} - -static const char cns_inbuf[] = { - 0x00, 0x0a, 0x6b, 0x74, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x7e -}; - -void -test_utils_decapsulate_sierra_cns (void *f, void *data) -{ - wmcbool success; - char outbuf[512]; - size_t decap_len = 0; - size_t used = 0; - wmcbool more = FALSE; - - success = hdlc_decapsulate_buffer (cns_inbuf, sizeof (cns_inbuf), - FALSE, 0, outbuf, sizeof (outbuf), - &decap_len, &used, &more); - g_assert (success == FALSE); -} - - -static const char uml290_encap_src[] = { - 0xc8, 0x0d, 0xda, 0x07, 0x0c, 0x00, 0x14, 0x00, 0x10, 0x00, 0x19, 0x00, - 0x04, 0x00, 0x01, 0x00, 0x07, 0x88 -}; - -static const char uml290_encap_outbuf[] = { - 0x41, 0x54, 0x2a, 0x57, 0x4d, 0x43, 0x3d, 0xc8, 0x7d, 0x2d, 0xda, 0x7d, - 0x27, 0x7d, 0x2c, 0x7d, 0x20, 0x7d, 0x34, 0x7d, 0x20, 0x7d, 0x30, 0x7d, - 0x20, 0x7d, 0x39, 0x7d, 0x20, 0x7d, 0x24, 0x7d, 0x20, 0x7d, 0x21, 0x7d, - 0x20, 0x7d, 0x27, 0x88, 0x0d -}; - -void -test_utils_encapsulate_uml290_wmc1 (void *f, void *data) -{ - char inbuf[512]; - char outbuf[512]; - size_t encap_len = 0; - - memcpy (inbuf, uml290_encap_src, sizeof (uml290_encap_src)); - encap_len = wmc_encapsulate (inbuf, sizeof (uml290_encap_src), - sizeof (inbuf), outbuf, sizeof (outbuf), TRUE); - g_assert (encap_len == sizeof (uml290_encap_outbuf)); - g_assert (memcmp (outbuf, uml290_encap_outbuf, encap_len) == 0); -} - -static const char uml290_src[] = { - 0xc8, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0xda, 0x07, 0x0c, 0x00, - 0x14, 0x00, 0x12, 0x00, 0x19, 0x00, 0x06, 0x00, 0xc2, 0x02, 0x00, 0x00, - 0x00, 0x00, 0x7d, 0x5d, 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, 0x7d, 0x5d, 0x00, 0x00, 0x00, 0x01, 0x00, - 0x00, 0x00, 0x01, 0x56, 0x65, 0x72, 0x69, 0x7a, 0x6f, 0x6e, 0x20, 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, 0x39, - 0x00, 0x00, 0x00, 0x40, 0x06, 0x00, 0x00, 0x30, 0x30, 0x7e -}; - -static const char uml290_expected[] = { - 0xc8, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0xda, 0x07, 0x0c, 0x00, - 0x14, 0x00, 0x12, 0x00, 0x19, 0x00, 0x06, 0x00, 0xc2, 0x02, 0x00, 0x00, - 0x00, 0x00, 0x7d, 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, 0x7d, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x01, 0x56, 0x65, 0x72, 0x69, 0x7a, 0x6f, 0x6e, 0x20, 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, 0x39, 0x00, 0x00, - 0x00, 0x40, 0x06, 0x00, 0x00 -}; - -void -test_utils_decapsulate_uml290_wmc1 (void *f, void *data) -{ - wmcbool success; - char outbuf[512]; - size_t decap_len = 0; - size_t used = 0; - wmcbool more = FALSE; - - success = hdlc_decapsulate_buffer (uml290_src, sizeof (uml290_src), - TRUE, 0x3030, outbuf, sizeof (outbuf), - &decap_len, &used, &more); - g_assert (success == TRUE); - g_assert (more == 0); - g_assert_cmpint (used, ==, sizeof (uml290_src)); - g_assert_cmpint (decap_len, ==, sizeof (uml290_expected)); - g_assert_cmpint (memcmp (outbuf, uml290_expected, decap_len), ==, 0); -} - - -static const char pc5740_src[] = { - 0xc8, 0x0b, 0x17, 0x00, 0x00, 0x00, 0x06, 0x00, 0xdb, 0x07, 0x06, 0x00, - 0x11, 0x00, 0x0d, 0x00, 0x2d, 0x00, 0x10, 0x00, 0xe4, 0x03, 0xd4, 0xfe, - 0xff, 0xff, 0x4e, 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, 0x0e, 0x92, 0x7e -}; - -static const char pc5740_expected[] = { - 0xc8, 0x0b, 0x17, 0x00, 0x00, 0x00, 0x06, 0x00, 0xdb, 0x07, 0x06, 0x00, - 0x11, 0x00, 0x0d, 0x00, 0x2d, 0x00, 0x10, 0x00, 0xe4, 0x03, 0xd4, 0xfe, - 0xff, 0xff, 0x4e, 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 -}; - -void -test_utils_decapsulate_pc5740_wmc1 (void *f, void *data) -{ - wmcbool success; - char outbuf[512]; - size_t decap_len = 0; - size_t used = 0; - wmcbool more = FALSE; - - success = hdlc_decapsulate_buffer (pc5740_src, sizeof (pc5740_src), - FALSE, 0, outbuf, sizeof (outbuf), - &decap_len, &used, &more); - g_assert (success == TRUE); - g_assert (more == 0); - g_assert_cmpint (used, ==, sizeof (pc5740_src)); - g_assert_cmpint (decap_len, ==, sizeof (pc5740_expected)); - g_assert_cmpint (memcmp (outbuf, pc5740_expected, decap_len), ==, 0); -} - diff --git a/libwmc/tests/test-wmc-utils.h b/libwmc/tests/test-wmc-utils.h deleted file mode 100644 index 96427068..00000000 --- a/libwmc/tests/test-wmc-utils.h +++ /dev/null @@ -1,34 +0,0 @@ -/* -*- 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_WMC_UTILS_H -#define TEST_WMC_UTILS_H - -void test_utils_decapsulate_basic_buffer (void *f, void *data); - -void test_utils_encapsulate_basic_buffer (void *f, void *data); - -void test_utils_decapsulate_sierra_cns (void *f, void *data); - -void test_utils_encapsulate_uml290_wmc1 (void *f, void *data); - -void test_utils_decapsulate_uml290_wmc1 (void *f, void *data); - -void test_utils_decapsulate_pc5740_wmc1 (void *f, void *data); - -#endif /* TEST_WMC_UTILS_H */ - diff --git a/libwmc/tests/test-wmc.c b/libwmc/tests/test-wmc.c deleted file mode 100644 index 1fc13ab1..00000000 --- a/libwmc/tests/test-wmc.c +++ /dev/null @@ -1,110 +0,0 @@ -/* -*- 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-wmc-crc.h" -#include "test-wmc-escaping.h" -#include "test-wmc-utils.h" -#include "test-wmc-com.h" - -typedef struct { - gpointer com_data; -} TestData; - -typedef GTestFixtureFunc TCFunc; - -#define TESTCASE(t, d) g_test_create_case (#t, 0, d, NULL, (TCFunc) t, NULL) - -static TestData * -test_data_new (const char *port, gboolean uml290, gboolean debug) -{ - TestData *d; - - d = g_malloc0 (sizeof (TestData)); - g_assert (d); - - if (port) - d->com_data = test_com_setup (port, uml290, debug); - - 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; - gboolean uml290 = FALSE, debug = FALSE; - - 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]; - } else if (!strcmp (argv[i], "--uml290")) - uml290 = TRUE; - else if (!strcmp (argv[i], "--debug")) - debug = TRUE; - } - - data = test_data_new (port, uml290, debug); - - 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_ctrl, NULL)); - g_test_suite_add (suite, TESTCASE (test_escape_unescape, NULL)); - g_test_suite_add (suite, TESTCASE (test_escape_unescape_ctrl, NULL)); - g_test_suite_add (suite, TESTCASE (test_utils_decapsulate_basic_buffer, NULL)); - g_test_suite_add (suite, TESTCASE (test_utils_encapsulate_basic_buffer, NULL)); - g_test_suite_add (suite, TESTCASE (test_utils_decapsulate_sierra_cns, NULL)); - g_test_suite_add (suite, TESTCASE (test_utils_decapsulate_uml290_wmc1, NULL)); - g_test_suite_add (suite, TESTCASE (test_utils_decapsulate_pc5740_wmc1, 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_init, data->com_data)); - g_test_suite_add (suite, TESTCASE (test_com_device_info, data->com_data)); - g_test_suite_add (suite, TESTCASE (test_com_network_info, data->com_data)); - g_test_suite_add (suite, TESTCASE (test_com_get_global_mode, data->com_data)); - } - - result = g_test_run (); - - test_data_free (data); - - return result; -} |