Debian Codegraph @

src/qmi-firmware-update/test/test-firehose.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) 2019 Zodiac Inflight Innovations
19 * Copyright (C) 2019 Aleksander Morgado <[email protected]>
20 */
21
22 #include "qfu-firehose-message.h"
23
24 static void
25 test_firehose_response_ack_parser_value (void)
26 {
27 const gchar *rsp = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<data>\n<response value=\"ACK\" />\n</data>";
28 gchar *value = NULL;
29 gchar *rawmode = NULL;
30
31 g_assert (qfu_firehose_message_parse_response_ack (rsp, &value, &rawmode));
32 g_assert_cmpstr (value, ==, "ACK");
33 g_assert (rawmode == NULL);
34 g_clear_pointer (&value, g_free);
35 }
36
37 static void
38 test_firehose_response_ack_parser_value_rawmode (void)
39 {
40 const gchar *rsp = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<data>\n<response value=\"ACK\" rawmode=\"true\" />\n</data>";
41 gchar *value = NULL;
42 gchar *rawmode = NULL;
43
44 g_assert (qfu_firehose_message_parse_response_ack (rsp, &value, &rawmode));
45 g_assert_cmpstr (value, ==, "ACK");
46 g_assert_cmpstr (rawmode, ==, "true");
47 g_clear_pointer (&value, g_free);
48 g_clear_pointer (&rawmode, g_free);
49 }
50
51 static void
52 test_firehose_response_configure_parser (void)
53 {
54 const gchar *rsp = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<data>\n<response value=\"NAK\" MemoryName=\"NAND\" MaxPayloadSizeFromTargetInBytes=\"2048\" MaxPayloadSizeToTargetInBytes=\"8192\" MaxPayloadSizeToTargetInBytesSupported=\"8192\" TargetName=\"9x55\" />\n</data>";
55 guint number = 0;
56
57 g_assert (qfu_firehose_message_parse_response_configure (rsp, &number));
58 g_assert_cmpuint (number, ==, 8192);
59 }
60
61 static void
62 test_firehose_log_parser_value (void)
63 {
64 const gchar *rsp = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<data>\n<log value=\"SWI supported functions: CWE\"/>\n</data>";
65 gchar *value = NULL;
66
67 g_assert (qfu_firehose_message_parse_log (rsp, &value));
68 g_assert_cmpstr (value, ==, "SWI supported functions: CWE");
69 g_clear_pointer (&value, g_free);
70 }
71
72 /******************************************************************************/
73
74 int main (int argc, char **argv)
75 {
76 g_test_init (&argc, &argv, NULL);
77
78 g_test_add_func ("/qmi-firmware-update/firehose/response-ack-parser/value", test_firehose_response_ack_parser_value);
79 g_test_add_func ("/qmi-firmware-update/firehose/response-ack-varser/value-rawmode", test_firehose_response_ack_parser_value_rawmode);
80 g_test_add_func ("/qmi-firmware-update/firehose/response-configure-parser", test_firehose_response_configure_parser);
81 g_test_add_func ("/qmi-firmware-update/firehose/log-parser/value", test_firehose_log_parser_value);
82
83 return g_test_run ();
84 }