first-ever CppUnit unit tests
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@3679 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
bec8d601c2
commit
2da10af05b
4 changed files with 175 additions and 1 deletions
36
Source/Tests/endian.cpp
Normal file
36
Source/Tests/endian.cpp
Normal file
|
@ -0,0 +1,36 @@
|
|||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include "../util.h"
|
||||
|
||||
class EndianTest : public CppUnit::TestFixture {
|
||||
|
||||
CPPUNIT_TEST_SUITE( EndianTest );
|
||||
CPPUNIT_TEST( testSwapEndian );
|
||||
CPPUNIT_TEST( testFixEndian );
|
||||
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) );
|
||||
}
|
||||
|
||||
void testFixEndian() {
|
||||
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);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( EndianTest );
|
Loading…
Add table
Add a link
Reference in a new issue