Debian Codegraph @

src/qmi-firmware-update/test/test-utils.c

raw
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * qmi-firmware-update -- Command line tool to update firmware in QMI devices
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Copyright (C) 2016 Zodiac Inflight Innovations
19 * Copyright (C) 2016 Aleksander Morgado <[email protected]>
20 */
21
22 #include "qfu-utils.h"
23
24 /******************************************************************************/
25
26 static void
27 common_version_parser_test (const gchar *version,
28 const gchar *expected_firmware_version,
29 const gchar *expected_config_version,
30 const gchar *expected_carrier)
31 {
32 gboolean res;
33 GError *error = NULL;
34 gchar *firmware_version = NULL;
35 gchar *config_version = NULL;
36 gchar *carrier = NULL;
37
38 res = qfu_utils_parse_cwe_version_string (version,
39 &firmware_version,
40 &config_version,
41 &carrier,
42 &error);
43 g_assert_no_error (error);
44 g_assert (res);
45
46 g_assert_cmpstr (firmware_version, ==, expected_firmware_version);
47 g_assert_cmpstr (config_version, ==, expected_config_version);
48 g_assert_cmpstr (carrier, ==, expected_carrier);
49
50 g_free (firmware_version);
51 g_free (config_version);
52 g_free (carrier);
53 }
54
55 static void
56 test_cwe_version_parser_mc7700 (void)
57 {
58 common_version_parser_test ("9999999_9999999_9200_03.05.29.03_00_generic_000.000_001_SPKG_MC",
59 "03.05.29.03",
60 "000.000_001",
61 "generic");
62 }
63
64 static void
65 test_cwe_version_parser_mc7354_cwe (void)
66 {
67 common_version_parser_test ("INTERNAL_?_SWI9X15C_05.05.63.01_?_?_?_?",
68 "05.05.63.01",
69 NULL,
70 NULL);
71 }
72
73 static void
74 test_cwe_version_parser_mc7354_nvu (void)
75 {
76 common_version_parser_test ("9999999_9902350_SWI9X15C_05.05.63.01_00_SPRINT_005.037_000",
77 "05.05.63.01",
78 "005.037_000",
79 "SPRINT");
80 }
81
82 static void
83 test_cwe_version_parser_mc7354b_spk (void)
84 {
85 common_version_parser_test ("9999999_9902574_SWI9X15C_05.05.66.00_00_GENNA-UMTS_005.028_000",
86 "05.05.66.00",
87 "005.028_000",
88 "GENNA-UMTS");
89 }
90
91 /******************************************************************************/
92
93 int main (int argc, char **argv)
94 {
95 g_test_init (&argc, &argv, NULL);
96
97 g_test_add_func ("/qmi-firmware-update/cwe-version-parser/mc7700", test_cwe_version_parser_mc7700);
98 g_test_add_func ("/qmi-firmware-update/cwe-version-parser/mc7354/cwe", test_cwe_version_parser_mc7354_cwe);
99 g_test_add_func ("/qmi-firmware-update/cwe-version-parser/mc7354/nvu", test_cwe_version_parser_mc7354_nvu);
100 g_test_add_func ("/qmi-firmware-update/cwe-version-parser/mc7354b/spk", test_cwe_version_parser_mc7354b_spk);
101
102 return g_test_run ();
103 }