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
131
132
133
134
135
136
137
138
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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:
*
* Copyright (C) 2016 Aleksander Morgado <aleksander@aleksander.es>
*/
#include <glib.h>
#include <glib-object.h>
#include <locale.h>
#include <arpa/inet.h>
#include <ModemManager.h>
#define _LIBMM_INSIDE_MM
#include <libmm-glib.h>
#include "mm-log.h"
#include "mm-modem-helpers.h"
#include "mm-modem-helpers-ublox.h"
/*****************************************************************************/
/* Test UUSBCONF? responses */
typedef struct {
const gchar *str;
MMUbloxUsbProfile profile;
} UusbconfResponseTest;
static const UusbconfResponseTest uusbconf_response_tests[] = {
{
.str = "+UUSBCONF: 3,\"RNDIS\",,\"0x1146\"\r\n",
.profile = MM_UBLOX_USB_PROFILE_RNDIS
},
{
.str = "+UUSBCONF: 2,\"ECM\",,\"0x1143\"\r\n",
.profile = MM_UBLOX_USB_PROFILE_ECM
},
{
.str = "+UUSBCONF: 0,\"\",,\"0x1141\"\r\n",
.profile = MM_UBLOX_USB_PROFILE_BACK_COMPATIBLE
},
};
static void
test_uusbconf_response (void)
{
guint i;
for (i = 0; i < G_N_ELEMENTS (uusbconf_response_tests); i++) {
MMUbloxUsbProfile profile = MM_UBLOX_USB_PROFILE_UNKNOWN;
GError *error = NULL;
gboolean success;
success = mm_ublox_parse_uusbconf_response (uusbconf_response_tests[i].str, &profile, &error);
g_assert_no_error (error);
g_assert (success);
g_assert_cmpuint (uusbconf_response_tests[i].profile, ==, profile);
}
}
/*****************************************************************************/
/* Test UBMCONF? responses */
typedef struct {
const gchar *str;
MMUbloxNetworkingMode mode;
} UbmconfResponseTest;
static const UbmconfResponseTest ubmconf_response_tests[] = {
{
.str = "+UBMCONF: 1\r\n",
.mode = MM_UBLOX_NETWORKING_MODE_ROUTER
},
{
.str = "+UBMCONF: 2\r\n",
.mode = MM_UBLOX_NETWORKING_MODE_BRIDGE
},
};
static void
test_ubmconf_response (void)
{
guint i;
for (i = 0; i < G_N_ELEMENTS (ubmconf_response_tests); i++) {
MMUbloxNetworkingMode mode = MM_UBLOX_NETWORKING_MODE_UNKNOWN;
GError *error = NULL;
gboolean success;
success = mm_ublox_parse_ubmconf_response (ubmconf_response_tests[i].str, &mode, &error);
g_assert_no_error (error);
g_assert (success);
g_assert_cmpuint (ubmconf_response_tests[i].mode, ==, mode);
}
}
/*****************************************************************************/
void
_mm_log (const char *loc,
const char *func,
guint32 level,
const char *fmt,
...)
{
#if defined ENABLE_TEST_MESSAGE_TRACES
/* Dummy log function */
va_list args;
gchar *msg;
va_start (args, fmt);
msg = g_strdup_vprintf (fmt, args);
va_end (args);
g_print ("%s\n", msg);
g_free (msg);
#endif
}
int main (int argc, char **argv)
{
setlocale (LC_ALL, "");
g_type_init ();
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/MM/ublox/uusbconf/response", test_uusbconf_response);
g_test_add_func ("/MM/ublox/ubmconf/response", test_ubmconf_response);
return g_test_run ();
}
|