Style fixes and proper-numeric-type usage in mfbt/tests/TestEndian.cpp. No bug, r=trivial

--HG--
extra : rebase_source : 54a658a6baf78852a3f8839b2cbb98700a7c91e7
This commit is contained in:
Jeff Walden 2013-06-13 19:27:11 -07:00
Родитель 66b88396c7
Коммит 13aed03de7
1 изменённых файлов: 30 добавлений и 28 удалений

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

@ -6,6 +6,8 @@
#include "mozilla/DebugOnly.h" #include "mozilla/DebugOnly.h"
#include "mozilla/Endian.h" #include "mozilla/Endian.h"
#include <stddef.h>
using mozilla::BigEndian; using mozilla::BigEndian;
using mozilla::DebugOnly; using mozilla::DebugOnly;
using mozilla::LittleEndian; using mozilla::LittleEndian;
@ -51,7 +53,7 @@ TestSingleNoSwap(T value, T notSwappedValue)
#define WRAP_COPYTO(NAME) \ #define WRAP_COPYTO(NAME) \
template<typename T> \ template<typename T> \
void \ void \
NAME(void* dst, const T* src, unsigned int count) \ NAME(void* dst, const T* src, size_t count) \
{ \ { \
NativeEndian::NAME<T>(dst, src, count); \ NativeEndian::NAME<T>(dst, src, count); \
} }
@ -63,7 +65,7 @@ WRAP_COPYTO(copyAndSwapToNetworkOrder)
#define WRAP_COPYFROM(NAME) \ #define WRAP_COPYFROM(NAME) \
template<typename T> \ template<typename T> \
void \ void \
NAME(T* dst, const void* src, unsigned int count) \ NAME(T* dst, const void* src, size_t count) \
{ \ { \
NativeEndian::NAME<T>(dst, src, count); \ NativeEndian::NAME<T>(dst, src, count); \
} }
@ -75,7 +77,7 @@ WRAP_COPYFROM(copyAndSwapFromNetworkOrder)
#define WRAP_IN_PLACE(NAME) \ #define WRAP_IN_PLACE(NAME) \
template<typename T> \ template<typename T> \
void \ void \
NAME(T* p, unsigned int count) \ NAME(T* p, size_t count) \
{ \ { \
NativeEndian::NAME<T>(p, count); \ NativeEndian::NAME<T>(p, count); \
} }
@ -91,14 +93,14 @@ enum SwapExpectation {
NoSwap NoSwap
}; };
template<typename T, size_t count> template<typename T, size_t Count>
void void
TestBulkSwapToSub(enum SwapExpectation expectSwap, TestBulkSwapToSub(enum SwapExpectation expectSwap,
const T (&values)[count], const T (&values)[Count],
void (*swapperFunc)(void*, const T*, unsigned int), void (*swapperFunc)(void*, const T*, size_t),
T (*readerFunc)(const void*)) T (*readerFunc)(const void*))
{ {
const size_t arraySize = 2 * count; const size_t arraySize = 2 * Count;
const size_t bufferSize = arraySize * sizeof(T); const size_t bufferSize = arraySize * sizeof(T);
static uint8_t buffer[bufferSize]; static uint8_t buffer[bufferSize];
const uint8_t fillValue = 0xa5; const uint8_t fillValue = 0xa5;
@ -109,7 +111,7 @@ TestBulkSwapToSub(enum SwapExpectation expectSwap,
memset(checkBuffer, fillValue, bufferSize); memset(checkBuffer, fillValue, bufferSize);
for (size_t startPosition = 0; startPosition < sizeof(T); ++startPosition) { for (size_t startPosition = 0; startPosition < sizeof(T); ++startPosition) {
for (size_t nValues = 0; nValues < count; ++nValues) { for (size_t nValues = 0; nValues < Count; ++nValues) {
memset(buffer, fillValue, bufferSize); memset(buffer, fillValue, bufferSize);
swapperFunc(buffer + startPosition, values, nValues); swapperFunc(buffer + startPosition, values, nValues);
@ -130,14 +132,14 @@ TestBulkSwapToSub(enum SwapExpectation expectSwap,
} }
} }
template<typename T, size_t count> template<typename T, size_t Count>
void void
TestBulkSwapFromSub(enum SwapExpectation expectSwap, TestBulkSwapFromSub(enum SwapExpectation expectSwap,
const T (&values)[count], const T (&values)[Count],
void (*swapperFunc)(T*, const void*, unsigned int), void (*swapperFunc)(T*, const void*, size_t),
T (*readerFunc)(const void*)) T (*readerFunc)(const void*))
{ {
const size_t arraySize = 2 * count; const size_t arraySize = 2 * Count;
const size_t bufferSize = arraySize * sizeof(T); const size_t bufferSize = arraySize * sizeof(T);
static T buffer[arraySize]; static T buffer[arraySize];
const uint8_t fillValue = 0xa5; const uint8_t fillValue = 0xa5;
@ -145,8 +147,8 @@ TestBulkSwapFromSub(enum SwapExpectation expectSwap,
memset(checkBuffer, fillValue, bufferSize); memset(checkBuffer, fillValue, bufferSize);
for (size_t startPosition = 0; startPosition < count; ++startPosition) { for (size_t startPosition = 0; startPosition < Count; ++startPosition) {
for (size_t nValues = 0; nValues < (count - startPosition); ++nValues) { for (size_t nValues = 0; nValues < (Count - startPosition); ++nValues) {
memset(buffer, fillValue, bufferSize); memset(buffer, fillValue, bufferSize);
swapperFunc(buffer + startPosition, values, nValues); swapperFunc(buffer + startPosition, values, nValues);
@ -166,14 +168,14 @@ TestBulkSwapFromSub(enum SwapExpectation expectSwap,
} }
template<typename T, size_t count> template<typename T, size_t Count>
void void
TestBulkInPlaceSub(enum SwapExpectation expectSwap, TestBulkInPlaceSub(enum SwapExpectation expectSwap,
const T (&values)[count], const T (&values)[Count],
void (*swapperFunc)(T* p, unsigned int), void (*swapperFunc)(T* p, size_t),
T (*readerFunc)(const void*)) T (*readerFunc)(const void*))
{ {
const size_t bufferCount = 4 * count; const size_t bufferCount = 4 * Count;
const size_t bufferSize = bufferCount * sizeof(T); const size_t bufferSize = bufferCount * sizeof(T);
static T buffer[bufferCount]; static T buffer[bufferCount];
const T fillValue = 0xa5; const T fillValue = 0xa5;
@ -183,8 +185,8 @@ TestBulkInPlaceSub(enum SwapExpectation expectSwap,
memset(checkBuffer, fillValue, bufferSize); memset(checkBuffer, fillValue, bufferSize);
for (size_t startPosition = 0; startPosition < count; ++startPosition) { for (size_t startPosition = 0; startPosition < Count; ++startPosition) {
for (size_t nValues = 0; nValues < count; ++nValues) { for (size_t nValues = 0; nValues < Count; ++nValues) {
memset(buffer, fillValue, bufferSize); memset(buffer, fillValue, bufferSize);
memcpy(buffer + startPosition, values, nValues * sizeof(T)); memcpy(buffer + startPosition, values, nValues * sizeof(T));
swapperFunc(buffer + startPosition, nValues); swapperFunc(buffer + startPosition, nValues);
@ -224,9 +226,9 @@ SPECIALIZE_READER(int16_t, readInt16)
SPECIALIZE_READER(int32_t, readInt32) SPECIALIZE_READER(int32_t, readInt32)
SPECIALIZE_READER(int64_t, readInt64) SPECIALIZE_READER(int64_t, readInt64)
template<typename T, size_t count> template<typename T, size_t Count>
void void
TestBulkSwap(const T (&bytes)[count]) TestBulkSwap(const T (&bytes)[Count])
{ {
#if MOZ_LITTLE_ENDIAN #if MOZ_LITTLE_ENDIAN
TestBulkSwapToSub(Swap, bytes, copyAndSwapToBigEndian<T>, Reader<T>::readBE); TestBulkSwapToSub(Swap, bytes, copyAndSwapToBigEndian<T>, Reader<T>::readBE);
@ -239,9 +241,9 @@ TestBulkSwap(const T (&bytes)[count])
#endif #endif
} }
template<typename T, size_t count> template<typename T, size_t Count>
void void
TestBulkNoSwap(const T (&bytes)[count]) TestBulkNoSwap(const T (&bytes)[Count])
{ {
#if MOZ_LITTLE_ENDIAN #if MOZ_LITTLE_ENDIAN
TestBulkSwapToSub(NoSwap, bytes, copyAndSwapToLittleEndian<T>, Reader<T>::readLE); TestBulkSwapToSub(NoSwap, bytes, copyAndSwapToLittleEndian<T>, Reader<T>::readLE);
@ -254,9 +256,9 @@ TestBulkNoSwap(const T (&bytes)[count])
#endif #endif
} }
template<typename T, size_t count> template<typename T, size_t Count>
void void
TestBulkInPlaceSwap(const T (&bytes)[count]) TestBulkInPlaceSwap(const T (&bytes)[Count])
{ {
#if MOZ_LITTLE_ENDIAN #if MOZ_LITTLE_ENDIAN
TestBulkInPlaceSub(Swap, bytes, swapToBigEndianInPlace<T>, Reader<T>::readBE); TestBulkInPlaceSub(Swap, bytes, swapToBigEndianInPlace<T>, Reader<T>::readBE);
@ -269,9 +271,9 @@ TestBulkInPlaceSwap(const T (&bytes)[count])
#endif #endif
} }
template<typename T, size_t count> template<typename T, size_t Count>
void void
TestBulkInPlaceNoSwap(const T (&bytes)[count]) TestBulkInPlaceNoSwap(const T (&bytes)[Count])
{ {
#if MOZ_LITTLE_ENDIAN #if MOZ_LITTLE_ENDIAN
TestBulkInPlaceSub(NoSwap, bytes, swapToLittleEndianInPlace<T>, Reader<T>::readLE); TestBulkInPlaceSub(NoSwap, bytes, swapToLittleEndianInPlace<T>, Reader<T>::readLE);