Skip to content

Commit 93815e6

Browse files
authored
Add golden tests for BloomFilter (#10874)
* upload initial code * add golden test with md5 calculator * resolve comments * add static const to kGoldenDocumentPrefix * resolve comments * resolve comments
1 parent 698c946 commit 93815e6

File tree

27 files changed

+566
-25
lines changed

27 files changed

+566
-25
lines changed

Firestore/Example/Firestore.xcodeproj/project.pbxproj

Lines changed: 360 additions & 0 deletions
Large diffs are not rendered by default.

Firestore/core/src/remote/bloom_filter.cc

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818

1919
#include <utility>
2020

21-
#include "CommonCrypto/CommonDigest.h"
2221
#include "Firestore/core/src/util/hard_assert.h"
22+
#include "Firestore/core/src/util/md5.h"
2323
#include "Firestore/core/src/util/statusor.h"
24-
#include "Firestore/core/src/util/warnings.h"
2524

2625
namespace firebase {
2726
namespace firestore {
@@ -30,23 +29,15 @@ namespace remote {
3029
using util::Status;
3130
using util::StatusOr;
3231

33-
// TODO(Mila): Replace CommonCrypto with platform based MD5 calculation and
34-
// remove suppress.
35-
SUPPRESS_DEPRECATED_DECLARATIONS_BEGIN();
36-
3732
BloomFilter::Hash BloomFilter::Md5HashDigest(absl::string_view key) const {
38-
unsigned char md5_digest[CC_MD5_DIGEST_LENGTH];
33+
std::array<uint8_t, 16> md5_digest{util::CalculateMd5Digest(key)};
3934

40-
CC_MD5_CTX context;
41-
CC_MD5_Init(&context);
42-
CC_MD5_Update(&context, key.data(), key.size());
43-
CC_MD5_Final(md5_digest, &context);
35+
// TODO(Mila): Handle big endian processor b/271174523.
36+
uint64_t* hash128 = reinterpret_cast<uint64_t*>(md5_digest.data());
37+
static_assert(sizeof(uint64_t[2]) == sizeof(uint8_t[16]), "");
4438

45-
// TODO(Mila): Replace this casting with safer function (b/270568625).
46-
uint64_t* hash128 = reinterpret_cast<uint64_t*>(md5_digest);
4739
return Hash{hash128[0], hash128[1]};
4840
}
49-
SUPPRESS_END();
5041

5142
int32_t BloomFilter::GetBitIndex(const Hash& hash, int32_t hash_index) const {
5243
HARD_ASSERT(hash_index >= 0);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "bits": { "bitmap": "RswZ", "padding": 1 }, "hashCount": 16 }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"membershipTestResults" : "10"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"bits":{"bitmap":"mwE=","padding":5},"hashCount":8}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"membershipTestResults" : "10"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"bits":{"bitmap":"","padding":0},"hashCount":0}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"membershipTestResults" : "00"}

Firestore/core/test/unit/remote/bloom_filter_golden_test_data/Validation_BloomFilterTest_MD5_50000_0001_bloom_filter_proto.json

Lines changed: 7 additions & 0 deletions
Large diffs are not rendered by default.

Firestore/core/test/unit/remote/bloom_filter_golden_test_data/Validation_BloomFilterTest_MD5_50000_0001_membership_test_result.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)