Skip to content

Fix test failures that occur during prod build #910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <utility>

#include "Firestore/core/src/firebase/firestore/immutable/map_entry.h"
#include "Firestore/core/src/firebase/firestore/util/firebase_assert.h"

namespace firebase {
namespace firestore {
Expand Down Expand Up @@ -101,7 +102,7 @@ class FixedArray {
void append(SourceIterator src_begin, SourceIterator src_end) {
size_type appending = static_cast<size_type>(src_end - src_begin);
size_type new_size = size_ + appending;
assert(new_size <= fixed_size);
FIREBASE_ASSERT(new_size <= fixed_size);

std::copy(src_begin, src_end, end());
size_ = new_size;
Expand All @@ -112,7 +113,7 @@ class FixedArray {
*/
void append(T&& value) {
size_type new_size = size_ + 1;
assert(new_size <= fixed_size);
FIREBASE_ASSERT(new_size <= fixed_size);

*end() = std::move(value);
size_ = new_size;
Expand Down
42 changes: 21 additions & 21 deletions Firestore/core/src/firebase/firestore/util/ordered_code.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,20 @@ inline static bool IsSpecialByte(char c) {
* assertion checking).
*/
inline static int AdvanceIfNoSpecialBytes(uint32_t v_32, const char* p) {
FIREBASE_ASSERT(UNALIGNED_LOAD32(p) == v_32);
FIREBASE_DEV_ASSERT(UNALIGNED_LOAD32(p) == v_32);
// See comments in SkipToNextSpecialByte if you wish to
// understand this expression (which checks for the occurrence
// of the special byte values 0 or 255 in any of the bytes of v_32).
if ((v_32 - 0x01010101u) & ~(v_32 + 0x01010101u) & 0x80808080u) {
// Special byte is in p[0..3]
FIREBASE_ASSERT(IsSpecialByte(p[0]) || IsSpecialByte(p[1]) ||
IsSpecialByte(p[2]) || IsSpecialByte(p[3]));
FIREBASE_DEV_ASSERT(IsSpecialByte(p[0]) || IsSpecialByte(p[1]) ||
IsSpecialByte(p[2]) || IsSpecialByte(p[3]));
return 0;
} else {
FIREBASE_ASSERT(!IsSpecialByte(p[0]));
FIREBASE_ASSERT(!IsSpecialByte(p[1]));
FIREBASE_ASSERT(!IsSpecialByte(p[2]));
FIREBASE_ASSERT(!IsSpecialByte(p[3]));
FIREBASE_DEV_ASSERT(!IsSpecialByte(p[0]));
FIREBASE_DEV_ASSERT(!IsSpecialByte(p[1]));
FIREBASE_DEV_ASSERT(!IsSpecialByte(p[2]));
FIREBASE_DEV_ASSERT(!IsSpecialByte(p[3]));
return 4;
}
}
Expand All @@ -126,8 +126,8 @@ inline static int AdvanceIfNoSpecialBytes(uint32_t v_32, const char* p) {
inline static const char* SkipToNextSpecialByte(const char* start,
const char* limit) {
// If these constants were ever changed, this routine needs to change
FIREBASE_ASSERT(kEscape1 == 0);
FIREBASE_ASSERT((kEscape2 & 0xff) == 255);
FIREBASE_DEV_ASSERT(kEscape1 == 0);
FIREBASE_DEV_ASSERT((kEscape2 & 0xff) == 255);
const char* p = start;
while (p + 8 <= limit) {
// Find out if any of the next 8 bytes are either 0 or 255 (our
Expand Down Expand Up @@ -165,7 +165,7 @@ inline static const char* SkipToNextSpecialByte(const char* start,
if (IsSpecialByte(p[0])) return p;
if (IsSpecialByte(p[1])) return p + 1;
if (IsSpecialByte(p[2])) return p + 2;
FIREBASE_ASSERT(
FIREBASE_DEV_ASSERT(
IsSpecialByte(p[3])); // Last byte must be the special one
return p + 3;
}
Expand Down Expand Up @@ -199,14 +199,14 @@ inline static void EncodeStringFragment(std::string* dest,
p = SkipToNextSpecialByte(p, limit);
if (p >= limit) break; // No more special characters that need escaping
char c = *(p++);
FIREBASE_ASSERT(IsSpecialByte(c));
FIREBASE_DEV_ASSERT(IsSpecialByte(c));
if (c == kEscape1) {
AppendBytes(dest, copy_start, static_cast<size_t>(p - copy_start) - 1);
dest->push_back(kEscape1);
dest->push_back(kNullCharacter);
copy_start = p;
} else {
FIREBASE_ASSERT(c == kEscape2);
FIREBASE_DEV_ASSERT(c == kEscape2);
AppendBytes(dest, copy_start, static_cast<size_t>(p - copy_start) - 1);
dest->push_back(kEscape2);
dest->push_back(kFFCharacter);
Expand Down Expand Up @@ -303,7 +303,7 @@ inline static bool ReadStringInternal(absl::string_view* src,
// If inversion is required, instead of inverting 'c', we invert the
// character constants to which 'c' is compared. We get the same
// behavior but save the runtime cost of inverting 'c'.
FIREBASE_ASSERT(IsSpecialByte(c));
FIREBASE_DEV_ASSERT(IsSpecialByte(c));
if (c == kEscape1) {
if (result) {
AppendBytes(result, copy_start,
Expand All @@ -324,7 +324,7 @@ inline static bool ReadStringInternal(absl::string_view* src,
}
copy_start = start;
} else {
FIREBASE_ASSERT(c == kEscape2);
FIREBASE_DEV_ASSERT(c == kEscape2);
if (result) {
AppendBytes(result, copy_start,
static_cast<size_t>(start - copy_start) - 1);
Expand Down Expand Up @@ -360,7 +360,7 @@ bool OrderedCode::ReadNumIncreasing(absl::string_view* src, uint64_t* result) {
// If len > 0 and src is longer than 1, the first byte of "payload"
// must be non-zero (otherwise the encoding is not minimal).
// In opt mode, we don't enforce that encodings must be minimal.
FIREBASE_ASSERT(0 == len || src->size() == 1 || (*src)[1] != '\0');
FIREBASE_DEV_ASSERT(0 == len || src->size() == 1 || (*src)[1] != '\0');

if (len + 1 > src->size() || len > 8) {
return false; // Not enough bytes or too many bytes
Expand Down Expand Up @@ -558,11 +558,11 @@ void OrderedCode::WriteSignedNumIncreasing(std::string* dest, int64_t val) {
};
UNALIGNED_STORE64(buf + 2, absl::ghtonll(static_cast<uint64_t>(val)));

FIREBASE_ASSERT_MESSAGE_WITH_EXPRESSION(sizeof(buf) == kMaxSigned64Length,
sizeof(buf) == kMaxSigned64Length,
"max length size mismatch");
FIREBASE_DEV_ASSERT_MESSAGE_WITH_EXPRESSION(sizeof(buf) == kMaxSigned64Length,
sizeof(buf) == kMaxSigned64Length,
"max length size mismatch");
const size_t len = static_cast<size_t>(SignedEncodingLengthPositive(x));
FIREBASE_ASSERT(len >= 2);
FIREBASE_DEV_ASSERT(len >= 2);
char* const begin = buf + sizeof(buf) - len;
begin[0] ^= kLengthToHeaderBits[len][0];
begin[1] ^= kLengthToHeaderBits[len][1]; // ok because len >= 2
Expand Down Expand Up @@ -609,8 +609,8 @@ bool OrderedCode::ReadSignedNumIncreasing(absl::string_view* src,

x ^= kLengthToMask[len]; // remove spurious header bits

FIREBASE_ASSERT(len == static_cast<size_t>(
SignedEncodingLength(static_cast<int64_t>(x))));
FIREBASE_DEV_ASSERT(len == static_cast<size_t>(SignedEncodingLength(
static_cast<int64_t>(x))));

if (result) *result = static_cast<int64_t>(x);
src->remove_prefix(static_cast<size_t>(len));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ TEST(ArraySortedMap, ChecksSize) {
map = map.insert(5, 10);

int next = kFixedSize;
ASSERT_DEATH_IF_SUPPORTED(map.insert(next, next), "new_size <= fixed_size");
ASSERT_ANY_THROW(map.insert(next, next));
}

TEST(ArraySortedMap, Empty) {
Expand Down