1 // Copyright 2024 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14
15 #include "pw_random_fuchsia/zircon_random_generator.h"
16
17 #include "pw_unit_test/framework.h"
18
19 namespace pw::random_fuchsia {
20
TEST(ZirconRandomGeneratorTest,Get)21 TEST(ZirconRandomGeneratorTest, Get) {
22 // Getting a random number should not crash.
23 std::array<std::byte, 4> value = {std::byte{0}};
24 ZirconRandomGenerator().Get(value);
25 }
26
TEST(ZirconRandomGeneratorTest,InjectEntropyBits)27 TEST(ZirconRandomGeneratorTest, InjectEntropyBits) {
28 ZirconRandomGenerator rng;
29 // Injecting 0 bits of entropy should safely do nothing.
30 rng.InjectEntropyBits(/*data=*/1, /*num_bits=*/0);
31 // Injecting too many bits should round down to 32 and not crash.
32 rng.InjectEntropyBits(/*data=*/1, /*num_bits=*/33);
33 // Inject the maximum number of bits.
34 rng.InjectEntropyBits(/*data=*/1, /*num_bits=*/32);
35 rng.InjectEntropyBits(/*data=*/1, /*num_bits=*/8);
36 rng.InjectEntropyBits(/*data=*/1, /*num_bits=*/31);
37 }
38
39 } // namespace pw::random_fuchsia
40