~phablet-team/ofono/rilmodem

« back to all changes in this revision

Viewing changes to unit/test-util.c

  • Committer: Marcel Holtmann
  • Author(s): Denis Kenzior
  • Date: 2009-05-13 03:22:20 UTC
  • Revision ID: git-v1:c7c793ac8091c6d8e8f5b0cb2e441a3f585e8a5b
Add directory with unit tests

Includes tests for SS parser, utility functions and SMS PDU
decoder / encoder utilities.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *
 
3
 *  oFono - Open Source Telephony
 
4
 *
 
5
 *  Copyright (C) 2008-2009  Intel Corporation. All rights reserved.
 
6
 *
 
7
 *  This program is free software; you can redistribute it and/or modify
 
8
 *  it under the terms of the GNU General Public License version 2 as
 
9
 *  published by the Free Software Foundation.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, write to the Free Software
 
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
19
 *
 
20
 */
 
21
 
 
22
#include <string.h>
 
23
#include <stdio.h>
 
24
#include <assert.h>
 
25
#include <glib.h>
 
26
 
 
27
#include "util.h"
 
28
 
 
29
const unsigned char invalid_gsm_extended[] = {
 
30
        0x1b, 0x15
 
31
};
 
32
 
 
33
const unsigned char invalid_gsm_extended_len[] = {
 
34
        0x1b, 0x28, 0x1b
 
35
};
 
36
 
 
37
unsigned short gsm_to_unicode_map[] =
 
