diff --git a/data/Data.cpp b/data/Data.cpp index 4b0337df..7d02cba8 100644 --- a/data/Data.cpp +++ b/data/Data.cpp @@ -104,4 +104,7 @@ bool operator==(const Data &lhs, const Data &rhs) { return lhs.size() == rhs.size() && 0 == memcmp(lhs.data(), rhs.data(), lhs.size()); } +bool operator!=(const Data &lhs, const Data &rhs) { + return !operator==(lhs, rhs); +} } diff --git a/data/Data.h b/data/Data.h index c3ce72dd..4d6ec069 100644 --- a/data/Data.h +++ b/data/Data.h @@ -41,8 +41,9 @@ private: DISALLOW_COPY_AND_ASSIGN(Data); }; -//TODO Test operator== +//TODO Test operator== and operator!= bool operator==(const Data &lhs, const Data &rhs); +bool operator!=(const Data &lhs, const Data &rhs); } diff --git a/test/data/DataFixtureTest.cpp b/test/data/DataFixtureTest.cpp new file mode 100644 index 00000000..0fa3914e --- /dev/null +++ b/test/data/DataFixtureTest.cpp @@ -0,0 +1,76 @@ +#include "google/gtest/gtest.h" + +#include "../../data/Data.h" +#include "../../data/DataFixture.h" + +using ::testing::Test; +using ::testing::WithParamInterface; +using ::testing::Values; + +namespace bf = boost::filesystem; + +using namespace cpputils; + +class DataFixtureTest: public Test { +}; + +TEST_F(DataFixtureTest, CreateEmptyFixture) { + Data data = DataFixture::generate(0); + EXPECT_EQ(0, data.size()); +} + +TEST_F(DataFixtureTest, CreateOneByteFixture) { + Data data = DataFixture::generate(1); + EXPECT_EQ(1, data.size()); +} + +TEST_F(DataFixtureTest, CreateLargerFixture) { + Data data = DataFixture::generate(20 * 1024 * 1024); + EXPECT_EQ(20 * 1024 * 1024, data.size()); +} + +TEST_F(DataFixtureTest, FixturesAreDeterministic_DefaultSeed) { + Data data1 = DataFixture::generate(1024 * 1024); + Data data2 = DataFixture::generate(1024 * 1024); + EXPECT_EQ(data1, data2); +} + +TEST_F(DataFixtureTest, FixturesAreDeterministic_SeedIs5) { + Data data1 = DataFixture::generate(1024 * 1024, 5); + Data data2 = DataFixture::generate(1024 * 1024, 5); + EXPECT_EQ(data1, data2); +} + +TEST_F(DataFixtureTest, DifferentSeedIsDifferentFixture) { + Data data1 = DataFixture::generate(1024 * 1024, 0); + 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)); +}