void test_case() { Key keys[2]; keys[0].ip = 0x12345678; keys[0].port = 0x9abc; keys[1].ip = 0x87654321; keys[1].port = 0xfedc; setTransmitters(keys, 1); char message[17]; char extraMessage[17]; generateMessage(message, 1); char* msg = message; assertLongEquals("Returned msg should has regular type", 1, *msg & 0xff); assertLongEquals("Returned msg should eq what send", 0x78, msg[1] & 0xff); assertLongEquals("Returned msg should eq what send", 0x9a, msg[6] & 0xff); generateMessage(message, 0); generateMessage(extraMessage, 1); assertLongEquals("Returned msg should has alterHashTable type", 2, *msg & 0xff); assertLongEquals("Returned msg again should has regular type", 1, extraMessage[0] & 0xff); assertLongEquals("Returned msg should eq what send", 0x78, msg[1] & 0xff); assertLongEquals("Returned msg should eq what send", 0x9a, msg[6] & 0xff); assertLongEquals("Should return generated msg", msg[7] & 0xff, extraMessage[1] & 0xff); assertLongEquals("Should return generated msg", msg[8] & 0xff, extraMessage[2] & 0xff); assertLongEquals("Should return generated msg", msg[12] & 0xff, extraMessage[6] & 0xff); }
void test_charArrayToKey() { Key key = {0x02468ace, 0x1379}; char array[13]; *(array + 1) = 0xff; *(array + 2) = 0xee; *(array + 3) = 0xdd; *(array + 4) = 0xcc; *(array + 5) = 0xbb; *(array + 6) = 0xaa; charArrayToKey(&key, &array[1]); assertLongEquals("First should eq last ip byte", 0xff, array[1] & 0xff); assertLongEquals("Second should eq pre last ip byte", 0xee, array[2] & 0xff); assertLongEquals("Third should eq after first ip byte", 0xdd, array[3] & 0xff); assertLongEquals("Fourth should eq first ip byte", 0xcc, array[4] & 0xff); assertLongEquals("Fifth should eq last port byte", 0xbb, array[5] & 0xff); assertLongEquals("Sixth should eq first port byte", 0xaa, array[6] & 0xff); }
/** * Test if there is no overflow using 16 bits with absLong function. */ bool absLongTest(void) { signed long value = 40000; signed long absValue = absLong(value); return assertLongEquals(value, absValue, ""); /* appendCRLF(getDebugOutputStreamLogger()); appendString(getDebugOutputStreamLogger(), "absLongTest\n"); appendString(getDebugOutputStreamLogger(), "NORMAL="); appendDec(getDebugOutputStreamLogger(), value); appendCRLF(getDebugOutputStreamLogger()); appendString(getDebugOutputStreamLogger(), "RESULT="); appendDec(getDebugOutputStreamLogger(), absValue); appendCRLF(getDebugOutputStreamLogger()); */ }
void test_keyToCharArray() { Key key = {0x02468ace, 0x1379}; char array[10]; keyToCharArray(&key, &array[1]); assertLongEquals("First should eq last ip byte", 0xce, array[1] & 0xff); assertLongEquals("Second should eq pre last ip byte", 0x8a, array[2] & 0xff); assertLongEquals("Third should eq after first ip byte", 0x46, array[3] & 0xff); assertLongEquals("Fourth should eq first ip byte", 0x02, array[4] & 0xff); assertLongEquals("Fifth should eq last port byte", 0x79, array[5] & 0xff); assertLongEquals("Sixth should eq first port byte", 0x13, array[6] & 0xff); }
void test_compareKeys() { Key key1 = {100, 10}; Key key2 = {100, 10}; assertLongEquals("Compare should eq", 0, compareKeys(&key1, &key2)); key1.ip = 99; assertLongEquals("Firs Keyk is less (ip less)", -1, compareKeys(&key1, &key2)); key1.port = 9; assertLongEquals("Firs Keyk is less (ip less port less)", -1, compareKeys(&key1, &key2)); key1.port = 11; assertLongEquals("Firs Keyk is less (ip less port greater)", -1, compareKeys(&key1, &key2)); key1.ip = 100; key1.port = 10; assertLongEquals("Compare should eq", 0, compareKeys(&key1, &key2)); key1.port = 9; assertLongEquals("Firs Keyk is less (ip eq port less)", -1, compareKeys(&key1, &key2)); key1.ip = 100; key1.port = 10; assertLongEquals("Compare should eq", 0, compareKeys(&key1, &key2)); key1.port = 11; assertLongEquals("Firs Keyk is greater (ip eq port greater)", 1, compareKeys(&key1, &key2)); key1.ip = 101; key1.port = 11; assertLongEquals("Firs Keyk is greater (ip greater port greater)", 1, compareKeys(&key1, &key2)); key1.port = 10; assertLongEquals("Firs Keyk is greater (ip greater port eq)", 1, compareKeys(&key1, &key2)); key1.port = 9; assertLongEquals("Firs Keyk is greater (ip greater port less)", 1, compareKeys(&key1, &key2)); }
void test_hashCode() { Key key = {6900000, 10}; assertLongEquals("Hash should eq ip", 6900000, hashCode(&key)); }