diff options
-rw-r--r-- | libqcdm/src/utils.c | 2 | ||||
-rw-r--r-- | libqcdm/tests/Makefile.am | 2 | ||||
-rw-r--r-- | libqcdm/tests/test-qcdm-utils.c | 63 | ||||
-rw-r--r-- | libqcdm/tests/test-qcdm-utils.h | 24 | ||||
-rw-r--r-- | libqcdm/tests/test-qcdm.c | 2 |
5 files changed, 92 insertions, 1 deletions
diff --git a/libqcdm/src/utils.c b/libqcdm/src/utils.c index ab281557..9b9ac5f0 100644 --- a/libqcdm/src/utils.c +++ b/libqcdm/src/utils.c @@ -296,7 +296,7 @@ dm_decapsulate_buffer (const char *inbuf, /* Check the CRC of the packet's data */ crc = crc16 (outbuf, unesc_len - 2); - pkt_crc = *((guint16 *) &outbuf[pkt_len - 2]); + pkt_crc = *((guint16 *) &outbuf[unesc_len - 2]); if (crc != GUINT_FROM_LE (pkt_crc)) { *out_used = pkt_len + 1; /* packet + CRC + 0x7E */ return FALSE; diff --git a/libqcdm/tests/Makefile.am b/libqcdm/tests/Makefile.am index 3d1b7ba5..eb38fdbb 100644 --- a/libqcdm/tests/Makefile.am +++ b/libqcdm/tests/Makefile.am @@ -8,6 +8,8 @@ test_qcdm_SOURCES = \ test-qcdm-crc.h \ test-qcdm-escaping.c \ test-qcdm-escaping.h \ + test-qcdm-utils.c \ + test-qcdm-utils.h \ test-qcdm-com.c \ test-qcdm-com.h \ test-qcdm-result.c \ diff --git a/libqcdm/tests/test-qcdm-utils.c b/libqcdm/tests/test-qcdm-utils.c new file mode 100644 index 00000000..34de8394 --- /dev/null +++ b/libqcdm/tests/test-qcdm-utils.c @@ -0,0 +1,63 @@ +/* -*- 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-utils.h" +#include "utils.h" + +static const char 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_buffer (void *f, void *data) +{ + gboolean success; + char outbuf[512]; + gsize decap_len = 0; + gsize used = 0; + gboolean more = FALSE; + + success = dm_decapsulate_buffer (inbuf, sizeof (inbuf), + outbuf, sizeof (outbuf), + &decap_len, &used, &more); + g_assert (success); + g_assert (decap_len == 214); + g_assert (used == 221); + g_assert (more == FALSE); +} + diff --git a/libqcdm/tests/test-qcdm-utils.h b/libqcdm/tests/test-qcdm-utils.h new file mode 100644 index 00000000..767a72ae --- /dev/null +++ b/libqcdm/tests/test-qcdm-utils.h @@ -0,0 +1,24 @@ +/* -*- 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_UTILS_H +#define TEST_QCDM_UTILS_H + +void test_utils_decapsulate_buffer (void *f, void *data); + +#endif /* TEST_QCDM_UTILS_H */ + diff --git a/libqcdm/tests/test-qcdm.c b/libqcdm/tests/test-qcdm.c index 01535cac..d87a2e31 100644 --- a/libqcdm/tests/test-qcdm.c +++ b/libqcdm/tests/test-qcdm.c @@ -22,6 +22,7 @@ #include "test-qcdm-escaping.h" #include "test-qcdm-com.h" #include "test-qcdm-result.h" +#include "test-qcdm-utils.h" typedef struct { gpointer com_data; @@ -82,6 +83,7 @@ int main (int argc, char **argv) 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_utils_decapsulate_buffer, 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)); |