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, char *argv[])
 

Function Documentation

§ test()

void test ( )

Definition at line 31 of file endian_test.cpp.

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

Referenced by main().

32 {
33  unsigned char bytes[] = {0xce, 0xfa, 0xca, 0xca, 0xfe, 0xca, 0x20, 0x04};
34  unsigned int n = *reinterpret_cast<unsigned int*>(bytes);
35 
36  #if defined(PWIZ_LITTLE_ENDIAN)
37  unit_assert(n == 0xcacaface);
38  unit_assert(endianize32(n) == 0xcefacaca);
39  #elif defined(PWIZ_BIG_ENDIAN)
40  unit_assert(n == 0xcefacaca);
41  unit_assert(endianize32(n) == 0xcacaface);
42  #endif
43 
44  unsigned long long m = *reinterpret_cast<unsigned long long*>(bytes);
45 
46  #if defined(PWIZ_LITTLE_ENDIAN)
47  unit_assert(m == 0x420cafecacafacell);
48  unit_assert(endianize64(m) == 0xcefacacafeca2004ll);
49  #elif defined(PWIZ_BIG_ENDIAN)
50  unit_assert(m == 0xcefacacafeca2004ll);
51  unit_assert(endianize64(m) == 0x420cafecacafacell);
52  #endif
53 }
unsigned long long endianize64(unsigned long long n)
Definition: endian.hpp:80
unsigned int endianize32(unsigned int n)
Definition: endian.hpp:74
#define unit_assert(x)
Definition: unit.hpp:85

§ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 56 of file endian_test.cpp.

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

57 {
58  TEST_PROLOG(argc, argv)
59 
60  try
61  {
62  test();
63  }
64  catch (exception& e)
65  {
66  TEST_FAILED(e.what())
67  }
68  catch (...)
69  {
70  TEST_FAILED("Caught unknown exception.")
71  }
72 
74 }
#define TEST_EPILOG
Definition: unit.hpp:182
void test()
Definition: endian_test.cpp:31
#define TEST_FAILED(x)
Definition: unit.hpp:176
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:174