~phablet-team/ofono/ofono-bug-updates

« back to all changes in this revision

Viewing changes to unit/test-cdmasms.c

  • Committer: Denis Kenzior
  • Author(s): Lucas De Marchi
  • Date: 2011-03-18 23:31:14 UTC
  • Revision ID: git-v1:888e07863b24026413bac8f449de377c879e1044
message: add cancelled state

Based on patch from Yang Gu <gyagp0@gmail.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *
3
 
 *  oFono - Open Source Telephony
4
 
 *
5
 
 *  Copyright (C) 2008-2011  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
 
#ifdef HAVE_CONFIG_H
23
 
#include <config.h>
24
 
#endif
25
 
 
26
 
#include <string.h>
27
 
 
28
 
#include <glib.h>
29
 
 
30
 
#include "cdma-smsutil.h"
31
 
 
32
 
static inline void check_text(const char *decoded, const char *expected)
33
 
{
34
 
        if (expected == NULL) {
35
 
                g_assert(decoded == NULL);
36
 
                return;
37
 
        }
38
 
 
39
 
        g_assert(decoded != NULL);
40
 
        g_assert(g_str_equal(decoded, expected));
41
 
}
42
 
 
43
 
struct wmt_deliver_test {
44
 
        const guint8 *tpdu;
45
 
        guint8 tpdu_len;
46
 
        const char *text;
47
 
        const char *oaddr;
48
 
};
49
 
 
50
 
guint8 wmt_deliver_1[] = { 0x00, 0x00, 0x02, 0x10, 0x02, 0x02, 0x05, 0x01,
51
 
                                0xC4, 0x8D, 0x15, 0x9C, 0x08, 0x0D, 0x00,
52
 
                                0x03, 0x1B, 0xEE, 0xF0, 0x01, 0x06, 0x10,
53
 
                                0x2C, 0x8C, 0xBB, 0x36, 0x6F };
54
 
 
55
 
guint8 wmt_deliver_2[] = { 0x00, 0x00, 0x02, 0x10, 0x02, 0x02, 0x07, 0x02,
56
 
                                0xA1, 0x62, 0x51, 0x55, 0xA6, 0x40, 0x08,
57
 
                                0x18, 0x00, 0x03, 0x10, 0x00, 0x40, 0x01,
58
 
                                0x06, 0x10, 0x25, 0x4C, 0xBC, 0xFA, 0x00,
59
 
                                0x03, 0x06, 0x03, 0x08, 0x20, 0x13, 0x43,
60
 
                                0x12, 0x0D, 0x01, 0x01 };
61
 
 
62
 
static struct wmt_deliver_test wmt_deliver_data_1 = {
63
 
        .tpdu = wmt_deliver_1,
64
 
        .tpdu_len = sizeof(wmt_deliver_1),
65
 
        .text = "Hello",
66
 
        .oaddr = "1234567"
67
 
};
68
 
 
69
 
static struct wmt_deliver_test wmt_deliver_data_2 = {
70
 
        .tpdu = wmt_deliver_2,
71
 
        .tpdu_len = sizeof(wmt_deliver_2),
72
 
        .text = "Test",
73
 
        .oaddr = "8589455699"
74
 
};
75
 
 
76
 
static void test_wmt_deliver(gconstpointer data)
77
 
{
78
 
        const struct wmt_deliver_test *test = data;
79
 
        gboolean ret;
80
 
        struct cdma_sms s;
81
 
        const char *addr;
82
 
        char *message;
83
 
 
84
 
        memset(&s, 0, sizeof(struct cdma_sms));
85
 
 
86
 
        ret = cdma_sms_decode(test->tpdu, test->tpdu_len, &s);
87
 
 
88
 
        g_assert(ret == TRUE);
89
 
 
90
 
        g_assert(s.type == CDMA_SMS_TP_MSG_TYPE_P2P);
91
 
 
92
 
        g_assert(s.p2p_msg.teleservice_id == CDMA_SMS_TELESERVICE_ID_WMT);
93
 
 
94
 
        addr = cdma_sms_address_to_string(&s.p2p_msg.oaddr);
95
 
        check_text(addr, test->oaddr);
96
 
 
97
 
        message = cdma_sms_decode_text(&s.p2p_msg.bd.wmt_deliver.ud);
98
 
        check_text(message, test->text);
99
 
 
100
 
        g_free(message);
101
 
}
102
 
 
103
 
int main(int argc, char **argv)
104
 
{
105
 
        g_test_init(&argc, &argv, NULL);
106
 
 
107
 
        g_test_add_data_func("/test-cdmasms/WMT DELIVER 1",
108
 
                        &wmt_deliver_data_1, test_wmt_deliver);
109
 
 
110
 
        g_test_add_data_func("/test-cdmasms/WMT DELIVER 2",
111
 
                        &wmt_deliver_data_2, test_wmt_deliver);
112
 
 
113
 
        return g_test_run();
114
 
}