ProteoWizard
Functions
endian_test.cpp File Reference
#include "Std.hpp"
#include "endian.hpp"
#include "pwiz/utility/misc/unit.hpp"

Go to the source code of this file.

Functions

void test ()
int main (int argc, const char *argv[])

Function Documentation

void test ( )

Definition at line 31 of file endian_test.cpp.

References pwiz::util::endianize32(), pwiz::util::endianize64(), and unit_assert.

{
unsigned char bytes[] = {0xce, 0xfa, 0xca, 0xca, 0xfe, 0xca, 0x20, 0x04};
unsigned int n = *reinterpret_cast<unsigned int*>(bytes);
#if defined(PWIZ_LITTLE_ENDIAN)
unit_assert(n == 0xcacaface);
unit_assert(endianize32(n) == 0xcefacaca);
#elif defined(PWIZ_BIG_ENDIAN)
unit_assert(n == 0xcefacaca);
unit_assert(endianize32(n) == 0xcacaface);
#endif
unsigned long long m = *reinterpret_cast<unsigned long long*>(bytes);
#if defined(PWIZ_LITTLE_ENDIAN)
unit_assert(m == 0x420cafecacafacell);
unit_assert(endianize64(m) == 0xcefacacafeca2004ll);
#elif defined(PWIZ_BIG_ENDIAN)
unit_assert(m == 0xcefacacafeca2004ll);
unit_assert(endianize64(m) == 0x420cafecacafacell);
#endif
}
int main ( int  argc,
const char *  argv[] 
)

Definition at line 56 of file endian_test.cpp.

References e(), test(), TEST_EPILOG, TEST_FAILED, and TEST_PROLOG.

{
TEST_PROLOG(argc, argv)
try
{
test();
}
catch (exception& e)
{
TEST_FAILED(e.what())
}
catch (...)
{
TEST_FAILED("Caught unknown exception.")
}
}