aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmi-firmware-update/test/test-utils.c
blob: 7a77eeb4d0b82b0bc844d2a46b1b3412575464de (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
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * qmi-firmware-update -- Command line tool to update firmware in QMI devices
 *
 * 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.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Copyright (C) 2016 Zodiac Inflight Innovations
 * Copyright (C) 2016 Aleksander Morgado <aleksander@aleksander.es>
 */

#include "qfu-utils.h"

/******************************************************************************/

static void
common_version_parser_test (const gchar *version,
                            const gchar *expected_firmware_version,
                            const gchar *expected_config_version,
                            const gchar *expected_carrier)
{
    gboolean  res;
    GError   *error = NULL;
    gchar    *firmware_version = NULL;
    gchar    *config_version = NULL;
    gchar    *carrier = NULL;

    res = qfu_utils_parse_cwe_version_string (version,
                                              &firmware_version,
                                              &config_version,
                                              &carrier,
                                              &error);
    g_assert_no_error (error);
    g_assert (res);

    g_assert_cmpstr (firmware_version, ==, expected_firmware_version);
    g_assert_cmpstr (config_version,   ==, expected_config_version);
    g_assert_cmpstr (carrier,          ==, expected_carrier);

    g_free (firmware_version);
    g_free (config_version);
    g_free (carrier);
}

static void
test_cwe_version_parser_mc7700 (void)
{
    common_version_parser_test ("9999999_9999999_9200_03.05.29.03_00_generic_000.000_001_SPKG_MC",
                                "03.05.29.03",
                                "000.000_001",
                                "generic");
}

static void
test_cwe_version_parser_mc7354_cwe (void)
{
    common_version_parser_test ("INTERNAL_?_SWI9X15C_05.05.63.01_?_?_?_?",
                                "05.05.63.01",
                                NULL,
                                NULL);
}

static void
test_cwe_version_parser_mc7354_nvu (void)
{
    common_version_parser_test ("9999999_9902350_SWI9X15C_05.05.63.01_00_SPRINT_005.037_000",
                                "05.05.63.01",
                                "005.037_000",
                                "SPRINT");
}

static void
test_cwe_version_parser_mc7354b_spk (void)
{
    common_version_parser_test ("9999999_9902574_SWI9X15C_05.05.66.00_00_GENNA-UMTS_005.028_000",
                                "05.05.66.00",
                                "005.028_000",
                                "GENNA-UMTS");
}

/******************************************************************************/

int main (int argc, char **argv)
{
    g_type_init ();
    g_test_init (&argc, &argv, NULL);

    g_test_add_func ("/qmi-firmware-update/cwe-version-parser/mc7700",      test_cwe_version_parser_mc7700);
    g_test_add_func ("/qmi-firmware-update/cwe-version-parser/mc7354/cwe",  test_cwe_version_parser_mc7354_cwe);
    g_test_add_func ("/qmi-firmware-update/cwe-version-parser/mc7354/nvu",  test_cwe_version_parser_mc7354_nvu);
    g_test_add_func ("/qmi-firmware-update/cwe-version-parser/mc7354b/spk", test_cwe_version_parser_mc7354b_spk);

    return g_test_run ();
}