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
parent e65c7cb8bd
commit feb2f8ac64

View File

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