llnamevalue_tut.cpp

Go to the documentation of this file.
00001 
00034 #include "linden_common.h"
00035 #include "lltut.h"
00036 #include "llnamevalue.h"
00037 #include "llsdserialize.h"
00038 
00039 namespace tut
00040 {
00041         struct namevalue_test
00042         {
00043                 namevalue_test() 
00044                 {                       
00045                 }
00046         };
00047         typedef test_group<namevalue_test> namevalue_t;
00048         typedef namevalue_t::object namevalue_object_t;
00049         tut::namevalue_t tut_namevalue("namevalue_test");
00050 
00051         
00052         template<> template<>
00053         void namevalue_object_t::test<1>()
00054         {
00055                 // LLNameValue()
00056                 LLNameValue nValue;
00057                 ensure("mName should have been NULL", nValue.mName == NULL);
00058                 ensure("getTypeEnum failed",nValue.getTypeEnum() == NVT_NULL);
00059                 ensure("getClassEnum failed",nValue.getClassEnum() == NVC_NULL);
00060                 ensure("getSendtoEnum failed",nValue.getSendtoEnum() == NVS_NULL);
00061 
00062                 LLNameValue nValue1(" SecondLife ASSET RW SIM 232324343");
00063 
00064         }
00065 
00066         // LLNameValue(const char* data);
00067         //      LLNameValue(const char* name, const char* data, const char* type, const char* nvclass, const char* nvsendto, 
00068         //                              TNameValueCallback nvcb = NULL, void** user_data = NULL);
00069         template<> template<>
00070         void namevalue_object_t::test<2>()
00071         {
00072                 LLNameValue nValue(" SecondLife ASSET RW S 232324343");
00073                 ensure("mName not set correctly", (0 == strcmp(nValue.mName,"SecondLife")));
00074                 ensure("getTypeEnum failed", nValue.getTypeEnum() == NVT_ASSET);
00075                 ensure("getClassEnum failed", nValue.getClassEnum() == NVC_READ_WRITE);
00076                 ensure("getSendtoEnum failed", nValue.getSendtoEnum() == NVS_SIM);
00077                 ensure("getString failed", (0==strcmp(nValue.getAsset(),"232324343")));
00078                 ensure("sendToData or sendToViewer failed", !nValue.sendToData() && !nValue.sendToViewer());
00079                 
00080                 LLNameValue nValue1("\n\r SecondLife_1 STRING READ_WRITE SIM 232324343");
00081                 ensure("1. mName not set correctly", (0 == strcmp(nValue1.mName,"SecondLife_1")));
00082                 ensure("1. getTypeEnum failed", nValue1.getTypeEnum() == NVT_STRING);
00083                 ensure("1. getClassEnum failed", nValue1.getClassEnum() == NVC_READ_WRITE);
00084                 ensure("1. getSendtoEnum failed", nValue1.getSendtoEnum() == NVS_SIM);
00085                 ensure("1. getString failed", (0==strcmp(nValue1.getString(),"232324343")));
00086                 ensure("1. sendToData or sendToViewer failed", !nValue1.sendToData() && !nValue1.sendToViewer());
00087 
00088                 LLNameValue nValue2("SecondLife", "23.5", "F32", "R", "DS");
00089                 ensure("2. getTypeEnum failed", nValue2.getTypeEnum() == NVT_F32);
00090                 ensure("2. getClassEnum failed", nValue2.getClassEnum() == NVC_READ_ONLY);
00091                 ensure("2. getSendtoEnum failed", nValue2.getSendtoEnum() == NVS_DATA_SIM);
00092                 ensure("2. getF32 failed", *nValue2.getF32() == 23.5f);
00093                 ensure("2. sendToData or sendToViewer failed", nValue2.sendToData() && !nValue2.sendToViewer());
00094 
00095                 LLNameValue nValue3("SecondLife", "-43456787", "S32", "READ_ONLY", "SIM_SPACE");
00096                 ensure("3. getTypeEnum failed", nValue3.getTypeEnum() == NVT_S32);
00097                 ensure("3. getClassEnum failed", nValue3.getClassEnum() == NVC_READ_ONLY);
00098                 ensure("3. getSendtoEnum failed", nValue3.getSendtoEnum() == NVS_DATA_SIM);
00099                 ensure("3. getS32 failed", *nValue3.getS32() == -43456787);
00100                 ensure("sendToData or sendToViewer failed", nValue3.sendToData() && !nValue3.sendToViewer());
00101 
00102                 LLNameValue nValue4("SecondLife", "<1.0, 2.0, 3.0>", "VEC3", "RW", "SV");
00103                 LLVector3 llvec4(1.0, 2.0, 3.0);
00104                 ensure("4. getTypeEnum failed", nValue4.getTypeEnum() == NVT_VEC3);
00105                 ensure("4. getClassEnum failed", nValue4.getClassEnum() == NVC_READ_WRITE);
00106                 ensure("4. getSendtoEnum failed", nValue4.getSendtoEnum() == NVS_SIM_VIEWER);
00107                 ensure("4. getVec3 failed", *nValue4.getVec3() == llvec4);
00108                 ensure("4. sendToData or sendToViewer failed", !nValue4.sendToData() && nValue4.sendToViewer());
00109 
00110                 LLNameValue nValue5("SecondLife", "-1.0, 2.4, 3", "VEC3", "RW", "SIM_VIEWER");
00111                 LLVector3 llvec5(-1.0f, 2.4f, 3);
00112                 ensure("5. getTypeEnum failed", nValue5.getTypeEnum() == NVT_VEC3);
00113                 ensure("5. getClassEnum failed", nValue5.getClassEnum() == NVC_READ_WRITE);
00114                 ensure("5. getSendtoEnum failed", nValue5.getSendtoEnum() == NVS_SIM_VIEWER);
00115                 ensure("5. getVec3 failed", *nValue5.getVec3() == llvec5);
00116                 ensure("5. sendToData or sendToViewer failed", !nValue5.sendToData() && nValue5.sendToViewer());
00117 
00118                 LLNameValue nValue6("SecondLife", "89764323", "U32", "RW", "DSV");
00119                 ensure("6. getTypeEnum failed", nValue6.getTypeEnum() == NVT_U32);
00120                 ensure("6. getClassEnum failed", nValue6.getClassEnum() == NVC_READ_WRITE);
00121                 ensure("6. getSendtoEnum failed", nValue6.getSendtoEnum() == NVS_DATA_SIM_VIEWER);
00122                 ensure("6. getU32 failed", *nValue6.getU32() == 89764323);
00123                 ensure("6. sendToData or sendToViewer failed", nValue6.sendToData() && nValue6.sendToViewer());
00124 
00125                 LLNameValue nValue7("SecondLife", "89764323323232", "U64", "RW", "SIM_SPACE_VIEWER");
00126                 U64 u64_7 = U64L(89764323323232);
00127                 ensure("7. getTypeEnum failed", nValue7.getTypeEnum() == NVT_U64);
00128                 ensure("7. getClassEnum failed", nValue7.getClassEnum() == NVC_READ_WRITE);
00129                 ensure("7. getSendtoEnum failed", nValue7.getSendtoEnum() == NVS_DATA_SIM_VIEWER);
00130                 ensure("7. getU32 failed", *nValue7.getU64() == u64_7);
00131                 ensure("7. sendToData or sendToViewer failed", nValue7.sendToData() && nValue7.sendToViewer());
00132         }
00133 
00134         // LLNameValue(const char* name, const char* data, const char* type, const char* nvclass, 
00135         //                              TNameValueCallback nvcb = NULL, void** user_data = NULL);
00136         template<> template<>
00137         void namevalue_object_t::test<3>()
00138         {
00139                 LLNameValue nValue("SecondLife", "232324343", "ASSET", "READ_WRITE");
00140                 ensure("mName not set correctly", (0 == strcmp(nValue.mName,"SecondLife")));
00141                 ensure("getTypeEnum failed", nValue.getTypeEnum() == NVT_ASSET);
00142                 ensure("getClassEnum failed", nValue.getClassEnum() == NVC_READ_WRITE);
00143                 ensure("getSendtoEnum failed", nValue.getSendtoEnum() == NVS_SIM);
00144                 ensure("getString failed", (0==strcmp(nValue.getAsset(),"232324343")));
00145 
00146                 LLNameValue nValue1("SecondLife", "232324343", "STRING", "READ_WRITE");
00147                 ensure("1. mName not set correctly", (0 == strcmp(nValue1.mName,"SecondLife")));
00148                 ensure("1. getTypeEnum failed", nValue1.getTypeEnum() == NVT_STRING);
00149                 ensure("1. getClassEnum failed", nValue1.getClassEnum() == NVC_READ_WRITE);
00150                 ensure("1. getSendtoEnum failed", nValue1.getSendtoEnum() == NVS_SIM);
00151                 ensure("1. getString failed", (0==strcmp(nValue1.getString(),"232324343")));
00152 
00153                 LLNameValue nValue2("SecondLife", "23.5", "F32", "R");
00154                 ensure("2. getTypeEnum failed", nValue2.getTypeEnum() == NVT_F32);
00155                 ensure("2. getClassEnum failed", nValue2.getClassEnum() == NVC_READ_ONLY);
00156                 ensure("2. getSendtoEnum failed", nValue2.getSendtoEnum() == NVS_SIM);
00157                 ensure("2. getF32 failed", *nValue2.getF32() == 23.5f);
00158 
00159                 LLNameValue nValue3("SecondLife", "-43456787", "S32", "READ_ONLY");
00160                 ensure("3. getTypeEnum failed", nValue3.getTypeEnum() == NVT_S32);
00161                 ensure("3. getClassEnum failed", nValue3.getClassEnum() == NVC_READ_ONLY);
00162                 ensure("3. getSendtoEnum failed", nValue3.getSendtoEnum() == NVS_SIM);
00163                 ensure("3. getS32 failed", *nValue3.getS32() == -43456787);
00164 
00165                 LLNameValue nValue4("SecondLife", "<1.0, 2.0, 3.0>", "VEC3", "RW");
00166                 LLVector3 llvec4(1.0, 2.0, 3.0);
00167                 ensure("4. getTypeEnum failed", nValue4.getTypeEnum() == NVT_VEC3);
00168                 ensure("4. getClassEnum failed", nValue4.getClassEnum() == NVC_READ_WRITE);
00169                 ensure("4. getSendtoEnum failed", nValue4.getSendtoEnum() == NVS_SIM);
00170                 ensure("4. getVec3 failed", *nValue4.getVec3() == llvec4);
00171 
00172                 LLNameValue nValue5("SecondLife", "-1.0, 2.4, 3", "VEC3", "RW");
00173                 LLVector3 llvec5(-1.0f, 2.4f, 3);
00174                 ensure("5. getTypeEnum failed", nValue5.getTypeEnum() == NVT_VEC3);
00175                 ensure("5. getClassEnum failed", nValue5.getClassEnum() == NVC_READ_WRITE);
00176                 ensure("5. getSendtoEnum failed", nValue5.getSendtoEnum() == NVS_SIM);
00177                 ensure("5. getVec3 failed", *nValue5.getVec3() == llvec5);
00178 
00179                 LLNameValue nValue6("SecondLife", "89764323", "U32", "RW");
00180                 ensure("6. getTypeEnum failed", nValue6.getTypeEnum() == NVT_U32);
00181                 ensure("6. getClassEnum failed", nValue6.getClassEnum() == NVC_READ_WRITE);
00182                 ensure("6. getSendtoEnum failed", nValue6.getSendtoEnum() == NVS_SIM);
00183                 ensure("6. getU32 failed", *nValue6.getU32() == 89764323);
00184 
00185                 LLNameValue nValue7("SecondLife", "89764323323232", "U64", "RW");
00186                 U64 u64_7 = U64L(89764323323232);
00187                 ensure("7. getTypeEnum failed", nValue7.getTypeEnum() == NVT_U64);
00188                 ensure("7. getClassEnum failed", nValue7.getClassEnum() == NVC_READ_WRITE);
00189                 ensure("7. getSendtoEnum failed", nValue7.getSendtoEnum() == NVS_SIM);
00190                 ensure("7. getU32 failed", *nValue7.getU64() == u64_7);
00191         }
00192 
00193         // LLNameValue(const char* name, const char* type, const char* nvclass, 
00194         //                              TNameValueCallback nvcb = NULL, void** user_data = NULL);
00195         template<> template<>
00196         void namevalue_object_t::test<4>()
00197         {
00198                 LLNameValue nValue("SecondLife",  "STRING", "READ_WRITE");
00199                 ensure("mName not set correctly", (0 == strcmp(nValue.mName,"SecondLife")));
00200                 ensure("getTypeEnum failed", nValue.getTypeEnum() == NVT_STRING);
00201                 ensure("getClassEnum failed", nValue.getClassEnum() == NVC_READ_WRITE);
00202                 ensure("getSendtoEnum failed", nValue.getSendtoEnum() == NVS_SIM);
00203 
00204                 LLNameValue nValue1("SecondLife",  "ASSET", "READ_WRITE");
00205                 ensure("1. mName not set correctly", (0 == strcmp(nValue1.mName,"SecondLife")));
00206                 ensure("1. getTypeEnum for RW failed", nValue1.getTypeEnum() == NVT_ASSET);
00207                 ensure("1. getClassEnum for RW failed", nValue1.getClassEnum() == NVC_READ_WRITE);
00208                 ensure("1. getSendtoEnum for RW failed", nValue1.getSendtoEnum() == NVS_SIM);
00209 
00210                 LLNameValue nValue2("SecondLife", "F32", "READ_ONLY");
00211                 ensure("2. getTypeEnum failed", nValue2.getTypeEnum() == NVT_F32);
00212                 ensure("2. getClassEnum failed", nValue2.getClassEnum() == NVC_READ_ONLY);
00213                 ensure("2. getSendtoEnum failed", nValue2.getSendtoEnum() == NVS_SIM);
00214 
00215                 LLNameValue nValue3("SecondLife", "S32", "READ_ONLY");
00216                 ensure("3. getTypeEnum failed", nValue3.getTypeEnum() == NVT_S32);
00217                 ensure("3. getClassEnum failed", nValue3.getClassEnum() == NVC_READ_ONLY);
00218                 ensure("3. getSendtoEnum failed", nValue3.getSendtoEnum() == NVS_SIM);
00219 
00220                 LLNameValue nValue4("SecondLife", "VEC3", "READ_WRITE");
00221                 ensure("4. getTypeEnum failed", nValue4.getTypeEnum() == NVT_VEC3);
00222                 ensure("4. getClassEnum failed", nValue4.getClassEnum() == NVC_READ_WRITE);
00223                 ensure("4. getSendtoEnum failed", nValue4.getSendtoEnum() == NVS_SIM);
00224 
00225                 LLNameValue nValue6("SecondLife", "U32", "READ_WRITE");
00226                 ensure("6. getTypeEnum failed", nValue6.getTypeEnum() == NVT_U32);
00227                 ensure("6. getClassEnum failed", nValue6.getClassEnum() == NVC_READ_WRITE);
00228                 ensure("6. getSendtoEnum failed", nValue6.getSendtoEnum() == NVS_SIM);
00229 
00230                 LLNameValue nValue7("SecondLife", "U64", "READ_WRITE");
00231                 ensure("7. getTypeEnum failed", nValue7.getTypeEnum() == NVT_U64);
00232                 ensure("7. getClassEnum failed", nValue7.getClassEnum() == NVC_READ_WRITE);
00233                 ensure("7. getSendtoEnum failed", nValue7.getSendtoEnum() == NVS_SIM);
00234         }
00235 
00236         template<> template<>
00237         void namevalue_object_t::test<5>()
00238         {
00239                 LLNameValue nValue("SecondLife", "This is a test", "STRING", "RW", "SIM");
00240 
00241                 ensure("getString failed", (0 == strcmp(nValue.getString(),"This is a test")));
00242         }
00243 
00244         template<> template<>
00245         void namevalue_object_t::test<6>()
00246         {
00247                 LLNameValue nValue("SecondLife", "This is a test", "ASSET", "RW", "S");
00248                 ensure("getAsset failed", (0 == strcmp(nValue.getAsset(),"This is a test")));
00249         }
00250                 
00251         template<> template<>
00252         void namevalue_object_t::test<7>()
00253         {
00254                 LLNameValue nValue("SecondLife", "555555", "F32", "RW", "SIM");
00255                 
00256                 ensure("getF32 failed",*nValue.getF32() == 555555.f);
00257         }
00258 
00259         template<> template<>
00260         void namevalue_object_t::test<8>()
00261         {
00262                 LLNameValue nValue("SecondLife", "-5555", "S32", "RW", "SIM");
00263 
00264                 ensure("getS32 failed", *nValue.getS32() == -5555);
00265 
00266                 S32 sVal = 0x7FFFFFFF;
00267                 nValue.setS32(sVal);
00268                 ensure("getS32 failed", *nValue.getS32() == sVal);
00269 
00270                 sVal = -0x7FFFFFFF;
00271                 nValue.setS32(sVal);
00272                 ensure("getS32 failed", *nValue.getS32() == sVal);
00273 
00274                 sVal = 0;
00275                 nValue.setS32(sVal);
00276                 ensure("getS32 failed", *nValue.getS32() == sVal);
00277         }
00278         
00279         template<> template<>
00280         void namevalue_object_t::test<9>()
00281         {
00282                 LLNameValue nValue("SecondLife", "<-3, 2, 1>", "VEC3", "RW", "SIM");
00283                 LLVector3 vecExpected(-3, 2, 1);
00284                 LLVector3 vec;
00285                 nValue.getVec3(vec);
00286                 ensure("getVec3 failed", vec == vecExpected);
00287         }
00288         
00289         template<> template<>
00290         void namevalue_object_t::test<10>()
00291         {
00292                 LLNameValue nValue("SecondLife", "12345678", "U32", "RW", "SIM");
00293 
00294                 ensure("getU32 failed",*nValue.getU32() == 12345678);
00295 
00296                 U32 val = 0xFFFFFFFF;
00297                 nValue.setU32(val);
00298                 ensure("U32 max", *nValue.getU32() == val);
00299 
00300                 val = 0;
00301                 nValue.setU32(val);             
00302                 ensure("U32 min", *nValue.getU32() == val);
00303         }
00304         
00305         template<> template<>
00306         void namevalue_object_t::test<11>()
00307         {
00308                 //skip_fail("incomplete support for U64.");
00309                 LLNameValue nValue("SecondLife", "44444444444", "U64", "RW", "SIM");
00310 
00311                 ensure("getU64 failed",*nValue.getU64() == U64L(44444444444));
00312 
00313                 // there is no LLNameValue::setU64()  
00314         }
00315         
00316         
00317         template<> template<>
00318         void namevalue_object_t::test<12>()
00319         {
00320                 //skip_fail("incomplete support for U64.");
00321                 LLNameValue nValue("SecondLife U64 RW DSV 44444444444");        
00322                 std::string ret_str = nValue.printNameValue();
00323                 
00324                 ensure_equals("1:printNameValue failed",ret_str,"SecondLife U64 RW DSV 44444444444");
00325                 
00326                 LLNameValue nValue1(ret_str.c_str());
00327                 ensure_equals("Serialization of printNameValue failed", *nValue.getU64(), *nValue1.getU64());           
00328         }
00329 
00330         template<> template<>
00331         void namevalue_object_t::test<13>()
00332         {
00333                 LLNameValue nValue("SecondLife STRING RW DSV 44444444444");     
00334                 std::string ret_str = nValue.printData();
00335                 ensure_equals("1:printData failed",ret_str,"44444444444");
00336 
00337                 LLNameValue nValue1("SecondLife S32 RW DSV 44444");     
00338                 ret_str = nValue1.printData();
00339                 ensure_equals("2:printData failed",ret_str,"44444");            
00340         }
00341         
00342         template<> template<>
00343         void namevalue_object_t::test<14>()
00344         {
00345                 LLNameValue nValue("SecodLife STRING RW SIM 22222");
00346                 std::ostringstream stream1,stream2,stream3, stream4, stream5;
00347                 stream1 << nValue;
00348                 ensure_equals("STRING << failed",stream1.str(),"22222");
00349 
00350                 LLNameValue nValue1("SecodLife F32 RW SIM 22222");
00351                 stream2 << nValue1;
00352                 ensure_equals("F32 << failed",stream2.str(),"22222");
00353 
00354                 LLNameValue nValue2("SecodLife S32 RW SIM 22222");
00355                 stream3<< nValue2;
00356                 ensure_equals("S32 << failed",stream3.str(),"22222");
00357 
00358                 LLNameValue nValue3("SecodLife U32 RW SIM 122222");
00359                 stream4<< nValue3;
00360                 ensure_equals("U32 << failed",stream4.str(),"122222");
00361 
00362                 // I don't think we use U64 name value pairs.  JC
00363                 //skip_fail("incomplete support for U64.");
00364                 //LLNameValue nValue4("SecodLife U64 RW SIM 22222");
00365                 //stream5<< nValue4;
00366                 //ensure("U64 << failed",0 == strcmp((stream5.str()).c_str(),"22222"));
00367         }
00368 
00369         template<> template<>
00370         void namevalue_object_t::test<15>()
00371         {
00372                 LLNameValue nValue("SecondLife", "This is a test", "ASSET", "R", "S");
00373 
00374                 ensure("getAsset failed", (0 == strcmp(nValue.getAsset(),"This is a test")));
00375                 // this should not have updated as it is read only.
00376                 nValue.setAsset("New Value should not be updated");
00377                 ensure("setAsset on ReadOnly failed", (0 == strcmp(nValue.getAsset(),"This is a test")));
00378 
00379                 LLNameValue nValue1("SecondLife", "1234", "U32", "R", "S");
00380                 // this should not have updated as it is read only.
00381                 nValue1.setU32(4567);
00382                 ensure("setU32 on ReadOnly failed", *nValue1.getU32() == 1234);
00383 
00384                 LLNameValue nValue2("SecondLife", "1234", "S32", "R", "S");
00385                 // this should not have updated as it is read only.
00386                 nValue2.setS32(4567);
00387                 ensure("setS32 on ReadOnly failed", *nValue2.getS32() == 1234);
00388 
00389                 LLNameValue nValue3("SecondLife", "1234", "F32", "R", "S");
00390                 // this should not have updated as it is read only.
00391                 nValue3.setF32(4567);
00392                 ensure("setF32 on ReadOnly failed", *nValue3.getF32() == 1234);
00393 
00394                 LLNameValue nValue4("SecondLife", "<1,2,3>", "VEC3", "R", "S");
00395                 // this should not have updated as it is read only.
00396                 LLVector3 vec(4,5,6);
00397                 nValue3.setVec3(vec);
00398                 LLVector3 vec1(1,2,3);
00399                 ensure("setVec3 on ReadOnly failed", *nValue4.getVec3() == vec1);
00400 
00401                 // cant test for U64 as no set64 exists nor any operators support U64 type
00402         }         
00403 }

Generated on Fri May 16 08:34:29 2008 for SecondLife by  doxygen 1.5.5