forked from open-telemetry/opentelemetry-specification
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add function to fill a buffer with random bytes (open-telemetry#87)
- Loading branch information
Johannes Tax
authored
Jun 5, 2020
1 parent
599bddb
commit 273a0ae
Showing
6 changed files
with
87 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,32 @@ | ||
#include "src/common/random.h" | ||
|
||
#include <algorithm> | ||
#include <iterator> | ||
|
||
#include <gtest/gtest.h> | ||
using opentelemetry::sdk::common::GetRandomNumberGenerator; | ||
using opentelemetry::sdk::common::Random; | ||
|
||
TEST(RandomTest, GenerateRandom64) | ||
{ | ||
EXPECT_NE(Random::GenerateRandom64(), Random::GenerateRandom64()); | ||
} | ||
|
||
TEST(RandomTest, GenerateRandomNumbers) | ||
TEST(RandomTest, GenerateRandomBuffer) | ||
{ | ||
auto &random_number_generator = GetRandomNumberGenerator(); | ||
EXPECT_NE(random_number_generator(), random_number_generator()); | ||
uint8_t buf1[8] = {0}; | ||
uint8_t buf2[8] = {0}; | ||
Random::GenerateRandomBuffer(buf1); | ||
Random::GenerateRandomBuffer(buf2); | ||
EXPECT_FALSE(std::equal(std::begin(buf1), std::end(buf1), std::begin(buf2))); | ||
|
||
// Edge cases. | ||
for (auto size : {1, 7, 8, 9, 16, 17}) | ||
{ | ||
std::vector<uint8_t> buf1(size); | ||
std::vector<uint8_t> buf2(size); | ||
|
||
Random::GenerateRandomBuffer(buf1); | ||
Random::GenerateRandomBuffer(buf2); | ||
EXPECT_FALSE(std::equal(std::begin(buf1), std::end(buf1), std::begin(buf2))); | ||
} | ||
} |