Coverage Report

Created: 2021-08-28 18:14

D:\git\skunkworks\herald-for-cpp\herald-tests\beaconpayload-tests.cpp
Line
Count
Source
1
//  Copyright 2020-2021 Herald Project Contributors
2
//  SPDX-License-Identifier: Apache-2.0
3
//
4
5
#include <memory>
6
#include <array>
7
#include <deque>
8
#include <forward_list>
9
#include <list>
10
#include <map>
11
#include <queue>
12
#include <set>
13
#include <stack>
14
#include <unordered_map>
15
#include <unordered_set>
16
#include <vector>
17
18
#include "catch.hpp"
19
20
#include "herald/herald.h"
21
22
#include "test-templates.h"
23
24
1
TEST_CASE("payload-beacon-basic", "[payload][beacon][basic]") {
25
1
  SECTION("payload-beacon-basic") {
26
1
    uint16_t country = 826;
27
1
    uint16_t state = 4;
28
1
    uint32_t code = 123456;
29
1
    herald::payload::extended::ConcreteExtendedDataV1 extended;
30
1
    extended.addSection(herald::payload::extended::ExtendedDataSegmentCodesV1::TextPremises,std::string("Adams Pizza"));
31
1
    herald::payload::beacon::ConcreteBeaconPayloadDataSupplierV1 pds(
32
1
      country,
33
1
      state,
34
1
      code,
35
1
      extended
36
1
    );
37
1
    BlankDevice bd;
38
1
    auto pd = pds.payload(herald::datatype::PayloadTimestamp(),bd);
39
1
40
1
    REQUIRE(pd.size() == 22); // 1 version code, 2 country, 2 state, 4 code, 13 extended = 22
41
1
  }
42
1
}
43
44
1
TEST_CASE("payload-beacon-toconstchar", "[payload][beacon][toconstchar]") {
45
1
  SECTION("payload-beacon-toconstchar") {
46
1
    uint16_t country = 826;
47
1
    uint16_t state = 4;
48
1
    uint32_t code = 123456;
49
1
    herald::payload::extended::ConcreteExtendedDataV1 extended;
50
1
    extended.addSection(herald::payload::extended::ExtendedDataSegmentCodesV1::TextPremises,std::string("Adams Pizza"));
51
1
    herald::payload::beacon::ConcreteBeaconPayloadDataSupplierV1 pds(
52
1
      country,
53
1
      state,
54
1
      code,
55
1
      extended
56
1
    );
57
1
    BlankDevice bd;
58
1
    auto pd = pds.payload(herald::datatype::PayloadTimestamp(),bd);
59
1
60
1
    REQUIRE(pd.size() == 22); // 1 version code, 2 country, 2 state, 4 code, 13 extended = 22
61
1
62
1
    const char* cc = "lorem ipsum dolar sit amet lorem ipsum dolar sit amet lorem ipsum dolar sit amet";
63
1
    const char* value = cc;
64
1
    char* newvalue = new char[pd.size()];
65
1
    std::size_t i;
66
23
    for (i = 0;i < pd.size();
i++22
) {
67
22
      newvalue[i] = (char)pd.at(i);
68
22
    }
69
1
    newvalue[i] = '\0';
70
1
    // WARNING - DO NOT USE strlen as it terminates on the first \0 (zero) uint8_t byte/character
71
1
    REQUIRE(pd.at(21) == std::byte(newvalue[21]));
72
1
    value = newvalue;
73
1
    REQUIRE(pd.at(21) == std::byte(value[21]));
74
1
  }
75
1
}