38
{
 
39
0x00,   0x0040,
 
40
0x01,   0x00A3,
 
41
0x02,   0x0024,
 
42
0x03,   0x00A5,
 
43
0x04,   0x00E8,
 
44
0x05,   0x00E9,
 
45
0x06,   0x00F9,
 
46
0x07,   0x00EC,
 
47
0x08,   0x00F2,
 
48
0x09,   0x00E7,
 
49
0x0A,   0x000A,
 
50
0x0B,   0x00D8,
 
51
0x0C,   0x00F8,
 
52
0x0D,   0x000D,
 
53
0x0E,   0x00C5,
 
54
0x0F,   0x00E5,
 
55
0x10,   0x0394,
 
56
0x11,   0x005F,
 
57
0x12,   0x03A6,
 
58
0x13,   0x0393,
 
59
0x14,   0x039B,
 
60
0x15,   0x03A9,
 
61
0x16,   0x03A0,
 
62
0x17,   0x03A8,
 
63
0x18,   0x03A3,
 
64
0x19,   0x0398,
 
65
0x1A,   0x039E,
 
66
/*0x1B, 0x00A0,*/
 
67
0x1B0A, 0x000C,
 
68
0x1B14, 0x005E,
 
69
0x1B28, 0x007B,
 
70
0x1B29, 0x007D,
 
71
0x1B2F, 0x005C,
 
72
0x1B3C, 0x005B,
 
73
0x1B3D, 0x007E,
 
74
0x1B3E, 0x005D,
 
75
0x1B40, 0x007C,
 
76
0x1B65, 0x20AC,
 
77
0x1C,   0x00C6,
 
78
0x1D,   0x00E6,
 
79
0x1E,   0x00DF,
 
80
0x1F,   0x00C9,
 
81
0x20,   0x0020,
 
82
0x21,   0x0021,
 
83
0x22,   0x0022,
 
84
0x23,   0x0023,
 
85
0x24,   0x00A4,
 
86
0x25,   0x0025,
 
87
0x26,   0x0026,
 
88
0x27,   0x0027,
 
89
0x28,   0x0028,
 
90
0x29,   0x0029,
 
91
0x2A,   0x002A,
 
92
0x2B,   0x002B,
 
93
0x2C,   0x002C,
 
94
0x2D,   0x002D,
 
95
0x2E,   0x002E,
 
96
0x2F,   0x002F,
 
97
0x30,   0x0030,
 
98
0x31,   0x0031,
 
99
0x32,   0x0032,
 
100
0x33,   0x0033,
 
101
0x34,   0x0034,
 
102
0x35,   0x0035,
 
103
0x36,   0x0036,
 
104
0x37,   0x0037,
 
105
0x38,   0x0038,
 
106
0x39,   0x0039,
 
107
0x3A,   0x003A,
 
108
0x3B,   0x003B,
 
109
0x3C,   0x003C,
 
110
0x3D,   0x003D,
 
111
0x3E,   0x003E,
 
112
0x3F,   0x003F,
 
113
0x40,   0x00A1,
 
114
0x41,   0x0041,
 
115
0x42,   0x0042,
 
116
0x43,   0x0043,
 
117
0x44,   0x0044,
 
118
0x45,   0x0045,
 
119
0x46,   0x0046,
 
120
0x47,   0x0047,
 
121
0x48,   0x0048,
 
122
0x49,   0x0049,
 
123
0x4A,   0x004A,
 
124
0x4B,   0x004B,
 
125
0x4C,   0x004C,
 
126
0x4D,   0x004D,
 
127
0x4E,   0x004E,
 
128
0x4F,   0x004F,
 
129
0x50,   0x0050,
 
130
0x51,   0x0051,
 
131
0x52,   0x0052,
 
132
0x53,   0x0053,
 
133
0x54,   0x0054,
 
134
0x55,   0x0055,
 
135
0x56,   0x0056,
 
136
0x57,   0x0057,
 
137
0x58,   0x0058,
 
138
0x59,   0x0059,
 
139
0x5A,   0x005A,
 
140
0x5B,   0x00C4,
 
141
0x5C,   0x00D6,
 
142
0x5D,   0x00D1,
 
143
0x5E,   0x00DC,
 
144
0x5F,   0x00A7,
 
145
0x60,   0x00BF,
 
146
0x61,   0x0061,
 
147
0x62,   0x0062,
 
148
0x63,   0x0063,
 
149
0x64,   0x0064,
 
150
0x65,   0x0065,
 
151
0x66,   0x0066,
 
152
0x67,   0x0067,
 
153
0x68,   0x0068,
 
154
0x69,   0x0069,
 
155
0x6A,   0x006A,
 
156
0x6B,   0x006B,
 
157
0x6C,   0x006C,
 
158
0x6D,   0x006D,
 
159
0x6E,   0x006E,
 
160
0x6F,   0x006F,
 
161
0x70,   0x0070,
 
162
0x71,   0x0071,
 
163
0x72,   0x0072,
 
164
0x73,   0x0073,
 
165
0x74,   0x0074,
 
166
0x75,   0x0075,
 
167
0x76,   0x0076,
 
168
0x77,   0x0077,
 
169
0x78,   0x0078,
 
170
0x79,   0x0079,
 
171
0x7A,   0x007A,
 
172
0x7B,   0x00E4,
 
173
0x7C,   0x00F6,
 
174
0x7D,   0x00F1,
 
175
0x7E,   0x00FC,
 
176
0x7F,   0x00E0,
 
177
};
 
178
 
 
179
#define UTF8_LENGTH(c) \
 
180
        ((c) < 0x80 ? 1 : \
 
181
         ((c) < 0x800 ? 2 : 3))
 
182
 
 
183
static void test_invalid()
 
184
{
 
185
        long nwritten;
 
186
        long nread;
 
187
        char *res;
 
188
 
 
189
        res = convert_gsm_to_utf8(invalid_gsm_extended, 0, &nread, &nwritten,
 
190
                                        0);
 
191
        g_assert(res == NULL);
 
192
        g_assert(nread == 0);
 
193
 
 
194
        res = convert_gsm_to_utf8(invalid_gsm_extended,
 
195
                                        sizeof(invalid_gsm_extended),
 
196
                                        &nread, &nwritten, 0);
 
197
        g_assert(res == NULL);
 
198
        g_assert(nread == 1);
 
199
 
 
200
        res = convert_gsm_to_utf8(invalid_gsm_extended_len,
 
201
                                        sizeof(invalid_gsm_extended_len),
 
202
                                        &nread, &nwritten, 0);
 
203
        g_assert(res == NULL);
 
204
        g_assert(nread == 3);
 
205
}
 
