From b8f9503c8da618382214820f75c0bff632e8ccc1 Mon Sep 17 00:00:00 2001 From: drbob Date: Sun, 20 Jun 2010 14:28:26 +0000 Subject: [PATCH] * Updated tlvbase_test.cc git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3178 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- .../src/tests/serialiser/tlvbase_test.cc | 70 +++++++++++-------- 1 file changed, 40 insertions(+), 30 deletions(-) diff --git a/libretroshare/src/tests/serialiser/tlvbase_test.cc b/libretroshare/src/tests/serialiser/tlvbase_test.cc index f6d15423e..1f0e92def 100644 --- a/libretroshare/src/tests/serialiser/tlvbase_test.cc +++ b/libretroshare/src/tests/serialiser/tlvbase_test.cc @@ -30,6 +30,7 @@ #include #include #include +#include #include "serialiser/rstlvbase.h" #include "util/utest.h" @@ -57,11 +58,15 @@ int test_RsTlvBase() std::string out; - + + // First two bytes are type. data[0]=0; data[1]=0; + // Next 4 bytes is size. data[2]=0; - data[3]=8; + data[3]=0; + data[4]=0; + data[5]=10; uint32_t off =0; GetTlvString((void*)data, 20, &off, 0, out); @@ -69,7 +74,7 @@ int test_RsTlvBase() std::cout << "Output is : " << out << std::endl; - uint16_t data2[] = {0, 0x0300}; + uint16_t data2[] = {0, 0, 0x0300}; uint16_t t = GetTlvSize((void*) data2); @@ -84,16 +89,17 @@ int test_RsTlvBase() //*************Test SetTlvBase*********** { - uint16_t data3 [2]; + uint16_t data3 [3]; off =0; uint32_t *offset = &off; - uint32_t const SIZE_SetTlvBase=4; + uint32_t const SIZE_SetTlvBase=6; uint32_t val_before = *offset; - SetTlvBase((void *)data3, SIZE_SetTlvBase, offset, 0x0011, 0x0001); + uint32_t base_set_size = 0x1234567; + SetTlvBase((void *)data3, SIZE_SetTlvBase, offset, 0x0011, base_set_size); CHECK(*offset - val_before == SIZE_SetTlvBase); CHECK(0x0011 == ntohs(data3[0])); - CHECK(0x0001 == ntohs(data3[1])); + CHECK(base_set_size == ntohl(*((uint32_t *) &(data3[1])))); } @@ -105,41 +111,42 @@ int test_RsTlvBase() * test GetTlvUInt32 & SetTlvGetUInt32 */ { - uint16_t data4[4]; + uint16_t data4[5]; bool ok = true; uint32_t off =0; uint32_t pre_set_off = off; uint32_t* offset = &off; uint32_t out = 3324; *offset =0; - ok = SetTlvUInt32((void*)data4, 8, offset, 0x0011, out); - CHECK(*offset - pre_set_off == 8); + ok = SetTlvUInt32((void*)data4, 10, offset, 0x0011, out); + CHECK(*offset - pre_set_off == 10); uint32_t readPos = 0; offset = &readPos; uint32_t in =0; - ok &= GetTlvUInt32((void*)data4, 8, offset, 0x0011, &in); - CHECK(*offset - pre_set_off == 8); + ok &= GetTlvUInt32((void*)data4, 10, offset, 0x0011, &in); + CHECK(*offset - pre_set_off == 10); CHECK(in == out); std::cerr<<"in = " <