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
139
140
141
142
143
144
145
146
|
/* -*- 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) 2020 Aleksander Morgado <aleksander@aleksander.es>
*/
#include <glib.h>
#include <glib-object.h>
#include <locale.h>
#include <ModemManager.h>
#define _LIBMM_INSIDE_MM
#include <libmm-glib.h>
#include <math.h>
#include "mm-log-test.h"
#include "mm-modem-helpers.h"
#include "mm-modem-helpers-quectel.h"
/*****************************************************************************/
/* Test ^CTZU test responses */
typedef struct {
const gchar *response;
gboolean expect_supports_disable;
gboolean expect_supports_enable;
gboolean expect_supports_enable_update_rtc;
gboolean expect_error;
} TestCtzuResponse;
static const TestCtzuResponse test_ctzu_response[] = {
{ "+CTZU: ", FALSE, FALSE, FALSE, TRUE },
{ "+CTZU: ()", FALSE, FALSE, FALSE, TRUE },
{ "+CTZU: (,)", FALSE, FALSE, FALSE, TRUE },
{ "+CTZU: (0,1)", TRUE, TRUE, FALSE, FALSE },
{ "+CTZU: (0,1,3)", TRUE, TRUE, TRUE, FALSE },
};
static void
common_test_ctzu (const gchar *response,
gboolean expect_supports_disable,
gboolean expect_supports_enable,
gboolean expect_supports_enable_update_rtc,
gboolean expect_error)
{
g_autoptr(GError) error = NULL;
gboolean res;
gboolean supports_disable = FALSE;
gboolean supports_enable = FALSE;
gboolean supports_enable_update_rtc = FALSE;
res = mm_quectel_parse_ctzu_test_response (response,
NULL,
&supports_disable,
&supports_enable,
&supports_enable_update_rtc,
&error);
if (expect_error) {
g_assert (error);
g_assert (!res);
} else {
g_assert_no_error (error);
g_assert (res);
g_assert_cmpuint (expect_supports_disable, ==, supports_disable);
g_assert_cmpuint (expect_supports_enable, ==, supports_enable);
g_assert_cmpuint (expect_supports_enable_update_rtc, ==, supports_enable_update_rtc);
}
}
static void
test_ctzu (void)
{
guint i;
for (i = 0; i < G_N_ELEMENTS (test_ctzu_response); i++)
common_test_ctzu (test_ctzu_response[i].response,
test_ctzu_response[i].expect_supports_disable,
test_ctzu_response[i].expect_supports_enable,
test_ctzu_response[i].expect_supports_enable_update_rtc,
test_ctzu_response[i].expect_error);
}
/*****************************************************************************/
/* Test ^FIRMVERSION test responses */
static void
test_firmversion (void)
{
gboolean valid = TRUE;
valid = mm_quectel_check_standard_firmware_version_valid ("EM05GFAR07A07M1G_01.016.01.016");
g_assert_cmpuint (valid, ==, TRUE);
valid = mm_quectel_check_standard_firmware_version_valid ("EM05GFAR07A07M1G_01.016.00.000");
g_assert_cmpuint (valid, ==, FALSE);
}
static void
test_parse_revision (void)
{
gboolean valid;
guint release;
guint minor;
valid = mm_quectel_get_version_from_revision ("EM05GFAR07A07M1G_01.016.01.016", &release, &minor, NULL);
g_assert_cmpuint (valid, ==, TRUE);
g_assert_cmpuint (release, ==, 7);
g_assert_cmpuint (minor, ==, 7);
valid = mm_quectel_get_version_from_revision ("EM05GFAR10A02M1G", &release, &minor, NULL);
g_assert_cmpuint (valid, ==, TRUE);
g_assert_cmpuint (release, ==, 10);
g_assert_cmpuint (minor, ==, 2);
valid = mm_quectel_get_version_from_revision ("EM05GFAR07AM1G", &release, &minor, NULL);
g_assert_cmpuint (valid, ==, FALSE);
valid = mm_quectel_get_version_from_revision ("EM05GFARA07M1G", &release, &minor, NULL);
g_assert_cmpuint (valid, ==, FALSE);
}
/*****************************************************************************/
int main (int argc, char **argv)
{
setlocale (LC_ALL, "");
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/MM/quectel/ctzu", test_ctzu);
g_test_add_func ("/MM/quectel/firmversion", test_firmversion);
g_test_add_func ("/MM/quectel/parse_revision", test_parse_revision);
return g_test_run ();
}
|