1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3
* This program is free software; you can redistribute it and/or modify
4
* it under the terms of the GNU General Public License as published by
5
* the Free Software Foundation; either version 2 of the License, or
6
* (at your option) any later version.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details:
13
* Copyright (C) 2013 Google, Inc.
17
#include <glib-object.h>
22
#define _LIBMM_INSIDE_MM
23
#include <libmm-glib.h>
25
#include "mm-sms-part-cdma.h"
28
/* If defined will print debugging traces */
29
#ifdef TEST_SMS_PART_ENABLE_TRACE
30
#define trace_pdu(pdu, pdu_len) do { \
34
for (i = 0; i < len; i++) { \
35
g_print (" 0x%02X", pdu[i]); \
36
if (((i + 1) % 12) == 0) \
42
#define trace_pdu(...)
45
/********************* PDU PARSER TESTS *********************/
48
common_test_part_from_hexpdu (const gchar *hexpdu,
49
MMSmsCdmaTeleserviceId expected_teleservice_id,
50
MMSmsCdmaServiceCategory expected_service_category,
51
const gchar *expected_address,
52
guint8 expected_bearer_reply_option,
53
const gchar *expected_text)
59
part = mm_sms_part_cdma_new_from_pdu (0, hexpdu, &error);
60
g_assert_no_error (error);
61
g_assert (part != NULL);
63
if (expected_teleservice_id != MM_SMS_CDMA_TELESERVICE_ID_UNKNOWN)
64
g_assert_cmpuint (expected_teleservice_id, ==, mm_sms_part_get_cdma_teleservice_id (part));
65
if (expected_service_category != MM_SMS_CDMA_SERVICE_CATEGORY_UNKNOWN)
66
g_assert_cmpuint (expected_service_category, ==, mm_sms_part_get_cdma_service_category (part));
67
if (expected_address) {
68
if (expected_address[0])
69
g_assert_cmpstr (expected_address, ==, mm_sms_part_get_number (part));
71
g_assert (mm_sms_part_get_number (part) == NULL);
73
if (expected_bearer_reply_option)
74
g_assert_cmpuint (expected_bearer_reply_option, ==, mm_sms_part_get_message_reference (part));
76
g_assert_cmpstr (expected_text, ==, mm_sms_part_get_text (part));
78
mm_sms_part_free (part);
82
common_test_part_from_pdu (const guint8 *pdu,
84
MMSmsCdmaTeleserviceId expected_teleservice_id,
85
MMSmsCdmaServiceCategory expected_service_category,
86
const gchar *expected_address,
87
guint8 expected_bearer_reply_option,
88
const gchar *expected_text)
92
hexpdu = mm_utils_bin2hexstr (pdu, pdu_size);
93
common_test_part_from_hexpdu (hexpdu,
94
expected_teleservice_id,
95
expected_service_category,
97
expected_bearer_reply_option,
103
common_test_invalid_part_from_hexpdu (const gchar *hexpdu)
106
GError *error = NULL;
109
part = mm_sms_part_cdma_new_from_pdu (0, hexpdu, &error);
110
g_assert (part == NULL);
111
/* We don't care for the specific error type */
112
g_assert (error != NULL);
113
g_error_free (error);
117
common_test_invalid_part_from_pdu (const guint8 *pdu,
122
hexpdu = mm_utils_bin2hexstr (pdu, pdu_size);
123
common_test_invalid_part_from_hexpdu (hexpdu);
130
static const guint8 pdu[] = {
136
/* originating address */
138
0x02, 0x8C, 0xE9, 0x5D, 0xCC, 0x65, 0x80,
139
/* bearer reply option */
144
0x00, 0x03, 0x16, 0x8D, 0x30, 0x01, 0x06,
145
0x10, 0x24, 0x18, 0x30, 0x60, 0x80, 0x03,
146
0x06, 0x10, 0x10, 0x04, 0x04, 0x48, 0x47
149
common_test_part_from_pdu (
151
MM_SMS_CDMA_TELESERVICE_ID_WMT,
152
MM_SMS_CDMA_SERVICE_CATEGORY_UNKNOWN,
159
test_invalid_parameter_length (void)
161
static const guint8 pdu[] = {
167
/* originating address */
169
0x02, 0x8C, 0xE9, 0x5D, 0xCC, 0x65, 0x80,
170
/* bearer reply option */
174
0x08, 0x20, /* wrong parameter length! */
175
0x00, 0x03, 0x16, 0x8D, 0x30, 0x01, 0x06,
176
0x10, 0x24, 0x18, 0x30, 0x60, 0x80, 0x03,
177
0x06, 0x10, 0x10, 0x04, 0x04, 0x48, 0x47
180
common_test_invalid_part_from_pdu (pdu, sizeof (pdu));
184
test_invalid_address_length (void)
186
static const guint8 pdu[] = {
192
/* originating address (wrong num_fields) */
194
0x03, 0x8C, 0xE9, 0x5D, 0xCC, 0x65, 0x80,
195
/* bearer reply option */
200
0x00, 0x03, 0x16, 0x8D, 0x30, 0x01, 0x06,
201
0x10, 0x24, 0x18, 0x30, 0x60, 0x80, 0x03,
202
0x06, 0x10, 0x10, 0x04, 0x04, 0x48, 0x47
205
common_test_part_from_pdu (
207
MM_SMS_CDMA_TELESERVICE_ID_WMT,
208
MM_SMS_CDMA_SERVICE_CATEGORY_UNKNOWN,
215
test_created_by_us (void)
217
static const guint8 pdu[] = {
223
/* destination address */
225
0x02, 0x8C, 0xE9, 0x5D, 0xCC, 0x65, 0x80,
228
0x00, 0x03, 0x20, 0x00, 0x00, /* message id */
229
0x01, 0x06, 0x10, 0x24, 0x18, 0x30, 0x60, 0x80 /* user_data */
232
common_test_part_from_pdu (
234
MM_SMS_CDMA_TELESERVICE_ID_WMT,
235
MM_SMS_CDMA_SERVICE_CATEGORY_UNKNOWN,
242
test_latin_encoding (void)
244
static const guint8 pdu[] = {
250
/* originating address */
252
0x02, 0x8C, 0xE9, 0x5D, 0xCC, 0x65, 0x80,
253
/* bearer reply option */
263
0x41, 0x29, 0x19, 0x22, 0xE1, 0x19, 0x1A, 0xE1,
264
0x1A, 0x01, 0x19, 0xA1, 0x19, 0xA1, 0xA9, 0xB1,
265
0xB9, 0xE9, 0x53, 0x4B, 0x23, 0xAB, 0x53, 0x23,
266
0xAB, 0x23, 0x2B, 0xAB, 0xAB, 0x2B, 0x23, 0xAB,
267
0x53, 0x23, 0x2B, 0xAB, 0x53, 0xAB, 0x20,
268
/* message center timestamp */
270
0x13, 0x10, 0x23, 0x20, 0x06, 0x37,
271
/* priority indicator */
276
common_test_part_from_pdu (
278
MM_SMS_CDMA_TELESERVICE_ID_WMT,
279
MM_SMS_CDMA_SERVICE_CATEGORY_UNKNOWN,
282
/* this is ASCII-7 but message uses latin encoding */
283
"#$\\##\\#@#4#4567=*idujdudeuuedujdeujud");
287
test_latin_encoding_2 (void)
289
static const guint8 pdu[] = {
295
/* originating address */
297
0x02, 0x8C, 0xE9, 0x5D, 0xCC, 0x65, 0x80,
298
/* bearer reply option */
308
0x40, 0x42, 0x1B, 0x0B, 0x6B, 0x83, 0x2F, 0x9B,
310
/* message center timestamp */
312
0x13, 0x10, 0x23, 0x20, 0x06, 0x37,
313
/* priority indicator */
318
common_test_part_from_pdu (
320
MM_SMS_CDMA_TELESERVICE_ID_WMT,
321
MM_SMS_CDMA_SERVICE_CATEGORY_UNKNOWN,
324
/* this is latin and message uses latin encoding */
329
test_unicode_encoding (void)
331
static const guint8 pdu[] = {
337
/* originating address */
339
0x02, 0x8C, 0xE9, 0x5D, 0xCC, 0x65, 0x80,
340
/* bearer reply option */
350
0x20, 0x52, 0x71, 0x6A, 0xB8, 0x5A, 0xA7, 0x92,
351
0xDB, 0xC3, 0x37, 0xC4, 0xB7, 0xDA, 0xDA, 0x82,
352
0x98, 0xB4, 0x50, 0x42, 0x94, 0x18,
353
/* message center timestamp */
355
0x13, 0x10, 0x24, 0x10, 0x45, 0x28,
356
/* priority indicator */
361
common_test_part_from_pdu (
363
MM_SMS_CDMA_TELESERVICE_ID_WMT,
364
MM_SMS_CDMA_SERVICE_CATEGORY_UNKNOWN,
370
/********************* PDU CREATOR TESTS *********************/
373
common_test_create_pdu (MMSmsCdmaTeleserviceId teleservice_id,
378
const guint8 *expected,
384
GError *error = NULL;
386
g_assert (number != NULL);
388
part = mm_sms_part_new (0, MM_SMS_PDU_TYPE_CDMA_SUBMIT);
389
mm_sms_part_set_cdma_teleservice_id (part, teleservice_id);
390
mm_sms_part_set_number (part, number);
392
mm_sms_part_set_text (part, text);
394
GByteArray *data_bytearray;
396
data_bytearray = g_byte_array_sized_new (data_size);
397
g_byte_array_append (data_bytearray, data, data_size);
398
mm_sms_part_take_data (part, data_bytearray);
401
pdu = mm_sms_part_cdma_get_submit_pdu (part, &len, &error);
403
trace_pdu (pdu, len);
405
g_assert_no_error (error);
406
g_assert (pdu != NULL);
407
g_assert_cmpuint (len, ==, expected_size);
408
g_assert_cmpint (memcmp (pdu, expected, len), ==, 0);
414
test_create_pdu_text_ascii_encoding (void)
416
static const char *number = "3305773196";
417
static const char *text = "AAAA";
418
static const guint8 expected[] = {
424
/* destination address */
426
0x02, 0x8C, 0xE9, 0x5D, 0xCC, 0x65, 0x80,
429
0x00, 0x03, 0x20, 0x00, 0x00, /* message id */
430
0x01, 0x06, 0x10, 0x24, 0x18, 0x30, 0x60, 0x80 /* user_data */
433
common_test_create_pdu (MM_SMS_CDMA_TELESERVICE_ID_WMT,
437
expected, sizeof (expected));
441
test_create_pdu_text_latin_encoding (void)
443
static const char *number = "3305773196";
444
static const char *text = "Campeón!";
445
static const guint8 expected[] = {
451
/* destination address */
453
0x02, 0x8C, 0xE9, 0x5D, 0xCC, 0x65, 0x80,
461
0x40, 0x42, 0x1B, 0x0B, 0x6B, 0x83, 0x2F, 0x9B,
465
common_test_create_pdu (MM_SMS_CDMA_TELESERVICE_ID_WMT,
469
expected, sizeof (expected));
473
test_create_pdu_text_unicode_encoding (void)
475
static const char *number = "3305773196";
476
static const char *text = "中國哲學書電子化計劃";
477
static const guint8 expected[] = {
483
/* destination address */
485
0x02, 0x8C, 0xE9, 0x5D, 0xCC, 0x65, 0x80,
493
0x20, 0x52, 0x71, 0x6A, 0xB8, 0x5A, 0xA7, 0x92,
494
0xDB, 0xC3, 0x37, 0xC4, 0xB7, 0xDA, 0xDA, 0x82,
495
0x98, 0xB4, 0x50, 0x42, 0x94, 0x18
498
common_test_create_pdu (MM_SMS_CDMA_TELESERVICE_ID_WMT,
502
expected, sizeof (expected));
505
/************************************************************/
508
_mm_log (const char *loc,
514
#if defined ENABLE_TEST_MESSAGE_TRACES
515
/* Dummy log function */
519
va_start (args, fmt);
520
msg = g_strdup_vprintf (fmt, args);
522
g_print ("%s\n", msg);
527
int main (int argc, char **argv)
529
setlocale (LC_ALL, "");
532
g_test_init (&argc, &argv, NULL);
534
g_test_add_func ("/MM/SMS/CDMA/PDU-Parser/pdu1", test_pdu1);
535
g_test_add_func ("/MM/SMS/CDMA/PDU-Parser/invalid-parameter-length", test_invalid_parameter_length);
536
g_test_add_func ("/MM/SMS/CDMA/PDU-Parser/invalid-address-length", test_invalid_address_length);
537
g_test_add_func ("/MM/SMS/CDMA/PDU-Parser/created-by-us", test_created_by_us);
538
g_test_add_func ("/MM/SMS/CDMA/PDU-Parser/latin-encoding", test_latin_encoding);
539
g_test_add_func ("/MM/SMS/CDMA/PDU-Parser/latin-encoding-2", test_latin_encoding_2);
540
g_test_add_func ("/MM/SMS/CDMA/PDU-Parser/unicode-encoding", test_unicode_encoding);
542
g_test_add_func ("/MM/SMS/CDMA/PDU-Creator/ascii-encoding", test_create_pdu_text_ascii_encoding);
543
g_test_add_func ("/MM/SMS/CDMA/PDU-Creator/latin-encoding", test_create_pdu_text_latin_encoding);
544
g_test_add_func ("/MM/SMS/CDMA/PDU-Creator/unicode-encoding", test_create_pdu_text_unicode_encoding);
546
return g_test_run ();