Coverage Report

Created: 2021-08-28 18:14

D:\git\skunkworks\herald-for-cpp\herald-tests\randomuuid-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
7
#include "catch.hpp"
8
9
#include "herald/herald.h"
10
11
12
// TEST_CASE("datatypes-uuid-basics", "[datatypes][uuid][ctor][basics]") {
13
//   SECTION("datatypes-uuid-basics") {
14
//     auto uuid1 = herald::datatype::UUID::random();
15
//     REQUIRE(uuid1.valid());
16
//     REQUIRE(uuid1.string().size() == 36); // 4 hyphens, 16 hex bytes = 36 characters
17
//   }
18
// }
19
20
21
1
TEST_CASE("random-allzeros","[randomness][allzeros][basic][datatypes]") {
22
1
23
1
  SECTION("random-allzeros-basic") {
24
1
    herald::datatype::AllZerosNotRandom rnd;
25
1
    REQUIRE(rnd.nextInt() == 0);
26
1
    REQUIRE(rnd.nextDouble() == 0);
27
1
    herald::datatype::Data expected(std::byte(0),4);
28
1
    herald::datatype::Data toFill;
29
1
    rnd.nextBytes(4, toFill);
30
1
    REQUIRE(toFill == expected);
31
1
  }
32
1
}
33
34
35
36
37
1
TEST_CASE("datatypes-uuid-notrandom","[randomness][uuid][basic][datatypes]") {
38
1
39
1
  SECTION("datatypes-uuid-notrandom") {
40
1
    herald::datatype::AllZerosNotRandom rnd;
41
1
    herald::datatype::RandomnessGenerator gen(std::move(rnd));
42
1
    auto emptyV4 = herald::datatype::UUID::random(gen);
43
1
    REQUIRE(emptyV4.string() == std::string("00000000-0000-4000-8000-000000000000")); // v4 variant 1
44
1
  }
45
1
}
46
47
48
49
50
1
TEST_CASE("datatypes-uuid-random","[randomness][uuid][basic][datatypes]") {
51
1
52
1
  SECTION("datatypes-uuid-random") {
53
1
    herald::datatype::IntegerDistributedRandomSource rnd;
54
1
    herald::datatype::RandomnessGenerator gen(std::move(rnd));
55
1
    auto randomV4 = herald::datatype::UUID::random(gen);
56
1
    std::string str = randomV4.string();
57
1
    INFO("UUID v4 random value: " << str);
58
1
    REQUIRE(str != std::string("00000000-0000-4000-8000-000000000000")); // v4 variant 1
59
1
  }
60
1
}