00001
00034 #include <tut/tut.h>
00035 #include "linden_common.h"
00036 #include "bitpack.h"
00037 #include "lltut.h"
00038
00039
00040 namespace tut
00041 {
00042 struct bit_pack
00043 {
00044 };
00045 typedef test_group<bit_pack> bit_pack_t;
00046 typedef bit_pack_t::object bit_pack_object_t;
00047 tut::bit_pack_t tut_bit_pack("bitpack");
00048
00049
00050 template<> template<>
00051 void bit_pack_object_t::test<1>()
00052 {
00053 U8 packbuffer[255];
00054 U8 unpackbuffer[255];
00055 int pack_bufsize = 0;
00056 int unpack_bufsize = 0;
00057
00058 LLBitPack bitpack(packbuffer, 255);
00059
00060 char str[] = "SecondLife is a 3D virtual world";
00061 int len = sizeof(str);
00062 pack_bufsize = bitpack.bitPack((U8*) str, len*8);
00063 pack_bufsize = bitpack.flushBitPack();
00064
00065 LLBitPack bitunpack(packbuffer, pack_bufsize*8);
00066 unpack_bufsize = bitunpack.bitUnpack(unpackbuffer, len*8);
00067 ensure("bitPack: unpack size should be same as string size prior to pack", len == unpack_bufsize);
00068 ensure_memory_matches("str->bitPack->bitUnpack should be equal to string", str, len, unpackbuffer, unpack_bufsize);
00069 }
00070
00071
00072 template<> template<>
00073 void bit_pack_object_t::test<2>()
00074 {
00075 U8 packbuffer[255];
00076 U8 unpackbuffer[255];
00077 int pack_bufsize = 0;
00078 int unpack_bufsize = 0;
00079
00080 LLBitPack bitpack(packbuffer, 255);
00081
00082 char str[] = "SecondLife";
00083 int len = sizeof(str);
00084 pack_bufsize = bitpack.bitPack((U8*) str, len*8);
00085 pack_bufsize = bitpack.flushBitPack();
00086
00087 LLBitPack bitunpack(packbuffer, pack_bufsize*8);
00088 unpack_bufsize = bitunpack.bitUnpack(&unpackbuffer[0], 8);
00089 ensure("bitPack: individual unpack: 0", unpackbuffer[0] == (U8) str[0]);
00090 unpack_bufsize = bitunpack.bitUnpack(&unpackbuffer[0], 8);
00091 ensure("bitPack: individual unpack: 1", unpackbuffer[0] == (U8) str[1]);
00092 unpack_bufsize = bitunpack.bitUnpack(&unpackbuffer[0], 8);
00093 ensure("bitPack: individual unpack: 2", unpackbuffer[0] == (U8) str[2]);
00094 unpack_bufsize = bitunpack.bitUnpack(&unpackbuffer[0], 8);
00095 ensure("bitPack: individual unpack: 3", unpackbuffer[0] == (U8) str[3]);
00096 unpack_bufsize = bitunpack.bitUnpack(&unpackbuffer[0], 8);
00097 ensure("bitPack: individual unpack: 4", unpackbuffer[0] == (U8) str[4]);
00098 unpack_bufsize = bitunpack.bitUnpack(&unpackbuffer[0], 8);
00099 ensure("bitPack: individual unpack: 5", unpackbuffer[0] == (U8) str[5]);
00100 unpack_bufsize = bitunpack.bitUnpack(unpackbuffer, 8*4);
00101 ensure_memory_matches("bitPack: 4 bytes unpack:", unpackbuffer, 4, str+6, 4);
00102 }
00103
00104
00105 template<> template<>
00106 void bit_pack_object_t::test<3>()
00107 {
00108 U8 packbuffer[255];
00109 int pack_bufsize = 0;
00110
00111 LLBitPack bitpack(packbuffer, 255);
00112 U32 num = 0x41fab67a;
00113 pack_bufsize = bitpack.bitPack((U8*)&num, 8*sizeof(U32));
00114 pack_bufsize = bitpack.flushBitPack();
00115
00116 LLBitPack bitunpack(packbuffer, pack_bufsize*8);
00117 U32 res = 0;
00118
00119
00120 bitunpack.bitUnpack((U8*) &res, sizeof(res)*8);
00121 ensure("U32->bitPack->bitUnpack->U32 should be equal", num == res);
00122 }
00123 }