aboutsummaryrefslogtreecommitdiff
path: root/libqcdm/tests/test-qcdm.c
blob: 35520c03864fc069a04745955193a5488d2d3949 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* -*- 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-crc.h"
#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;
} TestData;

#if GLIB_CHECK_VERSION(2,25,12)
typedef GTestFixtureFunc TCFunc;
#else
typedef void (*TCFunc)(void);
#endif

#define TESTCASE(t, d) g_test_create_case (#t, 0, d, NULL, (TCFunc) t, NULL)

static TestData *
test_data_new (const char *port)
{
	TestData *d;

	d = g_malloc0 (sizeof (TestData));
	g_assert (d);

    if (port)
        d->com_data = test_com_setup (port);

	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;

    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];
        }
    }

    data = test_data_new (port);

    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_unescape, NULL));
    g_test_suite_add (suite, TESTCASE (test_utils_decapsulate_buffer, NULL));
    g_test_suite_add (suite, TESTCASE (test_utils_encapsulate_buffer, NULL));
    g_test_suite_add (suite, TESTCASE (test_utils_decapsulate_sierra_cns, 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));
    g_test_suite_add (suite, TESTCASE (test_result_uint8_array, 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_version_info, data->com_data));
        g_test_suite_add (suite, TESTCASE (test_com_esn, data->com_data));
        g_test_suite_add (suite, TESTCASE (test_com_mdn, data->com_data));
        g_test_suite_add (suite, TESTCASE (test_com_read_roam_pref, data->com_data));
        g_test_suite_add (suite, TESTCASE (test_com_read_mode_pref, data->com_data));
        g_test_suite_add (suite, TESTCASE (test_com_read_hybrid_pref, data->com_data));
        g_test_suite_add (suite, TESTCASE (test_com_read_hdr_rev_pref, data->com_data));
        g_test_suite_add (suite, TESTCASE (test_com_status, data->com_data));
        g_test_suite_add (suite, TESTCASE (test_com_sw_version, data->com_data));
        g_test_suite_add (suite, TESTCASE (test_com_status_snapshot, data->com_data));
        g_test_suite_add (suite, TESTCASE (test_com_pilot_sets, data->com_data));
        g_test_suite_add (suite, TESTCASE (test_com_cm_subsys_state_info, data->com_data));
        g_test_suite_add (suite, TESTCASE (test_com_hdr_subsys_state_info, data->com_data));
        g_test_suite_add (suite, TESTCASE (test_com_ext_logmask, data->com_data));
        g_test_suite_add (suite, TESTCASE (test_com_event_report, data->com_data));
        g_test_suite_add (suite, TESTCASE (test_com_log_config, data->com_data));
        g_test_suite_add (suite, TESTCASE (test_com_zte_subsys_status, data->com_data));
        g_test_suite_add (suite, TESTCASE (test_com_nw_subsys_modem_snapshot_cdma, data->com_data));
        g_test_suite_add (suite, TESTCASE (test_com_nw_subsys_eri, data->com_data));
        g_test_suite_add (suite, TESTCASE (test_com_wcdma_subsys_state_info, data->com_data));
        g_test_suite_add (suite, TESTCASE (test_com_gsm_subsys_state_info, data->com_data));
    }

	result = g_test_run ();

	test_data_free (data);

	return result;
}