~aleteoryx/muditaos

ref: dc00afaad3fc80328fca1867eb1c793eb4f31866 muditaos/module-cellular/test/unittest_ATStream.cpp -rw-r--r-- 2.7 KiB
dc00afaa — breichel [EGD-5599] Change AT and DLC channels for big return 5 years ago
                                                                                
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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <string>
#define CATCH_CONFIG_MAIN

#include <catch2/catch.hpp>
#include "Modem/ATStream.hpp"
#include "Result.hpp"

TEST_CASE("Channel Test- AT return parser")
{
    SECTION("Parse AT - OK")
    {
        at::ATStream stream;
        uint32_t errcode = 0;
        auto code        = stream.parseState("OK", errcode);
        REQUIRE(code == at::Result::Code::OK);
    }

    SECTION("Parse AT - ERROR")
    {
        at::ATStream stream;
        uint32_t errcode = 0;
        auto code        = stream.parseState("ERROR", errcode);
        REQUIRE(code == at::Result::Code::ERROR);
    }

    SECTION("Parse AT - +CME ERROR: Valid")
    {
        at::ATStream stream;
        uint32_t errcode = 0;
        auto code        = stream.parseState("+CME ERROR: 33", errcode);
        REQUIRE(code == at::Result::Code::CME_ERROR);
        REQUIRE(errcode == 33);
    }

    SECTION("Parse AT - +CMS ERROR: Valid")
    {
        at::ATStream stream;
        uint32_t errcode = 0;
        auto code        = stream.parseState("+CMS ERROR: 33", errcode);
        REQUIRE(code == at::Result::Code::CMS_ERROR);
        REQUIRE(errcode == 33);
    }

    SECTION("Parse AT - +CMS ERROR: Invalid")
    {
        at::ATStream stream;
        uint32_t errcode = 0;
        auto code        = stream.parseState("+CMS ERROR: ssss", errcode);
        REQUIRE(code == at::Result::Code::PARSING_ERROR);
    }

    SECTION("Parse AT - +CMS ERROR: Invalid empty")
    {
        at::ATStream stream;
        uint32_t errcode = 0;
        auto code        = stream.parseState("+CMS ERROR:", errcode);
        REQUIRE(code == at::Result::Code::PARSING_ERROR);
    }

    SECTION("Parse AT - +CME ERROR: Valid")
    {
        at::ATStream stream;
        uint32_t errcode = 0;
        auto code        = stream.parseState("+CME ERROR: 33", errcode);
        REQUIRE(code == at::Result::Code::CME_ERROR);
        REQUIRE(errcode == 33);
    }

    SECTION("Parse AT - +CME ERROR: Invalid")
    {
        at::ATStream stream;
        uint32_t errcode = 0;
        auto code        = stream.parseState("+CME ERROR: ssss", errcode);
        REQUIRE(code == at::Result::Code::PARSING_ERROR);
    }

    SECTION("Parse AT - +CME ERROR: Invalid empty")
    {
        at::ATStream stream;
        uint32_t errcode = 0;
        auto code        = stream.parseState("+CME ERROR:", errcode);
        REQUIRE(code == at::Result::Code::PARSING_ERROR);
    }

    SECTION("Parse AT - Wrong data")
    {
        at::ATStream stream;
        uint32_t errcode = 0;
        auto code        = stream.parseState("+XME ERROR:", errcode);
        REQUIRE(code == at::Result::Code::NONE);
    }
}