libcryfs/test/cpp-utils/data/DataFixtureTest.cpp
Sebastian Messmer 9ccb006f61 - Switch some CI jobs to clang 15
- Fix clang-tidy warnings from Clang 15
2023-07-08 14:48:59 -07:00

76 lines
2.3 KiB
C++

#include <gtest/gtest.h>
#include <cstddef>
#include "cpp-utils/data/Data.h"
#include "cpp-utils/data/DataFixture.h"
using ::testing::Test;
using namespace cpputils;
class DataFixtureTest: public Test {
};
TEST_F(DataFixtureTest, CreateEmptyFixture) {
const Data data = DataFixture::generate(0);
EXPECT_EQ(0u, data.size());
}
TEST_F(DataFixtureTest, CreateOneByteFixture) {
const Data data = DataFixture::generate(1);
EXPECT_EQ(1u, data.size());
}
TEST_F(DataFixtureTest, CreateLargerFixture) {
const Data data = DataFixture::generate(20 * 1024 * 1024);
EXPECT_EQ(20u * 1024u * 1024u, data.size());
}
TEST_F(DataFixtureTest, FixturesAreDeterministic_DefaultSeed) {
const Data data1 = DataFixture::generate(1024 * 1024);
const Data data2 = DataFixture::generate(1024 * 1024);
EXPECT_EQ(data1, data2);
}
TEST_F(DataFixtureTest, FixturesAreDeterministic_SeedIs5) {
const Data data1 = DataFixture::generate(1024 * 1024, 5);
const Data data2 = DataFixture::generate(1024 * 1024, 5);
EXPECT_EQ(data1, data2);
}
TEST_F(DataFixtureTest, DifferentSeedIsDifferentFixture) {
const Data data1 = DataFixture::generate(1024 * 1024, 0);
const Data data2 = DataFixture::generate(1024 * 1024, 1);
EXPECT_NE(data1, data2);
}
TEST_F(DataFixtureTest, FixturesAreDeterministic_DifferentSize_DefaultSeed_1) {
Data data1 = DataFixture::generate(1024);
Data data2 = DataFixture::generate(1);
EXPECT_EQ(0, std::memcmp(data1.data(), data2.data(), 1));
}
TEST_F(DataFixtureTest, FixturesAreDeterministic_DifferentSize_DefaultSeed_2) {
Data data1 = DataFixture::generate(1024);
Data data2 = DataFixture::generate(501); //Intentionally not 64bit-aligned, because the generate() function generates 64bit values for performance
EXPECT_EQ(0, std::memcmp(data1.data(), data2.data(), 501));
}
TEST_F(DataFixtureTest, FixturesAreDeterministic_DifferentSize_SeedIs5_1) {
Data data1 = DataFixture::generate(1024, 5);
Data data2 = DataFixture::generate(1, 5);
EXPECT_EQ(0, std::memcmp(data1.data(), data2.data(), 1));
}
TEST_F(DataFixtureTest, FixturesAreDeterministic_DifferentSize_SeedIs5_2) {
Data data1 = DataFixture::generate(1024, 5);
Data data2 = DataFixture::generate(501, 5); //Intentionally not 64bit-aligned, because the generate() function generates 64bit values for performance
EXPECT_EQ(0, std::memcmp(data1.data(), data2.data(), 501));
}