Bug 807607 - Make MFBT tests use MOZ_RELEASE_ASSERT instead of MOZ_ASSERT to ensure test coverage in non-DEBUG - r=Waldo

find mfbt/tests/ -type f | xargs sed -i 's/MOZ_ASSERT/MOZ_RELEASE_ASSERT/g'
This commit is contained in:
Benoit Jacob 2014-04-24 17:06:50 -04:00
Родитель 311814b5b8
Коммит 7c2d5b3529
14 изменённых файлов: 852 добавлений и 858 удалений

Просмотреть файл

@ -4,12 +4,10 @@
#include "mozilla/Assertions.h"
#include "mozilla/Atomics.h"
#include "mozilla/DebugOnly.h"
#include <stdint.h>
using mozilla::Atomic;
using mozilla::DebugOnly;
using mozilla::MemoryOrdering;
using mozilla::Relaxed;
using mozilla::ReleaseAcquire;
@ -20,64 +18,64 @@ static void
TestTypeWithOrdering()
{
Atomic<T, Order> atomic(5);
MOZ_ASSERT(atomic == 5, "Atomic variable did not initialize");
MOZ_RELEASE_ASSERT(atomic == 5, "Atomic variable did not initialize");
// Test atomic increment
MOZ_ASSERT(++atomic == T(6), "Atomic increment did not work");
MOZ_ASSERT(atomic++ == T(6), "Atomic post-increment did not work");
MOZ_ASSERT(atomic == T(7), "Atomic post-increment did not work");
MOZ_RELEASE_ASSERT(++atomic == T(6), "Atomic increment did not work");
MOZ_RELEASE_ASSERT(atomic++ == T(6), "Atomic post-increment did not work");
MOZ_RELEASE_ASSERT(atomic == T(7), "Atomic post-increment did not work");
// Test atomic decrement
MOZ_ASSERT(--atomic == 6, "Atomic decrement did not work");
MOZ_ASSERT(atomic-- == 6, "Atomic post-decrement did not work");
MOZ_ASSERT(atomic == 5, "Atomic post-decrement did not work");
MOZ_RELEASE_ASSERT(--atomic == 6, "Atomic decrement did not work");
MOZ_RELEASE_ASSERT(atomic-- == 6, "Atomic post-decrement did not work");
MOZ_RELEASE_ASSERT(atomic == 5, "Atomic post-decrement did not work");
// Test other arithmetic.
DebugOnly<T> result;
T result;
result = (atomic += T(5));
MOZ_ASSERT(atomic == T(10), "Atomic += did not work");
MOZ_ASSERT(result == T(10), "Atomic += returned the wrong value");
MOZ_RELEASE_ASSERT(atomic == T(10), "Atomic += did not work");
MOZ_RELEASE_ASSERT(result == T(10), "Atomic += returned the wrong value");
result = (atomic -= T(3));
MOZ_ASSERT(atomic == T(7), "Atomic -= did not work");
MOZ_ASSERT(result == T(7), "Atomic -= returned the wrong value");
MOZ_RELEASE_ASSERT(atomic == T(7), "Atomic -= did not work");
MOZ_RELEASE_ASSERT(result == T(7), "Atomic -= returned the wrong value");
// Test assignment
result = (atomic = T(5));
MOZ_ASSERT(atomic == T(5), "Atomic assignment failed");
MOZ_ASSERT(result == T(5), "Atomic assignment returned the wrong value");
MOZ_RELEASE_ASSERT(atomic == T(5), "Atomic assignment failed");
MOZ_RELEASE_ASSERT(result == T(5), "Atomic assignment returned the wrong value");
// Test logical operations.
result = (atomic ^= T(2));
MOZ_ASSERT(atomic == T(7), "Atomic ^= did not work");
MOZ_ASSERT(result == T(7), "Atomic ^= returned the wrong value");
MOZ_RELEASE_ASSERT(atomic == T(7), "Atomic ^= did not work");
MOZ_RELEASE_ASSERT(result == T(7), "Atomic ^= returned the wrong value");
result = (atomic ^= T(4));
MOZ_ASSERT(atomic == T(3), "Atomic ^= did not work");
MOZ_ASSERT(result == T(3), "Atomic ^= returned the wrong value");
MOZ_RELEASE_ASSERT(atomic == T(3), "Atomic ^= did not work");
MOZ_RELEASE_ASSERT(result == T(3), "Atomic ^= returned the wrong value");
result = (atomic |= T(8));
MOZ_ASSERT(atomic == T(11), "Atomic |= did not work");
MOZ_ASSERT(result == T(11), "Atomic |= returned the wrong value");
MOZ_RELEASE_ASSERT(atomic == T(11), "Atomic |= did not work");
MOZ_RELEASE_ASSERT(result == T(11), "Atomic |= returned the wrong value");
result = (atomic |= T(8));
MOZ_ASSERT(atomic == T(11), "Atomic |= did not work");
MOZ_ASSERT(result == T(11), "Atomic |= returned the wrong value");
MOZ_RELEASE_ASSERT(atomic == T(11), "Atomic |= did not work");
MOZ_RELEASE_ASSERT(result == T(11), "Atomic |= returned the wrong value");
result = (atomic &= T(12));
MOZ_ASSERT(atomic == T(8), "Atomic &= did not work");
MOZ_ASSERT(result == T(8), "Atomic &= returned the wrong value");
MOZ_RELEASE_ASSERT(atomic == T(8), "Atomic &= did not work");
MOZ_RELEASE_ASSERT(result == T(8), "Atomic &= returned the wrong value");
// Test exchange.
atomic = T(30);
result = atomic.exchange(42);
MOZ_ASSERT(atomic == T(42), "Atomic exchange did not work");
MOZ_ASSERT(result == T(30), "Atomic exchange returned the wrong value");
MOZ_RELEASE_ASSERT(atomic == T(42), "Atomic exchange did not work");
MOZ_RELEASE_ASSERT(result == T(30), "Atomic exchange returned the wrong value");
// Test CAS.
atomic = T(1);
DebugOnly<bool> boolResult = atomic.compareExchange(0, 2);
MOZ_ASSERT(!boolResult, "CAS should have returned false.");
MOZ_ASSERT(atomic == T(1), "CAS shouldn't have done anything.");
bool boolResult = atomic.compareExchange(0, 2);
MOZ_RELEASE_ASSERT(!boolResult, "CAS should have returned false.");
MOZ_RELEASE_ASSERT(atomic == T(1), "CAS shouldn't have done anything.");
boolResult = atomic.compareExchange(1, 42);
MOZ_ASSERT(boolResult, "CAS should have succeeded.");
MOZ_ASSERT(atomic == T(42), "CAS should have changed atomic's value.");
MOZ_RELEASE_ASSERT(boolResult, "CAS should have succeeded.");
MOZ_RELEASE_ASSERT(atomic == T(42), "CAS should have changed atomic's value.");
}
template<typename T, MemoryOrdering Order>
@ -86,46 +84,46 @@ TestPointerWithOrdering()
{
T array1[10];
Atomic<T*, Order> atomic(array1);
MOZ_ASSERT(atomic == array1, "Atomic variable did not initialize");
MOZ_RELEASE_ASSERT(atomic == array1, "Atomic variable did not initialize");
// Test atomic increment
MOZ_ASSERT(++atomic == array1 + 1, "Atomic increment did not work");
MOZ_ASSERT(atomic++ == array1 + 1, "Atomic post-increment did not work");
MOZ_ASSERT(atomic == array1 + 2, "Atomic post-increment did not work");
MOZ_RELEASE_ASSERT(++atomic == array1 + 1, "Atomic increment did not work");
MOZ_RELEASE_ASSERT(atomic++ == array1 + 1, "Atomic post-increment did not work");
MOZ_RELEASE_ASSERT(atomic == array1 + 2, "Atomic post-increment did not work");
// Test atomic decrement
MOZ_ASSERT(--atomic == array1 + 1, "Atomic decrement did not work");
MOZ_ASSERT(atomic-- == array1 + 1, "Atomic post-decrement did not work");
MOZ_ASSERT(atomic == array1, "Atomic post-decrement did not work");
MOZ_RELEASE_ASSERT(--atomic == array1 + 1, "Atomic decrement did not work");
MOZ_RELEASE_ASSERT(atomic-- == array1 + 1, "Atomic post-decrement did not work");
MOZ_RELEASE_ASSERT(atomic == array1, "Atomic post-decrement did not work");
// Test other arithmetic operations
DebugOnly<T*> result;
T* result;
result = (atomic += 2);
MOZ_ASSERT(atomic == array1 + 2, "Atomic += did not work");
MOZ_ASSERT(result == array1 + 2, "Atomic += returned the wrong value");
MOZ_RELEASE_ASSERT(atomic == array1 + 2, "Atomic += did not work");
MOZ_RELEASE_ASSERT(result == array1 + 2, "Atomic += returned the wrong value");
result = (atomic -= 1);
MOZ_ASSERT(atomic == array1 + 1, "Atomic -= did not work");
MOZ_ASSERT(result == array1 + 1, "Atomic -= returned the wrong value");
MOZ_RELEASE_ASSERT(atomic == array1 + 1, "Atomic -= did not work");
MOZ_RELEASE_ASSERT(result == array1 + 1, "Atomic -= returned the wrong value");
// Test stores
result = (atomic = array1);
MOZ_ASSERT(atomic == array1, "Atomic assignment did not work");
MOZ_ASSERT(result == array1, "Atomic assignment returned the wrong value");
MOZ_RELEASE_ASSERT(atomic == array1, "Atomic assignment did not work");
MOZ_RELEASE_ASSERT(result == array1, "Atomic assignment returned the wrong value");
// Test exchange
atomic = array1 + 2;
result = atomic.exchange(array1);
MOZ_ASSERT(atomic == array1, "Atomic exchange did not work");
MOZ_ASSERT(result == array1 + 2, "Atomic exchange returned the wrong value");
MOZ_RELEASE_ASSERT(atomic == array1, "Atomic exchange did not work");
MOZ_RELEASE_ASSERT(result == array1 + 2, "Atomic exchange returned the wrong value");
atomic = array1;
DebugOnly<bool> boolResult = atomic.compareExchange(array1 + 1, array1 + 2);
MOZ_ASSERT(!boolResult, "CAS should have returned false.");
MOZ_ASSERT(atomic == array1, "CAS shouldn't have done anything.");
bool boolResult = atomic.compareExchange(array1 + 1, array1 + 2);
MOZ_RELEASE_ASSERT(!boolResult, "CAS should have returned false.");
MOZ_RELEASE_ASSERT(atomic == array1, "CAS shouldn't have done anything.");
boolResult = atomic.compareExchange(array1, array1 + 3);
MOZ_ASSERT(boolResult, "CAS should have succeeded.");
MOZ_ASSERT(atomic == array1 + 3, "CAS should have changed atomic's value.");
MOZ_RELEASE_ASSERT(boolResult, "CAS should have succeeded.");
MOZ_RELEASE_ASSERT(atomic == array1 + 3, "CAS should have changed atomic's value.");
}
enum EnumType {
@ -140,29 +138,29 @@ static void
TestEnumWithOrdering()
{
Atomic<EnumType, Order> atomic(EnumType_2);
MOZ_ASSERT(atomic == EnumType_2, "Atomic variable did not initialize");
MOZ_RELEASE_ASSERT(atomic == EnumType_2, "Atomic variable did not initialize");
// Test assignment
DebugOnly<EnumType> result;
EnumType result;
result = (atomic = EnumType_3);
MOZ_ASSERT(atomic == EnumType_3, "Atomic assignment failed");
MOZ_ASSERT(result == EnumType_3, "Atomic assignment returned the wrong value");
MOZ_RELEASE_ASSERT(atomic == EnumType_3, "Atomic assignment failed");
MOZ_RELEASE_ASSERT(result == EnumType_3, "Atomic assignment returned the wrong value");
// Test exchange.
atomic = EnumType_1;
result = atomic.exchange(EnumType_2);
MOZ_ASSERT(atomic == EnumType_2, "Atomic exchange did not work");
MOZ_ASSERT(result == EnumType_1, "Atomic exchange returned the wrong value");
MOZ_RELEASE_ASSERT(atomic == EnumType_2, "Atomic exchange did not work");
MOZ_RELEASE_ASSERT(result == EnumType_1, "Atomic exchange returned the wrong value");
// Test CAS.
atomic = EnumType_1;
DebugOnly<bool> boolResult = atomic.compareExchange(EnumType_0, EnumType_2);
MOZ_ASSERT(!boolResult, "CAS should have returned false.");
MOZ_ASSERT(atomic == EnumType_1, "CAS shouldn't have done anything.");
bool boolResult = atomic.compareExchange(EnumType_0, EnumType_2);
MOZ_RELEASE_ASSERT(!boolResult, "CAS should have returned false.");
MOZ_RELEASE_ASSERT(atomic == EnumType_1, "CAS shouldn't have done anything.");
boolResult = atomic.compareExchange(EnumType_1, EnumType_3);
MOZ_ASSERT(boolResult, "CAS should have succeeded.");
MOZ_ASSERT(atomic == EnumType_3, "CAS should have changed atomic's value.");
MOZ_RELEASE_ASSERT(boolResult, "CAS should have succeeded.");
MOZ_RELEASE_ASSERT(atomic == EnumType_3, "CAS should have changed atomic's value.");
}
template <MemoryOrdering Order>
@ -170,29 +168,29 @@ static void
TestBoolWithOrdering()
{
Atomic<bool, Order> atomic(false);
MOZ_ASSERT(atomic == false, "Atomic variable did not initialize");
MOZ_RELEASE_ASSERT(atomic == false, "Atomic variable did not initialize");
// Test assignment
DebugOnly<bool> result;
bool result;
result = (atomic = true);
MOZ_ASSERT(atomic == true, "Atomic assignment failed");
MOZ_ASSERT(result == true, "Atomic assignment returned the wrong value");
MOZ_RELEASE_ASSERT(atomic == true, "Atomic assignment failed");
MOZ_RELEASE_ASSERT(result == true, "Atomic assignment returned the wrong value");
// Test exchange.
atomic = false;
result = atomic.exchange(true);
MOZ_ASSERT(atomic == true, "Atomic exchange did not work");
MOZ_ASSERT(result == false, "Atomic exchange returned the wrong value");
MOZ_RELEASE_ASSERT(atomic == true, "Atomic exchange did not work");
MOZ_RELEASE_ASSERT(result == false, "Atomic exchange returned the wrong value");
// Test CAS.
atomic = false;
DebugOnly<bool> boolResult = atomic.compareExchange(true, false);
MOZ_ASSERT(!boolResult, "CAS should have returned false.");
MOZ_ASSERT(atomic == false, "CAS shouldn't have done anything.");
bool boolResult = atomic.compareExchange(true, false);
MOZ_RELEASE_ASSERT(!boolResult, "CAS should have returned false.");
MOZ_RELEASE_ASSERT(atomic == false, "CAS shouldn't have done anything.");
boolResult = atomic.compareExchange(false, true);
MOZ_ASSERT(boolResult, "CAS should have succeeded.");
MOZ_ASSERT(atomic == true, "CAS should have changed atomic's value.");
MOZ_RELEASE_ASSERT(boolResult, "CAS should have succeeded.");
MOZ_RELEASE_ASSERT(atomic == true, "CAS should have changed atomic's value.");
}
template <typename T>

Просмотреть файл

@ -26,7 +26,7 @@ int
main()
{
BloomFilter<12, FilterChecker> *filter = new BloomFilter<12, FilterChecker>();
MOZ_ASSERT(filter);
MOZ_RELEASE_ASSERT(filter);
FilterChecker one(1);
FilterChecker two(0x20000);
@ -34,22 +34,22 @@ main()
FilterChecker multiple(0x20001);
filter->add(&one);
MOZ_ASSERT(filter->mightContain(&one),
MOZ_RELEASE_ASSERT(filter->mightContain(&one),
"Filter should contain 'one'");
MOZ_ASSERT(!filter->mightContain(&multiple),
MOZ_RELEASE_ASSERT(!filter->mightContain(&multiple),
"Filter claims to contain 'multiple' when it should not");
MOZ_ASSERT(filter->mightContain(&many),
MOZ_RELEASE_ASSERT(filter->mightContain(&many),
"Filter should contain 'many' (false positive)");
filter->add(&two);
MOZ_ASSERT(filter->mightContain(&multiple),
MOZ_RELEASE_ASSERT(filter->mightContain(&multiple),
"Filter should contain 'multiple' (false positive)");
// Test basic removals
filter->remove(&two);
MOZ_ASSERT(!filter->mightContain(&multiple),
MOZ_RELEASE_ASSERT(!filter->mightContain(&multiple),
"Filter claims to contain 'multiple' when it should not after two "
"was removed");
@ -58,14 +58,14 @@ main()
for (size_t i = 0; i < FILTER_SIZE - 1; ++i)
filter->add(&two);
MOZ_ASSERT(filter->mightContain(&multiple),
MOZ_RELEASE_ASSERT(filter->mightContain(&multiple),
"Filter should contain 'multiple' after 'two' added lots of times "
"(false positive)");
for (size_t i = 0; i < FILTER_SIZE - 1; ++i)
filter->remove(&two);
MOZ_ASSERT(!filter->mightContain(&multiple),
MOZ_RELEASE_ASSERT(!filter->mightContain(&multiple),
"Filter claims to contain 'multiple' when it should not after two "
"was removed lots of times");
@ -73,29 +73,29 @@ main()
for (size_t i = 0; i < FILTER_SIZE + 1; ++i)
filter->add(&two);
MOZ_ASSERT(filter->mightContain(&multiple),
MOZ_RELEASE_ASSERT(filter->mightContain(&multiple),
"Filter should contain 'multiple' after 'two' added lots more "
"times (false positive)");
for (size_t i = 0; i < FILTER_SIZE + 1; ++i)
filter->remove(&two);
MOZ_ASSERT(filter->mightContain(&multiple),
MOZ_RELEASE_ASSERT(filter->mightContain(&multiple),
"Filter claims to not contain 'multiple' even though we should "
"have run out of space in the buckets (false positive)");
MOZ_ASSERT(filter->mightContain(&two),
MOZ_RELEASE_ASSERT(filter->mightContain(&two),
"Filter claims to not contain 'two' even though we should have "
"run out of space in the buckets (false positive)");
filter->remove(&one);
MOZ_ASSERT(!filter->mightContain(&one),
MOZ_RELEASE_ASSERT(!filter->mightContain(&one),
"Filter should not contain 'one', because we didn't overflow its "
"bucket");
filter->clear();
MOZ_ASSERT(!filter->mightContain(&multiple),
MOZ_RELEASE_ASSERT(!filter->mightContain(&multiple),
"clear() failed to work");
return 0;

Просмотреть файл

@ -17,7 +17,7 @@ template<typename Uint, typename Ulong>
struct UintUlongBitwiseCast<Uint, Ulong, true>
{
static void test() {
MOZ_ASSERT(BitwiseCast<Ulong>(Uint(8675309)) == Ulong(8675309));
MOZ_RELEASE_ASSERT(BitwiseCast<Ulong>(Uint(8675309)) == Ulong(8675309));
}
};
@ -30,71 +30,71 @@ struct UintUlongBitwiseCast<Uint, Ulong, false>
static void
TestBitwiseCast()
{
MOZ_ASSERT(BitwiseCast<int>(int(8675309)) == int(8675309));
MOZ_RELEASE_ASSERT(BitwiseCast<int>(int(8675309)) == int(8675309));
UintUlongBitwiseCast<unsigned int, unsigned long>::test();
}
static void
TestSameSize()
{
MOZ_ASSERT((IsInBounds<int16_t, int16_t>(int16_t(0))));
MOZ_ASSERT((IsInBounds<int16_t, int16_t>(int16_t(INT16_MIN))));
MOZ_ASSERT((IsInBounds<int16_t, int16_t>(int16_t(INT16_MAX))));
MOZ_ASSERT((IsInBounds<uint16_t, uint16_t>(uint16_t(UINT16_MAX))));
MOZ_ASSERT((IsInBounds<uint16_t, int16_t>(uint16_t(0))));
MOZ_ASSERT((!IsInBounds<uint16_t, int16_t>(uint16_t(-1))));
MOZ_ASSERT((!IsInBounds<int16_t, uint16_t>(int16_t(-1))));
MOZ_ASSERT((IsInBounds<int16_t, uint16_t>(int16_t(INT16_MAX))));
MOZ_ASSERT((!IsInBounds<int16_t, uint16_t>(int16_t(INT16_MIN))));
MOZ_ASSERT((IsInBounds<int32_t, uint32_t>(int32_t(INT32_MAX))));
MOZ_ASSERT((!IsInBounds<int32_t, uint32_t>(int32_t(INT32_MIN))));
MOZ_RELEASE_ASSERT((IsInBounds<int16_t, int16_t>(int16_t(0))));
MOZ_RELEASE_ASSERT((IsInBounds<int16_t, int16_t>(int16_t(INT16_MIN))));
MOZ_RELEASE_ASSERT((IsInBounds<int16_t, int16_t>(int16_t(INT16_MAX))));
MOZ_RELEASE_ASSERT((IsInBounds<uint16_t, uint16_t>(uint16_t(UINT16_MAX))));
MOZ_RELEASE_ASSERT((IsInBounds<uint16_t, int16_t>(uint16_t(0))));
MOZ_RELEASE_ASSERT((!IsInBounds<uint16_t, int16_t>(uint16_t(-1))));
MOZ_RELEASE_ASSERT((!IsInBounds<int16_t, uint16_t>(int16_t(-1))));
MOZ_RELEASE_ASSERT((IsInBounds<int16_t, uint16_t>(int16_t(INT16_MAX))));
MOZ_RELEASE_ASSERT((!IsInBounds<int16_t, uint16_t>(int16_t(INT16_MIN))));
MOZ_RELEASE_ASSERT((IsInBounds<int32_t, uint32_t>(int32_t(INT32_MAX))));
MOZ_RELEASE_ASSERT((!IsInBounds<int32_t, uint32_t>(int32_t(INT32_MIN))));
}
static void
TestToBiggerSize()
{
MOZ_ASSERT((IsInBounds<int16_t, int32_t>(int16_t(0))));
MOZ_ASSERT((IsInBounds<int16_t, int32_t>(int16_t(INT16_MIN))));
MOZ_ASSERT((IsInBounds<int16_t, int32_t>(int16_t(INT16_MAX))));
MOZ_ASSERT((IsInBounds<uint16_t, uint32_t>(uint16_t(UINT16_MAX))));
MOZ_ASSERT((IsInBounds<uint16_t, int32_t>(uint16_t(0))));
MOZ_ASSERT((IsInBounds<uint16_t, int32_t>(uint16_t(-1))));
MOZ_ASSERT((!IsInBounds<int16_t, uint32_t>(int16_t(-1))));
MOZ_ASSERT((IsInBounds<int16_t, uint32_t>(int16_t(INT16_MAX))));
MOZ_ASSERT((!IsInBounds<int16_t, uint32_t>(int16_t(INT16_MIN))));
MOZ_ASSERT((IsInBounds<int32_t, uint64_t>(int32_t(INT32_MAX))));
MOZ_ASSERT((!IsInBounds<int32_t, uint64_t>(int32_t(INT32_MIN))));
MOZ_RELEASE_ASSERT((IsInBounds<int16_t, int32_t>(int16_t(0))));
MOZ_RELEASE_ASSERT((IsInBounds<int16_t, int32_t>(int16_t(INT16_MIN))));
MOZ_RELEASE_ASSERT((IsInBounds<int16_t, int32_t>(int16_t(INT16_MAX))));
MOZ_RELEASE_ASSERT((IsInBounds<uint16_t, uint32_t>(uint16_t(UINT16_MAX))));
MOZ_RELEASE_ASSERT((IsInBounds<uint16_t, int32_t>(uint16_t(0))));
MOZ_RELEASE_ASSERT((IsInBounds<uint16_t, int32_t>(uint16_t(-1))));
MOZ_RELEASE_ASSERT((!IsInBounds<int16_t, uint32_t>(int16_t(-1))));
MOZ_RELEASE_ASSERT((IsInBounds<int16_t, uint32_t>(int16_t(INT16_MAX))));
MOZ_RELEASE_ASSERT((!IsInBounds<int16_t, uint32_t>(int16_t(INT16_MIN))));
MOZ_RELEASE_ASSERT((IsInBounds<int32_t, uint64_t>(int32_t(INT32_MAX))));
MOZ_RELEASE_ASSERT((!IsInBounds<int32_t, uint64_t>(int32_t(INT32_MIN))));
}
static void
TestToSmallerSize()
{
MOZ_ASSERT((IsInBounds<int16_t, int8_t>(int16_t(0))));
MOZ_ASSERT((!IsInBounds<int16_t, int8_t>(int16_t(INT16_MIN))));
MOZ_ASSERT((!IsInBounds<int16_t, int8_t>(int16_t(INT16_MAX))));
MOZ_ASSERT((!IsInBounds<uint16_t, uint8_t>(uint16_t(UINT16_MAX))));
MOZ_ASSERT((IsInBounds<uint16_t, int8_t>(uint16_t(0))));
MOZ_ASSERT((!IsInBounds<uint16_t, int8_t>(uint16_t(-1))));
MOZ_ASSERT((!IsInBounds<int16_t, uint8_t>(int16_t(-1))));
MOZ_ASSERT((!IsInBounds<int16_t, uint8_t>(int16_t(INT16_MAX))));
MOZ_ASSERT((!IsInBounds<int16_t, uint8_t>(int16_t(INT16_MIN))));
MOZ_ASSERT((!IsInBounds<int32_t, uint16_t>(int32_t(INT32_MAX))));
MOZ_ASSERT((!IsInBounds<int32_t, uint16_t>(int32_t(INT32_MIN))));
MOZ_RELEASE_ASSERT((IsInBounds<int16_t, int8_t>(int16_t(0))));
MOZ_RELEASE_ASSERT((!IsInBounds<int16_t, int8_t>(int16_t(INT16_MIN))));
MOZ_RELEASE_ASSERT((!IsInBounds<int16_t, int8_t>(int16_t(INT16_MAX))));
MOZ_RELEASE_ASSERT((!IsInBounds<uint16_t, uint8_t>(uint16_t(UINT16_MAX))));
MOZ_RELEASE_ASSERT((IsInBounds<uint16_t, int8_t>(uint16_t(0))));
MOZ_RELEASE_ASSERT((!IsInBounds<uint16_t, int8_t>(uint16_t(-1))));
MOZ_RELEASE_ASSERT((!IsInBounds<int16_t, uint8_t>(int16_t(-1))));
MOZ_RELEASE_ASSERT((!IsInBounds<int16_t, uint8_t>(int16_t(INT16_MAX))));
MOZ_RELEASE_ASSERT((!IsInBounds<int16_t, uint8_t>(int16_t(INT16_MIN))));
MOZ_RELEASE_ASSERT((!IsInBounds<int32_t, uint16_t>(int32_t(INT32_MAX))));
MOZ_RELEASE_ASSERT((!IsInBounds<int32_t, uint16_t>(int32_t(INT32_MIN))));
// Boundary cases
MOZ_ASSERT((!IsInBounds<int64_t, int32_t>(int64_t(INT32_MIN) - 1)));
MOZ_ASSERT((IsInBounds<int64_t, int32_t>(int64_t(INT32_MIN))));
MOZ_ASSERT((IsInBounds<int64_t, int32_t>(int64_t(INT32_MIN) + 1)));
MOZ_ASSERT((IsInBounds<int64_t, int32_t>(int64_t(INT32_MAX) - 1)));
MOZ_ASSERT((IsInBounds<int64_t, int32_t>(int64_t(INT32_MAX))));
MOZ_ASSERT((!IsInBounds<int64_t, int32_t>(int64_t(INT32_MAX) + 1)));
MOZ_RELEASE_ASSERT((!IsInBounds<int64_t, int32_t>(int64_t(INT32_MIN) - 1)));
MOZ_RELEASE_ASSERT((IsInBounds<int64_t, int32_t>(int64_t(INT32_MIN))));
MOZ_RELEASE_ASSERT((IsInBounds<int64_t, int32_t>(int64_t(INT32_MIN) + 1)));
MOZ_RELEASE_ASSERT((IsInBounds<int64_t, int32_t>(int64_t(INT32_MAX) - 1)));
MOZ_RELEASE_ASSERT((IsInBounds<int64_t, int32_t>(int64_t(INT32_MAX))));
MOZ_RELEASE_ASSERT((!IsInBounds<int64_t, int32_t>(int64_t(INT32_MAX) + 1)));
MOZ_ASSERT((!IsInBounds<int64_t, uint32_t>(int64_t(-1))));
MOZ_ASSERT((IsInBounds<int64_t, uint32_t>(int64_t(0))));
MOZ_ASSERT((IsInBounds<int64_t, uint32_t>(int64_t(1))));
MOZ_ASSERT((IsInBounds<int64_t, uint32_t>(int64_t(UINT32_MAX) - 1)));
MOZ_ASSERT((IsInBounds<int64_t, uint32_t>(int64_t(UINT32_MAX))));
MOZ_ASSERT((!IsInBounds<int64_t, uint32_t>(int64_t(UINT32_MAX) + 1)));
MOZ_RELEASE_ASSERT((!IsInBounds<int64_t, uint32_t>(int64_t(-1))));
MOZ_RELEASE_ASSERT((IsInBounds<int64_t, uint32_t>(int64_t(0))));
MOZ_RELEASE_ASSERT((IsInBounds<int64_t, uint32_t>(int64_t(1))));
MOZ_RELEASE_ASSERT((IsInBounds<int64_t, uint32_t>(int64_t(UINT32_MAX) - 1)));
MOZ_RELEASE_ASSERT((IsInBounds<int64_t, uint32_t>(int64_t(UINT32_MAX))));
MOZ_RELEASE_ASSERT((!IsInBounds<int64_t, uint32_t>(int64_t(UINT32_MAX) + 1)));
}
int

Просмотреть файл

@ -3,11 +3,9 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/DebugOnly.h"
#include "mozilla/MathAlgorithms.h"
using mozilla::CeilingLog2;
using mozilla::DebugOnly;
using mozilla::FloorLog2;
using mozilla::RoundUpPow2;
@ -15,65 +13,65 @@ static void
TestCeiling()
{
for (uint32_t i = 0; i <= 1; i++)
MOZ_ASSERT(CeilingLog2(i) == 0);
MOZ_RELEASE_ASSERT(CeilingLog2(i) == 0);
for (uint32_t i = 2; i <= 2; i++)
MOZ_ASSERT(CeilingLog2(i) == 1);
MOZ_RELEASE_ASSERT(CeilingLog2(i) == 1);
for (uint32_t i = 3; i <= 4; i++)
MOZ_ASSERT(CeilingLog2(i) == 2);
MOZ_RELEASE_ASSERT(CeilingLog2(i) == 2);
for (uint32_t i = 5; i <= 8; i++)
MOZ_ASSERT(CeilingLog2(i) == 3);
MOZ_RELEASE_ASSERT(CeilingLog2(i) == 3);
for (uint32_t i = 9; i <= 16; i++)
MOZ_ASSERT(CeilingLog2(i) == 4);
MOZ_RELEASE_ASSERT(CeilingLog2(i) == 4);
}
static void
TestFloor()
{
for (uint32_t i = 0; i <= 1; i++)
MOZ_ASSERT(FloorLog2(i) == 0);
MOZ_RELEASE_ASSERT(FloorLog2(i) == 0);
for (uint32_t i = 2; i <= 3; i++)
MOZ_ASSERT(FloorLog2(i) == 1);
MOZ_RELEASE_ASSERT(FloorLog2(i) == 1);
for (uint32_t i = 4; i <= 7; i++)
MOZ_ASSERT(FloorLog2(i) == 2);
MOZ_RELEASE_ASSERT(FloorLog2(i) == 2);
for (uint32_t i = 8; i <= 15; i++)
MOZ_ASSERT(FloorLog2(i) == 3);
MOZ_RELEASE_ASSERT(FloorLog2(i) == 3);
for (uint32_t i = 16; i <= 31; i++)
MOZ_ASSERT(FloorLog2(i) == 4);
MOZ_RELEASE_ASSERT(FloorLog2(i) == 4);
}
static void
TestRoundUpPow2()
{
MOZ_ASSERT(RoundUpPow2(0) == 1);
MOZ_ASSERT(RoundUpPow2(1) == 1);
MOZ_ASSERT(RoundUpPow2(2) == 2);
MOZ_ASSERT(RoundUpPow2(3) == 4);
MOZ_ASSERT(RoundUpPow2(4) == 4);
MOZ_ASSERT(RoundUpPow2(5) == 8);
MOZ_ASSERT(RoundUpPow2(6) == 8);
MOZ_ASSERT(RoundUpPow2(7) == 8);
MOZ_ASSERT(RoundUpPow2(8) == 8);
MOZ_ASSERT(RoundUpPow2(9) == 16);
MOZ_RELEASE_ASSERT(RoundUpPow2(0) == 1);
MOZ_RELEASE_ASSERT(RoundUpPow2(1) == 1);
MOZ_RELEASE_ASSERT(RoundUpPow2(2) == 2);
MOZ_RELEASE_ASSERT(RoundUpPow2(3) == 4);
MOZ_RELEASE_ASSERT(RoundUpPow2(4) == 4);
MOZ_RELEASE_ASSERT(RoundUpPow2(5) == 8);
MOZ_RELEASE_ASSERT(RoundUpPow2(6) == 8);
MOZ_RELEASE_ASSERT(RoundUpPow2(7) == 8);
MOZ_RELEASE_ASSERT(RoundUpPow2(8) == 8);
MOZ_RELEASE_ASSERT(RoundUpPow2(9) == 16);
MOZ_ASSERT(RoundUpPow2(15) == 16);
MOZ_ASSERT(RoundUpPow2(16) == 16);
MOZ_ASSERT(RoundUpPow2(17) == 32);
MOZ_RELEASE_ASSERT(RoundUpPow2(15) == 16);
MOZ_RELEASE_ASSERT(RoundUpPow2(16) == 16);
MOZ_RELEASE_ASSERT(RoundUpPow2(17) == 32);
MOZ_ASSERT(RoundUpPow2(31) == 32);
MOZ_ASSERT(RoundUpPow2(32) == 32);
MOZ_ASSERT(RoundUpPow2(33) == 64);
MOZ_RELEASE_ASSERT(RoundUpPow2(31) == 32);
MOZ_RELEASE_ASSERT(RoundUpPow2(32) == 32);
MOZ_RELEASE_ASSERT(RoundUpPow2(33) == 64);
DebugOnly<size_t> MaxPow2 = size_t(1) << (sizeof(size_t) * CHAR_BIT - 1);
MOZ_ASSERT(RoundUpPow2(MaxPow2 - 1) == MaxPow2);
MOZ_ASSERT(RoundUpPow2(MaxPow2) == MaxPow2);
size_t MaxPow2 = size_t(1) << (sizeof(size_t) * CHAR_BIT - 1);
MOZ_RELEASE_ASSERT(RoundUpPow2(MaxPow2 - 1) == MaxPow2);
MOZ_RELEASE_ASSERT(RoundUpPow2(MaxPow2) == MaxPow2);
// not valid to round up when past the max power of two
}

Просмотреть файл

@ -10,19 +10,19 @@ using mozilla::CountPopulation32;
static void
TestCountPopulation32()
{
MOZ_ASSERT(CountPopulation32(0xFFFFFFFF) == 32);
MOZ_ASSERT(CountPopulation32(0xF0FF1000) == 13);
MOZ_ASSERT(CountPopulation32(0x7F8F0001) == 13);
MOZ_ASSERT(CountPopulation32(0x3FFF0100) == 15);
MOZ_ASSERT(CountPopulation32(0x1FF50010) == 12);
MOZ_ASSERT(CountPopulation32(0x00800000) == 1);
MOZ_ASSERT(CountPopulation32(0x00400000) == 1);
MOZ_ASSERT(CountPopulation32(0x00008000) == 1);
MOZ_ASSERT(CountPopulation32(0x00004000) == 1);
MOZ_ASSERT(CountPopulation32(0x00000080) == 1);
MOZ_ASSERT(CountPopulation32(0x00000040) == 1);
MOZ_ASSERT(CountPopulation32(0x00000001) == 1);
MOZ_ASSERT(CountPopulation32(0x00000000) == 0);
MOZ_RELEASE_ASSERT(CountPopulation32(0xFFFFFFFF) == 32);
MOZ_RELEASE_ASSERT(CountPopulation32(0xF0FF1000) == 13);
MOZ_RELEASE_ASSERT(CountPopulation32(0x7F8F0001) == 13);
MOZ_RELEASE_ASSERT(CountPopulation32(0x3FFF0100) == 15);
MOZ_RELEASE_ASSERT(CountPopulation32(0x1FF50010) == 12);
MOZ_RELEASE_ASSERT(CountPopulation32(0x00800000) == 1);
MOZ_RELEASE_ASSERT(CountPopulation32(0x00400000) == 1);
MOZ_RELEASE_ASSERT(CountPopulation32(0x00008000) == 1);
MOZ_RELEASE_ASSERT(CountPopulation32(0x00004000) == 1);
MOZ_RELEASE_ASSERT(CountPopulation32(0x00000080) == 1);
MOZ_RELEASE_ASSERT(CountPopulation32(0x00000040) == 1);
MOZ_RELEASE_ASSERT(CountPopulation32(0x00000001) == 1);
MOZ_RELEASE_ASSERT(CountPopulation32(0x00000000) == 0);
}
int main()

Просмотреть файл

@ -13,81 +13,81 @@ using mozilla::CountTrailingZeroes64;
static void
TestLeadingZeroes32()
{
MOZ_ASSERT(CountLeadingZeroes32(0xF0FF1000) == 0);
MOZ_ASSERT(CountLeadingZeroes32(0x7F8F0001) == 1);
MOZ_ASSERT(CountLeadingZeroes32(0x3FFF0100) == 2);
MOZ_ASSERT(CountLeadingZeroes32(0x1FF50010) == 3);
MOZ_ASSERT(CountLeadingZeroes32(0x00800000) == 8);
MOZ_ASSERT(CountLeadingZeroes32(0x00400000) == 9);
MOZ_ASSERT(CountLeadingZeroes32(0x00008000) == 16);
MOZ_ASSERT(CountLeadingZeroes32(0x00004000) == 17);
MOZ_ASSERT(CountLeadingZeroes32(0x00000080) == 24);
MOZ_ASSERT(CountLeadingZeroes32(0x00000040) == 25);
MOZ_ASSERT(CountLeadingZeroes32(0x00000001) == 31);
MOZ_RELEASE_ASSERT(CountLeadingZeroes32(0xF0FF1000) == 0);
MOZ_RELEASE_ASSERT(CountLeadingZeroes32(0x7F8F0001) == 1);
MOZ_RELEASE_ASSERT(CountLeadingZeroes32(0x3FFF0100) == 2);
MOZ_RELEASE_ASSERT(CountLeadingZeroes32(0x1FF50010) == 3);
MOZ_RELEASE_ASSERT(CountLeadingZeroes32(0x00800000) == 8);
MOZ_RELEASE_ASSERT(CountLeadingZeroes32(0x00400000) == 9);
MOZ_RELEASE_ASSERT(CountLeadingZeroes32(0x00008000) == 16);
MOZ_RELEASE_ASSERT(CountLeadingZeroes32(0x00004000) == 17);
MOZ_RELEASE_ASSERT(CountLeadingZeroes32(0x00000080) == 24);
MOZ_RELEASE_ASSERT(CountLeadingZeroes32(0x00000040) == 25);
MOZ_RELEASE_ASSERT(CountLeadingZeroes32(0x00000001) == 31);
}
static void
TestLeadingZeroes64()
{
MOZ_ASSERT(CountLeadingZeroes64(0xF000F0F010000000) == 0);
MOZ_ASSERT(CountLeadingZeroes64(0x70F080F000000001) == 1);
MOZ_ASSERT(CountLeadingZeroes64(0x30F0F0F000100000) == 2);
MOZ_ASSERT(CountLeadingZeroes64(0x10F0F05000000100) == 3);
MOZ_ASSERT(CountLeadingZeroes64(0x0080000000000001) == 8);
MOZ_ASSERT(CountLeadingZeroes64(0x0040000010001000) == 9);
MOZ_ASSERT(CountLeadingZeroes64(0x000080F010000000) == 16);
MOZ_ASSERT(CountLeadingZeroes64(0x000040F010000000) == 17);
MOZ_ASSERT(CountLeadingZeroes64(0x0000008000100100) == 24);
MOZ_ASSERT(CountLeadingZeroes64(0x0000004100010010) == 25);
MOZ_ASSERT(CountLeadingZeroes64(0x0000000080100100) == 32);
MOZ_ASSERT(CountLeadingZeroes64(0x0000000041001010) == 33);
MOZ_ASSERT(CountLeadingZeroes64(0x0000000000800100) == 40);
MOZ_ASSERT(CountLeadingZeroes64(0x0000000000411010) == 41);
MOZ_ASSERT(CountLeadingZeroes64(0x0000000000008001) == 48);
MOZ_ASSERT(CountLeadingZeroes64(0x0000000000004010) == 49);
MOZ_ASSERT(CountLeadingZeroes64(0x0000000000000081) == 56);
MOZ_ASSERT(CountLeadingZeroes64(0x0000000000000040) == 57);
MOZ_ASSERT(CountLeadingZeroes64(0x0000000000000001) == 63);
MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0xF000F0F010000000) == 0);
MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x70F080F000000001) == 1);
MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x30F0F0F000100000) == 2);
MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x10F0F05000000100) == 3);
MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0080000000000001) == 8);
MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0040000010001000) == 9);
MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x000080F010000000) == 16);
MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x000040F010000000) == 17);
MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0000008000100100) == 24);
MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0000004100010010) == 25);
MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0000000080100100) == 32);
MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0000000041001010) == 33);
MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0000000000800100) == 40);
MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0000000000411010) == 41);
MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0000000000008001) == 48);
MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0000000000004010) == 49);
MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0000000000000081) == 56);
MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0000000000000040) == 57);
MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0000000000000001) == 63);
}
static void
TestTrailingZeroes32()
{
MOZ_ASSERT(CountTrailingZeroes32(0x0100FFFF) == 0);
MOZ_ASSERT(CountTrailingZeroes32(0x7000FFFE) == 1);
MOZ_ASSERT(CountTrailingZeroes32(0x0080FFFC) == 2);
MOZ_ASSERT(CountTrailingZeroes32(0x0080FFF8) == 3);
MOZ_ASSERT(CountTrailingZeroes32(0x010FFF00) == 8);
MOZ_ASSERT(CountTrailingZeroes32(0x7000FE00) == 9);
MOZ_ASSERT(CountTrailingZeroes32(0x10CF0000) == 16);
MOZ_ASSERT(CountTrailingZeroes32(0x0BDE0000) == 17);
MOZ_ASSERT(CountTrailingZeroes32(0x0F000000) == 24);
MOZ_ASSERT(CountTrailingZeroes32(0xDE000000) == 25);
MOZ_ASSERT(CountTrailingZeroes32(0x80000000) == 31);
MOZ_RELEASE_ASSERT(CountTrailingZeroes32(0x0100FFFF) == 0);
MOZ_RELEASE_ASSERT(CountTrailingZeroes32(0x7000FFFE) == 1);
MOZ_RELEASE_ASSERT(CountTrailingZeroes32(0x0080FFFC) == 2);
MOZ_RELEASE_ASSERT(CountTrailingZeroes32(0x0080FFF8) == 3);
MOZ_RELEASE_ASSERT(CountTrailingZeroes32(0x010FFF00) == 8);
MOZ_RELEASE_ASSERT(CountTrailingZeroes32(0x7000FE00) == 9);
MOZ_RELEASE_ASSERT(CountTrailingZeroes32(0x10CF0000) == 16);
MOZ_RELEASE_ASSERT(CountTrailingZeroes32(0x0BDE0000) == 17);
MOZ_RELEASE_ASSERT(CountTrailingZeroes32(0x0F000000) == 24);
MOZ_RELEASE_ASSERT(CountTrailingZeroes32(0xDE000000) == 25);
MOZ_RELEASE_ASSERT(CountTrailingZeroes32(0x80000000) == 31);
}
static void
TestTrailingZeroes64()
{
MOZ_ASSERT(CountTrailingZeroes64(0x000100000F0F0F0F) == 0);
MOZ_ASSERT(CountTrailingZeroes64(0x070000000F0F0F0E) == 1);
MOZ_ASSERT(CountTrailingZeroes64(0x000008000F0F0F0C) == 2);
MOZ_ASSERT(CountTrailingZeroes64(0x000008000F0F0F08) == 3);
MOZ_ASSERT(CountTrailingZeroes64(0xC001000F0F0F0F00) == 8);
MOZ_ASSERT(CountTrailingZeroes64(0x0200000F0F0F0E00) == 9);
MOZ_ASSERT(CountTrailingZeroes64(0xB0C10F0FEFDF0000) == 16);
MOZ_ASSERT(CountTrailingZeroes64(0x0AAA00F0FF0E0000) == 17);
MOZ_ASSERT(CountTrailingZeroes64(0xD010F0FEDF000000) == 24);
MOZ_ASSERT(CountTrailingZeroes64(0x7AAF0CF0BE000000) == 25);
MOZ_ASSERT(CountTrailingZeroes64(0x20F0A5D100000000) == 32);
MOZ_ASSERT(CountTrailingZeroes64(0x489BF0B200000000) == 33);
MOZ_ASSERT(CountTrailingZeroes64(0xE0F0D10000000000) == 40);
MOZ_ASSERT(CountTrailingZeroes64(0x97F0B20000000000) == 41);
MOZ_ASSERT(CountTrailingZeroes64(0x2C07000000000000) == 48);
MOZ_ASSERT(CountTrailingZeroes64(0x1FBA000000000000) == 49);
MOZ_ASSERT(CountTrailingZeroes64(0x0100000000000000) == 56);
MOZ_ASSERT(CountTrailingZeroes64(0x0200000000000000) == 57);
MOZ_ASSERT(CountTrailingZeroes64(0x8000000000000000) == 63);
MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x000100000F0F0F0F) == 0);
MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x070000000F0F0F0E) == 1);
MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x000008000F0F0F0C) == 2);
MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x000008000F0F0F08) == 3);
MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0xC001000F0F0F0F00) == 8);
MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x0200000F0F0F0E00) == 9);
MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0xB0C10F0FEFDF0000) == 16);
MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x0AAA00F0FF0E0000) == 17);
MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0xD010F0FEDF000000) == 24);
MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x7AAF0CF0BE000000) == 25);
MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x20F0A5D100000000) == 32);
MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x489BF0B200000000) == 33);
MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0xE0F0D10000000000) == 40);
MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x97F0B20000000000) == 41);
MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x2C07000000000000) == 48);
MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x1FBA000000000000) == 49);
MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x0100000000000000) == 56);
MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x0200000000000000) == 57);
MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x8000000000000000) == 63);
}
int main()