206
 
 
207
static void test_valid()
 
208
{
 
209
        long nwritten;
 
210
        long nread;
 
211
        char *res;
 
212
        int i;
 
213
        long size;
 
214
        gunichar *verify;
 
215
        unsigned char *back;
 
216
 
 
217
        unsigned char buf[2];
 
218
 
 
219
        static int map_size =
 
220
                sizeof(gsm_to_unicode_map) / sizeof(unsigned short) / 2;
 
221
 
 
222
        for (i = 0; i < map_size; i++) {
 
223
                unsigned short c = gsm_to_unicode_map[i*2];
 
224
 
 
225
                if (c & 0x1b00) {
 
226
                        buf[0] = 0x1b;
 
227
                        buf[1] = c & 0x7f;
 
228
                        size = 2;
 
229
                } else {
 
230
                        size = 1;
 
231
                        buf[0] = c & 0x7f;
 
232
                }
 
233
 
 
234
                res = convert_gsm_to_utf8(buf, size, &nread, &nwritten, 0);
 
235
                g_assert(res);
 
236
 
 
237
                if (g_test_verbose())
 
238
                        g_print("size: %ld, nread:%ld, nwritten:%ld, %s\n",
 
239
                                size, nread, nwritten, res);
 
240
 
 
241
                g_assert(nread == size);
 
242
 
 
243
                verify = g_utf8_to_ucs4(res, -1, NULL, NULL, NULL);
 
244
 
 
245
                g_assert(verify[0] == gsm_to_unicode_map[i*2+1]);
 
246
                g_assert(verify[1] == 0);
 
247
 
 
248
                g_assert(nwritten == UTF8_LENGTH(verify[0]));
 
249
 
 
250
                back = convert_utf8_to_gsm(res, -1, &nread, &nwritten, 0);
 
251
 
 
252
                g_assert(back);
 
253
 
 
254
                g_assert(nwritten == size);
 
255
                if (c & 0x1b00) {
 
256
                        g_assert(back[0] == 0x1b);
 
257
                        g_assert(back[1] == (c & 0x7f));
 
258
                } else {
 
259
                        g_assert(back[0] == (c & 0x7f));
 
260
                }
 
261
 
 
262
                g_free(back);
 
263
                g_free(verify);
 
264
                g_free(res);
 
265
        }
 
266
}
 
267
 
 
268
static const char hex_packed[] = "493A283D0795C3F33C88FE06C9CB6132885EC6D34"
 
269
                                        "1EDF27C1E3E97E7207B3A0C0A5241E377BB1D"
 
270
                                        "7693E72E";
 
271
static const char expected[] = "It is easy to read text messages via AT commands.";
 
272
static int reported_text_size = 49;
 
273
 
 
274
static void test_decode_encode()
 
