-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfill.test.cc
68 lines (49 loc) · 1.58 KB
/
fill.test.cc
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
// Copyright (c) 2022 Mikael Simonsson <https://mikaelsimonsson.com>.
// SPDX-License-Identifier: BSL-1.0
#include "snn-core/random/fill.hh"
#include "snn-core/array.hh"
#include "snn-core/unittest.hh"
#include "snn-core/fn/common.hh"
namespace snn::app
{
namespace
{
bool example()
{
array<char, 8> buf; // Zero initiated.
snn_require(buf.all(fn::is_zero{}));
random::fill(buf.view());
snn_require(!buf.all(fn::is_zero{}));
return true;
}
}
}
namespace snn
{
void unittest()
{
snn_require(app::example());
{
array<char, 8> buf; // Zero initiated.
snn_require(buf.all(fn::is_zero{}));
random::fill(buf.view());
snn_require(!buf.all(fn::is_zero{})); // Very unlikely.
buf.fill('\0');
random::fill(buf.view(0, 0)); // Empty view, does nothing.
snn_require(buf.all(fn::is_zero{}));
}
{
// Fill more than 256 bytes (some implementations will only provide 256 bytes of random
// data at a time).
str s{container::fill, 300, '\0'};
snn_require(s.size() == 300);
snn_require(s.all(fn::is_zero{}));
str needle{container::fill, 8, '\0'}; // 64-bit needle.
snn_require(needle.size() == 8);
snn_require(needle.all(fn::is_zero{}));
snn_require(s.contains(needle));
random::fill(s.view());
snn_require(!s.contains(needle)); // Very unlikely.
}
}
}