aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/quectel/tests/test-modem-helpers-quectel.c
blob: dee01865ea720a3ebbc1c18267a2e1b30857a4dd (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
/* -*- 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;
} TestCtzuResponse;

static const TestCtzuResponse test_ctzu_response[] = {
    { "+CTZU: (0,1)",   TRUE, TRUE, FALSE },
    { "+CTZU: (0,1,3)", TRUE, TRUE, TRUE  },
};

static void
common_test_ctzu (const gchar *response,
                  gboolean     expect_supports_disable,
                  gboolean     expect_supports_enable,
                  gboolean     expect_supports_enable_update_rtc)
{
    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);
    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 ^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);
}

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

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);

    return g_test_run ();
}