lldatapacker_tut.cpp

Go to the documentation of this file.
00001 
00034 #include <tut/tut.h>
00035 #include "lltut.h"
00036 #include "linden_common.h"
00037 #include "lldatapacker.h"
00038 #include "v4color.h"
00039 #include "v4coloru.h"
00040 #include "v2math.h"
00041 #include "v3math.h"
00042 #include "v4math.h"
00043 #include "llsdserialize.h"
00044 
00045 #define TEST_FILE_NAME  "datapacker_test.txt"
00046 namespace tut
00047 {
00048         struct datapacker_test
00049         {
00050         };
00051         typedef test_group<datapacker_test> datapacker_test_t;
00052         typedef datapacker_test_t::object datapacker_test_object_t;
00053         tut::datapacker_test_t tut_datapacker_test("datapacker_test");
00054 
00055         //*********LLDataPackerBinaryBuffer
00056         template<> template<>
00057         void datapacker_test_object_t::test<1>()
00058         {
00059                 U8 packbuf[128];
00060                 F32 f_val1 = 44.44f, f_unpkval1;
00061                 F32 f_val2 = 12344.443232f, f_unpkval2;
00062                 F32 f_val3 = 44.4456789f, f_unpkval3;
00063                 LLDataPackerBinaryBuffer lldp(packbuf,128);
00064                 lldp.packFixed( f_val1, "linden_lab", FALSE, 8, 8);
00065                 lldp.packFixed( f_val2, "linden_lab", FALSE, 14, 16);
00066                 lldp.packFixed( f_val3, "linden_lab", FALSE, 8, 23);
00067 
00068                 LLDataPackerBinaryBuffer lldp1(packbuf, lldp.getCurrentSize());
00069                 lldp1.unpackFixed(f_unpkval1, "linden_lab", FALSE, 8, 8);
00070                 lldp1.unpackFixed(f_unpkval2, "linden_lab", FALSE, 14, 16);
00071                 lldp1.unpackFixed(f_unpkval3, "linden_lab", FALSE, 8, 23);
00072                 ensure_approximately_equals("LLDataPackerBinaryBuffer::packFixed 8 failed", f_val1, f_unpkval1, 8);
00073                 ensure_approximately_equals("LLDataPackerBinaryBuffer::packFixed 16 failed", f_val2, f_unpkval2, 16);
00074                 ensure_approximately_equals("LLDataPackerBinaryBuffer::packFixed 23 failed", f_val3, f_unpkval3, 31);
00075         }
00076 
00077         template<> template<>
00078         void datapacker_test_object_t::test<2>()
00079         {
00080                 U8 packbuf[1024];
00081 
00082                 char str[] = "SecondLife is virtual World\0";
00083                 char strBinary[] = "SecondLife is virtual World";
00084                 char strBinaryFixed[] = "Fixed Data";
00085                 S32 sizeBinaryFixed = sizeof(strBinaryFixed);
00086                 U8 valU8 = 'C';
00087                 U16 valU16 = 0xFFFF;
00088                 U32 valU32 = 0xFFFFFFFF;
00089                 S32 valS32 = -94967295;
00090                 F32 valF32 = 4354355.44f ;
00091                 LLColor4 llcol4(3.3f, 0, 4.4f, 5.5f);
00092                 LLColor4U llcol4u(3, 128, 24, 33);
00093                 LLVector2 llvec2(333.33f, 444.44f);
00094                 LLVector3 llvec3(333.33f, 444.44f, 555.55f);
00095                 LLVector4 llvec4(333.33f, 444.44f, 555.55f, 666.66f);
00096                 LLUUID uuid;
00097 
00098                 std::string unpkstr;
00099                 char unpkstrBinary[256];
00100                 char unpkstrBinaryFixed[256];
00101                 S32 unpksizeBinary;
00102                 U8 unpkvalU8;
00103                 U16 unpkvalU16;
00104                 U32 unpkvalU32;
00105                 S32 unpkvalS32;
00106                 F32 unpkvalF32;
00107                 LLColor4 unpkllcol4;
00108                 LLColor4U unpkllcol4u;
00109                 LLVector2 unpkllvec2;
00110                 LLVector3 unpkllvec3;
00111                 LLVector4 unpkllvec4;
00112                 LLUUID unpkuuid;
00113 
00114                 LLDataPackerBinaryBuffer lldp(packbuf,1024);
00115                 lldp.packString(str , "linden_lab_str");
00116                 lldp.packBinaryData((U8*)strBinary, sizeof(strBinary), "linden_lab_bd");
00117                 lldp.packBinaryDataFixed((U8*)strBinaryFixed, sizeBinaryFixed, "linden_lab_bdf");
00118                 lldp.packU8(valU8,"linden_lab_u8");
00119                 lldp.packU16(valU16,"linden_lab_u16");
00120                 lldp.packU32(valU32, "linden_lab_u32");
00121                 lldp.packS32(valS32, "linden_lab_s32");
00122                 lldp.packF32(valF32, "linden_lab_f32");
00123                 lldp.packColor4(llcol4, "linden_lab_col4");
00124                 lldp.packColor4U(llcol4u, "linden_lab_col4u");
00125                 lldp.packVector2(llvec2, "linden_lab_vec2");
00126                 lldp.packVector3(llvec3, "linden_lab_vec3");
00127                 lldp.packVector4(llvec4, "linden_lab_vec4");
00128                 uuid.generate();
00129                 lldp.packUUID(uuid, "linden_lab_uuid");
00130 
00131                 S32 cur_size = lldp.getCurrentSize();
00132 
00133                 LLDataPackerBinaryBuffer lldp1(packbuf, cur_size);
00134                 lldp1.unpackString(unpkstr , "linden_lab_str");
00135                 lldp1.unpackBinaryData((U8*)unpkstrBinary, unpksizeBinary, "linden_lab_bd");
00136                 lldp1.unpackBinaryDataFixed((U8*)unpkstrBinaryFixed, sizeBinaryFixed, "linden_lab_bdf");
00137                 lldp1.unpackU8(unpkvalU8,"linden_lab_u8");
00138                 lldp1.unpackU16(unpkvalU16,"linden_lab_u16");
00139                 lldp1.unpackU32(unpkvalU32, "linden_lab_u32");
00140                 lldp1.unpackS32(unpkvalS32, "linden_lab_s32");
00141                 lldp1.unpackF32(unpkvalF32, "linden_lab_f32");
00142                 lldp1.unpackColor4(unpkllcol4, "linden_lab_col4");
00143                 lldp1.unpackColor4U(unpkllcol4u, "linden_lab_col4u");
00144                 lldp1.unpackVector2(unpkllvec2, "linden_lab_vec2");
00145                 lldp1.unpackVector3(unpkllvec3, "linden_lab_vec3");
00146                 lldp1.unpackVector4(unpkllvec4, "linden_lab_vec4");
00147                 lldp1.unpackUUID(unpkuuid, "linden_lab_uuid");
00148 
00149                 ensure("LLDataPackerBinaryBuffer::packString failed", strcmp(str, unpkstr.c_str())  == 0);
00150                 ensure("LLDataPackerBinaryBuffer::packBinaryData failed", strcmp(strBinary, unpkstrBinary)  == 0);
00151                 ensure("LLDataPackerBinaryBuffer::packBinaryDataFixed failed", strcmp(strBinaryFixed, unpkstrBinaryFixed) == 0);
00152                 ensure_equals("LLDataPackerBinaryBuffer::packU8 failed", valU8, unpkvalU8);
00153                 ensure_equals("LLDataPackerBinaryBuffer::packU16 failed", valU16, unpkvalU16);
00154                 ensure_equals("LLDataPackerBinaryBuffer::packU32 failed", valU32, unpkvalU32);
00155                 ensure_equals("LLDataPackerBinaryBuffer::packS32 failed", valS32, unpkvalS32);
00156                 ensure("LLDataPackerBinaryBuffer::packF32 failed", is_approx_equal(valF32, unpkvalF32));
00157                 ensure_equals("LLDataPackerBinaryBuffer::packColor4 failed", llcol4, unpkllcol4);
00158                 ensure_equals("LLDataPackerBinaryBuffer::packColor4U failed", llcol4u, unpkllcol4u);
00159                 ensure_equals("LLDataPackerBinaryBuffer::packVector2 failed", llvec2, unpkllvec2);
00160                 ensure_equals("LLDataPackerBinaryBuffer::packVector3 failed", llvec3, unpkllvec3);
00161                 ensure_equals("LLDataPackerBinaryBuffer::packVector4 failed", llvec4, unpkllvec4);
00162                 ensure_equals("LLDataPackerBinaryBuffer::packUUID failed", uuid, unpkuuid);
00163         }
00164 
00165         template<> template<>
00166         void datapacker_test_object_t::test<3>()
00167         {
00168                 U8 packbuf[128];
00169                 char str[] = "SecondLife is virtual World";
00170                 S32 strSize = sizeof(str); // include '\0'
00171                 LLDataPackerBinaryBuffer lldp(packbuf, 128);
00172                 lldp.packString(str , "linden_lab");
00173 
00174                 ensure("LLDataPackerBinaryBuffer: current size is wrong", strSize == lldp.getCurrentSize());
00175                 ensure("LLDataPackerBinaryBuffer: buffer size is wrong", 128 == lldp.getBufferSize());
00176 
00177                 lldp.reset();
00178                 ensure("LLDataPackerBinaryBuffer::reset failed",0 == lldp.getCurrentSize());
00179         }
00180 
00181         template<> template<>
00182         void datapacker_test_object_t::test<4>()
00183         {
00184                 U8* packbuf = new U8[128];
00185                 char str[] = "SecondLife is virtual World";
00186                 LLDataPackerBinaryBuffer lldp(packbuf, 128);
00187                 lldp.packString(str , "linden_lab");
00188                 lldp.freeBuffer();
00189                 ensure("LLDataPackerBinaryBuffer.freeBuffer failed" , 0 == lldp.getBufferSize());
00190 
00191         }
00192 
00193         template<> template<>
00194         void datapacker_test_object_t::test<5>()
00195         {
00196                 U8 buf[] = "SecondLife is virtual World";
00197                 S32 size = sizeof(buf);
00198                 LLDataPackerBinaryBuffer lldp(buf, size);
00199                 U8 new_buf[] = "Its Amazing";
00200                 size = sizeof(new_buf);
00201                 lldp.assignBuffer(new_buf, size);
00202                 ensure("LLDataPackerBinaryBuffer::assignBuffer failed" , ((lldp.getBufferSize() == size) && (0 == lldp.getCurrentSize()))) ;
00203         }
00204 
00205         template<> template<>
00206         void datapacker_test_object_t::test<6>()
00207         {
00208                 U8 packbuf[128];
00209                 char str[] = "SecondLife is virtual World";
00210                 LLDataPackerBinaryBuffer lldp(packbuf, 128);
00211                 lldp.packString(str , "linden_lab");
00212                 U8 new_buffer[128];
00213                 std::string unpkbuf;
00214                 LLDataPackerBinaryBuffer lldp1(new_buffer,128); 
00215                 lldp1 = lldp;
00216                 lldp1.unpackString(unpkbuf, "linden_lab");
00217                 ensure("1. LLDataPackerBinaryBuffer::operator= failed" , lldp1.getBufferSize() == lldp.getBufferSize());
00218                 ensure_equals("2.LLDataPackerBinaryBuffer::operator= failed", str,unpkbuf);
00219         }
00220 
00221         //*********LLDataPackerAsciiBuffer
00222 
00223         template<> template<>
00224         void datapacker_test_object_t::test<7>()
00225         {
00226                 char packbuf[128];
00227                 F32 f_val = 44.44f, f_unpkval;
00228                 LLDataPackerAsciiBuffer lldp(packbuf,128);
00229                 lldp.packFixed( f_val, "linden_lab", FALSE, 8, 8);
00230 
00231                 LLDataPackerAsciiBuffer lldp1(packbuf, lldp.getCurrentSize());
00232                 lldp1.unpackFixed(f_unpkval, "linden_lab", FALSE, 8, 8);
00233                 ensure_approximately_equals("LLDataPackerAsciiBuffer::packFixed failed", f_val, f_unpkval, 8);
00234         }
00235 
00236         template<> template<>
00237         void datapacker_test_object_t::test<8>()
00238         {
00239                 char packbuf[1024];
00240 
00241                 char str[] = "SecondLife is virtual World\0";
00242                 char strBinary[] = "SecondLife is virtual World";
00243                 char strBinaryFixed[] = "Fixed Data";
00244                 S32 sizeBinaryFixed = sizeof(strBinaryFixed);
00245                 U8 valU8 = 'C';
00246                 U16 valU16 = 0xFFFF;
00247                 U32 valU32 = 0xFFFFFFFF;
00248                 S32 valS32 = -94967295;
00249                 F32 valF32 = 4354355.44f ;
00250                 LLColor4 llcol4(3.3f, 0, 4.4f, 5.5f);
00251                 LLColor4U llcol4u(3, 128, 24, 33);
00252                 LLVector2 llvec2(333.33f, 444.44f);
00253                 LLVector3 llvec3(333.33f, 444.44f, 555.55f);
00254                 LLVector4 llvec4(4354355.44f, 444.44f, 555.55f, 666.66f);
00255                 LLUUID uuid;
00256 
00257                 std::string unpkstr;
00258                 char unpkstrBinary[256];
00259                 char unpkstrBinaryFixed[256];
00260                 S32 unpksizeBinary;
00261                 U8 unpkvalU8;
00262                 U16 unpkvalU16;
00263                 U32 unpkvalU32;
00264                 S32 unpkvalS32;
00265                 F32 unpkvalF32;
00266                 LLColor4 unpkllcol4;
00267                 LLColor4U unpkllcol4u;
00268                 LLVector2 unpkllvec2;
00269                 LLVector3 unpkllvec3;
00270                 LLVector4 unpkllvec4;
00271                 LLUUID unpkuuid;
00272 
00273                 LLDataPackerAsciiBuffer lldp(packbuf,1024);
00274                 lldp.packString(str , "linden_lab_str");
00275                 lldp.packBinaryData((U8*)strBinary, sizeof(strBinary), "linden_lab_bd");
00276                 lldp.packBinaryDataFixed((U8*)strBinaryFixed, sizeBinaryFixed, "linden_lab_bdf");
00277                 lldp.packU8(valU8,"linden_lab_u8");
00278                 lldp.packU16(valU16,"linden_lab_u16");
00279                 lldp.packU32(valU32, "linden_lab_u32");
00280                 lldp.packS32(valS32, "linden_lab_s32");
00281                 lldp.packF32(valF32, "linden_lab_f32");
00282                 lldp.packColor4(llcol4, "linden_lab_col4");
00283                 lldp.packColor4U(llcol4u, "linden_lab_col4u");
00284                 lldp.packVector2(llvec2, "linden_lab_vec2");
00285                 lldp.packVector3(llvec3, "linden_lab_vec3");
00286                 lldp.packVector4(llvec4, "linden_lab_vec4");
00287                 uuid.generate();
00288                 lldp.packUUID(uuid, "linden_lab_uuid");
00289 
00290                 S32 cur_size = lldp.getCurrentSize();
00291 
00292                 LLDataPackerAsciiBuffer lldp1(packbuf, cur_size);
00293                 lldp1.unpackString(unpkstr , "linden_lab_str");
00294                 lldp1.unpackBinaryData((U8*)unpkstrBinary, unpksizeBinary, "linden_lab_bd");
00295                 lldp1.unpackBinaryDataFixed((U8*)unpkstrBinaryFixed, sizeBinaryFixed, "linden_lab_bdf");
00296                 lldp1.unpackU8(unpkvalU8,"linden_lab_u8");
00297                 lldp1.unpackU16(unpkvalU16,"linden_lab_u16");
00298                 lldp1.unpackU32(unpkvalU32, "linden_lab_u32");
00299                 lldp1.unpackS32(unpkvalS32, "linden_lab_s32");
00300                 lldp1.unpackF32(unpkvalF32, "linden_lab_f32");
00301                 lldp1.unpackColor4(unpkllcol4, "linden_lab_col4");
00302                 lldp1.unpackColor4U(unpkllcol4u, "linden_lab_col4u");
00303                 lldp1.unpackVector2(unpkllvec2, "linden_lab_vec2");
00304                 lldp1.unpackVector3(unpkllvec3, "linden_lab_vec3");
00305                 lldp1.unpackVector4(unpkllvec4, "linden_lab_vec4");
00306                 lldp1.unpackUUID(unpkuuid, "linden_lab_uuid");
00307 
00308                 ensure("LLDataPackerAsciiBuffer::packString failed", strcmp(str, unpkstr.c_str())  == 0);
00309                 ensure("LLDataPackerAsciiBuffer::packBinaryData failed", strcmp(strBinary, unpkstrBinary)  == 0);
00310                 ensure("LLDataPackerAsciiBuffer::packBinaryDataFixed failed", strcmp(strBinaryFixed, unpkstrBinaryFixed) == 0);
00311                 ensure_equals("LLDataPackerAsciiBuffer::packU8 failed", valU8, unpkvalU8);
00312                 ensure_equals("LLDataPackerAsciiBuffer::packU16 failed", valU16, unpkvalU16);
00313                 ensure_equals("LLDataPackerAsciiBuffer::packU32 failed", valU32, unpkvalU32);
00314                 ensure_equals("LLDataPackerAsciiBuffer::packS32 failed", valS32, unpkvalS32);
00315                 ensure("LLDataPackerAsciiBuffer::packF32 failed", is_approx_equal(valF32, unpkvalF32));
00316                 ensure_equals("LLDataPackerAsciiBuffer::packColor4 failed", llcol4, unpkllcol4);
00317                 ensure_equals("LLDataPackerAsciiBuffer::packColor4U failed", llcol4u, unpkllcol4u);
00318                 ensure_equals("LLDataPackerAsciiBuffer::packVector2 failed", llvec2, unpkllvec2);
00319                 ensure_equals("LLDataPackerAsciiBuffer::packVector3 failed", llvec3, unpkllvec3);
00320                 ensure_equals("LLDataPackerAsciiBuffer::packVector4 failed", llvec4, unpkllvec4);
00321                 ensure_equals("LLDataPackerAsciiBuffer::packUUID failed", uuid, unpkuuid);
00322         }
00323 
00324         template<> template<>
00325         void datapacker_test_object_t::test<9>()
00326         {
00327                 char* packbuf = new char[128];
00328                 char str[] = "SecondLife is virtual World";
00329                 LLDataPackerAsciiBuffer lldp(packbuf, 128);
00330                 lldp.packString(str , "linden_lab");
00331                 lldp.freeBuffer();
00332                 ensure("LLDataPackerAsciiBuffer::freeBuffer failed" , 0 == lldp.getBufferSize());
00333         }
00334 
00335         template<> template<>
00336         void datapacker_test_object_t::test<10>()
00337         {
00338                 char buf[] = "SecondLife is virtual World";
00339                 S32 size = sizeof(buf);
00340                 LLDataPackerAsciiBuffer lldp(buf, size);
00341                 char new_buf[] = "Its Amazing";
00342                 size = sizeof(new_buf);
00343                 lldp.assignBuffer(new_buf, size);
00344                 ensure("LLDataPackerAsciiBuffer::assignBuffer failed" , ((lldp.getBufferSize() == size) && (1 == lldp.getCurrentSize()))) ;
00345         }
00346 
00347         //*********LLDataPackerAsciiFile
00348 
00349         template<> template<>
00350         void datapacker_test_object_t::test<11>()
00351         {
00352                 F32 f_val = 44.44f, f_unpkval;
00353 
00354                 FILE* fp = fopen(TEST_FILE_NAME, "w+");
00355                 if(!fp)
00356                 {
00357                         llerrs << "File couldnt be open" <<llendl;
00358                         return;
00359                 }
00360 
00361                 LLDataPackerAsciiFile lldp(fp,2);
00362                 lldp.packFixed( f_val, "linden_lab", FALSE, 8, 8);
00363 
00364                 fflush(fp);     
00365                 fseek(fp,0,SEEK_SET);
00366                 LLDataPackerAsciiFile lldp1(fp,2);
00367 
00368                 lldp1.unpackFixed(f_unpkval, "linden_lab", FALSE, 8, 8);
00369                 fclose(fp);
00370 
00371                 ensure_approximately_equals("LLDataPackerAsciiFile::packFixed failed", f_val, f_unpkval, 8);
00372         }
00373 
00374         template<> template<>
00375         void datapacker_test_object_t::test<12>()
00376         {
00377                 char str[] = "SecondLife is virtual World\0";
00378                 char strBinary[] = "SecondLife is virtual World";
00379                 char strBinaryFixed[] = "Fixed Data";
00380                 S32 sizeBinaryFixed = sizeof(strBinaryFixed);
00381                 U8 valU8 = 'C';
00382                 U16 valU16 = 0xFFFF;
00383                 U32 valU32 = 0xFFFFFFFF;
00384                 S32 valS32 = -94967295;
00385                 F32 valF32 = 4354355.44f ;
00386                 LLColor4 llcol4(3.3f, 0, 4.4f, 5.5f);
00387                 LLColor4U llcol4u(3, 128, 24, 33);
00388                 LLVector2 llvec2(333.33f, 444.44f);
00389                 LLVector3 llvec3(333.33f, 444.44f, 555.55f);
00390                 LLVector4 llvec4(333.33f, 444.44f, 555.55f, 666.66f);
00391                 LLUUID uuid;
00392 
00393                 std::string unpkstr;
00394                 char unpkstrBinary[256];
00395                 char unpkstrBinaryFixed[256];
00396                 S32 unpksizeBinary;
00397                 U8 unpkvalU8;
00398                 U16 unpkvalU16;
00399                 U32 unpkvalU32;
00400                 S32 unpkvalS32;
00401                 F32 unpkvalF32;
00402                 LLColor4 unpkllcol4;
00403                 LLColor4U unpkllcol4u;
00404                 LLVector2 unpkllvec2;
00405                 LLVector3 unpkllvec3;
00406                 LLVector4 unpkllvec4;
00407                 LLUUID unpkuuid;
00408 
00409                 FILE* fp = fopen(TEST_FILE_NAME,"w+");
00410                 if(!fp)
00411                 {
00412                         llerrs << "File couldnt be open" <<llendl;
00413                         return;
00414                 }
00415 
00416                 LLDataPackerAsciiFile lldp(fp,2);
00417 
00418                 lldp.packString(str , "linden_lab_str");
00419                 lldp.packBinaryData((U8*)strBinary, sizeof(strBinary), "linden_lab_bd");
00420                 lldp.packBinaryDataFixed((U8*)strBinaryFixed, sizeBinaryFixed, "linden_lab_bdf");
00421                 lldp.packU8(valU8,"linden_lab_u8");
00422                 lldp.packU16(valU16,"linden_lab_u16");
00423                 lldp.packU32(valU32, "linden_lab_u32");
00424                 lldp.packS32(valS32, "linden_lab_s32");
00425                 lldp.packF32(valF32, "linden_lab_f32");
00426                 lldp.packColor4(llcol4, "linden_lab_col4");
00427                 lldp.packColor4U(llcol4u, "linden_lab_col4u");
00428                 lldp.packVector2(llvec2, "linden_lab_vec2");
00429                 lldp.packVector3(llvec3, "linden_lab_vec3");
00430                 lldp.packVector4(llvec4, "linden_lab_vec4");
00431                 uuid.generate();
00432                 lldp.packUUID(uuid, "linden_lab_uuid");
00433 
00434                 fflush(fp);     
00435                 fseek(fp,0,SEEK_SET);
00436                 LLDataPackerAsciiFile lldp1(fp,2);
00437 
00438                 lldp1.unpackString(unpkstr , "linden_lab_str");
00439                 lldp1.unpackBinaryData((U8*)unpkstrBinary, unpksizeBinary, "linden_lab_bd");
00440                 lldp1.unpackBinaryDataFixed((U8*)unpkstrBinaryFixed, sizeBinaryFixed, "linden_lab_bdf");
00441                 lldp1.unpackU8(unpkvalU8,"linden_lab_u8");
00442                 lldp1.unpackU16(unpkvalU16,"linden_lab_u16");
00443                 lldp1.unpackU32(unpkvalU32, "linden_lab_u32");
00444                 lldp1.unpackS32(unpkvalS32, "linden_lab_s32");
00445                 lldp1.unpackF32(unpkvalF32, "linden_lab_f32");
00446                 lldp1.unpackColor4(unpkllcol4, "linden_lab_col4");
00447                 lldp1.unpackColor4U(unpkllcol4u, "linden_lab_col4u");
00448                 lldp1.unpackVector2(unpkllvec2, "linden_lab_vec2");
00449                 lldp1.unpackVector3(unpkllvec3, "linden_lab_vec3");
00450                 lldp1.unpackVector4(unpkllvec4, "linden_lab_vec4");
00451                 lldp1.unpackUUID(unpkuuid, "linden_lab_uuid");
00452 
00453                 fclose(fp);
00454 
00455                 ensure("LLDataPackerAsciiFile::packString failed", strcmp(str, unpkstr.c_str())  == 0);
00456                 ensure("LLDataPackerAsciiFile::packBinaryData failed", strcmp(strBinary, unpkstrBinary)  == 0);
00457                 ensure("LLDataPackerAsciiFile::packBinaryDataFixed failed", strcmp(strBinaryFixed, unpkstrBinaryFixed) == 0);
00458                 ensure_equals("LLDataPackerAsciiFile::packU8 failed", valU8, unpkvalU8);
00459                 ensure_equals("LLDataPackerAsciiFile::packU16 failed", valU16, unpkvalU16);
00460                 ensure_equals("LLDataPackerAsciiFile::packU32 failed", valU32, unpkvalU32);
00461                 ensure_equals("LLDataPackerAsciiFile::packS32 failed", valS32, unpkvalS32);
00462                 ensure("LLDataPackerAsciiFile::packF32 failed", is_approx_equal(valF32, unpkvalF32));
00463                 ensure_equals("LLDataPackerAsciiFile::packColor4 failed", llcol4, unpkllcol4);
00464                 ensure_equals("LLDataPackerAsciiFile::packColor4U failed", llcol4u, unpkllcol4u);
00465                 ensure_equals("LLDataPackerAsciiFile::packVector2 failed", llvec2, unpkllvec2);
00466                 ensure_equals("LLDataPackerAsciiFile::packVector3 failed", llvec3, unpkllvec3);
00467                 ensure_equals("LLDataPackerAsciiFile::packVector4 failed", llvec4, unpkllvec4);
00468                 ensure_equals("LLDataPackerAsciiFile::packUUID failed", uuid, unpkuuid);
00469         }
00470 
00471         template<> template<>
00472         void datapacker_test_object_t::test<13>()
00473         {
00474                 F32 f_val = 44.44f, f_unpkval;
00475 
00476                 std::ostringstream ostr;
00477                 LLDataPackerAsciiFile lldp(ostr,2);
00478                 lldp.packFixed( f_val, "linden_lab", FALSE, 8, 8);
00479 
00480                 std::istringstream istr(ostr.str());
00481                 LLDataPackerAsciiFile lldp1(istr,2);
00482 
00483                 lldp1.unpackFixed(f_unpkval, "linden_lab", FALSE, 8, 8);
00484 
00485                 ensure_approximately_equals("LLDataPackerAsciiFile::packFixed (iostring) failed", f_val, f_unpkval, 8);
00486         }
00487 
00488         template<> template<>
00489         void datapacker_test_object_t::test<14>()
00490         {
00491                 char str[] = "SecondLife is virtual World\0";
00492                 char strBinary[] = "SecondLife is virtual World";
00493                 char strBinaryFixed[] = "Fixed Data";
00494                 S32 sizeBinaryFixed = sizeof(strBinaryFixed);
00495                 U8 valU8 = 'C';
00496                 U16 valU16 = 0xFFFF;
00497                 U32 valU32 = 0xFFFFFFFF;
00498                 S32 valS32 = -94967295;
00499                 F32 valF32 = 4354355.44f ;
00500                 LLColor4 llcol4(3.3f, 0, 4.4f, 5.5f);
00501                 LLColor4U llcol4u(3, 128, 24, 33);
00502                 LLVector2 llvec2(3333333.33f, 444.333344f);
00503                 LLVector3 llvec3(3323233.33f, 444.4324f, 555.553232f);
00504                 LLVector4 llvec4(333.33233f, 444.4323234f, 55323225.55f, 6323236.66f);
00505                 LLUUID uuid;
00506 
00507                 std::string unpkstr;
00508                 char unpkstrBinary[256];
00509                 char unpkstrBinaryFixed[256];
00510                 S32 unpksizeBinary;
00511                 U8 unpkvalU8;
00512                 U16 unpkvalU16;
00513                 U32 unpkvalU32;
00514                 S32 unpkvalS32;
00515                 F32 unpkvalF32;
00516                 LLColor4 unpkllcol4;
00517                 LLColor4U unpkllcol4u;
00518                 LLVector2 unpkllvec2;
00519                 LLVector3 unpkllvec3;
00520                 LLVector4 unpkllvec4;
00521                 LLUUID unpkuuid;
00522 
00523                 std::ostringstream ostr;
00524                 LLDataPackerAsciiFile lldp(ostr,2);
00525 
00526                 lldp.packString(str , "linden_lab_str");
00527                 lldp.packBinaryData((U8*)strBinary, sizeof(strBinary), "linden_lab_bd");
00528                 lldp.packBinaryDataFixed((U8*)strBinaryFixed, sizeBinaryFixed, "linden_lab_bdf");
00529                 lldp.packU8(valU8,"linden_lab_u8");
00530                 lldp.packU16(valU16,"linden_lab_u16");
00531                 lldp.packU32(valU32, "linden_lab_u32");
00532                 lldp.packS32(valS32, "linden_lab_s32");
00533                 lldp.packF32(valF32, "linden_lab_f32");
00534                 lldp.packColor4(llcol4, "linden_lab_col4");
00535                 lldp.packColor4U(llcol4u, "linden_lab_col4u");
00536                 lldp.packVector2(llvec2, "linden_lab_vec2");
00537                 lldp.packVector3(llvec3, "linden_lab_vec3");
00538                 lldp.packVector4(llvec4, "linden_lab_vec4");
00539                 uuid.generate();
00540                 lldp.packUUID(uuid, "linden_lab_uuid");
00541 
00542                 std::istringstream istr(ostr.str());
00543                 LLDataPackerAsciiFile lldp1(istr,2);
00544 
00545                 lldp1.unpackString(unpkstr , "linden_lab_str");
00546                 lldp1.unpackBinaryData((U8*)unpkstrBinary, unpksizeBinary, "linden_lab_bd");
00547                 lldp1.unpackBinaryDataFixed((U8*)unpkstrBinaryFixed, sizeBinaryFixed, "linden_lab_bdf");
00548                 lldp1.unpackU8(unpkvalU8,"linden_lab_u8");
00549                 lldp1.unpackU16(unpkvalU16,"linden_lab_u16");
00550                 lldp1.unpackU32(unpkvalU32, "linden_lab_u32");
00551                 lldp1.unpackS32(unpkvalS32, "linden_lab_s32");
00552                 lldp1.unpackF32(unpkvalF32, "linden_lab_f32");
00553                 lldp1.unpackColor4(unpkllcol4, "linden_lab_col4");
00554                 lldp1.unpackColor4U(unpkllcol4u, "linden_lab_col4u");
00555                 lldp1.unpackVector2(unpkllvec2, "linden_lab_vec2");
00556                 lldp1.unpackVector3(unpkllvec3, "linden_lab_vec3");
00557                 lldp1.unpackVector4(unpkllvec4, "linden_lab_vec4");
00558                 lldp1.unpackUUID(unpkuuid, "linden_lab_uuid");
00559 
00560                 ensure("LLDataPackerAsciiFile::packString (iostring) failed", strcmp(str, unpkstr.c_str())  == 0);
00561                 ensure("LLDataPackerAsciiFile::packBinaryData (iostring) failed", strcmp(strBinary, unpkstrBinary)  == 0);
00562                 ensure("LLDataPackerAsciiFile::packBinaryDataFixed (iostring) failed", strcmp(strBinaryFixed, unpkstrBinaryFixed) == 0);
00563                 ensure_equals("LLDataPackerAsciiFile::packU8 (iostring) failed", valU8, unpkvalU8);
00564                 ensure_equals("LLDataPackerAsciiFile::packU16 (iostring) failed", valU16, unpkvalU16);
00565                 ensure_equals("LLDataPackerAsciiFile::packU32 (iostring) failed", valU32, unpkvalU32);
00566                 ensure_equals("LLDataPackerAsciiFile::packS32 (iostring) failed", valS32, unpkvalS32);
00567                 ensure("LLDataPackerAsciiFile::packF32 (iostring) failed", is_approx_equal(valF32, unpkvalF32));
00568                 ensure_equals("LLDataPackerAsciiFile::packColor4 (iostring) failed", llcol4, unpkllcol4);
00569                 ensure_equals("LLDataPackerAsciiFile::packColor4U (iostring) failed", llcol4u, unpkllcol4u);
00570                 ensure_equals("LLDataPackerAsciiFile::packVector2 (iostring) failed", llvec2, unpkllvec2);
00571                 ensure_equals("LLDataPackerAsciiFile::packVector3 (iostring) failed", llvec3, unpkllvec3);
00572                 ensure_equals("LLDataPackerAsciiFile::packVector4 (iostring) failed", llvec4, unpkllvec4);
00573                 ensure_equals("LLDataPackerAsciiFile::packUUID (iostring) failed", uuid, unpkuuid);
00574         }
00575 }

Generated on Thu Jul 1 06:08:24 2010 for Second Life Viewer by  doxygen 1.4.7