File: endian.cpp

package info (click to toggle)
nsis 2.37-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 8,860 kB
  • ctags: 8,113
  • sloc: cpp: 32,080; ansic: 29,202; python: 1,118; xml: 451; pascal: 113; makefile: 80
file content (56 lines) | stat: -rwxr-xr-x 1,460 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <cppunit/extensions/HelperMacros.h>
#include "../Platform.h"

class EndianTest : public CppUnit::TestFixture {

  CPPUNIT_TEST_SUITE( EndianTest );
  CPPUNIT_TEST( testSwapEndian );
  CPPUNIT_TEST( testFixEndian16 );
  CPPUNIT_TEST( testFixEndian32 );
  CPPUNIT_TEST_SUITE_END();

public:
  void testSwapEndian() {
    CPPUNIT_ASSERT_EQUAL( (int)0x78563412, (int)SWAP_ENDIAN_INT32(0x12345678) );
    CPPUNIT_ASSERT_EQUAL( (int)0xFFFFFFFF, (int)SWAP_ENDIAN_INT32(0xFFFFFFFF) );
    CPPUNIT_ASSERT_EQUAL( (int)0, (int)SWAP_ENDIAN_INT32(0) );
    CPPUNIT_ASSERT_EQUAL( (int)0x3412, (int)SWAP_ENDIAN_INT16(0x1234) );
    CPPUNIT_ASSERT_EQUAL( (int)0xFFFF, (int)SWAP_ENDIAN_INT16(0xFFFF) );
    CPPUNIT_ASSERT_EQUAL( (int)0, (int)SWAP_ENDIAN_INT16(0) );
  }

  void testFixEndian32() {
    int i=1;
    int actual = 0x12345678;
    FIX_ENDIAN_INT32_INPLACE(actual);
    int expected;
    if (((char*)&i)[0] == 1) {
      // little endian
      expected = 0x12345678;
    }
    else {
      // big endian
      expected = 0x78563412;
    }
    CPPUNIT_ASSERT_EQUAL(expected, actual);
  }

  void testFixEndian16() {
    int i=1;
    int actual = 0x1234;
    FIX_ENDIAN_INT16_INPLACE(actual);
    int expected;
    if (((char*)&i)[0] == 1) {
      // little endian
      expected = 0x1234;
    }
    else {
      // big endian
      expected = 0x3412;
    }
    CPPUNIT_ASSERT_EQUAL(expected, actual);
  }

};

CPPUNIT_TEST_SUITE_REGISTRATION( EndianTest );