275
{
 
276
        const char *sms = hex_packed;
 
277
        unsigned char *decoded, *packed;
 
278
        char *utf8, *hex_packed;
 
279
        unsigned char *gsm, *gsm_encoded;
 
280
        long hex_decoded_size;
 
281
        long unpacked_size, packed_size;
 
282
        long gsm_encoded_size;
 
283
        long i;
 
284
 
 
285
        if (g_test_verbose())
 
286
                g_print("Size of the orig string: %u\n",
 
287
                        (unsigned int)strlen(sms));
 
288
 
 
289
        decoded = decode_hex(sms, -1, &hex_decoded_size, 0);
 
290
 
 
291
        g_assert(decoded != NULL);
 
292
 
 
293
        if (g_test_verbose())
 
294
                g_print("Decode to %ld bytes\n", hex_decoded_size);
 
295
 
 
296
        if (g_test_verbose()) {
 
297
                g_print("%s\n", sms);
 
298
 
 
299
                for (i = 0; i < hex_decoded_size; i++)
 
300
                        g_print("%02X", decoded[i]);
 
301
                g_print("\n");
 
302
        }
 
303
 
 
304
        gsm = unpack_7bit(decoded, hex_decoded_size, 0, FALSE,
 
305
                                reported_text_size, &unpacked_size, 0xff);
 
306
 
 
307
        g_assert(gsm != NULL);
 
308
 
 
309
        if (g_test_verbose())
 
310
                g_print("String unpacked to %ld bytes\n", unpacked_size);
 
311
 
 
312
        utf8 = convert_gsm_to_utf8(gsm, -1, NULL, NULL, 0xff);
 
313
 
 
314
        g_assert(utf8 != NULL);
 
315
 
 
316
        if (g_test_verbose())
 
317
                g_print("String is: -->%s<--\n", utf8);
 
318
 
 
319
        g_assert(strcmp(utf8, expected) == 0);
 
320
 
 
321
        gsm_encoded = convert_utf8_to_gsm(utf8, -1, NULL,
 
322
                                                &gsm_encoded_size, 0xff);
 
323
 
 
324
        g_assert(gsm_encoded != NULL);
 
325
 
 
326
        if (g_test_verbose())
 
327
                g_print("Converted back to GSM string of %ld bytes\n",
 
328
                                gsm_encoded_size);
 
329
 
 
330
        g_assert(gsm_encoded[gsm_encoded_size] == 0xff);
 
331
        g_assert(gsm_encoded_size == unpacked_size);
 
332
        g_assert(memcmp(gsm_encoded, gsm, gsm_encoded_size) == 0);
 
333
 
 
334
        g_free(utf8);
 
335
        g_free(gsm);
 
336
 
 
337
        packed = pack_7bit(gsm_encoded, -1, 0, FALSE, &packed_size, 0xff);
 
338
 
 
339
        g_assert(gsm_encoded != NULL);
 
340
 
 
341
        if (g_test_verbose())
 
342
                g_print("Packed GSM to size of %ld bytes\n", packed_size);
 
343
 
 
344
        if (g_test_verbose()) {
 
345
                for (i = 0; i < packed_size; i++)
 
346
                        g_print("%02X", packed[i]);
 
347
                g_print("\n");
 
348
        }
 
349
 
 
350
        g_assert(packed_size == hex_decoded_size);
 
351
        g_assert(memcmp(packed, decoded, packed_size) == 0);
 
352
 
 
353
        g_free(decoded);
 
354
 
 
355
        hex_packed = encode_hex(packed, packed_size, 0);
 
356
 
 
357
        g_assert(hex_packed != NULL);
 
358
 
 
359
        g_free(packed);
 
360
 
 
361
        if (g_test_verbose())
 
362
                g_print("Hex encoded packed to size %ld bytes\n",
 
363
                                (long)strlen(hex_packed));
 
364
 
 
365
        g_assert(strlen(hex_packed) == strlen(sms));
 
366
        g_assert(strcmp(hex_packed, sms) == 0);
 
367
 
 
368
        g_free(hex_packed);
 
369
}
 
370
 
 
371
static void test_pack_size()
 