Просмотреть файл

@ -3,13 +3,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/Assertions.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/Endian.h"
#include <stddef.h>
using mozilla::BigEndian;
using mozilla::DebugOnly;
using mozilla::LittleEndian;
using mozilla::NativeEndian;
@ -18,13 +16,13 @@ void
TestSingleSwap(T value, T swappedValue)
{
#if MOZ_LITTLE_ENDIAN
MOZ_ASSERT(NativeEndian::swapToBigEndian(value) == swappedValue);
MOZ_ASSERT(NativeEndian::swapFromBigEndian(value) == swappedValue);
MOZ_ASSERT(NativeEndian::swapToNetworkOrder(value) == swappedValue);
MOZ_ASSERT(NativeEndian::swapFromNetworkOrder(value) == swappedValue);
MOZ_RELEASE_ASSERT(NativeEndian::swapToBigEndian(value) == swappedValue);
MOZ_RELEASE_ASSERT(NativeEndian::swapFromBigEndian(value) == swappedValue);
MOZ_RELEASE_ASSERT(NativeEndian::swapToNetworkOrder(value) == swappedValue);
MOZ_RELEASE_ASSERT(NativeEndian::swapFromNetworkOrder(value) == swappedValue);
#else
MOZ_ASSERT(NativeEndian::swapToLittleEndian(value) == swappedValue);
MOZ_ASSERT(NativeEndian::swapFromLittleEndian(value) == swappedValue);
MOZ_RELEASE_ASSERT(NativeEndian::swapToLittleEndian(value) == swappedValue);
MOZ_RELEASE_ASSERT(NativeEndian::swapFromLittleEndian(value) == swappedValue);
#endif
}
@ -33,13 +31,13 @@ void
TestSingleNoSwap(T value, T notSwappedValue)
{
#if MOZ_LITTLE_ENDIAN
MOZ_ASSERT(NativeEndian::swapToLittleEndian(value) == notSwappedValue);
MOZ_ASSERT(NativeEndian::swapFromLittleEndian(value) == notSwappedValue);
MOZ_RELEASE_ASSERT(NativeEndian::swapToLittleEndian(value) == notSwappedValue);
MOZ_RELEASE_ASSERT(NativeEndian::swapFromLittleEndian(value) == notSwappedValue);
#else
MOZ_ASSERT(NativeEndian::swapToBigEndian(value) == notSwappedValue);
MOZ_ASSERT(NativeEndian::swapFromBigEndian(value) == notSwappedValue);
MOZ_ASSERT(NativeEndian::swapToNetworkOrder(value) == notSwappedValue);
MOZ_ASSERT(NativeEndian::swapFromNetworkOrder(value) == notSwappedValue);
MOZ_RELEASE_ASSERT(NativeEndian::swapToBigEndian(value) == notSwappedValue);
MOZ_RELEASE_ASSERT(NativeEndian::swapFromBigEndian(value) == notSwappedValue);
MOZ_RELEASE_ASSERT(NativeEndian::swapToNetworkOrder(value) == notSwappedValue);
MOZ_RELEASE_ASSERT(NativeEndian::swapFromNetworkOrder(value) == notSwappedValue);
#endif
}
@ -106,7 +104,7 @@ TestBulkSwapToSub(enum SwapExpectation expectSwap,
const uint8_t fillValue = 0xa5;
static uint8_t checkBuffer[bufferSize];
MOZ_ASSERT(bufferSize > 2 * sizeof(T));
MOZ_RELEASE_ASSERT(bufferSize > 2 * sizeof(T));
memset(checkBuffer, fillValue, bufferSize);
@ -115,17 +113,17 @@ TestBulkSwapToSub(enum SwapExpectation expectSwap,
memset(buffer, fillValue, bufferSize);
swapperFunc(buffer + startPosition, values, nValues);
MOZ_ASSERT(memcmp(buffer, checkBuffer, startPosition) == 0);
DebugOnly<size_t> valuesEndPosition = startPosition + sizeof(T) * nValues;
MOZ_ASSERT(memcmp(buffer + valuesEndPosition,
MOZ_RELEASE_ASSERT(memcmp(buffer, checkBuffer, startPosition) == 0);
size_t valuesEndPosition = startPosition + sizeof(T) * nValues;
MOZ_RELEASE_ASSERT(memcmp(buffer + valuesEndPosition,
checkBuffer + valuesEndPosition,
bufferSize - valuesEndPosition) == 0);
if (expectSwap == NoSwap) {
MOZ_ASSERT(memcmp(buffer + startPosition, values,
MOZ_RELEASE_ASSERT(memcmp(buffer + startPosition, values,
nValues * sizeof(T)) == 0);
}
for (size_t i = 0; i < nValues; ++i) {
MOZ_ASSERT(readerFunc(buffer + startPosition + sizeof(T) * i) ==
MOZ_RELEASE_ASSERT(readerFunc(buffer + startPosition + sizeof(T) * i) ==
values[i]);
}
}
@ -152,17 +150,17 @@ TestBulkSwapFromSub(enum SwapExpectation expectSwap,
memset(buffer, fillValue, bufferSize);
swapperFunc(buffer + startPosition, values, nValues);
MOZ_ASSERT(memcmp(buffer, checkBuffer, startPosition * sizeof(T)) == 0);
DebugOnly<size_t> valuesEndPosition = startPosition + nValues;
MOZ_ASSERT(memcmp(buffer + valuesEndPosition,
MOZ_RELEASE_ASSERT(memcmp(buffer, checkBuffer, startPosition * sizeof(T)) == 0);
size_t valuesEndPosition = startPosition + nValues;
MOZ_RELEASE_ASSERT(memcmp(buffer + valuesEndPosition,
checkBuffer + valuesEndPosition,
(arraySize - valuesEndPosition) * sizeof(T)) == 0);
if (expectSwap == NoSwap) {
MOZ_ASSERT(memcmp(buffer + startPosition, values,
MOZ_RELEASE_ASSERT(memcmp(buffer + startPosition, values,
nValues * sizeof(T)) == 0);
}
for (size_t i = 0; i < nValues; ++i)
MOZ_ASSERT(readerFunc(buffer + startPosition + i) == values[i]);
MOZ_RELEASE_ASSERT(readerFunc(buffer + startPosition + i) == values[i]);
}
}
}
@ -181,7 +179,7 @@ TestBulkInPlaceSub(enum SwapExpectation expectSwap,
const T fillValue = 0xa5;
static T checkBuffer[bufferCount];
MOZ_ASSERT(bufferSize > 2 * sizeof(T));
MOZ_RELEASE_ASSERT(bufferSize > 2 * sizeof(T));
memset(checkBuffer, fillValue, bufferSize);
@ -191,17 +189,17 @@ TestBulkInPlaceSub(enum SwapExpectation expectSwap,
memcpy(buffer + startPosition, values, nValues * sizeof(T));
swapperFunc(buffer + startPosition, nValues);
MOZ_ASSERT(memcmp(buffer, checkBuffer, startPosition * sizeof(T)) == 0);
DebugOnly<size_t> valuesEndPosition = startPosition + nValues;
MOZ_ASSERT(memcmp(buffer + valuesEndPosition,
MOZ_RELEASE_ASSERT(memcmp(buffer, checkBuffer, startPosition * sizeof(T)) == 0);
size_t valuesEndPosition = startPosition + nValues;
MOZ_RELEASE_ASSERT(memcmp(buffer + valuesEndPosition,
checkBuffer + valuesEndPosition,
bufferSize - valuesEndPosition * sizeof(T)) == 0);
if (expectSwap == NoSwap) {
MOZ_ASSERT(memcmp(buffer + startPosition, values,
MOZ_RELEASE_ASSERT(memcmp(buffer + startPosition, values,
nValues * sizeof(T)) == 0);
}
for (size_t i = 0; i < nValues; ++i)
MOZ_ASSERT(readerFunc(buffer + startPosition + i) == values[i]);
MOZ_RELEASE_ASSERT(readerFunc(buffer + startPosition + i) == values[i]);
}
}
}
@ -304,53 +302,53 @@ main()
int64_t(0xf1f2f3f4f5f6f7f8) };
uint8_t buffer[8];
MOZ_ASSERT(LittleEndian::readUint16(&unsigned_bytes[0]) == 0x201);
MOZ_ASSERT(BigEndian::readUint16(&unsigned_bytes[0]) == 0x102);
MOZ_RELEASE_ASSERT(LittleEndian::readUint16(&unsigned_bytes[0]) == 0x201);
MOZ_RELEASE_ASSERT(BigEndian::readUint16(&unsigned_bytes[0]) == 0x102);
MOZ_ASSERT(LittleEndian::readUint32(&unsigned_bytes[0]) == 0x4030201U);
MOZ_ASSERT(BigEndian::readUint32(&unsigned_bytes[0]) == 0x1020304U);
MOZ_RELEASE_ASSERT(LittleEndian::readUint32(&unsigned_bytes[0]) == 0x4030201U);
MOZ_RELEASE_ASSERT(BigEndian::readUint32(&unsigned_bytes[0]) == 0x1020304U);
MOZ_ASSERT(LittleEndian::readUint64(&unsigned_bytes[0]) == 0x807060504030201ULL);
MOZ_ASSERT(BigEndian::readUint64(&unsigned_bytes[0]) == 0x102030405060708ULL);
MOZ_RELEASE_ASSERT(LittleEndian::readUint64(&unsigned_bytes[0]) == 0x807060504030201ULL);
MOZ_RELEASE_ASSERT(BigEndian::readUint64(&unsigned_bytes[0]) == 0x102030405060708ULL);
LittleEndian::writeUint16(&buffer[0], 0x201);
MOZ_ASSERT(memcmp(&unsigned_bytes[0], &buffer[0], sizeof(uint16_t)) == 0);
MOZ_RELEASE_ASSERT(memcmp(&unsigned_bytes[0], &buffer[0], sizeof(uint16_t)) == 0);
BigEndian::writeUint16(&buffer[0], 0x102);
MOZ_ASSERT(memcmp(&unsigned_bytes[0], &buffer[0], sizeof(uint16_t)) == 0);
MOZ_RELEASE_ASSERT(memcmp(&unsigned_bytes[0], &buffer[0], sizeof(uint16_t)) == 0);
LittleEndian::writeUint32(&buffer[0], 0x4030201U);
MOZ_ASSERT(memcmp(&unsigned_bytes[0], &buffer[0], sizeof(uint32_t)) == 0);
MOZ_RELEASE_ASSERT(memcmp(&unsigned_bytes[0], &buffer[0], sizeof(uint32_t)) == 0);
BigEndian::writeUint32(&buffer[0], 0x1020304U);
MOZ_ASSERT(memcmp(&unsigned_bytes[0], &buffer[0], sizeof(uint32_t)) == 0);
MOZ_RELEASE_ASSERT(memcmp(&unsigned_bytes[0], &buffer[0], sizeof(uint32_t)) == 0);
LittleEndian::writeUint64(&buffer[0], 0x807060504030201ULL);
MOZ_ASSERT(memcmp(&unsigned_bytes[0], &buffer[0], sizeof(uint64_t)) == 0);
MOZ_RELEASE_ASSERT(memcmp(&unsigned_bytes[0], &buffer[0], sizeof(uint64_t)) == 0);
BigEndian::writeUint64(&buffer[0], 0x102030405060708ULL);
MOZ_ASSERT(memcmp(&unsigned_bytes[0], &buffer[0], sizeof(uint64_t)) == 0);
MOZ_RELEASE_ASSERT(memcmp(&unsigned_bytes[0], &buffer[0], sizeof(uint64_t)) == 0);
MOZ_ASSERT(LittleEndian::readInt16(&signed_bytes[0]) == int16_t(0xf2f1));
MOZ_ASSERT(BigEndian::readInt16(&signed_bytes[0]) == int16_t(0xf1f2));
MOZ_RELEASE_ASSERT(LittleEndian::readInt16(&signed_bytes[0]) == int16_t(0xf2f1));
MOZ_RELEASE_ASSERT(BigEndian::readInt16(&signed_bytes[0]) == int16_t(0xf1f2));
MOZ_ASSERT(LittleEndian::readInt32(&signed_bytes[0]) == int32_t(0xf4f3f2f1));
MOZ_ASSERT(BigEndian::readInt32(&signed_bytes[0]) == int32_t(0xf1f2f3f4));
MOZ_RELEASE_ASSERT(LittleEndian::readInt32(&signed_bytes[0]) == int32_t(0xf4f3f2f1));
MOZ_RELEASE_ASSERT(BigEndian::readInt32(&signed_bytes[0]) == int32_t(0xf1f2f3f4));
MOZ_ASSERT(LittleEndian::readInt64(&signed_bytes[0]) == int64_t(0xf8f7f6f5f4f3f2f1LL));
MOZ_ASSERT(BigEndian::readInt64(&signed_bytes[0]) == int64_t(0xf1f2f3f4f5f6f7f8LL));
MOZ_RELEASE_ASSERT(LittleEndian::readInt64(&signed_bytes[0]) == int64_t(0xf8f7f6f5f4f3f2f1LL));
MOZ_RELEASE_ASSERT(BigEndian::readInt64(&signed_bytes[0]) == int64_t(0xf1f2f3f4f5f6f7f8LL));
LittleEndian::writeInt16(&buffer[0], 0xf2f1);
MOZ_ASSERT(memcmp(&signed_bytes[0], &buffer[0], sizeof(int16_t)) == 0);
MOZ_RELEASE_ASSERT(memcmp(&signed_bytes[0], &buffer[0], sizeof(int16_t)) == 0);
BigEndian::writeInt16(&buffer[0], 0xf1f2);
MOZ_ASSERT(memcmp(&signed_bytes[0], &buffer[0], sizeof(int16_t)) == 0);
MOZ_RELEASE_ASSERT(memcmp(&signed_bytes[0], &buffer[0], sizeof(int16_t)) == 0);
LittleEndian::writeInt32(&buffer[0], 0xf4f3f2f1);
MOZ_ASSERT(memcmp(&signed_bytes[0], &buffer[0], sizeof(int32_t)) == 0);
MOZ_RELEASE_ASSERT(memcmp(&signed_bytes[0], &buffer[0], sizeof(int32_t)) == 0);
BigEndian::writeInt32(&buffer[0], 0xf1f2f3f4);
MOZ_ASSERT(memcmp(&signed_bytes[0], &buffer[0], sizeof(int32_t)) == 0);
MOZ_RELEASE_ASSERT(memcmp(&signed_bytes[0], &buffer[0], sizeof(int32_t)) == 0);
LittleEndian::writeInt64(&buffer[0], 0xf8f7f6f5f4f3f2f1LL);
MOZ_ASSERT(memcmp(&signed_bytes[0], &buffer[0], sizeof(int64_t)) == 0);
MOZ_RELEASE_ASSERT(memcmp(&signed_bytes[0], &buffer[0], sizeof(int64_t)) == 0);
BigEndian::writeInt64(&buffer[0], 0xf1f2f3f4f5f6f7f8LL);
MOZ_ASSERT(memcmp(&signed_bytes[0], &buffer[0], sizeof(int64_t)) == 0);
MOZ_RELEASE_ASSERT(memcmp(&signed_bytes[0], &buffer[0], sizeof(int64_t)) == 0);
TestSingleSwap(uint16_t(0xf2f1), uint16_t(0xf1f2));
TestSingleSwap(uint32_t(0xf4f3f2f1), uint32_t(0xf1f2f3f4));

Просмотреть файл

@ -59,150 +59,150 @@ class EnumSetSuite {
private:
void testSize() {
MOZ_ASSERT(mAlcidae.size() == 0);
MOZ_ASSERT(mDiomedeidae.size() == 1);
MOZ_ASSERT(mPetrelProcellariidae.size() == 2);
MOZ_ASSERT(mNonPetrelProcellariidae.size() == 3);
MOZ_ASSERT(mPetrels.size() == 4);
MOZ_RELEASE_ASSERT(mAlcidae.size() == 0);
MOZ_RELEASE_ASSERT(mDiomedeidae.size() == 1);
MOZ_RELEASE_ASSERT(mPetrelProcellariidae.size() == 2);
MOZ_RELEASE_ASSERT(mNonPetrelProcellariidae.size() == 3);
MOZ_RELEASE_ASSERT(mPetrels.size() == 4);
}
void testContains() {
MOZ_ASSERT(!mPetrels.contains(PENGUIN));
MOZ_ASSERT(!mPetrels.contains(ALBATROSS));
MOZ_ASSERT(!mPetrels.contains(FULMAR));
MOZ_ASSERT(!mPetrels.contains(PRION));
MOZ_ASSERT(!mPetrels.contains(SHEARWATER));
MOZ_ASSERT(mPetrels.contains(GADFLY_PETREL));
MOZ_ASSERT(mPetrels.contains(TRUE_PETREL));
MOZ_ASSERT(mPetrels.contains(DIVING_PETREL));
MOZ_ASSERT(mPetrels.contains(STORM_PETREL));
MOZ_ASSERT(!mPetrels.contains(PELICAN));
MOZ_ASSERT(!mPetrels.contains(GANNET));
MOZ_ASSERT(!mPetrels.contains(BOOBY));
MOZ_ASSERT(!mPetrels.contains(CORMORANT));
MOZ_ASSERT(!mPetrels.contains(FRIGATEBIRD));
MOZ_ASSERT(!mPetrels.contains(TROPICBIRD));
MOZ_ASSERT(!mPetrels.contains(SKUA));
MOZ_ASSERT(!mPetrels.contains(GULL));
MOZ_ASSERT(!mPetrels.contains(TERN));
MOZ_ASSERT(!mPetrels.contains(SKIMMER));
MOZ_ASSERT(!mPetrels.contains(AUK));
MOZ_RELEASE_ASSERT(!mPetrels.contains(PENGUIN));
MOZ_RELEASE_ASSERT(!mPetrels.contains(ALBATROSS));
MOZ_RELEASE_ASSERT(!mPetrels.contains(FULMAR));
MOZ_RELEASE_ASSERT(!mPetrels.contains(PRION));
MOZ_RELEASE_ASSERT(!mPetrels.contains(SHEARWATER));
MOZ_RELEASE_ASSERT(mPetrels.contains(GADFLY_PETREL));
MOZ_RELEASE_ASSERT(mPetrels.contains(TRUE_PETREL));
MOZ_RELEASE_ASSERT(mPetrels.contains(DIVING_PETREL));
MOZ_RELEASE_ASSERT(mPetrels.contains(STORM_PETREL));
MOZ_RELEASE_ASSERT(!mPetrels.contains(PELICAN));
MOZ_RELEASE_ASSERT(!mPetrels.contains(GANNET));
MOZ_RELEASE_ASSERT(!mPetrels.contains(BOOBY));
MOZ_RELEASE_ASSERT(!mPetrels.contains(CORMORANT));
MOZ_RELEASE_ASSERT(!mPetrels.contains(FRIGATEBIRD));
MOZ_RELEASE_ASSERT(!mPetrels.contains(TROPICBIRD));
MOZ_RELEASE_ASSERT(!mPetrels.contains(SKUA));
MOZ_RELEASE_ASSERT(!mPetrels.contains(GULL));
MOZ_RELEASE_ASSERT(!mPetrels.contains(TERN));
MOZ_RELEASE_ASSERT(!mPetrels.contains(SKIMMER));
MOZ_RELEASE_ASSERT(!mPetrels.contains(AUK));
}
void testCopy() {
EnumSet<SeaBird> likes = mPetrels;
likes -= TRUE_PETREL;
MOZ_ASSERT(mPetrels.size() == 4);
MOZ_ASSERT(mPetrels.contains(TRUE_PETREL));
MOZ_RELEASE_ASSERT(mPetrels.size() == 4);
MOZ_RELEASE_ASSERT(mPetrels.contains(TRUE_PETREL));
MOZ_ASSERT(likes.size() == 3);
MOZ_ASSERT(likes.contains(GADFLY_PETREL));
MOZ_ASSERT(likes.contains(DIVING_PETREL));
MOZ_ASSERT(likes.contains(STORM_PETREL));
MOZ_RELEASE_ASSERT(likes.size() == 3);
MOZ_RELEASE_ASSERT(likes.contains(GADFLY_PETREL));
MOZ_RELEASE_ASSERT(likes.contains(DIVING_PETREL));
MOZ_RELEASE_ASSERT(likes.contains(STORM_PETREL));
}
void testAddTo() {
EnumSet<SeaBird> seen = mPetrels;
seen += CORMORANT;
seen += TRUE_PETREL;
MOZ_ASSERT(mPetrels.size() == 4);
MOZ_ASSERT(!mPetrels.contains(CORMORANT));
MOZ_ASSERT(seen.size() == 5);
MOZ_ASSERT(seen.contains(GADFLY_PETREL));
MOZ_ASSERT(seen.contains(TRUE_PETREL));
MOZ_ASSERT(seen.contains(DIVING_PETREL));
MOZ_ASSERT(seen.contains(STORM_PETREL));
MOZ_ASSERT(seen.contains(CORMORANT));
MOZ_RELEASE_ASSERT(mPetrels.size() == 4);
MOZ_RELEASE_ASSERT(!mPetrels.contains(CORMORANT));
MOZ_RELEASE_ASSERT(seen.size() == 5);
MOZ_RELEASE_ASSERT(seen.contains(GADFLY_PETREL));
MOZ_RELEASE_ASSERT(seen.contains(TRUE_PETREL));
MOZ_RELEASE_ASSERT(seen.contains(DIVING_PETREL));
MOZ_RELEASE_ASSERT(seen.contains(STORM_PETREL));
MOZ_RELEASE_ASSERT(seen.contains(CORMORANT));
}
void testAdd() {
EnumSet<SeaBird> seen = mPetrels + CORMORANT +
STORM_PETREL;
MOZ_ASSERT(mPetrels.size() == 4);
MOZ_ASSERT(!mPetrels.contains(CORMORANT));
MOZ_ASSERT(seen.size() == 5);
MOZ_ASSERT(seen.contains(GADFLY_PETREL));
MOZ_ASSERT(seen.contains(TRUE_PETREL));
MOZ_ASSERT(seen.contains(DIVING_PETREL));
MOZ_ASSERT(seen.contains(STORM_PETREL));
MOZ_ASSERT(seen.contains(CORMORANT));
MOZ_RELEASE_ASSERT(mPetrels.size() == 4);
MOZ_RELEASE_ASSERT(!mPetrels.contains(CORMORANT));
MOZ_RELEASE_ASSERT(seen.size() == 5);
MOZ_RELEASE_ASSERT(seen.contains(GADFLY_PETREL));
MOZ_RELEASE_ASSERT(seen.contains(TRUE_PETREL));
MOZ_RELEASE_ASSERT(seen.contains(DIVING_PETREL));
MOZ_RELEASE_ASSERT(seen.contains(STORM_PETREL));
MOZ_RELEASE_ASSERT(seen.contains(CORMORANT));
}
void testAddAll() {
EnumSet<SeaBird> procellariidae;
procellariidae += mPetrelProcellariidae;
procellariidae += mNonPetrelProcellariidae;
MOZ_ASSERT(procellariidae.size() == 5);
MOZ_RELEASE_ASSERT(procellariidae.size() == 5);
// Both procellariidae and mPetrels include GADFLY_PERTEL and TRUE_PETREL
EnumSet<SeaBird> procellariiformes;
procellariiformes += mDiomedeidae;
procellariiformes += procellariidae;
procellariiformes += mPetrels;
MOZ_ASSERT(procellariiformes.size() == 8);
MOZ_RELEASE_ASSERT(procellariiformes.size() == 8);
}
void testUnion() {
EnumSet<SeaBird> procellariidae = mPetrelProcellariidae +
mNonPetrelProcellariidae;
MOZ_ASSERT(procellariidae.size() == 5);
MOZ_RELEASE_ASSERT(procellariidae.size() == 5);
// Both procellariidae and mPetrels include GADFLY_PETREL and TRUE_PETREL
EnumSet<SeaBird> procellariiformes = mDiomedeidae + procellariidae +
mPetrels;
MOZ_ASSERT(procellariiformes.size() == 8);
MOZ_RELEASE_ASSERT(procellariiformes.size() == 8);
}
void testRemoveFrom() {
EnumSet<SeaBird> likes = mPetrels;
likes -= TRUE_PETREL;
likes -= DIVING_PETREL;
MOZ_ASSERT(likes.size() == 2);
MOZ_ASSERT(likes.contains(GADFLY_PETREL));
MOZ_ASSERT(likes.contains(STORM_PETREL));
MOZ_RELEASE_ASSERT(likes.size() == 2);
MOZ_RELEASE_ASSERT(likes.contains(GADFLY_PETREL));
MOZ_RELEASE_ASSERT(likes.contains(STORM_PETREL));
}
void testRemove() {
EnumSet<SeaBird> likes = mPetrels - TRUE_PETREL -
DIVING_PETREL;
MOZ_ASSERT(likes.size() == 2);
MOZ_ASSERT(likes.contains(GADFLY_PETREL));
MOZ_ASSERT(likes.contains(STORM_PETREL));
MOZ_RELEASE_ASSERT(likes.size() == 2);
MOZ_RELEASE_ASSERT(likes.contains(GADFLY_PETREL));
MOZ_RELEASE_ASSERT(likes.contains(STORM_PETREL));
}
void testRemoveAllFrom() {
EnumSet<SeaBird> likes = mPetrels;
likes -= mPetrelProcellariidae;
MOZ_ASSERT(likes.size() == 2);
MOZ_ASSERT(likes.contains(DIVING_PETREL));
MOZ_ASSERT(likes.contains(STORM_PETREL));
MOZ_RELEASE_ASSERT(likes.size() == 2);
MOZ_RELEASE_ASSERT(likes.contains(DIVING_PETREL));
MOZ_RELEASE_ASSERT(likes.contains(STORM_PETREL));
}
void testRemoveAll() {
EnumSet<SeaBird> likes = mPetrels - mPetrelProcellariidae;
MOZ_ASSERT(likes.size() == 2);
MOZ_ASSERT(likes.contains(DIVING_PETREL));
MOZ_ASSERT(likes.contains(STORM_PETREL));
MOZ_RELEASE_ASSERT(likes.size() == 2);
MOZ_RELEASE_ASSERT(likes.contains(DIVING_PETREL));
MOZ_RELEASE_ASSERT(likes.contains(STORM_PETREL));
}
void testIntersect() {
EnumSet<SeaBird> likes = mPetrels;
likes &= mPetrelProcellariidae;
MOZ_ASSERT(likes.size() == 2);
MOZ_ASSERT(likes.contains(GADFLY_PETREL));
MOZ_ASSERT(likes.contains(TRUE_PETREL));
MOZ_RELEASE_ASSERT(likes.size() == 2);
MOZ_RELEASE_ASSERT(likes.contains(GADFLY_PETREL));
MOZ_RELEASE_ASSERT(likes.contains(TRUE_PETREL));
}
void testInsersection() {
EnumSet<SeaBird> likes = mPetrels & mPetrelProcellariidae;
MOZ_ASSERT(likes.size() == 2);
MOZ_ASSERT(likes.contains(GADFLY_PETREL));
MOZ_ASSERT(likes.contains(TRUE_PETREL));
MOZ_RELEASE_ASSERT(likes.size() == 2);
MOZ_RELEASE_ASSERT(likes.contains(GADFLY_PETREL));
MOZ_RELEASE_ASSERT(likes.contains(TRUE_PETREL));
}
void testEquality() {
EnumSet<SeaBird> likes = mPetrels & mPetrelProcellariidae;
MOZ_ASSERT(likes == EnumSet<SeaBird>(GADFLY_PETREL,
MOZ_RELEASE_ASSERT(likes == EnumSet<SeaBird>(GADFLY_PETREL,
TRUE_PETREL));
}
@ -212,8 +212,8 @@ class EnumSetSuite {
likes += TRUE_PETREL;
likes += DIVING_PETREL;
likes += STORM_PETREL;
MOZ_ASSERT(likes.size() == 4);
MOZ_ASSERT(likes == mPetrels);
MOZ_RELEASE_ASSERT(likes.size() == 4);
MOZ_RELEASE_ASSERT(likes == mPetrels);
}

Просмотреть файл

@ -28,16 +28,16 @@ template<typename T>
static void
ShouldBeIdentical(T d1, T d2)
{
MOZ_ASSERT(NumbersAreIdentical(d1, d2));
MOZ_ASSERT(NumbersAreIdentical(d2, d1));
MOZ_RELEASE_ASSERT(NumbersAreIdentical(d1, d2));
MOZ_RELEASE_ASSERT(NumbersAreIdentical(d2, d1));
}
template<typename T>
static void
ShouldNotBeIdentical(T d1, T d2)
{
MOZ_ASSERT(!NumbersAreIdentical(d1, d2));
MOZ_ASSERT(!NumbersAreIdentical(d2, d1));
MOZ_RELEASE_ASSERT(!NumbersAreIdentical(d1, d2));
MOZ_RELEASE_ASSERT(!NumbersAreIdentical(d2, d1));
}
static void
@ -190,33 +190,33 @@ TestAreIdentical()
static void
TestDoubleExponentComponent()
{
MOZ_ASSERT(ExponentComponent(0.0) == -int_fast16_t(FloatingPoint<double>::ExponentBias));
MOZ_ASSERT(ExponentComponent(-0.0) == -int_fast16_t(FloatingPoint<double>::ExponentBias));
MOZ_ASSERT(ExponentComponent(0.125) == -3);
MOZ_ASSERT(ExponentComponent(0.5) == -1);
MOZ_ASSERT(ExponentComponent(1.0) == 0);
MOZ_ASSERT(ExponentComponent(1.5) == 0);
MOZ_ASSERT(ExponentComponent(2.0) == 1);
MOZ_ASSERT(ExponentComponent(7.0) == 2);
MOZ_ASSERT(ExponentComponent(PositiveInfinity<double>()) == FloatingPoint<double>::ExponentBias + 1);
MOZ_ASSERT(ExponentComponent(NegativeInfinity<double>()) == FloatingPoint<double>::ExponentBias + 1);
MOZ_ASSERT(ExponentComponent(UnspecifiedNaN<double>()) == FloatingPoint<double>::ExponentBias + 1);
MOZ_RELEASE_ASSERT(ExponentComponent(0.0) == -int_fast16_t(FloatingPoint<double>::ExponentBias));
MOZ_RELEASE_ASSERT(ExponentComponent(-0.0) == -int_fast16_t(FloatingPoint<double>::ExponentBias));
MOZ_RELEASE_ASSERT(ExponentComponent(0.125) == -3);
MOZ_RELEASE_ASSERT(ExponentComponent(0.5) == -1);
MOZ_RELEASE_ASSERT(ExponentComponent(1.0) == 0);
MOZ_RELEASE_ASSERT(ExponentComponent(1.5) == 0);
MOZ_RELEASE_ASSERT(ExponentComponent(2.0) == 1);
MOZ_RELEASE_ASSERT(ExponentComponent(7.0) == 2);
MOZ_RELEASE_ASSERT(ExponentComponent(PositiveInfinity<double>()) == FloatingPoint<double>::ExponentBias + 1);
MOZ_RELEASE_ASSERT(ExponentComponent(NegativeInfinity<double>()) == FloatingPoint<double>::ExponentBias + 1);
MOZ_RELEASE_ASSERT(ExponentComponent(UnspecifiedNaN<double>()) == FloatingPoint<double>::ExponentBias + 1);
}
static void
TestFloatExponentComponent()
{
MOZ_ASSERT(ExponentComponent(0.0f) == -int_fast16_t(FloatingPoint<float>::ExponentBias));
MOZ_ASSERT(ExponentComponent(-0.0f) == -int_fast16_t(FloatingPoint<float>::ExponentBias));
MOZ_ASSERT(ExponentComponent(0.125f) == -3);
MOZ_ASSERT(ExponentComponent(0.5f) == -1);
MOZ_ASSERT(ExponentComponent(1.0f) == 0);
MOZ_ASSERT(ExponentComponent(1.5f) == 0);
MOZ_ASSERT(ExponentComponent(2.0f) == 1);
MOZ_ASSERT(ExponentComponent(7.0f) == 2);
MOZ_ASSERT(ExponentComponent(PositiveInfinity<float>()) == FloatingPoint<float>::ExponentBias + 1);
MOZ_ASSERT(ExponentComponent(NegativeInfinity<float>()) == FloatingPoint<float>::ExponentBias + 1);
MOZ_ASSERT(ExponentComponent(UnspecifiedNaN<float>()) == FloatingPoint<float>::ExponentBias + 1);
MOZ_RELEASE_ASSERT(ExponentComponent(0.0f) == -int_fast16_t(FloatingPoint<float>::ExponentBias));
MOZ_RELEASE_ASSERT(ExponentComponent(-0.0f) == -int_fast16_t(FloatingPoint<float>::ExponentBias));
MOZ_RELEASE_ASSERT(ExponentComponent(0.125f) == -3);
MOZ_RELEASE_ASSERT(ExponentComponent(0.5f) == -1);
MOZ_RELEASE_ASSERT(ExponentComponent(1.0f) == 0);
MOZ_RELEASE_ASSERT(ExponentComponent(1.5f) == 0);
MOZ_RELEASE_ASSERT(ExponentComponent(2.0f) == 1);
MOZ_RELEASE_ASSERT(ExponentComponent(7.0f) == 2);
MOZ_RELEASE_ASSERT(ExponentComponent(PositiveInfinity<float>()) == FloatingPoint<float>::ExponentBias + 1);
MOZ_RELEASE_ASSERT(ExponentComponent(NegativeInfinity<float>()) == FloatingPoint<float>::ExponentBias + 1);
MOZ_RELEASE_ASSERT(ExponentComponent(UnspecifiedNaN<float>()) == FloatingPoint<float>::ExponentBias + 1);
}
static void
@ -229,136 +229,136 @@ TestExponentComponent()
static void
TestDoublesPredicates()
{
MOZ_ASSERT(IsNaN(UnspecifiedNaN<double>()));
MOZ_ASSERT(IsNaN(SpecificNaN<double>(1, 17)));;
MOZ_ASSERT(IsNaN(SpecificNaN<double>(0, 0xfffffffffff0fULL)));
MOZ_ASSERT(!IsNaN(0.0));
MOZ_ASSERT(!IsNaN(-0.0));
MOZ_ASSERT(!IsNaN(1.0));
MOZ_ASSERT(!IsNaN(PositiveInfinity<double>()));
MOZ_ASSERT(!IsNaN(NegativeInfinity<double>()));
MOZ_RELEASE_ASSERT(IsNaN(UnspecifiedNaN<double>()));
MOZ_RELEASE_ASSERT(IsNaN(SpecificNaN<double>(1, 17)));;
MOZ_RELEASE_ASSERT(IsNaN(SpecificNaN<double>(0, 0xfffffffffff0fULL)));
MOZ_RELEASE_ASSERT(!IsNaN(0.0));
MOZ_RELEASE_ASSERT(!IsNaN(-0.0));
MOZ_RELEASE_ASSERT(!IsNaN(1.0));
MOZ_RELEASE_ASSERT(!IsNaN(PositiveInfinity<double>()));
MOZ_RELEASE_ASSERT(!IsNaN(NegativeInfinity<double>()));
MOZ_ASSERT(IsInfinite(PositiveInfinity<double>()));
MOZ_ASSERT(IsInfinite(NegativeInfinity<double>()));
MOZ_ASSERT(!IsInfinite(UnspecifiedNaN<double>()));
MOZ_ASSERT(!IsInfinite(0.0));
MOZ_ASSERT(!IsInfinite(-0.0));
MOZ_ASSERT(!IsInfinite(1.0));
MOZ_RELEASE_ASSERT(IsInfinite(PositiveInfinity<double>()));
MOZ_RELEASE_ASSERT(IsInfinite(NegativeInfinity<double>()));
MOZ_RELEASE_ASSERT(!IsInfinite(UnspecifiedNaN<double>()));
MOZ_RELEASE_ASSERT(!IsInfinite(0.0));
MOZ_RELEASE_ASSERT(!IsInfinite(-0.0));
MOZ_RELEASE_ASSERT(!IsInfinite(1.0));
MOZ_ASSERT(!IsFinite(PositiveInfinity<double>()));
MOZ_ASSERT(!IsFinite(NegativeInfinity<double>()));
MOZ_ASSERT(!IsFinite(UnspecifiedNaN<double>()));
MOZ_ASSERT(IsFinite(0.0));
MOZ_ASSERT(IsFinite(-0.0));
MOZ_ASSERT(IsFinite(1.0));
MOZ_RELEASE_ASSERT(!IsFinite(PositiveInfinity<double>()));
MOZ_RELEASE_ASSERT(!IsFinite(NegativeInfinity<double>()));
MOZ_RELEASE_ASSERT(!IsFinite(UnspecifiedNaN<double>()));
MOZ_RELEASE_ASSERT(IsFinite(0.0));
MOZ_RELEASE_ASSERT(IsFinite(-0.0));
MOZ_RELEASE_ASSERT(IsFinite(1.0));
MOZ_ASSERT(!IsNegative(PositiveInfinity<double>()));
MOZ_ASSERT(IsNegative(NegativeInfinity<double>()));
MOZ_ASSERT(IsNegative(-0.0));
MOZ_ASSERT(!IsNegative(0.0));
MOZ_ASSERT(IsNegative(-1.0));
MOZ_ASSERT(!IsNegative(1.0));
MOZ_RELEASE_ASSERT(!IsNegative(PositiveInfinity<double>()));
MOZ_RELEASE_ASSERT(IsNegative(NegativeInfinity<double>()));
MOZ_RELEASE_ASSERT(IsNegative(-0.0));
MOZ_RELEASE_ASSERT(!IsNegative(0.0));
MOZ_RELEASE_ASSERT(IsNegative(-1.0));
MOZ_RELEASE_ASSERT(!IsNegative(1.0));
MOZ_ASSERT(!IsNegativeZero(PositiveInfinity<double>()));
MOZ_ASSERT(!IsNegativeZero(NegativeInfinity<double>()));
MOZ_ASSERT(!IsNegativeZero(SpecificNaN<double>(1, 17)));;
MOZ_ASSERT(!IsNegativeZero(SpecificNaN<double>(1, 0xfffffffffff0fULL)));
MOZ_ASSERT(!IsNegativeZero(SpecificNaN<double>(0, 17)));;
MOZ_ASSERT(!IsNegativeZero(SpecificNaN<double>(0, 0xfffffffffff0fULL)));
MOZ_ASSERT(!IsNegativeZero(UnspecifiedNaN<double>()));
MOZ_ASSERT(IsNegativeZero(-0.0));
MOZ_ASSERT(!IsNegativeZero(0.0));
MOZ_ASSERT(!IsNegativeZero(-1.0));
MOZ_ASSERT(!IsNegativeZero(1.0));
MOZ_RELEASE_ASSERT(!IsNegativeZero(PositiveInfinity<double>()));
MOZ_RELEASE_ASSERT(!IsNegativeZero(NegativeInfinity<double>()));
MOZ_RELEASE_ASSERT(!IsNegativeZero(SpecificNaN<double>(1, 17)));;
MOZ_RELEASE_ASSERT(!IsNegativeZero(SpecificNaN<double>(1, 0xfffffffffff0fULL)));
MOZ_RELEASE_ASSERT(!IsNegativeZero(SpecificNaN<double>(0, 17)));;
MOZ_RELEASE_ASSERT(!IsNegativeZero(SpecificNaN<double>(0, 0xfffffffffff0fULL)));
MOZ_RELEASE_ASSERT(!IsNegativeZero(UnspecifiedNaN<double>()));
MOZ_RELEASE_ASSERT(IsNegativeZero(-0.0));
MOZ_RELEASE_ASSERT(!IsNegativeZero(0.0));
MOZ_RELEASE_ASSERT(!IsNegativeZero(-1.0));
MOZ_RELEASE_ASSERT(!IsNegativeZero(1.0));
int32_t i;
MOZ_ASSERT(NumberIsInt32(0.0, &i)); MOZ_ASSERT(i == 0);
MOZ_ASSERT(!NumberIsInt32(-0.0, &i));
MOZ_ASSERT(NumberEqualsInt32(0.0, &i)); MOZ_ASSERT(i == 0);
MOZ_ASSERT(NumberEqualsInt32(-0.0, &i)); MOZ_ASSERT(i == 0);
MOZ_ASSERT(NumberIsInt32(double(INT32_MIN), &i)); MOZ_ASSERT(i == INT32_MIN);
MOZ_ASSERT(NumberIsInt32(double(INT32_MAX), &i)); MOZ_ASSERT(i == INT32_MAX);
MOZ_ASSERT(NumberEqualsInt32(double(INT32_MIN), &i)); MOZ_ASSERT(i == INT32_MIN);
MOZ_ASSERT(NumberEqualsInt32(double(INT32_MAX), &i)); MOZ_ASSERT(i == INT32_MAX);
MOZ_ASSERT(!NumberIsInt32(0.5, &i));
MOZ_ASSERT(!NumberIsInt32(double(INT32_MAX) + 0.1, &i));
MOZ_ASSERT(!NumberIsInt32(double(INT32_MIN) - 0.1, &i));
MOZ_ASSERT(!NumberIsInt32(NegativeInfinity<double>(), &i));
MOZ_ASSERT(!NumberIsInt32(PositiveInfinity<double>(), &i));
MOZ_ASSERT(!NumberIsInt32(UnspecifiedNaN<double>(), &i));
MOZ_ASSERT(!NumberEqualsInt32(0.5, &i));
MOZ_ASSERT(!NumberEqualsInt32(double(INT32_MAX) + 0.1, &i));
MOZ_ASSERT(!NumberEqualsInt32(double(INT32_MIN) - 0.1, &i));
MOZ_ASSERT(!NumberEqualsInt32(NegativeInfinity<double>(), &i));
MOZ_ASSERT(!NumberEqualsInt32(PositiveInfinity<double>(), &i));
MOZ_ASSERT(!NumberEqualsInt32(UnspecifiedNaN<double>(), &i));
MOZ_RELEASE_ASSERT(NumberIsInt32(0.0, &i)); MOZ_RELEASE_ASSERT(i == 0);
MOZ_RELEASE_ASSERT(!NumberIsInt32(-0.0, &i));
MOZ_RELEASE_ASSERT(NumberEqualsInt32(0.0, &i)); MOZ_RELEASE_ASSERT(i == 0);
MOZ_RELEASE_ASSERT(NumberEqualsInt32(-0.0, &i)); MOZ_RELEASE_ASSERT(i == 0);
MOZ_RELEASE_ASSERT(NumberIsInt32(double(INT32_MIN), &i)); MOZ_RELEASE_ASSERT(i == INT32_MIN);
MOZ_RELEASE_ASSERT(NumberIsInt32(double(INT32_MAX), &i)); MOZ_RELEASE_ASSERT(i == INT32_MAX);
MOZ_RELEASE_ASSERT(NumberEqualsInt32(double(INT32_MIN), &i)); MOZ_RELEASE_ASSERT(i == INT32_MIN);
MOZ_RELEASE_ASSERT(NumberEqualsInt32(double(INT32_MAX), &i)); MOZ_RELEASE_ASSERT(i == INT32_MAX);
MOZ_RELEASE_ASSERT(!NumberIsInt32(0.5, &i));
MOZ_RELEASE_ASSERT(!NumberIsInt32(double(INT32_MAX) + 0.1, &i));
MOZ_RELEASE_ASSERT(!NumberIsInt32(double(INT32_MIN) - 0.1, &i));
MOZ_RELEASE_ASSERT(!NumberIsInt32(NegativeInfinity<double>(), &i));
MOZ_RELEASE_ASSERT(!NumberIsInt32(PositiveInfinity<double>(), &i));
MOZ_RELEASE_ASSERT(!NumberIsInt32(UnspecifiedNaN<double>(), &i));
MOZ_RELEASE_ASSERT(!NumberEqualsInt32(0.5, &i));
MOZ_RELEASE_ASSERT(!NumberEqualsInt32(double(INT32_MAX) + 0.1, &i));
MOZ_RELEASE_ASSERT(!NumberEqualsInt32(double(INT32_MIN) - 0.1, &i));
MOZ_RELEASE_ASSERT(!NumberEqualsInt32(NegativeInfinity<double>(), &i));
MOZ_RELEASE_ASSERT(!NumberEqualsInt32(PositiveInfinity<double>(), &i));
MOZ_RELEASE_ASSERT(!NumberEqualsInt32(UnspecifiedNaN<double>(), &i));
}
static void
TestFloatsPredicates()
{
MOZ_ASSERT(IsNaN(UnspecifiedNaN<float>()));
MOZ_ASSERT(IsNaN(SpecificNaN<float>(1, 17)));;
MOZ_ASSERT(IsNaN(SpecificNaN<float>(0, 0x7fff0fUL)));
MOZ_ASSERT(!IsNaN(0.0f));
MOZ_ASSERT(!IsNaN(-0.0f));
MOZ_ASSERT(!IsNaN(1.0f));
MOZ_ASSERT(!IsNaN(PositiveInfinity<float>()));
MOZ_ASSERT(!IsNaN(NegativeInfinity<float>()));
MOZ_RELEASE_ASSERT(IsNaN(UnspecifiedNaN<float>()));
MOZ_RELEASE_ASSERT(IsNaN(SpecificNaN<float>(1, 17)));;
MOZ_RELEASE_ASSERT(IsNaN(SpecificNaN<float>(0, 0x7fff0fUL)));
MOZ_RELEASE_ASSERT(!IsNaN(0.0f));
MOZ_RELEASE_ASSERT(!IsNaN(-0.0f));
MOZ_RELEASE_ASSERT(!IsNaN(1.0f));
MOZ_RELEASE_ASSERT(!IsNaN(PositiveInfinity<float>()));
MOZ_RELEASE_ASSERT(!IsNaN(NegativeInfinity<float>()));
MOZ_ASSERT(IsInfinite(PositiveInfinity<float>()));
MOZ_ASSERT(IsInfinite(NegativeInfinity<float>()));
MOZ_ASSERT(!IsInfinite(UnspecifiedNaN<float>()));
MOZ_ASSERT(!IsInfinite(0.0f));
MOZ_ASSERT(!IsInfinite(-0.0f));
MOZ_ASSERT(!IsInfinite(1.0f));
MOZ_RELEASE_ASSERT(IsInfinite(PositiveInfinity<float>()));
MOZ_RELEASE_ASSERT(IsInfinite(NegativeInfinity<float>()));
MOZ_RELEASE_ASSERT(!IsInfinite(UnspecifiedNaN<float>()));
MOZ_RELEASE_ASSERT(!IsInfinite(0.0f));
MOZ_RELEASE_ASSERT(!IsInfinite(-0.0f));
MOZ_RELEASE_ASSERT(!IsInfinite(1.0f));
MOZ_ASSERT(!IsFinite(PositiveInfinity<float>()));
MOZ_ASSERT(!IsFinite(NegativeInfinity<float>()));
MOZ_ASSERT(!IsFinite(UnspecifiedNaN<float>()));
MOZ_ASSERT(IsFinite(0.0f));
MOZ_ASSERT(IsFinite(-0.0f));
MOZ_ASSERT(IsFinite(1.0f));
MOZ_RELEASE_ASSERT(!IsFinite(PositiveInfinity<float>()));
MOZ_RELEASE_ASSERT(!IsFinite(NegativeInfinity<float>()));
MOZ_RELEASE_ASSERT(!IsFinite(UnspecifiedNaN<float>()));
MOZ_RELEASE_ASSERT(IsFinite(0.0f));
MOZ_RELEASE_ASSERT(IsFinite(-0.0f));
MOZ_RELEASE_ASSERT(IsFinite(1.0f));
MOZ_ASSERT(!IsNegative(PositiveInfinity<float>()));
MOZ_ASSERT(IsNegative(NegativeInfinity<float>()));
MOZ_ASSERT(IsNegative(-0.0f));
MOZ_ASSERT(!IsNegative(0.0f));
MOZ_ASSERT(IsNegative(-1.0f));
MOZ_ASSERT(!IsNegative(1.0f));
MOZ_RELEASE_ASSERT(!IsNegative(PositiveInfinity<float>()));
MOZ_RELEASE_ASSERT(IsNegative(NegativeInfinity<float>()));
MOZ_RELEASE_ASSERT(IsNegative(-0.0f));
MOZ_RELEASE_ASSERT(!IsNegative(0.0f));
MOZ_RELEASE_ASSERT(IsNegative(-1.0f));
MOZ_RELEASE_ASSERT(!IsNegative(1.0f));
MOZ_ASSERT(!IsNegativeZero(PositiveInfinity<float>()));
MOZ_ASSERT(!IsNegativeZero(NegativeInfinity<float>()));
MOZ_ASSERT(!IsNegativeZero(SpecificNaN<float>(1, 17)));;
MOZ_ASSERT(!IsNegativeZero(SpecificNaN<float>(1, 0x7fff0fUL)));
MOZ_ASSERT(!IsNegativeZero(SpecificNaN<float>(0, 17)));;
MOZ_ASSERT(!IsNegativeZero(SpecificNaN<float>(0, 0x7fff0fUL)));
MOZ_ASSERT(!IsNegativeZero(UnspecifiedNaN<float>()));
MOZ_ASSERT(IsNegativeZero(-0.0f));
MOZ_ASSERT(!IsNegativeZero(0.0f));
MOZ_ASSERT(!IsNegativeZero(-1.0f));
MOZ_ASSERT(!IsNegativeZero(1.0f));
MOZ_RELEASE_ASSERT(!IsNegativeZero(PositiveInfinity<float>()));
MOZ_RELEASE_ASSERT(!IsNegativeZero(NegativeInfinity<float>()));
MOZ_RELEASE_ASSERT(!IsNegativeZero(SpecificNaN<float>(1, 17)));;
MOZ_RELEASE_ASSERT(!IsNegativeZero(SpecificNaN<float>(1, 0x7fff0fUL)));
MOZ_RELEASE_ASSERT(!IsNegativeZero(SpecificNaN<float>(0, 17)));;
MOZ_RELEASE_ASSERT(!IsNegativeZero(SpecificNaN<float>(0, 0x7fff0fUL)));
MOZ_RELEASE_ASSERT(!IsNegativeZero(UnspecifiedNaN<float>()));
MOZ_RELEASE_ASSERT(IsNegativeZero(-0.0f));
MOZ_RELEASE_ASSERT(!IsNegativeZero(0.0f));
MOZ_RELEASE_ASSERT(!IsNegativeZero(-1.0f));
MOZ_RELEASE_ASSERT(!IsNegativeZero(1.0f));
int32_t i;
const int32_t BIG = 2097151;
MOZ_ASSERT(NumberIsInt32(0.0f, &i)); MOZ_ASSERT(i == 0);
MOZ_ASSERT(!NumberIsInt32(-0.0f, &i));
MOZ_ASSERT(NumberEqualsInt32(0.0f, &i)); MOZ_ASSERT(i == 0);
MOZ_ASSERT(NumberEqualsInt32(-0.0f, &i)); MOZ_ASSERT(i == 0);
MOZ_ASSERT(NumberIsInt32(float(INT32_MIN), &i)); MOZ_ASSERT(i == INT32_MIN);
MOZ_ASSERT(NumberIsInt32(float(BIG), &i)); MOZ_ASSERT(i == BIG);
MOZ_ASSERT(NumberEqualsInt32(float(INT32_MIN), &i)); MOZ_ASSERT(i == INT32_MIN);
MOZ_ASSERT(NumberEqualsInt32(float(BIG), &i)); MOZ_ASSERT(i == BIG);
MOZ_ASSERT(!NumberIsInt32(0.5f, &i));
MOZ_ASSERT(!NumberIsInt32(float(BIG) + 0.1f, &i));
MOZ_ASSERT(!NumberIsInt32(NegativeInfinity<float>(), &i));
MOZ_ASSERT(!NumberIsInt32(PositiveInfinity<float>(), &i));
MOZ_ASSERT(!NumberIsInt32(UnspecifiedNaN<float>(), &i));
MOZ_ASSERT(!NumberEqualsInt32(0.5f, &i));
MOZ_ASSERT(!NumberEqualsInt32(float(BIG) + 0.1f, &i));
MOZ_ASSERT(!NumberEqualsInt32(NegativeInfinity<float>(), &i));
MOZ_ASSERT(!NumberEqualsInt32(PositiveInfinity<float>(), &i));
MOZ_ASSERT(!NumberEqualsInt32(UnspecifiedNaN<float>(), &i));
MOZ_RELEASE_ASSERT(NumberIsInt32(0.0f, &i)); MOZ_RELEASE_ASSERT(i == 0);
MOZ_RELEASE_ASSERT(!NumberIsInt32(-0.0f, &i));
MOZ_RELEASE_ASSERT(NumberEqualsInt32(0.0f, &i)); MOZ_RELEASE_ASSERT(i == 0);
MOZ_RELEASE_ASSERT(NumberEqualsInt32(-0.0f, &i)); MOZ_RELEASE_ASSERT(i == 0);
MOZ_RELEASE_ASSERT(NumberIsInt32(float(INT32_MIN), &i)); MOZ_RELEASE_ASSERT(i == INT32_MIN);
MOZ_RELEASE_ASSERT(NumberIsInt32(float(BIG), &i)); MOZ_RELEASE_ASSERT(i == BIG);
MOZ_RELEASE_ASSERT(NumberEqualsInt32(float(INT32_MIN), &i)); MOZ_RELEASE_ASSERT(i == INT32_MIN);
MOZ_RELEASE_ASSERT(NumberEqualsInt32(float(BIG), &i)); MOZ_RELEASE_ASSERT(i == BIG);
MOZ_RELEASE_ASSERT(!NumberIsInt32(0.5f, &i));
MOZ_RELEASE_ASSERT(!NumberIsInt32(float(BIG) + 0.1f, &i));
MOZ_RELEASE_ASSERT(!NumberIsInt32(NegativeInfinity<float>(), &i));
MOZ_RELEASE_ASSERT(!NumberIsInt32(PositiveInfinity<float>(), &i));
MOZ_RELEASE_ASSERT(!NumberIsInt32(UnspecifiedNaN<float>(), &i));
MOZ_RELEASE_ASSERT(!NumberEqualsInt32(0.5f, &i));
MOZ_RELEASE_ASSERT(!NumberEqualsInt32(float(BIG) + 0.1f, &i));
MOZ_RELEASE_ASSERT(!NumberEqualsInt32(NegativeInfinity<float>(), &i));
MOZ_RELEASE_ASSERT(!NumberEqualsInt32(PositiveInfinity<float>(), &i));
MOZ_RELEASE_ASSERT(!NumberEqualsInt32(UnspecifiedNaN<float>(), &i));
}
static void
@ -377,64 +377,64 @@ TestFloatsAreApproximatelyEqual()
// Additive tests using the default epsilon
// ... around 1.0
MOZ_ASSERT(FuzzyEqualsAdditive(1.0f, 1.0f + lessThanEpsilon));
MOZ_ASSERT(FuzzyEqualsAdditive(1.0f, 1.0f - lessThanEpsilon));
MOZ_ASSERT(FuzzyEqualsAdditive(1.0f, 1.0f + epsilon));
MOZ_ASSERT(FuzzyEqualsAdditive(1.0f, 1.0f - epsilon));
MOZ_ASSERT(!FuzzyEqualsAdditive(1.0f, 1.0f + moreThanEpsilon));
MOZ_ASSERT(!FuzzyEqualsAdditive(1.0f, 1.0f - moreThanEpsilon));
MOZ_RELEASE_ASSERT(FuzzyEqualsAdditive(1.0f, 1.0f + lessThanEpsilon));
MOZ_RELEASE_ASSERT(FuzzyEqualsAdditive(1.0f, 1.0f - lessThanEpsilon));
MOZ_RELEASE_ASSERT(FuzzyEqualsAdditive(1.0f, 1.0f + epsilon));
MOZ_RELEASE_ASSERT(FuzzyEqualsAdditive(1.0f, 1.0f - epsilon));
MOZ_RELEASE_ASSERT(!FuzzyEqualsAdditive(1.0f, 1.0f + moreThanEpsilon));
MOZ_RELEASE_ASSERT(!FuzzyEqualsAdditive(1.0f, 1.0f - moreThanEpsilon));
// ... around 1.0e2 (this is near the upper bound of the range where
// adding moreThanEpsilon will still be representable and return false)
MOZ_ASSERT(FuzzyEqualsAdditive(1.0e2f, 1.0e2f + lessThanEpsilon));
MOZ_ASSERT(FuzzyEqualsAdditive(1.0e2f, 1.0e2f + epsilon));
MOZ_ASSERT(!FuzzyEqualsAdditive(1.0e2f, 1.0e2f + moreThanEpsilon));
MOZ_RELEASE_ASSERT(FuzzyEqualsAdditive(1.0e2f, 1.0e2f + lessThanEpsilon));
MOZ_RELEASE_ASSERT(FuzzyEqualsAdditive(1.0e2f, 1.0e2f + epsilon));
MOZ_RELEASE_ASSERT(!FuzzyEqualsAdditive(1.0e2f, 1.0e2f + moreThanEpsilon));
// ... around 1.0e-10
MOZ_ASSERT(FuzzyEqualsAdditive(1.0e-10f, 1.0e-10f + lessThanEpsilon));
MOZ_ASSERT(FuzzyEqualsAdditive(1.0e-10f, 1.0e-10f + epsilon));
MOZ_ASSERT(!FuzzyEqualsAdditive(1.0e-10f, 1.0e-10f + moreThanEpsilon));
MOZ_RELEASE_ASSERT(FuzzyEqualsAdditive(1.0e-10f, 1.0e-10f + lessThanEpsilon));
MOZ_RELEASE_ASSERT(FuzzyEqualsAdditive(1.0e-10f, 1.0e-10f + epsilon));
MOZ_RELEASE_ASSERT(!FuzzyEqualsAdditive(1.0e-10f, 1.0e-10f + moreThanEpsilon));
// ... straddling 0
MOZ_ASSERT(FuzzyEqualsAdditive(1.0e-6f, -1.0e-6f));
MOZ_ASSERT(!FuzzyEqualsAdditive(1.0e-5f, -1.0e-5f));
MOZ_RELEASE_ASSERT(FuzzyEqualsAdditive(1.0e-6f, -1.0e-6f));
MOZ_RELEASE_ASSERT(!FuzzyEqualsAdditive(1.0e-5f, -1.0e-5f));
// Using a small epsilon
MOZ_ASSERT(FuzzyEqualsAdditive(1.0e-5f, 1.0e-5f + 1.0e-10f, 1.0e-9f));
MOZ_ASSERT(!FuzzyEqualsAdditive(1.0e-5f, 1.0e-5f + 1.0e-10f, 1.0e-11f));
MOZ_RELEASE_ASSERT(FuzzyEqualsAdditive(1.0e-5f, 1.0e-5f + 1.0e-10f, 1.0e-9f));
MOZ_RELEASE_ASSERT(!FuzzyEqualsAdditive(1.0e-5f, 1.0e-5f + 1.0e-10f, 1.0e-11f));
// Using a big epsilon
MOZ_ASSERT(FuzzyEqualsAdditive(1.0e20f, 1.0e20f + 1.0e15f, 1.0e16f));
MOZ_ASSERT(!FuzzyEqualsAdditive(1.0e20f, 1.0e20f + 1.0e15f, 1.0e14f));
MOZ_RELEASE_ASSERT(FuzzyEqualsAdditive(1.0e20f, 1.0e20f + 1.0e15f, 1.0e16f));
MOZ_RELEASE_ASSERT(!FuzzyEqualsAdditive(1.0e20f, 1.0e20f + 1.0e15f, 1.0e14f));
// Multiplicative tests using the default epsilon
// ... around 1.0
MOZ_ASSERT(FuzzyEqualsMultiplicative(1.0f, 1.0f + lessThanEpsilon));
MOZ_ASSERT(FuzzyEqualsMultiplicative(1.0f, 1.0f - lessThanEpsilon));
MOZ_ASSERT(FuzzyEqualsMultiplicative(1.0f, 1.0f + epsilon));
MOZ_ASSERT(!FuzzyEqualsMultiplicative(1.0f, 1.0f - epsilon));
MOZ_ASSERT(!FuzzyEqualsMultiplicative(1.0f, 1.0f + moreThanEpsilon));
MOZ_ASSERT(!FuzzyEqualsMultiplicative(1.0f, 1.0f - moreThanEpsilon));
MOZ_RELEASE_ASSERT(FuzzyEqualsMultiplicative(1.0f, 1.0f + lessThanEpsilon));
MOZ_RELEASE_ASSERT(FuzzyEqualsMultiplicative(1.0f, 1.0f - lessThanEpsilon));
MOZ_RELEASE_ASSERT(FuzzyEqualsMultiplicative(1.0f, 1.0f + epsilon));
MOZ_RELEASE_ASSERT(!FuzzyEqualsMultiplicative(1.0f, 1.0f - epsilon));
MOZ_RELEASE_ASSERT(!FuzzyEqualsMultiplicative(1.0f, 1.0f + moreThanEpsilon));
MOZ_RELEASE_ASSERT(!FuzzyEqualsMultiplicative(1.0f, 1.0f - moreThanEpsilon));
// ... around 1.0e10
MOZ_ASSERT(FuzzyEqualsMultiplicative(1.0e10f, 1.0e10f + (lessThanEpsilon * 1.0e10f)));
MOZ_ASSERT(!FuzzyEqualsMultiplicative(1.0e10f, 1.0e10f + (moreThanEpsilon * 1.0e10f)));
MOZ_RELEASE_ASSERT(FuzzyEqualsMultiplicative(1.0e10f, 1.0e10f + (lessThanEpsilon * 1.0e10f)));
MOZ_RELEASE_ASSERT(!FuzzyEqualsMultiplicative(1.0e10f, 1.0e10f + (moreThanEpsilon * 1.0e10f)));
// ... around 1.0e-10
MOZ_ASSERT(FuzzyEqualsMultiplicative(1.0e-10f, 1.0e-10f + (lessThanEpsilon * 1.0e-10f)));
MOZ_ASSERT(!FuzzyEqualsMultiplicative(1.0e-10f, 1.0e-10f + (moreThanEpsilon * 1.0e-10f)));
MOZ_RELEASE_ASSERT(FuzzyEqualsMultiplicative(1.0e-10f, 1.0e-10f + (lessThanEpsilon * 1.0e-10f)));
MOZ_RELEASE_ASSERT(!FuzzyEqualsMultiplicative(1.0e-10f, 1.0e-10f + (moreThanEpsilon * 1.0e-10f)));
// ... straddling 0
MOZ_ASSERT(!FuzzyEqualsMultiplicative(1.0e-6f, -1.0e-6f));
MOZ_ASSERT(FuzzyEqualsMultiplicative(1.0e-6f, -1.0e-6f, 1.0e2f));
MOZ_RELEASE_ASSERT(!FuzzyEqualsMultiplicative(1.0e-6f, -1.0e-6f));
MOZ_RELEASE_ASSERT(FuzzyEqualsMultiplicative(1.0e-6f, -1.0e-6f, 1.0e2f));
// Using a small epsilon
MOZ_ASSERT(FuzzyEqualsMultiplicative(1.0e-5f, 1.0e-5f + 1.0e-10f, 1.0e-4f));
MOZ_ASSERT(!FuzzyEqualsMultiplicative(1.0e-5f, 1.0e-5f + 1.0e-10f, 1.0e-5f));
MOZ_RELEASE_ASSERT(FuzzyEqualsMultiplicative(1.0e-5f, 1.0e-5f + 1.0e-10f, 1.0e-4f));
MOZ_RELEASE_ASSERT(!FuzzyEqualsMultiplicative(1.0e-5f, 1.0e-5f + 1.0e-10f, 1.0e-5f));
// Using a big epsilon
MOZ_ASSERT(FuzzyEqualsMultiplicative(1.0f, 2.0f, 1.0f));
MOZ_ASSERT(!FuzzyEqualsMultiplicative(1.0f, 2.0f, 0.1f));
MOZ_RELEASE_ASSERT(FuzzyEqualsMultiplicative(1.0f, 2.0f, 1.0f));
MOZ_RELEASE_ASSERT(!FuzzyEqualsMultiplicative(1.0f, 2.0f, 0.1f));
// "real world case"
float oneThird = 10.0f / 3.0f;
MOZ_ASSERT(FuzzyEqualsAdditive(10.0f, 3.0f * oneThird));
MOZ_ASSERT(FuzzyEqualsMultiplicative(10.0f, 3.0f * oneThird));
MOZ_RELEASE_ASSERT(FuzzyEqualsAdditive(10.0f, 3.0f * oneThird));
MOZ_RELEASE_ASSERT(FuzzyEqualsMultiplicative(10.0f, 3.0f * oneThird));
// NaN check
MOZ_ASSERT(!FuzzyEqualsAdditive(SpecificNaN<float>(1, 1), SpecificNaN<float>(1, 1)));
MOZ_ASSERT(!FuzzyEqualsAdditive(SpecificNaN<float>(1, 2), SpecificNaN<float>(0, 8)));
MOZ_ASSERT(!FuzzyEqualsMultiplicative(SpecificNaN<float>(1, 1), SpecificNaN<float>(1, 1)));
MOZ_ASSERT(!FuzzyEqualsMultiplicative(SpecificNaN<float>(1, 2), SpecificNaN<float>(0, 200)));
MOZ_RELEASE_ASSERT(!FuzzyEqualsAdditive(SpecificNaN<float>(1, 1), SpecificNaN<float>(1, 1)));
MOZ_RELEASE_ASSERT(!FuzzyEqualsAdditive(SpecificNaN<float>(1, 2), SpecificNaN<float>(0, 8)));
MOZ_RELEASE_ASSERT(!FuzzyEqualsMultiplicative(SpecificNaN<float>(1, 1), SpecificNaN<float>(1, 1)));
MOZ_RELEASE_ASSERT(!FuzzyEqualsMultiplicative(SpecificNaN<float>(1, 2), SpecificNaN<float>(0, 200)));
}
static void
@ -446,64 +446,64 @@ TestDoublesAreApproximatelyEqual()
// Additive tests using the default epsilon
// ... around 1.0
MOZ_ASSERT(FuzzyEqualsAdditive(1.0, 1.0 + lessThanEpsilon));
MOZ_ASSERT(FuzzyEqualsAdditive(1.0, 1.0 - lessThanEpsilon));
MOZ_ASSERT(FuzzyEqualsAdditive(1.0, 1.0 + epsilon));
MOZ_ASSERT(FuzzyEqualsAdditive(1.0, 1.0 - epsilon));
MOZ_ASSERT(!FuzzyEqualsAdditive(1.0, 1.0 + moreThanEpsilon));
MOZ_ASSERT(!FuzzyEqualsAdditive(1.0, 1.0 - moreThanEpsilon));
MOZ_RELEASE_ASSERT(FuzzyEqualsAdditive(1.0, 1.0 + lessThanEpsilon));
MOZ_RELEASE_ASSERT(FuzzyEqualsAdditive(1.0, 1.0 - lessThanEpsilon));
MOZ_RELEASE_ASSERT(FuzzyEqualsAdditive(1.0, 1.0 + epsilon));
MOZ_RELEASE_ASSERT(FuzzyEqualsAdditive(1.0, 1.0 - epsilon));
MOZ_RELEASE_ASSERT(!FuzzyEqualsAdditive(1.0, 1.0 + moreThanEpsilon));
MOZ_RELEASE_ASSERT(!FuzzyEqualsAdditive(1.0, 1.0 - moreThanEpsilon));
// ... around 1.0e4 (this is near the upper bound of the range where
// adding moreThanEpsilon will still be representable and return false)
MOZ_ASSERT(FuzzyEqualsAdditive(1.0e4, 1.0e4 + lessThanEpsilon));
MOZ_ASSERT(FuzzyEqualsAdditive(1.0e4, 1.0e4 + epsilon));
MOZ_ASSERT(!FuzzyEqualsAdditive(1.0e4, 1.0e4 + moreThanEpsilon));
MOZ_RELEASE_ASSERT(FuzzyEqualsAdditive(1.0e4, 1.0e4 + lessThanEpsilon));
MOZ_RELEASE_ASSERT(FuzzyEqualsAdditive(1.0e4, 1.0e4 + epsilon));
MOZ_RELEASE_ASSERT(!FuzzyEqualsAdditive(1.0e4, 1.0e4 + moreThanEpsilon));
// ... around 1.0e-25
MOZ_ASSERT(FuzzyEqualsAdditive(1.0e-25, 1.0e-25 + lessThanEpsilon));
MOZ_ASSERT(FuzzyEqualsAdditive(1.0e-25, 1.0e-25 + epsilon));
MOZ_ASSERT(!FuzzyEqualsAdditive(1.0e-25, 1.0e-25 + moreThanEpsilon));
MOZ_RELEASE_ASSERT(FuzzyEqualsAdditive(1.0e-25, 1.0e-25 + lessThanEpsilon));
MOZ_RELEASE_ASSERT(FuzzyEqualsAdditive(1.0e-25, 1.0e-25 + epsilon));
MOZ_RELEASE_ASSERT(!FuzzyEqualsAdditive(1.0e-25, 1.0e-25 + moreThanEpsilon));
// ... straddling 0
MOZ_ASSERT(FuzzyEqualsAdditive(1.0e-13, -1.0e-13));
MOZ_ASSERT(!FuzzyEqualsAdditive(1.0e-12, -1.0e-12));
MOZ_RELEASE_ASSERT(FuzzyEqualsAdditive(1.0e-13, -1.0e-13));
MOZ_RELEASE_ASSERT(!FuzzyEqualsAdditive(1.0e-12, -1.0e-12));
// Using a small epsilon
MOZ_ASSERT(FuzzyEqualsAdditive(1.0e-15, 1.0e-15 + 1.0e-30, 1.0e-29));
MOZ_ASSERT(!FuzzyEqualsAdditive(1.0e-15, 1.0e-15 + 1.0e-30, 1.0e-31));
MOZ_RELEASE_ASSERT(FuzzyEqualsAdditive(1.0e-15, 1.0e-15 + 1.0e-30, 1.0e-29));
MOZ_RELEASE_ASSERT(!FuzzyEqualsAdditive(1.0e-15, 1.0e-15 + 1.0e-30, 1.0e-31));
// Using a big epsilon
MOZ_ASSERT(FuzzyEqualsAdditive(1.0e40, 1.0e40 + 1.0e25, 1.0e26));
MOZ_ASSERT(!FuzzyEqualsAdditive(1.0e40, 1.0e40 + 1.0e25, 1.0e24));
MOZ_RELEASE_ASSERT(FuzzyEqualsAdditive(1.0e40, 1.0e40 + 1.0e25, 1.0e26));
MOZ_RELEASE_ASSERT(!FuzzyEqualsAdditive(1.0e40, 1.0e40 + 1.0e25, 1.0e24));
// Multiplicative tests using the default epsilon
// ... around 1.0
MOZ_ASSERT(FuzzyEqualsMultiplicative(1.0, 1.0 + lessThanEpsilon));
MOZ_ASSERT(FuzzyEqualsMultiplicative(1.0, 1.0 - lessThanEpsilon));
MOZ_ASSERT(FuzzyEqualsMultiplicative(1.0, 1.0 + epsilon));
MOZ_ASSERT(!FuzzyEqualsMultiplicative(1.0, 1.0 - epsilon));
MOZ_ASSERT(!FuzzyEqualsMultiplicative(1.0, 1.0 + moreThanEpsilon));
MOZ_ASSERT(!FuzzyEqualsMultiplicative(1.0, 1.0 - moreThanEpsilon));
MOZ_RELEASE_ASSERT(FuzzyEqualsMultiplicative(1.0, 1.0 + lessThanEpsilon));
MOZ_RELEASE_ASSERT(FuzzyEqualsMultiplicative(1.0, 1.0 - lessThanEpsilon));
MOZ_RELEASE_ASSERT(FuzzyEqualsMultiplicative(1.0, 1.0 + epsilon));
MOZ_RELEASE_ASSERT(!FuzzyEqualsMultiplicative(1.0, 1.0 - epsilon));
MOZ_RELEASE_ASSERT(!FuzzyEqualsMultiplicative(1.0, 1.0 + moreThanEpsilon));
MOZ_RELEASE_ASSERT(!FuzzyEqualsMultiplicative(1.0, 1.0 - moreThanEpsilon));
// ... around 1.0e30
MOZ_ASSERT(FuzzyEqualsMultiplicative(1.0e30, 1.0e30 + (lessThanEpsilon * 1.0e30)));
MOZ_ASSERT(!FuzzyEqualsMultiplicative(1.0e30, 1.0e30 + (moreThanEpsilon * 1.0e30)));
MOZ_RELEASE_ASSERT(FuzzyEqualsMultiplicative(1.0e30, 1.0e30 + (lessThanEpsilon * 1.0e30)));
MOZ_RELEASE_ASSERT(!FuzzyEqualsMultiplicative(1.0e30, 1.0e30 + (moreThanEpsilon * 1.0e30)));
// ... around 1.0e-30
MOZ_ASSERT(FuzzyEqualsMultiplicative(1.0e-30, 1.0e-30 + (lessThanEpsilon * 1.0e-30)));
MOZ_ASSERT(!FuzzyEqualsMultiplicative(1.0e-30, 1.0e-30 + (moreThanEpsilon * 1.0e-30)));
MOZ_RELEASE_ASSERT(FuzzyEqualsMultiplicative(1.0e-30, 1.0e-30 + (lessThanEpsilon * 1.0e-30)));
MOZ_RELEASE_ASSERT(!FuzzyEqualsMultiplicative(1.0e-30, 1.0e-30 + (moreThanEpsilon * 1.0e-30)));
// ... straddling 0
MOZ_ASSERT(!FuzzyEqualsMultiplicative(1.0e-6, -1.0e-6));
MOZ_ASSERT(FuzzyEqualsMultiplicative(1.0e-6, -1.0e-6, 1.0e2));
MOZ_RELEASE_ASSERT(!FuzzyEqualsMultiplicative(1.0e-6, -1.0e-6));
MOZ_RELEASE_ASSERT(FuzzyEqualsMultiplicative(1.0e-6, -1.0e-6, 1.0e2));
// Using a small epsilon
MOZ_ASSERT(FuzzyEqualsMultiplicative(1.0e-15, 1.0e-15 + 1.0e-30, 1.0e-15));
MOZ_ASSERT(!FuzzyEqualsMultiplicative(1.0e-15, 1.0e-15 + 1.0e-30, 1.0e-16));
MOZ_RELEASE_ASSERT(FuzzyEqualsMultiplicative(1.0e-15, 1.0e-15 + 1.0e-30, 1.0e-15));
MOZ_RELEASE_ASSERT(!FuzzyEqualsMultiplicative(1.0e-15, 1.0e-15 + 1.0e-30, 1.0e-16));
// Using a big epsilon
MOZ_ASSERT(FuzzyEqualsMultiplicative(1.0e40, 2.0e40, 1.0));
MOZ_ASSERT(!FuzzyEqualsMultiplicative(1.0e40, 2.0e40, 0.1));
MOZ_RELEASE_ASSERT(FuzzyEqualsMultiplicative(1.0e40, 2.0e40, 1.0));
MOZ_RELEASE_ASSERT(!FuzzyEqualsMultiplicative(1.0e40, 2.0e40, 0.1));
// "real world case"
double oneThird = 10.0 / 3.0;
MOZ_ASSERT(FuzzyEqualsAdditive(10.0, 3.0 * oneThird));
MOZ_ASSERT(FuzzyEqualsMultiplicative(10.0, 3.0 * oneThird));
MOZ_RELEASE_ASSERT(FuzzyEqualsAdditive(10.0, 3.0 * oneThird));
MOZ_RELEASE_ASSERT(FuzzyEqualsMultiplicative(10.0, 3.0 * oneThird));
// NaN check
MOZ_ASSERT(!FuzzyEqualsAdditive(SpecificNaN<double>(1, 1), SpecificNaN<double>(1, 1)));
MOZ_ASSERT(!FuzzyEqualsAdditive(SpecificNaN<double>(1, 2), SpecificNaN<double>(0, 8)));
MOZ_ASSERT(!FuzzyEqualsMultiplicative(SpecificNaN<double>(1, 1), SpecificNaN<double>(1, 1)));
MOZ_ASSERT(!FuzzyEqualsMultiplicative(SpecificNaN<double>(1, 2), SpecificNaN<double>(0, 200)));
MOZ_RELEASE_ASSERT(!FuzzyEqualsAdditive(SpecificNaN<double>(1, 1), SpecificNaN<double>(1, 1)));
MOZ_RELEASE_ASSERT(!FuzzyEqualsAdditive(SpecificNaN<double>(1, 2), SpecificNaN<double>(0, 8)));
MOZ_RELEASE_ASSERT(!FuzzyEqualsMultiplicative(SpecificNaN<double>(1, 1), SpecificNaN<double>(1, 1)));
MOZ_RELEASE_ASSERT(!FuzzyEqualsMultiplicative(SpecificNaN<double>(1, 2), SpecificNaN<double>(0, 200)));
}
static void

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -50,65 +50,65 @@ class RollingMeanSuite
private:
void testZero() {
RollingMean<uint32_t, uint64_t> mean(3);
MOZ_ASSERT(mean.empty());
MOZ_RELEASE_ASSERT(mean.empty());
}
void testClear() {
RollingMean<uint32_t, uint64_t> mean(3);
mean.insert(4);
MOZ_ASSERT(mean.mean() == 4);
MOZ_RELEASE_ASSERT(mean.mean() == 4);
mean.clear();
MOZ_ASSERT(mean.empty());
MOZ_RELEASE_ASSERT(mean.empty());
mean.insert(3);
MOZ_ASSERT(mean.mean() == 3);
MOZ_RELEASE_ASSERT(mean.mean() == 3);
}
void testRolling() {
RollingMean<uint32_t, uint64_t> mean(3);
mean.insert(10);
MOZ_ASSERT(mean.mean() == 10);
MOZ_RELEASE_ASSERT(mean.mean() == 10);
mean.insert(20);
MOZ_ASSERT(mean.mean() == 15);
MOZ_RELEASE_ASSERT(mean.mean() == 15);
mean.insert(35);
MOZ_ASSERT(mean.mean() == 21);
MOZ_RELEASE_ASSERT(mean.mean() == 21);
mean.insert(5);
MOZ_ASSERT(mean.mean() == 20);
MOZ_RELEASE_ASSERT(mean.mean() == 20);
mean.insert(10);
MOZ_ASSERT(mean.mean() == 16);
MOZ_RELEASE_ASSERT(mean.mean() == 16);
}
void testClass() {
RollingMean<MyClass, MyClass> mean(3);
mean.insert(MyClass(4));
MOZ_ASSERT(mean.mean() == MyClass(4));
MOZ_RELEASE_ASSERT(mean.mean() == MyClass(4));
mean.clear();
MOZ_ASSERT(mean.empty());
MOZ_RELEASE_ASSERT(mean.empty());
}
void testMove() {
RollingMean<uint32_t, uint64_t> mean(3);
mean = RollingMean<uint32_t, uint64_t>(4);
MOZ_ASSERT(mean.maxValues() == 4);
MOZ_RELEASE_ASSERT(mean.maxValues() == 4);
mean.insert(10);
MOZ_ASSERT(mean.mean() == 10);
MOZ_RELEASE_ASSERT(mean.mean() == 10);
mean = RollingMean<uint32_t, uint64_t>(3);
mean.insert(30);
mean.insert(40);
mean.insert(50);
mean.insert(60);
MOZ_ASSERT(mean.mean() == 50);
MOZ_RELEASE_ASSERT(mean.mean() == 50);
}
};

Просмотреть файл

@ -198,7 +198,7 @@ main()
"size");
for (size_t i = 0; i < SHA1Sum::HashSize; i++)
MOZ_ASSERT(hash[i] == expected[i]);
MOZ_RELEASE_ASSERT(hash[i] == expected[i]);
return 0;
}

Просмотреть файл

@ -162,16 +162,16 @@ struct D : private B1, private B2 {};
static void
StandardIsBaseOfTests()
{
MOZ_ASSERT((IsBaseOf<B, D>::value) == true);
MOZ_ASSERT((IsBaseOf<const B, D>::value) == true);
MOZ_ASSERT((IsBaseOf<B, const D>::value) == true);
MOZ_ASSERT((IsBaseOf<B, const B>::value) == true);
MOZ_ASSERT((IsBaseOf<D, B>::value) == false);
MOZ_ASSERT((IsBaseOf<B&, D&>::value) == false);
MOZ_ASSERT((IsBaseOf<B[3], D[3]>::value) == false);
static_assert((IsBaseOf<B, D>::value) == true, "IsBaseOf fails on diamond");
static_assert((IsBaseOf<const B, D>::value) == true, "IsBaseOf fails on diamond plus constness change");
static_assert((IsBaseOf<B, const D>::value) == true, "IsBaseOf fails on diamond plus constness change");
static_assert((IsBaseOf<B, const B>::value) == true, "IsBaseOf fails on constness change");
static_assert((IsBaseOf<D, B>::value) == false, "IsBaseOf got the direction of inheritance wrong");
static_assert((IsBaseOf<B&, D&>::value) == false, "IsBaseOf should return false on references");
static_assert((IsBaseOf<B[3], D[3]>::value) == false, "IsBaseOf should return false on arrays");
// We fail at the following test. To fix it, we need to specialize IsBaseOf
// for all built-in types.
// MOZ_ASSERT((IsBaseOf<int, int>::value) == false);
// static_assert((IsBaseOf<int, int>::value) == false);
}
} /* namespace CPlusPlus11IsBaseOf */
@ -186,23 +186,23 @@ class F : public B, public E { };
static void
TestIsBaseOf()
{
MOZ_ASSERT((IsBaseOf<A, B>::value),
static_assert((IsBaseOf<A, B>::value),
"A is a base of B");
MOZ_ASSERT((!IsBaseOf<B, A>::value),
static_assert((!IsBaseOf<B, A>::value),
"B is not a base of A");
MOZ_ASSERT((IsBaseOf<A, C>::value),
static_assert((IsBaseOf<A, C>::value),
"A is a base of C");
MOZ_ASSERT((!IsBaseOf<C, A>::value),
static_assert((!IsBaseOf<C, A>::value),
"C is not a base of A");
MOZ_ASSERT((IsBaseOf<A, F>::value),
static_assert((IsBaseOf<A, F>::value),
"A is a base of F");
MOZ_ASSERT((!IsBaseOf<F, A>::value),
static_assert((!IsBaseOf<F, A>::value),
"F is not a base of A");
MOZ_ASSERT((!IsBaseOf<A, D>::value),
static_assert((!IsBaseOf<A, D>::value),
"A is not a base of D");
MOZ_ASSERT((!IsBaseOf<D, A>::value),
static_assert((!IsBaseOf<D, A>::value),
"D is not a base of A");
MOZ_ASSERT((IsBaseOf<B, B>::value),
static_assert((IsBaseOf<B, B>::value),
"B is the same as B (and therefore, a base of B)");
}
@ -210,34 +210,34 @@ static void
TestIsConvertible()
{
// Pointer type convertibility
MOZ_ASSERT((IsConvertible<A*, A*>::value),
static_assert((IsConvertible<A*, A*>::value),
"A* should convert to A*");
MOZ_ASSERT((IsConvertible<B*, A*>::value),
static_assert((IsConvertible<B*, A*>::value),
"B* should convert to A*");
MOZ_ASSERT((!IsConvertible<A*, B*>::value),
static_assert((!IsConvertible<A*, B*>::value),
"A* shouldn't convert to B*");
MOZ_ASSERT((!IsConvertible<A*, C*>::value),
static_assert((!IsConvertible<A*, C*>::value),
"A* shouldn't convert to C*");
MOZ_ASSERT((!IsConvertible<A*, D*>::value),
static_assert((!IsConvertible<A*, D*>::value),
"A* shouldn't convert to unrelated D*");
MOZ_ASSERT((!IsConvertible<D*, A*>::value),
static_assert((!IsConvertible<D*, A*>::value),
"D* shouldn't convert to unrelated A*");
// Instance type convertibility
MOZ_ASSERT((IsConvertible<A, A>::value),
static_assert((IsConvertible<A, A>::value),
"A is A");
MOZ_ASSERT((IsConvertible<B, A>::value),
static_assert((IsConvertible<B, A>::value),
"B converts to A");
MOZ_ASSERT((!IsConvertible<D, A>::value),
static_assert((!IsConvertible<D, A>::value),
"D and A are unrelated");
MOZ_ASSERT((!IsConvertible<A, D>::value),
static_assert((!IsConvertible<A, D>::value),
"A and D are unrelated");
// These cases seem to require C++11 support to properly implement them, so
// for now just disable them.
//MOZ_ASSERT((!IsConvertible<C*, A*>::value),
//static_assert((!IsConvertible<C*, A*>::value),
// "C* shouldn't convert to A* (private inheritance)");
//MOZ_ASSERT((!IsConvertible<C, A>::value),
//static_assert((!IsConvertible<C, A>::value),
// "C doesn't convert to A (private inheritance)");
}

Просмотреть файл

@ -38,8 +38,8 @@ Example()
// Destroying the underlying object clears weak pointers to it.
delete ptr;
MOZ_ASSERT(!weak, "Deleting |ptr| clears weak pointers to it.");
MOZ_ASSERT(!other, "Deleting |ptr| clears all weak pointers to it.");
MOZ_RELEASE_ASSERT(!weak, "Deleting |ptr| clears weak pointers to it.");
MOZ_RELEASE_ASSERT(!other, "Deleting |ptr| clears all weak pointers to it.");
}
struct A : public SupportsWeakPtr<A>
@ -63,13 +63,13 @@ main()
WeakPtr<A> ptr = a->asWeakPtr();
{
WeakPtr<A> ptr2 = a->asWeakPtr();
MOZ_ASSERT(ptr->data == 5);
MOZ_RELEASE_ASSERT(ptr->data == 5);
WeakPtr<A> ptr3 = a->asWeakPtr();
MOZ_ASSERT(ptr->data == 5);
MOZ_RELEASE_ASSERT(ptr->data == 5);
}
delete a;
MOZ_ASSERT(!ptr);
MOZ_RELEASE_ASSERT(!ptr);
delete a2;