c316ea9d3df759da0e996afc5749dc18c2238934
[iec.git] / src / type3_AndroidCloud / anbox-master / tests / anbox / support / at_parser_tests.cpp
1 /*
2  * Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 3, as published
6  * by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranties of
10  * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11  * PURPOSE.  See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program.  If not, see <http://www.gnu.org/licenses/>.
15  *
16  */
17
18 #include "anbox/qemu/at_parser.h"
19
20 #include <gtest/gtest.h>
21
22 #include <algorithm>
23
24 TEST(AtParser, BasicCommands) {
25     anbox::qemu::AtParser parser;
26
27     std::string command = "ATE0Q0V1\nATE0Q0V1\n";
28     std::vector<uint8_t> data;
29     std::copy(command.begin(), command.end(), std::back_inserter(data));
30
31     int commands_expected = 0;
32     int commands_found = 0;
33     auto assert_at_command = [&](const std::string &expected_command) {
34         commands_expected++;
35         return [&](const std::string &command) {
36             commands_found++;
37             ASSERT_STRCASEEQ(expected_command.c_str(), command.c_str());
38         };
39     };
40
41     parser.register_command("E0Q0V1", assert_at_command("E0Q0V1"));
42     parser.register_command("E0Q0V1", assert_at_command("E0Q0V1"));
43
44     parser.process_data(data);
45
46     ASSERT_EQ(commands_expected, commands_found);
47 }