| 1 |
|
|---|
| 2 |
#include "UnitTest++.h" |
|---|
| 3 |
#include "OpenSG/OSGBaseFunctions.h" |
|---|
| 4 |
|
|---|
| 5 |
using namespace UnitTest; |
|---|
| 6 |
|
|---|
| 7 |
namespace { |
|---|
| 8 |
|
|---|
| 9 |
struct ByteOrderFixture |
|---|
| 10 |
{ |
|---|
| 11 |
ByteOrderFixture() |
|---|
| 12 |
{ |
|---|
| 13 |
OSG::UInt8 bytes_a[] = |
|---|
| 14 |
{ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, |
|---|
| 15 |
0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10 }; |
|---|
| 16 |
OSG::UInt8 bytes_b[] = |
|---|
| 17 |
{ 0x10, 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, |
|---|
| 18 |
0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; |
|---|
| 19 |
|
|---|
| 20 |
uint16_a = *reinterpret_cast<OSG::UInt16*>(&(bytes_a[0])); |
|---|
| 21 |
uint16_b = *reinterpret_cast<OSG::UInt16*>(&(bytes_b[14])); |
|---|
| 22 |
uint32_a = *reinterpret_cast<OSG::UInt32*>(&(bytes_a[0])); |
|---|
| 23 |
uint32_b = *reinterpret_cast<OSG::UInt32*>(&(bytes_b[12])); |
|---|
| 24 |
uint64_a = *reinterpret_cast<OSG::UInt64*>(&(bytes_a[0])); |
|---|
| 25 |
uint64_b = *reinterpret_cast<OSG::UInt64*>(&(bytes_b[8])); |
|---|
| 26 |
|
|---|
| 27 |
real32_a = *reinterpret_cast<OSG::Real32*>(&(bytes_a[0])); |
|---|
| 28 |
real32_b = *reinterpret_cast<OSG::Real32*>(&(bytes_b[12])); |
|---|
| 29 |
real64_a = *reinterpret_cast<OSG::Real64*>(&(bytes_a[0])); |
|---|
| 30 |
real64_b = *reinterpret_cast<OSG::Real64*>(&(bytes_b[8])); |
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
} |
|---|
| 34 |
|
|---|
| 35 |
~ByteOrderFixture() |
|---|
| 36 |
{ |
|---|
| 37 |
} |
|---|
| 38 |
|
|---|
| 39 |
OSG::UInt16 uint16_a; |
|---|
| 40 |
OSG::UInt16 uint16_b; |
|---|
| 41 |
OSG::UInt32 uint32_a; |
|---|
| 42 |
OSG::UInt32 uint32_b; |
|---|
| 43 |
OSG::UInt64 uint64_a; |
|---|
| 44 |
OSG::UInt64 uint64_b; |
|---|
| 45 |
|
|---|
| 46 |
OSG::Real32 real32_a; |
|---|
| 47 |
OSG::Real32 real32_b; |
|---|
| 48 |
OSG::Real64 real64_a; |
|---|
| 49 |
OSG::Real64 real64_b; |
|---|
| 50 |
OSG::Real128 real128_a; |
|---|
| 51 |
OSG::Real128 real128_b; |
|---|
| 52 |
}; |
|---|
| 53 |
|
|---|
| 54 |
TEST_FIXTURE(ByteOrderFixture, HostToBigEndian) |
|---|
| 55 |
{ |
|---|
| 56 |
#if BYTE_ORDER == LITTLE_ENDIAN |
|---|
| 57 |
CHECK_EQUAL(OSG::osgHostToBigEndian(uint16_a), uint16_b); |
|---|
| 58 |
CHECK_EQUAL(OSG::osgHostToBigEndian(uint32_a), uint32_b); |
|---|
| 59 |
CHECK_EQUAL(OSG::osgHostToBigEndian(uint64_a), uint64_b); |
|---|
| 60 |
CHECK_EQUAL(OSG::osgHostToBigEndian(real32_a), real32_b); |
|---|
| 61 |
CHECK_EQUAL(OSG::osgHostToBigEndian(real64_a), real64_b); |
|---|
| 62 |
|
|---|
| 63 |
#else |
|---|
| 64 |
CHECK_EQUAL(OSG::osgHostToBigEndian(uint16_a), uint16_a); |
|---|
| 65 |
CHECK_EQUAL(OSG::osgHostToBigEndian(uint32_a), uint32_a); |
|---|
| 66 |
CHECK_EQUAL(OSG::osgHostToBigEndian(uint64_a), uint64_a); |
|---|
| 67 |
CHECK_EQUAL(OSG::osgHostToBigEndian(real32_a), real32_a); |
|---|
| 68 |
CHECK_EQUAL(OSG::osgHostToBigEndian(real64_a), real64_a); |
|---|
| 69 |
|
|---|
| 70 |
#endif |
|---|
| 71 |
} |
|---|
| 72 |
|
|---|
| 73 |
TEST_FIXTURE(ByteOrderFixture, HostToLittleEndian) |
|---|
| 74 |
{ |
|---|
| 75 |
#if BYTE_ORDER == LITTLE_ENDIAN |
|---|
| 76 |
CHECK_EQUAL(OSG::osgHostToLittleEndian(uint16_a), uint16_a); |
|---|
| 77 |
CHECK_EQUAL(OSG::osgHostToLittleEndian(uint32_a), uint32_a); |
|---|
| 78 |
CHECK_EQUAL(OSG::osgHostToLittleEndian(uint64_a), uint64_a); |
|---|
| 79 |
CHECK_EQUAL(OSG::osgHostToLittleEndian(real32_a), real32_a); |
|---|
| 80 |
CHECK_EQUAL(OSG::osgHostToLittleEndian(real64_a), real64_a); |
|---|
| 81 |
|
|---|
| 82 |
#else |
|---|
| 83 |
CHECK_EQUAL(OSG::osgHostToLittleEndian(uint16_a), uint16_b); |
|---|
| 84 |
CHECK_EQUAL(OSG::osgHostToLittleEndian(uint32_a), uint32_b); |
|---|
| 85 |
CHECK_EQUAL(OSG::osgHostToLittleEndian(uint64_a), uint64_b); |
|---|
| 86 |
CHECK_EQUAL(OSG::osgHostToLittleEndian(real32_a), real32_b); |
|---|
| 87 |
CHECK_EQUAL(OSG::osgHostToLittleEndian(real64_a), real64_b); |
|---|
| 88 |
|
|---|
| 89 |
#endif |
|---|
| 90 |
} |
|---|
| 91 |
|
|---|
| 92 |
TEST_FIXTURE(ByteOrderFixture, BigEndianToHost) |
|---|
| 93 |
{ |
|---|
| 94 |
#if BYTE_ORDER == LITTLE_ENDIAN |
|---|
| 95 |
CHECK_EQUAL(OSG::osgBigEndianToHost(uint16_a), uint16_b); |
|---|
| 96 |
CHECK_EQUAL(OSG::osgBigEndianToHost(uint32_a), uint32_b); |
|---|
| 97 |
CHECK_EQUAL(OSG::osgBigEndianToHost(uint64_a), uint64_b); |
|---|
| 98 |
CHECK_EQUAL(OSG::osgBigEndianToHost(real32_a), real32_b); |
|---|
| 99 |
CHECK_EQUAL(OSG::osgBigEndianToHost(real64_a), real64_b); |
|---|
| 100 |
|
|---|
| 101 |
#else |
|---|
| 102 |
CHECK_EQUAL(OSG::osgBigEndianToHost(uint16_a), uint16_a); |
|---|
| 103 |
CHECK_EQUAL(OSG::osgBigEndianToHost(uint32_a), uint32_a); |
|---|
| 104 |
CHECK_EQUAL(OSG::osgBigEndianToHost(uint64_a), uint64_a); |
|---|
| 105 |
CHECK_EQUAL(OSG::osgBigEndianToHost(real32_a), real32_a); |
|---|
| 106 |
CHECK_EQUAL(OSG::osgBigEndianToHost(real64_a), real64_a); |
|---|
| 107 |
|
|---|
| 108 |
#endif |
|---|
| 109 |
} |
|---|
| 110 |
|
|---|
| 111 |
TEST_FIXTURE(ByteOrderFixture, LittleEndianToHost) |
|---|
| 112 |
{ |
|---|
| 113 |
#if BYTE_ORDER == LITTLE_ENDIAN |
|---|
| 114 |
CHECK_EQUAL(OSG::osgLittleEndianToHost(uint16_a), uint16_a); |
|---|
| 115 |
CHECK_EQUAL(OSG::osgLittleEndianToHost(uint32_a), uint32_a); |
|---|
| 116 |
CHECK_EQUAL(OSG::osgLittleEndianToHost(uint64_a), uint64_a); |
|---|
| 117 |
CHECK_EQUAL(OSG::osgLittleEndianToHost(real32_a), real32_a); |
|---|
| 118 |
CHECK_EQUAL(OSG::osgLittleEndianToHost(real64_a), real64_a); |
|---|
| 119 |
|
|---|
| 120 |
#else |
|---|
| 121 |
CHECK_EQUAL(OSG::osgLittleEndianToHost(uint16_a), uint16_b); |
|---|
| 122 |
CHECK_EQUAL(OSG::osgLittleEndianToHost(uint32_a), uint32_b); |
|---|
| 123 |
CHECK_EQUAL(OSG::osgLittleEndianToHost(uint64_a), uint64_b); |
|---|
| 124 |
CHECK_EQUAL(OSG::osgLittleEndianToHost(real32_a), real32_b); |
|---|
| 125 |
CHECK_EQUAL(OSG::osgLittleEndianToHost(real64_a), real64_b); |
|---|
| 126 |
|
|---|
| 127 |
#endif |
|---|
| 128 |
} |
|---|
| 129 |
|
|---|
| 130 |
} |
|---|