372
{
 
373
        unsigned char c1[] = { 'a' };
 
374
        unsigned char c2[] = { 'a', 'b' };
 
375
        unsigned char c3[] = { 'a', 'b', 'c' };
 
376
        unsigned char c4[] = { 'a', 'b', 'c', 'd' };
 
377
        unsigned char c5[] = { 'a', 'b', 'c', 'd', 'e' };
 
378
        unsigned char c6[] = { 'a', 'b', 'c', 'd', 'e', 'f' };
 
379
        unsigned char c7[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g' };
 
380
        unsigned char c8[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' };
 
381
 
 
382
        unsigned char *packed;
 
383
        long size;
 
384
 
 
385
        packed = pack_7bit(c1, 1, 0, FALSE, &size, 0);
 
386
        g_assert(packed != NULL);
 
387
        g_assert(size == 1);
 
388
        g_free(packed);
 
389
 
 
390
        packed = pack_7bit(c2, 2, 0, FALSE, &size, 0);
 
391
        g_assert(packed != NULL);
 
392
        g_assert(size == 2);
 
393
        g_free(packed);
 
394
 
 
395
        packed = pack_7bit(c3, 3, 0, FALSE, &size, 0);
 
396
        g_assert(packed != NULL);
 
397
        g_assert(size == 3);
 
398
        g_free(packed);
 
399
 
 
400
        packed = pack_7bit(c4, 4, 0, FALSE, &size, 0);
 
401
        g_assert(packed != NULL);
 
402
        g_assert(size == 4);
 
403
        g_free(packed);
 
404
 
 
405
        packed = pack_7bit(c5, 5, 0, FALSE, &size, 0);
 
406
        g_assert(packed != NULL);
 
407
        g_assert(size == 5);
 
408
        g_free(packed);
 
409
 
 
410
        packed = pack_7bit(c6, 6, 0, FALSE, &size, 0);
 
411
        g_assert(packed != NULL);
 
412
        g_assert(size == 6);
 
413
        g_free(packed);
 
414
 
 
415
        packed = pack_7bit(c7, 7, 0, FALSE, &size, 0);
 
416
        g_assert(packed != NULL);
 
417
        g_assert(size == 7);
 
418
        g_assert((packed[6] & 0xfe) == 0);
 
419
        g_free(packed);
 
420
 
 
421
        packed = pack_7bit(c7, 7, 0, TRUE, &size, 0);
 
422
        g_assert(packed != NULL);
 
423
        g_assert(size == 7);
 
424
        g_assert(((packed[6] & 0xfe) >> 1) == '\r');
 
425
        g_free(packed);
 
426
 
 
427
        packed = pack_7bit(c8, 8, 0, FALSE, &size, 0);
 
428
        g_assert(packed != NULL);
 
429
        g_assert(size == 7);
 
430
        g_free(packed);
 
431
}
 
432
 
 
433
static void test_cr_handling()
 
434
{
 
435
        unsigned char c7[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g' };
 
436
        unsigned char c7_expected[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', '\r' };
 
437
        unsigned char c8[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', '\r' };
 
438
        unsigned char c8_expected[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', '\r', '\r' };
 
439
 
 
440
        unsigned char *packed;
 
441
        unsigned char *unpacked;
 
442
        long packed_size;
 
443
        long unpacked_size;
 
444
 
 
445
        packed = pack_7bit(c8, 8, 0, TRUE, &packed_size, 0);
 
446
        g_assert(packed != NULL);
 
447
        g_assert(packed_size == 8);
 
448
        g_assert(((packed[6] & 0xfe) >> 1) == '\r');
 
449
        g_assert((packed[7] & 0x7f) == '\r');
 
450
 
 
451
        unpacked = unpack_7bit(packed, 8, 0, TRUE, -1, &unpacked_size, 0);
 
452
        if (g_test_verbose())
 
453
                g_print("Unpacked to size: %ld\n", unpacked_size);
 
454
 
 
455
        g_assert(unpacked != NULL);
 
456
        g_assert(unpacked_size == 9);
 
457
        g_assert(memcmp(c8_expected, unpacked, 9) == 0);
 
458
 
 
459
        g_free(unpacked);
 
460
        g_free(packed);
 
461
 
 
462
        packed = pack_7bit(c7, 7, 0, TRUE, &packed_size, 0);
 
463
        g_assert(packed != NULL);
 
464
        g_assert(packed_size == 7);
 
465
        g_assert(((packed[6] & 0xfe) >> 1) == '\r');
 
466
 
 
467
        unpacked = unpack_7bit(packed, 7, 0, TRUE, -1, &unpacked_size, 0);
 
468
        if (g_test_verbose())
 
469
                g_print("Unpacked to size: %ld\n", unpacked_size);
 
470
 
 
471
        g_assert(unpacked != NULL);
 
472
        g_assert(unpacked_size == 7);
 
473
        g_assert(memcmp(c7, unpacked, 7) == 0);
 
474
 
 
475
        g_free(unpacked);
 
476
        g_free(packed);
 
477
 
 
478
        /* As above, but now unpack using SMS style, we should now have cr at
 
479
         * the end of the stream
 
480
         */
 
481
        packed = pack_7bit(c7, 7, 0, TRUE, &packed_size, 0);
 
482
        unpacked = unpack_7bit(packed, 7, 0, FALSE, 8, &unpacked_size, 0);
 
483
        if (g_test_verbose())
 
484
                g_print("Unpacked to size: %ld\n", unpacked_size);
 
485
 
 
486
        g_assert(unpacked != NULL);
 
487
        g_assert(unpacked_size == 8);
 
488
        g_assert(memcmp(c7_expected, unpacked, 8) == 0);
 
489
 
 
490
        g_free(unpacked);
 
491
        g_free(packed);
 
492
}
 
493
 
 
494
static void test_sms_handling()
 
495
{
 
496
        unsigned char c7[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g' };
 
497
 
 
498
        unsigned char *packed;
 
499
        unsigned char *unpacked;
 
500
        long packed_size;
 
501
        long unpacked_size;
 
502
 
 
503
        packed = pack_7bit(c7, 7, 0, FALSE, &packed_size, 0);
 
504
        g_assert(packed != NULL);
 
505
        g_assert(packed_size == 7);
 
506
 
 
507
        unpacked = unpack_7bit(packed, 7, 0, FALSE, 8, &unpacked_size, 0xff);
 
508
        if (g_test_verbose())
 
509
                g_print("Unpacked to size: %ld\n", unpacked_size);
 
510
 
 
511
        g_assert(unpacked != NULL);
 
512
        g_assert(unpacked_size == 8);
 
513
        g_assert(unpacked[7] == 0);
 
514
        g_assert(unpacked[8] == 0xff);
 
515
 
 
516
        g_free(unpacked);
 
517
        g_free(packed);
 
518
 
 
519
        packed = pack_7bit(c7, 7, 0, FALSE, &packed_size, 0);
 
520
        g_assert(packed != NULL);
 
521
        g_assert(packed_size == 7);
 
522
 
 
523
        unpacked = unpack_7bit(packed, 7, 0, FALSE, 7, &unpacked_size, 0xff);
 
524
        if (g_test_verbose())
 
525
                g_print("Unpacked to size: %ld\n", unpacked_size);
 
526
 
 
527
        g_assert(unpacked != NULL);
 
528
        g_assert(unpacked_size == 7);
 
529
        g_assert(unpacked[7] == 0xff);
 
530
 
 
531
        g_free(unpacked);
 
532
        g_free(packed);
 
533
}
 
534
 
 
535
static void test_offset_handling()
 
536
{
 
537
        unsigned char c7[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g' };
 
538
        unsigned char c8[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' };
 
539
        unsigned char c9[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i' };
 
540
        unsigned char *packed;
 
541
        unsigned char *unpacked;
 
542
        long packed_size;
 
543
        long unpacked_size;
 
544
 
 
545
        /* Pack at offset = 2 bytes, e.g. starting with 21st bit */
 
546
        packed = pack_7bit(c7, 6, 2, FALSE, &packed_size, 0);
 
547
 
 
548
        if (g_test_verbose())
 
549
                g_print("Packed to size: %ld\n", packed_size);
 
550
 
 
551
        g_assert(packed != NULL);
 
552
        g_assert(packed_size == 6);
 
553
 
 
554
        unpacked = unpack_7bit(packed, 6, 2, FALSE, 6, &unpacked_size, 0xff);
 
555
        if (g_test_verbose())
 
556
                g_print("Unpacked to size: %ld\n", unpacked_size);
 
557
 
 
558
        g_assert(unpacked != NULL);
 
559
        g_assert(unpacked_size == 6);
 
560
        g_assert(unpacked[6] == 0xff);
 
561
        g_assert(unpacked[0] == 'a');
 
562
        g_assert(unpacked[5] == 'f');
 
563
 
 
564
        g_free(unpacked);
 
565
        g_free(packed);
 
566
 
 
567
        /* Pack at offset = 6 bytes, we should be able to fit one character
 
568
         * into the first byte, and the other 7 characters into the following
 
569
         * 7 bytes.  The 7 MSB bits of the last byte should be 0 since
 
570
         * we're not using CBS packing
 
571
         */
 
572
        packed = pack_7bit(c8, 8, 6, FALSE, &packed_size, 0);
 
573
 
 
574
        if (g_test_verbose())
 
575
                g_print("Packed to size: %ld\n", packed_size);
 
576
 
 
577
        g_assert(packed != NULL);
 
578
        g_assert(packed_size == 8);
 
579
 
 
580
        unpacked = unpack_7bit(packed, 8, 6, FALSE, 8, &unpacked_size, 0xff);
 
581
        if (g_test_verbose())
 
582
                g_print("Unpacked to size: %ld\n", unpacked_size);
 
583
 
 
584
        g_assert(unpacked != NULL);
 
585
        g_assert(unpacked_size == 8);
 
586
        g_assert(unpacked[8] == 0xff);
 
587
        g_assert(unpacked[0] == 'a');
 
588
        g_assert(unpacked[7] == 'h');
 
589
 
 
590
        g_free(unpacked);
 
591
        g_free(packed);
 
592
 
 
593
        /* Same as above, but instead pack in 9 characters */
 
594
        packed = pack_7bit(c9, 9, 6, FALSE, &packed_size, 0);
 
595
 
 
596
        if (g_test_verbose())
 
597
                g_print("Packed to size: %ld\n", packed_size);
 
598
 
 
599
        g_assert(packed != NULL);
 
600
        g_assert(packed_size == 8);
 
601
 
 
602
        unpacked = unpack_7bit(packed, 8, 6, FALSE, 9, &unpacked_size, 0xff);
 
603
        if (g_test_verbose())
 
604
                g_print("Unpacked to size: %ld\n", unpacked_size);
 
605
 
 
606
        g_assert(unpacked != NULL);
 
607
        g_assert(unpacked_size == 9);
 
608
        g_assert(unpacked[9] == 0xff);
 
609
        g_assert(unpacked[0] == 'a');
 
610
        g_assert(unpacked[8] == 'i');
 
611
 
 
612
        g_free(unpacked);
 
613
        g_free(packed);
 
614
}
 
615
 
 
616
int main(int argc, char **argv)
 
617
{
 
618
        g_test_init(&argc, &argv, NULL);
 
619
 
 
620
        g_test_add_func("/testutil/Invalid Conversions", test_invalid);
 
621
        g_test_add_func("/testutil/Valid Conversions", test_valid);
 
622
        g_test_add_func("/testutil/Decode Encode", test_decode_encode);
 
623
        g_test_add_func("/testutil/Pack Size", test_pack_size);
 
624
        g_test_add_func("/testutil/CBS CR Handling", test_cr_handling);
 
625
        g_test_add_func("/testutil/SMS Handling", test_sms_handling);
 
626
        g_test_add_func("/testutil/Offset Handling", test_offset_handling);
 
627
 
 
628
        return g_test_run();
 
629
}