Coverage Report

Created: 2021-08-28 18:14

D:\git\skunkworks\herald-for-cpp\herald-tests\datatypes-tests.cpp
Line
Count
Source
1
//  Copyright 2020-2021 Herald Project Contributors
2
//  SPDX-License-Identifier: Apache-2.0
3
//
4
5
#include "catch.hpp"
6
7
#include "herald/herald.h"
8
9
10
1
TEST_CASE("datatypes-base64string-reversible", "[datatypes][base64string][reversible]") {
11
1
  // Story:-
12
1
  //   [Who]   As an app programmer
13
1
  //   [What]  I need to encode and decode in base64
14
1
  //   [Value] So I have a reliable string based way of exchanging information
15
1
  SECTION("datatypes-base64string-reversible") {
16
1
    herald::datatype::Base64String str;
17
1
    bool encodeOk = herald::datatype::Base64String::from("d290Y2hh",str);
18
1
    REQUIRE(encodeOk);
19
1
    REQUIRE(str.encoded() == "d290Y2hh");
20
1
  }
21
1
}
22
23
1
TEST_CASE("datatypes-proximity-basics", "[datatypes][proximity][basics]") {
24
1
  SECTION("datatypes-proximity-basics") {
25
1
    herald::datatype::Proximity p{herald::datatype::ProximityMeasurementUnit::RSSI, 11.0};
26
1
27
1
    REQUIRE(p.unit == herald::datatype::ProximityMeasurementUnit::RSSI);
28
1
    REQUIRE(p.value == 11.0);
29
1
  }
30
1
}
31
32
33
34
35
36
37
38
1
TEST_CASE("datatypes-encounter-basics", "[datatypes][encounter][basics]") {
39
1
  SECTION("datatypes-encounter-basics") {
40
1
    herald::datatype::Proximity prox{herald::datatype::ProximityMeasurementUnit::RSSI, 11.0};
41
1
    herald::datatype::PayloadData payload{std::byte('b'),6};
42
1
    herald::datatype::Date date{1608483600};
43
1
    herald::datatype::Encounter e{prox,payload,date}; // ctor
44
1
45
1
    REQUIRE(e.isValid() == true);
46
1
    REQUIRE(e.timestamp().secondsSinceUnixEpoch() == 1608483600);
47
1
    REQUIRE(e.proximity().unit == herald::datatype::ProximityMeasurementUnit::RSSI);
48
1
    REQUIRE(e.proximity().value == 11.0);
49
1
    REQUIRE(e.payload().size() == 6);
50
1
  }
51
1
}
52
53
// TODO Encounter to csvString format test
54
55
56
57
58
59
60
1
TEST_CASE("datatypes-errorcode-ctor-default", "[datatypes][errorcode][ctor-default]") {
61
1
  SECTION("datatypes-errorcode-ctor-default") {
62
1
    herald::datatype::ErrorCode ec;
63
1
    REQUIRE(ec()); // bool conversion to true
64
1
    REQUIRE(ec.message() == std::string(""));
65
1
  }
66
1
}
67
68
69
2
TEST_CASE("datatypes-errorcode-ctor-bool", "[datatypes][errorcode][ctor-bool]") {
70
2
  SECTION("datatypes-errorcode-ctor-bool-true") {
71
1
    herald::datatype::ErrorCode ec(true);
72
1
    REQUIRE(ec()); // bool conversion to true
73
1
    REQUIRE(ec.message() == std::string(""));
74
1
  }
75
2
  SECTION("datatypes-errorcode-ctor-bool-false") {
76
1
    herald::datatype::ErrorCode ec(false);
77
1
    REQUIRE(!ec()); // bool conversion to true
78
1
    REQUIRE(ec.message() == std::string(""));
79
1
  }
80
2
}
81
82
2
TEST_CASE("datatypes-errorcode-ctor-bool-string", "[datatypes][errorcode][ctor-bool-string]") {
83
2
  SECTION("datatypes-errorcode-ctor-bool-string-true") {
84
1
    herald::datatype::ErrorCode ec(true, "wibble");
85
1
    REQUIRE(ec()); // bool conversion to true
86
1
    REQUIRE(ec.message() == std::string("wibble"));
87
1
  }
88
2
  SECTION("datatypes-errorcode-ctor-bool-string-false") {
89
1
    herald::datatype::ErrorCode ec(false, "wibble");
90
1
    REQUIRE(!ec()); // bool conversion to true
91
1
    REQUIRE(ec.message() == std::string("wibble"));
92
1
  }
93
2
}
94
95
96
1
TEST_CASE("datatypes-rssi-ctor-int", "[datatypes][rssi][ctor][int]") {
97
1
  SECTION("datatypes-rssi-ctor-int") {
98
1
    herald::datatype::RSSI rssi{11};
99
1
    REQUIRE(rssi.intValue() == 11);
100
1
101
1
    herald::datatype::RSSI other{11};
102
1
    REQUIRE(other == rssi);
103
1
  }
104
1
}
105
106
107
108
1
TEST_CASE("datatypes-rssi-ctor-copy", "[datatypes][rssi][ctor][copy]") {
109
1
  SECTION("datatypes-rssi-ctor-copy") {
110
1
    herald::datatype::RSSI rssi{11};
111
1
    REQUIRE(rssi.intValue() == 11);
112
1
113
1
    herald::datatype::RSSI other{rssi};
114
1
    REQUIRE(other == rssi);
115
1
  }
116
1
}
117
118
119
120
121
122
123
1
TEST_CASE("datatypes-placename-basics", "[datatypes][placename][ctor][basics]") {
124
1
  SECTION("datatypes-placename-basics") {
125
1
    herald::datatype::PlacenameLocationReference plr{"Chesterfield"};
126
1
    REQUIRE(plr.description().size() >= 12);
127
1
  }
128
1
}
129
130
131
132
133
1
TEST_CASE("datatypes-uuid-notblank", "[datatypes][uuid][notblank]") {
134
1
  SECTION("datatypes-uuid-notblank") {
135
1
    auto serviceUUID = herald::datatype::UUID::fromString("428132af-4746-42d3-801e-4572d65bfd9b");
136
1
    // INFO("Service UUID " << std::string(serviceUUID));
137
1
    auto blankUUID = herald::datatype::UUID::fromString("");
138
1
    // INFO("Blank UUID " << std::string(blankUUID));
139
1
    REQUIRE(serviceUUID != blankUUID);
140
1
  }
141
1
}
142
143
144
145
146
147
// TEST_CASE("datatypes-memory-use","[datatypes][memory]") {
148
149
//   SECTION("datatypes-memory-use") {
150
//     // TODO always output sizes to a CSV report file
151
152
//     using namespace herald::datatype;
153
//     Base64String b64 = Base64String::encode(Data(std::byte(2),8));
154
//     INFO("Base64String size for 8 chars: " << sizeof(b64));
155
//     REQUIRE(sizeof(b64) <= 40); // std::string of ~12 chars plus 64 bit size
156
//     Data d{std::byte(1),32};
157
//     INFO("Data size for 32 bytes: " << sizeof(d));
158
//     REQUIRE(sizeof(d) <= 40);
159
160
//     // TODO other types here
161
//   }
162
// }