Reduce use of memcmp and use operator==(Data, Data) instead
This commit is contained in:
parent
a2c89ed73a
commit
77b67a8137
@ -26,14 +26,13 @@ public:
|
||||
void CheckEncryptThenDecryptIsIdentity(const Data &plaintext) {
|
||||
Data ciphertext = Encrypt(plaintext);
|
||||
Data decrypted = Decrypt(ciphertext);
|
||||
EXPECT_EQ(plaintext.size(), decrypted.size());
|
||||
EXPECT_EQ(0, std::memcmp(plaintext.data(), decrypted.data(), plaintext.size()));
|
||||
EXPECT_EQ(plaintext, decrypted);
|
||||
}
|
||||
|
||||
void CheckEncryptIsIndeterministic(const Data &plaintext) {
|
||||
Data ciphertext = Encrypt(plaintext);
|
||||
Data ciphertext2 = Encrypt(plaintext);
|
||||
EXPECT_NE(0, std::memcmp(ciphertext.data(), ciphertext2.data(), ciphertext.size()));
|
||||
EXPECT_NE(ciphertext, ciphertext2);
|
||||
}
|
||||
|
||||
void CheckEncryptedSize(const Data &plaintext) {
|
||||
|
@ -69,7 +69,7 @@ TEST_P(OnDiskBlockCreateSizeTest, OnDiskSizeIsCorrect) {
|
||||
|
||||
TEST_P(OnDiskBlockCreateSizeTest, OnDiskBlockIsZeroedOut) {
|
||||
Data fileContent = Data::LoadFromFile(file.path()).value();
|
||||
EXPECT_EQ(0, std::memcmp(ZEROES.data(), fileContent.data(), fileContent.size()));
|
||||
EXPECT_EQ(ZEROES, fileContent);
|
||||
}
|
||||
|
||||
// This test is also tested by OnDiskBlockStoreTest, but there the block is created using the BlockStore interface.
|
||||
|
@ -38,17 +38,13 @@ public:
|
||||
|
||||
unique_ptr<OnDiskBlock> CreateBlockAndLoadItFromDisk() {
|
||||
{
|
||||
Data data(randomData.size());
|
||||
std::memcpy(data.data(), randomData.data(), randomData.size());
|
||||
auto block = OnDiskBlock::CreateOnDisk(dir.path(), key, std::move(data));
|
||||
OnDiskBlock::CreateOnDisk(dir.path(), key, randomData.copy());
|
||||
}
|
||||
return OnDiskBlock::LoadFromDisk(dir.path(), key);
|
||||
}
|
||||
|
||||
unique_ptr<OnDiskBlock> CreateBlock() {
|
||||
Data data(randomData.size());
|
||||
std::memcpy(data.data(), randomData.data(), randomData.size());
|
||||
return OnDiskBlock::CreateOnDisk(dir.path(), key, std::move(data));
|
||||
return OnDiskBlock::CreateOnDisk(dir.path(), key, randomData.copy());
|
||||
}
|
||||
|
||||
void WriteDataToBlock(const unique_ptr<OnDiskBlock> &block) {
|
||||
@ -62,8 +58,7 @@ public:
|
||||
|
||||
void EXPECT_STORED_FILE_DATA_CORRECT() {
|
||||
Data actual = Data::LoadFromFile(file.path()).value();
|
||||
EXPECT_EQ(randomData.size(), actual.size());
|
||||
EXPECT_EQ(0, std::memcmp(randomData.data(), actual.data(), randomData.size()));
|
||||
EXPECT_EQ(randomData, actual);
|
||||
}
|
||||
};
|
||||
INSTANTIATE_TEST_CASE_P(OnDiskBlockFlushTest, OnDiskBlockFlushTest, Values((size_t)0, (size_t)1, (size_t)1024, (size_t)4096, (size_t)10*1024*1024));
|
||||
|
@ -46,11 +46,6 @@ private:
|
||||
cpputils::Data foregroundData;
|
||||
cpputils::Data backgroundData;
|
||||
|
||||
void EXPECT_DATA_EQ(const cpputils::Data &expected, const cpputils::Data &actual) {
|
||||
EXPECT_EQ(expected.size(), actual.size());
|
||||
EXPECT_EQ(0, std::memcmp(expected.data(), actual.data(), expected.size()));
|
||||
}
|
||||
|
||||
blockstore::Key CreateBlockWriteToItAndReturnKey(const cpputils::Data &to_write) {
|
||||
auto newblock = blockStore->create(cpputils::Data(testData.blocksize).FillWithZeroes());
|
||||
|
||||
@ -61,7 +56,7 @@ private:
|
||||
void EXPECT_DATA_READS_AS(const cpputils::Data &expected, const blockstore::Block &block, off_t offset, size_t count) {
|
||||
cpputils::Data read(count);
|
||||
std::memcpy(read.data(), (uint8_t*)block.data() + offset, count);
|
||||
EXPECT_DATA_EQ(expected, read);
|
||||
EXPECT_EQ(expected, read);
|
||||
}
|
||||
|
||||
void EXPECT_DATA_READS_AS_OUTSIDE_OF(const cpputils::Data &expected, const blockstore::Block &block, off_t start, size_t count) {
|
||||
|
Loading…
Reference in New Issue
Block a user