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                         mExpectedNameValueReference.string = NULL;
00046                         mExpectedNameValueType = NVT_NULL;
00047                         mCallbackCount = 0;
00048                 }
00049 
00050                 ~namevalue_test() 
00051                 {
00052                         reset();
00053                 };
00054                 
00055                 void reset() 
00056                 {
00057                         switch(mExpectedNameValueType)
00058                         {
00059                         case NVT_STRING: 
00060                         case NVT_ASSET: 
00061                                 delete [] mExpectedNameValueReference.string;
00062                                 mExpectedNameValueReference.string = NULL;
00063                                 break;
00064                         case NVT_F32:
00065                                 delete mExpectedNameValueReference.f32;
00066                                 mExpectedNameValueReference.f32 = NULL;
00067                                 break;
00068                         case NVT_S32:
00069                                 delete mExpectedNameValueReference.s32;
00070                                 mExpectedNameValueReference.s32 = NULL;
00071                                 break;
00072                         case NVT_U32:
00073                                 delete mExpectedNameValueReference.u32;
00074                                 mExpectedNameValueReference.u32 = NULL;
00075                                 break;
00076                         case NVT_VEC3:
00077                                 delete mExpectedNameValueReference.vec3;
00078                                 mExpectedNameValueReference.vec3 = NULL;
00079                                 break;
00080                         case NVT_U64:
00081                                 delete mExpectedNameValueReference.u64;
00082                                 mExpectedNameValueReference.u64 = NULL;
00083                         default:
00084                                 break;
00085                         }
00086 
00087                         mExpectedNameValueType = NVT_NULL;
00088                         mCallbackCount = 0;
00089                 }
00090 
00091                 void setExpectedResult(ENameValueType type, void* value)
00092                 {
00093                         reset();
00094                         mExpectedNameValueType = type;
00095                         switch(type)
00096                         {
00097                         case NVT_STRING:
00098                         case NVT_ASSET: 
00099                                 mExpectedNameValueReference.string = new char[strlen((const char*) value)+1];
00100                                 strcpy(mExpectedNameValueReference.string, (const char*) value);
00101                                 break;
00102                         case NVT_F32:
00103                                 mExpectedNameValueReference.f32 = new F32(*((F32*) value));
00104                                 break;
00105                         case NVT_S32:
00106                                 mExpectedNameValueReference.s32 = new S32(*((S32*) value));
00107                                 break;
00108                         case NVT_U32:
00109                                 mExpectedNameValueReference.u32 = new U32(*((U32*) value));
00110                                 break;
00111                         case NVT_VEC3:
00112                                 mExpectedNameValueReference.vec3 = new LLVector3(*((LLVector3*) value));
00113                                 break;
00114                         case NVT_U64:
00115                                 mExpectedNameValueReference.u64 = new U64(*((U64*) value));
00116                         default:
00117                                 break;
00118                         }
00119                 }
00120 
00121                 void verifyChange(LLNameValue* changed)
00122                 {
00123                         std::string str = "";
00124                         str += "Expected Value of type: ";
00125                         str += NameValueTypeStrings[mExpectedNameValueType];
00126                         str += "not equal";
00127 
00128                         switch(mExpectedNameValueType)
00129                         {
00130                         case NVT_STRING:
00131                                 ensure_memory_matches(str.c_str(),  changed->getString(), strlen(changed->getString()), mExpectedNameValueReference.string, strlen(mExpectedNameValueReference.string)); 
00132                                 break;
00133                         case NVT_ASSET: 
00134                                 ensure_memory_matches(str.c_str(),  changed->getAsset(), strlen(changed->getAsset()), mExpectedNameValueReference.string, strlen(mExpectedNameValueReference.string)); 
00135                                 break;
00136                         case NVT_F32:
00137                                 ensure(str, *(changed->getF32()) == *mExpectedNameValueReference.f32);
00138                                 break;
00139                         case NVT_S32:
00140                                 ensure(str, *(changed->getS32()) == *mExpectedNameValueReference.s32);
00141                                 break;
00142                         case NVT_U32:
00143                                 ensure(str, *(changed->getU32()) == *mExpectedNameValueReference.u32);
00144                                 break;
00145                         case NVT_VEC3:
00146                                 ensure(str, *(changed->getVec3()) == *mExpectedNameValueReference.vec3);
00147                                 break;
00148                         case NVT_U64:
00149                                 ensure(str, *(changed->getU64()) == *mExpectedNameValueReference.u64);
00150                                 break;
00151                         default:
00152                                 break;
00153                         }
00154                 }
00155 
00156                 void HandleCallback(LLNameValue* changed)
00157                 {
00158                         mCallbackCount++;
00159                         verifyChange(changed);
00160                         ensure("Callback called more than once", mCallbackCount == 1);
00161                 }
00162 
00163                 static void NameValueCallbackFunction(LLNameValue* changed, void** data)
00164                 {
00165                         namevalue_test* pNameValue = (namevalue_test*)data;
00166                         pNameValue->HandleCallback(changed);
00167                 }
00168 
00169                 ENameValueType          mExpectedNameValueType;
00170                 UNameValueReference     mExpectedNameValueReference;
00171                 int  mCallbackCount;
00172         };
00173         typedef test_group<namevalue_test> namevalue_t;
00174         typedef namevalue_t::object namevalue_object_t;
00175         tut::namevalue_t tut_namevalue("namevalue_test");
00176 
00177         
00178         template<> template<>
00179         void namevalue_object_t::test<1>()
00180         {
00181                 // LLNameValue()
00182                 LLNameValue nValue;
00183                 ensure("mName should have been NULL", nValue.mName == NULL);
00184                 ensure("getTypeEnum failed",nValue.getTypeEnum() == NVT_NULL);
00185                 ensure("getClassEnum failed",nValue.getClassEnum() == NVC_NULL);
00186                 ensure("getSendtoEnum failed",nValue.getSendtoEnum() == NVS_NULL);
00187 
00188                 LLNameValue nValue1(" SecondLife ASSET RW SIM 232324343");
00189 
00190         }
00191 
00192         // LLNameValue(const char* data);
00193         //      LLNameValue(const char* name, const char* data, const char* type, const char* nvclass, const char* nvsendto, 
00194         //                              TNameValueCallback nvcb = NULL, void** user_data = NULL);
00195         template<> template<>
00196         void namevalue_object_t::test<2>()
00197         {
00198                 LLNameValue nValue(" SecondLife ASSET RW S 232324343");
00199                 ensure("mName not set correctly", (0 == strcmp(nValue.mName,"SecondLife")));
00200                 ensure("getTypeEnum failed", nValue.getTypeEnum() == NVT_ASSET);
00201                 ensure("getClassEnum failed", nValue.getClassEnum() == NVC_READ_WRITE);
00202                 ensure("getSendtoEnum failed", nValue.getSendtoEnum() == NVS_SIM);
00203                 ensure("getString failed", (0==strcmp(nValue.getAsset(),"232324343")));
00204                 ensure("sendToData or sendToViewer failed", !nValue.sendToData() && !nValue.sendToViewer());
00205                 
00206                 LLNameValue nValue1("\n\r SecondLife_1 STRING READ_WRITE SIM 232324343");
00207                 ensure("1. mName not set correctly", (0 == strcmp(nValue1.mName,"SecondLife_1")));
00208                 ensure("1. getTypeEnum failed", nValue1.getTypeEnum() == NVT_STRING);
00209                 ensure("1. getClassEnum failed", nValue1.getClassEnum() == NVC_READ_WRITE);
00210                 ensure("1. getSendtoEnum failed", nValue1.getSendtoEnum() == NVS_SIM);
00211                 ensure("1. getString failed", (0==strcmp(nValue1.getString(),"232324343")));
00212                 ensure("1. sendToData or sendToViewer failed", !nValue1.sendToData() && !nValue1.sendToViewer());
00213 
00214                 LLNameValue nValue2("SecondLife", "23.5", "F32", "R", "DS");
00215                 ensure("2. getTypeEnum failed", nValue2.getTypeEnum() == NVT_F32);
00216                 ensure("2. getClassEnum failed", nValue2.getClassEnum() == NVC_READ_ONLY);
00217                 ensure("2. getSendtoEnum failed", nValue2.getSendtoEnum() == NVS_DATA_SIM);
00218                 ensure("2. getF32 failed", *nValue2.getF32() == 23.5f);
00219                 ensure("2. sendToData or sendToViewer failed", nValue2.sendToData() && !nValue2.sendToViewer());
00220 
00221                 LLNameValue nValue3("SecondLife", "-43456787", "S32", "READ_ONLY", "SIM_SPACE");
00222                 ensure("3. getTypeEnum failed", nValue3.getTypeEnum() == NVT_S32);
00223                 ensure("3. getClassEnum failed", nValue3.getClassEnum() == NVC_READ_ONLY);
00224                 ensure("3. getSendtoEnum failed", nValue3.getSendtoEnum() == NVS_DATA_SIM);
00225                 ensure("3. getS32 failed", *nValue3.getS32() == -43456787);
00226                 ensure("sendToData or sendToViewer failed", nValue3.sendToData() && !nValue3.sendToViewer());
00227 
00228                 LLNameValue nValue4("SecondLife", "<1.0, 2.0, 3.0>", "VEC3", "CB", "SV");
00229                 LLVector3 llvec4(1.0, 2.0, 3.0);
00230                 ensure("4. getTypeEnum failed", nValue4.getTypeEnum() == NVT_VEC3);
00231                 ensure("4. getClassEnum failed", nValue4.getClassEnum() == NVC_CALLBACK);
00232                 ensure("4. getSendtoEnum failed", nValue4.getSendtoEnum() == NVS_SIM_VIEWER);
00233                 ensure("4. getVec3 failed", *nValue4.getVec3() == llvec4);
00234                 ensure("4. sendToData or sendToViewer failed", !nValue4.sendToData() && nValue4.sendToViewer());
00235 
00236                 LLNameValue nValue5("SecondLife", "-1.0, 2.4, 3", "VEC3", "CALLBACK", "SIM_VIEWER");
00237                 LLVector3 llvec5(-1.0f, 2.4f, 3);
00238                 ensure("5. getTypeEnum failed", nValue5.getTypeEnum() == NVT_VEC3);
00239                 ensure("5. getClassEnum failed", nValue5.getClassEnum() == NVC_CALLBACK);
00240                 ensure("5. getSendtoEnum failed", nValue5.getSendtoEnum() == NVS_SIM_VIEWER);
00241                 ensure("5. getVec3 failed", *nValue5.getVec3() == llvec5);
00242                 ensure("5. sendToData or sendToViewer failed", !nValue5.sendToData() && nValue5.sendToViewer());
00243 
00244                 LLNameValue nValue6("SecondLife", "89764323", "U32", "CALLBACK", "DSV");
00245                 ensure("6. getTypeEnum failed", nValue6.getTypeEnum() == NVT_U32);
00246                 ensure("6. getClassEnum failed", nValue6.getClassEnum() == NVC_CALLBACK);
00247                 ensure("6. getSendtoEnum failed", nValue6.getSendtoEnum() == NVS_DATA_SIM_VIEWER);
00248                 ensure("6. getU32 failed", *nValue6.getU32() == 89764323);
00249                 ensure("6. sendToData or sendToViewer failed", nValue6.sendToData() && nValue6.sendToViewer());
00250 
00251                 LLNameValue nValue7("SecondLife", "89764323323232", "U64", "CALLBACK", "SIM_SPACE_VIEWER");
00252                 U64 u64_7 = U64L(89764323323232);
00253                 ensure("7. getTypeEnum failed", nValue7.getTypeEnum() == NVT_U64);
00254                 ensure("7. getClassEnum failed", nValue7.getClassEnum() == NVC_CALLBACK);
00255                 ensure("7. getSendtoEnum failed", nValue7.getSendtoEnum() == NVS_DATA_SIM_VIEWER);
00256                 ensure("7. getU32 failed", *nValue7.getU64() == u64_7);
00257                 ensure("7. sendToData or sendToViewer failed", nValue7.sendToData() && nValue7.sendToViewer());
00258         }
00259 
00260         // LLNameValue(const char* name, const char* data, const char* type, const char* nvclass, 
00261         //                              TNameValueCallback nvcb = NULL, void** user_data = NULL);
00262         template<> template<>
00263         void namevalue_object_t::test<3>()
00264         {
00265                 LLNameValue nValue("SecondLife", "232324343", "ASSET", "READ_WRITE");
00266                 ensure("mName not set correctly", (0 == strcmp(nValue.mName,"SecondLife")));
00267                 ensure("getTypeEnum failed", nValue.getTypeEnum() == NVT_ASSET);
00268                 ensure("getClassEnum failed", nValue.getClassEnum() == NVC_READ_WRITE);
00269                 ensure("getSendtoEnum failed", nValue.getSendtoEnum() == NVS_SIM);
00270                 ensure("getString failed", (0==strcmp(nValue.getAsset(),"232324343")));
00271 
00272                 LLNameValue nValue1("SecondLife", "232324343", "STRING", "READ_WRITE");
00273                 ensure("1. mName not set correctly", (0 == strcmp(nValue1.mName,"SecondLife")));
00274                 ensure("1. getTypeEnum failed", nValue1.getTypeEnum() == NVT_STRING);
00275                 ensure("1. getClassEnum failed", nValue1.getClassEnum() == NVC_READ_WRITE);
00276                 ensure("1. getSendtoEnum failed", nValue1.getSendtoEnum() == NVS_SIM);
00277                 ensure("1. getString failed", (0==strcmp(nValue1.getString(),"232324343")));
00278 
00279                 LLNameValue nValue2("SecondLife", "23.5", "F32", "R");
00280                 ensure("2. getTypeEnum failed", nValue2.getTypeEnum() == NVT_F32);
00281                 ensure("2. getClassEnum failed", nValue2.getClassEnum() == NVC_READ_ONLY);
00282                 ensure("2. getSendtoEnum failed", nValue2.getSendtoEnum() == NVS_SIM);
00283                 ensure("2. getF32 failed", *nValue2.getF32() == 23.5f);
00284 
00285                 LLNameValue nValue3("SecondLife", "-43456787", "S32", "READ_ONLY");
00286                 ensure("3. getTypeEnum failed", nValue3.getTypeEnum() == NVT_S32);
00287                 ensure("3. getClassEnum failed", nValue3.getClassEnum() == NVC_READ_ONLY);
00288                 ensure("3. getSendtoEnum failed", nValue3.getSendtoEnum() == NVS_SIM);
00289                 ensure("3. getS32 failed", *nValue3.getS32() == -43456787);
00290 
00291                 LLNameValue nValue4("SecondLife", "<1.0, 2.0, 3.0>", "VEC3", "CB");
00292                 LLVector3 llvec4(1.0, 2.0, 3.0);
00293                 ensure("4. getTypeEnum failed", nValue4.getTypeEnum() == NVT_VEC3);
00294                 ensure("4. getClassEnum failed", nValue4.getClassEnum() == NVC_CALLBACK);
00295                 ensure("4. getSendtoEnum failed", nValue4.getSendtoEnum() == NVS_SIM);
00296                 ensure("4. getVec3 failed", *nValue4.getVec3() == llvec4);
00297 
00298                 LLNameValue nValue5("SecondLife", "-1.0, 2.4, 3", "VEC3", "CALLBACK");
00299                 LLVector3 llvec5(-1.0f, 2.4f, 3);
00300                 ensure("5. getTypeEnum failed", nValue5.getTypeEnum() == NVT_VEC3);
00301                 ensure("5. getClassEnum failed", nValue5.getClassEnum() == NVC_CALLBACK);
00302                 ensure("5. getSendtoEnum failed", nValue5.getSendtoEnum() == NVS_SIM);
00303                 ensure("5. getVec3 failed", *nValue5.getVec3() == llvec5);
00304 
00305                 LLNameValue nValue6("SecondLife", "89764323", "U32", "CALLBACK");
00306                 ensure("6. getTypeEnum failed", nValue6.getTypeEnum() == NVT_U32);
00307                 ensure("6. getClassEnum failed", nValue6.getClassEnum() == NVC_CALLBACK);
00308                 ensure("6. getSendtoEnum failed", nValue6.getSendtoEnum() == NVS_SIM);
00309                 ensure("6. getU32 failed", *nValue6.getU32() == 89764323);
00310 
00311                 LLNameValue nValue7("SecondLife", "89764323323232", "U64", "CALLBACK");
00312                 U64 u64_7 = U64L(89764323323232);
00313                 ensure("7. getTypeEnum failed", nValue7.getTypeEnum() == NVT_U64);
00314                 ensure("7. getClassEnum failed", nValue7.getClassEnum() == NVC_CALLBACK);
00315                 ensure("7. getSendtoEnum failed", nValue7.getSendtoEnum() == NVS_SIM);
00316                 ensure("7. getU32 failed", *nValue7.getU64() == u64_7);
00317         }
00318 
00319         // LLNameValue(const char* name, const char* type, const char* nvclass, 
00320         //                              TNameValueCallback nvcb = NULL, void** user_data = NULL);
00321         template<> template<>
00322         void namevalue_object_t::test<4>()
00323         {
00324                 LLNameValue nValue("SecondLife",  "STRING", "READ_WRITE");
00325                 ensure("mName not set correctly", (0 == strcmp(nValue.mName,"SecondLife")));
00326                 ensure("getTypeEnum failed", nValue.getTypeEnum() == NVT_STRING);
00327                 ensure("getClassEnum failed", nValue.getClassEnum() == NVC_READ_WRITE);
00328                 ensure("getSendtoEnum failed", nValue.getSendtoEnum() == NVS_SIM);
00329 
00330                 LLNameValue nValue1("SecondLife",  "ASSET", "READ_WRITE");
00331                 ensure("1. mName not set correctly", (0 == strcmp(nValue1.mName,"SecondLife")));
00332                 ensure("1. getTypeEnum for RW failed", nValue1.getTypeEnum() == NVT_ASSET);
00333                 ensure("1. getClassEnum for RW failed", nValue1.getClassEnum() == NVC_READ_WRITE);
00334                 ensure("1. getSendtoEnum for RW failed", nValue1.getSendtoEnum() == NVS_SIM);
00335 
00336                 LLNameValue nValue2("SecondLife", "F32", "READ_ONLY");
00337                 ensure("2. getTypeEnum failed", nValue2.getTypeEnum() == NVT_F32);
00338                 ensure("2. getClassEnum failed", nValue2.getClassEnum() == NVC_READ_ONLY);
00339                 ensure("2. getSendtoEnum failed", nValue2.getSendtoEnum() == NVS_SIM);
00340 
00341                 LLNameValue nValue3("SecondLife", "S32", "READ_ONLY");
00342                 ensure("3. getTypeEnum failed", nValue3.getTypeEnum() == NVT_S32);
00343                 ensure("3. getClassEnum failed", nValue3.getClassEnum() == NVC_READ_ONLY);
00344                 ensure("3. getSendtoEnum failed", nValue3.getSendtoEnum() == NVS_SIM);
00345 
00346                 skip_fail("NVC_CALLBACK does not parse.");
00347 
00348                 LLNameValue nValue4("SecondLife", "VEC3", "CALLBACK");
00349                 ensure("4. getTypeEnum failed", nValue4.getTypeEnum() == NVT_VEC3);
00350                 ensure("4. getClassEnum failed", nValue4.getClassEnum() == NVC_CALLBACK);
00351                 ensure("4. getSendtoEnum failed", nValue4.getSendtoEnum() == NVS_SIM);
00352 
00353                 LLNameValue nValue6("SecondLife", "U32", "CALLBACK");
00354                 ensure("6. getTypeEnum failed", nValue6.getTypeEnum() == NVT_U32);
00355                 ensure("6. getClassEnum failed", nValue6.getClassEnum() == NVC_CALLBACK);
00356                 ensure("6. getSendtoEnum failed", nValue6.getSendtoEnum() == NVS_SIM);
00357 
00358                 LLNameValue nValue7("SecondLife", "U64", "CALLBACK");
00359                 ensure("7. getTypeEnum failed", nValue7.getTypeEnum() == NVT_U64);
00360                 ensure("7. getClassEnum failed", nValue7.getClassEnum() == NVC_CALLBACK);
00361                 ensure("7. getSendtoEnum failed", nValue7.getSendtoEnum() == NVS_SIM);
00362         }
00363 
00364         template<> template<>
00365         void namevalue_object_t::test<5>()
00366         {
00367                 skip_fail("callback will be called more than once.");
00368                 LLNameValue nValue("SecondLife", "This is a test", "STRING", "CB", "SIM", NameValueCallbackFunction, (void**) this);
00369 
00370                 ensure("getString failed", (0 == strcmp(nValue.getString(),"This is a test")));
00371                 reset();
00372 
00373                 setExpectedResult(NVT_STRING, (void*)"New Value");
00374                 nValue.setString("New Value");
00375                 ensure("String nonzero failed", nValue.nonzero() == TRUE);
00376                 reset();
00377                 setExpectedResult(NVT_STRING, (void*)"");
00378                 nValue.setString("");
00379                 ensure("String nonzero failed", nValue.nonzero() == FALSE);
00380                 reset();
00381         }
00382 
00383         template<> template<>
00384         void namevalue_object_t::test<6>()
00385         {
00386                 skip_fail("callback will be called more than once.");
00387                 LLNameValue nValue("SecondLife", "This is a test", "ASSET", "CALLBACK", "S", NameValueCallbackFunction, (void**) this);
00388                 ensure("getAsset failed", (0 == strcmp(nValue.getAsset(),"This is a test")));
00389                 reset();
00390 
00391                 setExpectedResult(NVT_ASSET, (void*)"New Value");
00392                 nValue.setAsset("New Value");
00393                 reset();
00394         }
00395                 
00396         template<> template<>
00397         void namevalue_object_t::test<7>()
00398         {
00399                 skip_fail("callback will be called more than once.");
00400                 LLNameValue nValue("SecondLife", "555555", "F32", "CB", "SIM", NameValueCallbackFunction, (void**) this);
00401                 
00402                 ensure("getF32 failed",*nValue.getF32() == 555555.f);
00403                 reset();
00404 
00405                 F32 fVal = 0.1f;
00406                 setExpectedResult(NVT_F32, &fVal);
00407                 nValue.setF32(fVal);
00408 
00409                 fVal = -11111.1f;
00410                 setExpectedResult(NVT_F32, &fVal);
00411                 nValue.setF32(fVal);
00412                 ensure("F32 nonzero failed", nValue.nonzero() == TRUE);
00413                 reset();
00414 
00415                 fVal = 0.;
00416                 setExpectedResult(NVT_F32, &fVal);
00417                 nValue.setF32(fVal);
00418                 ensure("F32 nonzero failed", nValue.nonzero() == FALSE);
00419                 reset();
00420         }
00421 
00422         template<> template<>
00423         void namevalue_object_t::test<8>()
00424         {
00425                 skip_fail("callback will be called more than once.");
00426                 LLNameValue nValue("SecondLife", "-5555", "S32", "CB", "SIM", NameValueCallbackFunction, (void**) this);
00427 
00428                 ensure("getS32 failed", *nValue.getS32() == -5555);
00429                 reset();
00430 
00431                 S32 sVal = 0x7FFFFFFF;
00432                 setExpectedResult(NVT_S32, &sVal);
00433                 nValue.setS32(sVal);
00434 
00435                 sVal = -0x7FFFFFFF;
00436                 setExpectedResult(NVT_S32, &sVal);
00437                 nValue.setS32(sVal);
00438                 ensure("S32 nonzero failed", nValue.nonzero() == TRUE);
00439                 reset();
00440 
00441                 sVal = 0;
00442                 setExpectedResult(NVT_S32, &sVal);
00443                 nValue.setS32(sVal);
00444                 ensure("S32 nonzero failed", nValue.nonzero() == FALSE);
00445                 reset();
00446         }
00447         
00448         template<> template<>
00449         void namevalue_object_t::test<9>()
00450         {
00451                 LLNameValue nValue("SecondLife", "<-3, 2, 1>", "VEC3", "CB", "SIM", NameValueCallbackFunction, (void**) this);
00452                 LLVector3 vecExpected(-3, 2, 1);
00453                 LLVector3 vec;
00454                 nValue.getVec3(vec);
00455                 ensure("getVec3 failed", vec == vecExpected);
00456                 reset();
00457 
00458                 vecExpected.setVec(2, -1, 0);
00459                 setExpectedResult(NVT_VEC3, &vecExpected);
00460                 nValue.setVec3(vecExpected);
00461                 ensure("VEC3 nonzero failed", nValue.nonzero() == TRUE);
00462                 reset();
00463 
00464                 vecExpected.setVec(0, 0, 0);
00465                 setExpectedResult(NVT_VEC3, &vecExpected);
00466                 nValue.setVec3(vecExpected);
00467                 ensure("VEC3 nonzero failed", nValue.nonzero() == FALSE);
00468                 reset();
00469         }
00470         
00471         template<> template<>
00472         void namevalue_object_t::test<10>()
00473         {
00474                 LLNameValue nValue("SecondLife", "12345678", "U32", "CB", "SIM", NameValueCallbackFunction, (void**) this);
00475 
00476                 ensure("getU32 failed",*nValue.getU32() == 12345678);
00477 
00478                 U32 val = 0xFFFFFFFF;
00479                 setExpectedResult(NVT_U32, &val);
00480                 nValue.setU32(val);
00481                 ensure("U32 nonzero failed", nValue.nonzero() == TRUE);
00482                 reset();
00483 
00484                 val = 0;
00485                 setExpectedResult(NVT_U32, &val);
00486                 nValue.setU32(val);             
00487                 ensure("U32 nonzero failed", nValue.nonzero() == FALSE);
00488                 reset();
00489         }
00490         
00491         template<> template<>
00492         void namevalue_object_t::test<11>()
00493         {
00494                 skip_fail("incomplete support for U64.");
00495                 LLNameValue nValue("SecondLife", "44444444444", "U64", "CB", "SIM", NameValueCallbackFunction, (void**) this);
00496 
00497                 ensure("getU64 failed",*nValue.getU64() == U64L(44444444444));
00498                 ensure("U64 nonzero failed", nValue.nonzero() == TRUE);
00499 
00500                 // there is no LLNameValue::setU64()  
00501         }
00502         
00503         template<> template<>
00504         void namevalue_object_t::test<12>()
00505         {
00506                 LLNameValue nValue("SecondLife F32 RW SIM -333.337600");        
00507                 F32 val = nValue.magnitude();
00508                 ensure_equals("F32 magnitude failed", val, 333.337600f);
00509         
00510                 LLNameValue nValue1("SecondLife STRING RW SIM 3300");   
00511                 val = nValue1.magnitude();
00512                 ensure_equals("STRING magnitude failed",val,4.0f);
00513                 
00514                 LLNameValue nValue2("SecondLife S32 RW SIM -3300");     
00515                 val = nValue2.magnitude();
00516                 ensure_equals("S32 magnitude failed", val, 3300.);
00517                 
00518                 LLNameValue nValue3("SecondLife U32 RW SIM 3300");      
00519                 val = nValue3.magnitude();
00520                 ensure_equals("U32 magnitude failed", val, 3300.);
00521                 
00522                 LLNameValue nValue4("SecondLife VEC3 RW SIM <1,2,3>");  
00523                 LLVector3 vec(1,2,3);
00524                 val = nValue4.magnitude();
00525                 ensure_equals("VEC3 magnitude failed", val, vec.magVec());
00526                 
00527                 skip_fail("incomplete support for U64.");
00528                 LLNameValue nValue5("SecondLife U64 RW SIM 12345");     
00529                 val = nValue5.magnitude();
00530                 ensure_equals("U62 magnitude failed", val, 12345);              
00531         }
00532         
00533         template<> template<>
00534         void namevalue_object_t::test<13>()
00535         {
00536                 skip_fail("incomplete support for U64.");
00537                 LLNameValue nValue("SecondLife U64 RW DSV 44444444444");        
00538                 std::string ret_str = nValue.printNameValue();
00539                 
00540                 ensure_equals("1:printNameValue failed",ret_str,"SecondLife U64 RW DSV 44444444444");
00541                 
00542                 LLNameValue nValue1(ret_str.c_str());
00543                 ensure_equals("Serialization of printNameValue failed", nValue, nValue1);               
00544         }
00545 
00546         template<> template<>
00547         void namevalue_object_t::test<14>()
00548         {
00549                 LLNameValue nValue("SecondLife STRING RW DSV 44444444444");     
00550                 std::string ret_str = nValue.printData();
00551                 ensure_equals("1:printData failed",ret_str,"44444444444");
00552 
00553                 LLNameValue nValue1("SecondLife S32 RW DSV 44444");     
00554                 ret_str = nValue1.printData();
00555                 ensure_equals("2:printData failed",ret_str,"44444");            
00556         }
00557         
00558         template<> template<>
00559         void namevalue_object_t::test<15>()
00560         {
00561                 LLNameValue nValue("SecodLife STRING RW SIM 22222");
00562                 std::ostringstream stream1,stream2,stream3, stream4, stream5;
00563                 stream1 << nValue;
00564                 ensure_equals("STRING << failed",stream1.str(),"22222");
00565 
00566                 LLNameValue nValue1("SecodLife F32 RW SIM 22222");
00567                 stream2 << nValue1;
00568                 ensure_equals("F32 << failed",stream2.str(),"22222");
00569 
00570                 LLNameValue nValue2("SecodLife S32 RW SIM 22222");
00571                 stream3<< nValue2;
00572                 ensure_equals("S32 << failed",stream3.str(),"22222");
00573 
00574                 LLNameValue nValue3("SecodLife U32 RW SIM 122222");
00575                 stream4<< nValue3;
00576                 ensure_equals("U32 << failed",stream4.str(),"122222");
00577 
00578                 skip_fail("incomplete support for U64.");
00579                 LLNameValue nValue4("SecodLife U64 RW SIM 22222");
00580                 stream5<< nValue4;
00581                 ensure("U64 << failed",0 == strcmp((stream5.str()).c_str(),"22222"));
00582         }
00583 
00584         template<> template<>
00585         void namevalue_object_t::test<16>()
00586         {
00587                 LLNameValue nValue1("SecondLife STRING RW DSV 44444");
00588                 LLNameValue nValue2("SecondLife STRING RW SIM 33333");
00589                 LLNameValue nValue3("SecondLife");
00590                 nValue3 = nValue1 + nValue2;
00591                 ensure("1:operator+ failed",(0==strcmp(nValue3.getString(),"4444433333")));
00592                 
00593                 LLNameValue nValue4("SecondLife F32 R DSV 44444");
00594                 LLNameValue nValue5("SecondLife F32 RW SIM 33333");
00595                 LLNameValue nValue6("SecondLife");
00596                 nValue6 = nValue4 + nValue5;
00597                 ensure_equals("2:operator+ failed",*nValue6.getF32(),77777.0);
00598                 
00599                 LLNameValue nValue7("SecondLife F32 R DSV 44444");
00600                 LLNameValue nValue8("SecondLife S32 RW SIM 33333");
00601                 LLNameValue nValue9("SecondLife F32");
00602                 nValue9 = nValue7 + nValue8;
00603                 ensure_equals("3:operator+ failed",*nValue9.getF32(),77777.0);
00604                 
00605                 LLNameValue nValue10("SecondLife VEC3 RW SIM <4, 4, 4>");
00606                 LLNameValue nValue11("SecondLife VEC3 RW SV <3, 3, 3>");
00607                 LLNameValue nValue12("SecondLife VEC3");
00608                 nValue12 = nValue10 + nValue11;
00609                 LLVector3 vec(7,7,7);
00610                 ensure_equals("4:operator+ failed",*nValue12.getVec3(), vec);   
00611         }
00612 
00613         template<> template<>
00614         void namevalue_object_t::test<17>()
00615         {
00616                 LLNameValue nValue7(" SecondLife S32 RW SIM 22222");
00617                 LLNameValue nValue8(" SecondLife  F32 RW SIM 33333");
00618                 LLNameValue nValue9(" SecondLife F32");
00619                 nValue9 = nValue7 - nValue8;
00620                 ensure_equals("1:operator- failed",*nValue9.getF32(),-11111.f);
00621                 
00622                 LLNameValue nValue10(" SecondLife VEC3 RW SIM <2, 2, 2>");
00623                 LLNameValue nValue11(" SecondLife VEC3 RW SIM <3, 3, 3>");
00624                 LLNameValue nValue12(" SecondLife VEC3");
00625                 LLVector3 vec(-1,-1,-1);
00626                 nValue12 = nValue10 - nValue11;
00627                 ensure_equals("2:operator- failed",*nValue12.getVec3(), vec);
00628         }
00629 
00630         template<> template<>
00631         void namevalue_object_t::test<18>()
00632         {
00633 
00634                 LLNameValue nValue1(" SecondLife F32 RW SIM 22222");
00635                 LLNameValue nValue2(" SecondLife F32 RW SIM 33333");
00636                 LLNameValue nValue3(" SecondLife F32");
00637                 nValue3 = nValue1 * nValue2;
00638                 ensure_equals("1:operator* failed",*nValue3.getF32(),740725926.f);
00639                 
00640                 LLNameValue nValue4(" SecondLife S32 RW SIM 22222");
00641                 LLNameValue nValue5(" SecondLife  F32 RW SIM 33333");
00642                 LLNameValue nValue6(" SecondLife F32");
00643                 nValue6 = nValue4 * nValue5;
00644                 ensure_equals("2:operator* failed",*nValue6.getF32(),740725926.f);
00645 
00646                 LLNameValue nValue10(" SecondLife VEC3 RW SIM <2, 2, 2>");
00647                 LLNameValue nValue11(" SecondLife VEC3 RW SIM <3, 3, 3>");
00648                 LLNameValue nValue12(" SecondLife F32");
00649                 LLVector3 vec1(2,2,2);
00650                 LLVector3 vec2(3,3,3);
00651                 nValue12 = nValue10 * nValue11;
00652                 ensure_equals("2:operator* failed",*nValue12.getF32(), (vec1 * vec2));
00653         }
00654 
00655         template<> template<>
00656         void namevalue_object_t::test<19>()
00657         {
00658                 LLNameValue nValue1(" SecondLife S32 RW SIM 22222");
00659                 LLNameValue nValue2(" Virtual F32 RW SIM 44444");
00660                 LLNameValue nValue3(" SecondLife F32");
00661                 nValue3 = nValue1 / nValue2;
00662                 ensure_equals("1:operator/ failed",*nValue3.getF32(),0.5);
00663                 
00664                 LLNameValue nValue4(" SecondLife F32 RW SIM 33333");
00665                 LLNameValue nValue5(" SecondLife S32 RW SIM 22222");
00666                 LLNameValue nValue6(" SecondLife F32");
00667                 nValue6 = nValue4 / nValue5;
00668                 ensure_equals("2:operator/ failed",*nValue6.getF32(),1.5);
00669         }
00670         
00671         template<> template<>
00672         void namevalue_object_t::test<20>()
00673         {
00674                 LLNameValue nValue1(" SecondLife S32 RW SIM 22222");
00675                 LLNameValue nValue2(" Virtual S32 RW SIM 33333");
00676                 LLNameValue nValue3(" SecondLife S32");
00677                 nValue3 = nValue1 % nValue2;
00678                 ensure_equals("1:operator% failed",*nValue3.getS32(),22222);
00679 
00680                 LLNameValue nValue4(" SecondLife U32 RW SIM 3");
00681                 LLNameValue nValue5(" SecondLife S32 RW SIM 2");
00682                 LLNameValue nValue6(" SecondLife S32");
00683                 nValue6 = nValue4 % nValue5;
00684                 ensure_equals("2:operator% failed",*nValue6.getS32(),1);
00685 
00686                 LLNameValue nValue10(" SecondLife VEC3 RW SIM <4, 5, 6>");
00687                 LLNameValue nValue11(" SecondLife VEC3 RW SIM <1, 2, 3>");
00688                 LLNameValue nValue12(" SecondLife VEC3");
00689                 LLVector3 vec1(4,5,6);
00690                 LLVector3 vec2(1,2,3);
00691                 LLVector3 vec3(vec1 % vec2);
00692                 nValue12 = nValue10 % nValue11;
00693                 ensure_equals("5:operator% failed",*nValue12.getVec3(), vec3);
00694         }
00695 
00696         template<> template<>
00697         void namevalue_object_t::test<21>()
00698         {
00699                 LLNameValue nValue1(" SecondLife STRING RW SIM 22222");
00700                 LLNameValue nValue2(" Virtual STRING RW SIM 22222");
00701                 ensure("1:operator== failed", nValue1 == nValue2);
00702 
00703                 LLNameValue nValue3(" SecondLife F32 RW SIM 33333");
00704                 LLNameValue nValue4(" Virtual F32 RW SIM 22222");
00705                 ensure("2:operator== failed",!(nValue3 == nValue4));
00706 
00707                 LLNameValue nValue5(" SecondLife STRING RW SIM 22222");
00708                 LLNameValue nValue6(" Virtual STRING RW SIM 33333");
00709                 ensure("3:operator== failed",!(nValue5 == nValue6));
00710 
00711                 LLNameValue nValue7(" SecondLife VEC3 RW SIM <2, 2, 2>");
00712                 LLNameValue nValue8(" Virtual VEC3 RW SIM <2, 2, 2>");
00713                 ensure("4:operator== failed",(nValue7 == nValue8));             
00714         }
00715 
00716         template<> template<>
00717         void namevalue_object_t::test<22>()
00718         {
00719                 LLNameValue nValue1(" SecondLife STRING RW SIM 22222");
00720                 LLNameValue nValue2(" Virtual STRING RW SIM 33333");
00721                 bool b_ret = (nValue1 <= nValue2) ? 1 : 0;
00722                 ensure("1:operator<= failed",(1==b_ret));       
00723 
00724                 LLNameValue nValue3(" SecondLife F32 RW SIM 33333");
00725                 LLNameValue nValue4(" Virtual F32 RW SIM 22222");
00726                 b_ret = (nValue3 <= nValue4) ? 1 : 0;
00727                 ensure("2:operator<= failed",(0==b_ret));
00728         }
00729 
00730         template<> template<>
00731         void namevalue_object_t::test<23>()
00732         {
00733                 LLNameValue nValue1(" SecondLife STRING RW SIM 22222");
00734                 LLNameValue nValue2(" Virtual STRING RW SIM 33333");
00735                 bool b_ret = (nValue1 >= nValue2) ? 1 : 0;
00736                 ensure("operator>= failed",!b_ret);     
00737 
00738                 LLNameValue nValue3(" SecondLife F32 RW SIM 33333");
00739                 LLNameValue nValue4(" Virtual F32 RW SIM 22222");
00740                 b_ret = (nValue3 >= nValue4) ? 1 : 0;
00741                 ensure("2:operator<= failed",b_ret);
00742 
00743         }
00744 
00745         template<> template<>
00746         void namevalue_object_t::test<24>()
00747         {
00748                 LLNameValue nValue1(" SecondLife STRING RW SIM 33333");
00749                 LLNameValue nValue2(" Virtual STRING RW SIM 33333");
00750                 bool b_ret = (nValue1 < nValue2) ? 1 : 0;
00751                 ensure("operator< failed",!b_ret);      
00752 
00753                 LLNameValue nValue3(" SecondLife F32 RW SIM 11111");
00754                 LLNameValue nValue4(" Virtual F32 RW SIM 22222");
00755                 b_ret = (nValue3 < nValue4) ? 1 : 0;
00756                 ensure("2:operator< failed",b_ret);
00757 
00758         }
00759 
00760         template<> template<>
00761         void namevalue_object_t::test<25>()
00762         {
00763                 LLNameValue nValue1(" SecondLife STRING RW SIM 33333");
00764                 LLNameValue nValue2(" Virtual STRING RW SIM 33333");
00765                 bool b_ret = (nValue1 > nValue2) ? 1 : 0;
00766                 ensure("1:operator> failed",!b_ret);    
00767 
00768                 LLNameValue nValue3(" SecondLife F32 RW SIM 11111");
00769                 LLNameValue nValue4(" Virtual F32 RW SIM 22222");
00770                 b_ret = (nValue3 > nValue4) ? 1 : 0;
00771                 ensure("2:operator> failed",!b_ret);
00772 
00773                 LLNameValue nValue5(" SecondLife S32 RW SIM 22222");
00774                 LLNameValue nValue6(" Virtual F32 RW SIM 11111");
00775                 b_ret = (nValue5 > nValue6) ? 1 : 0;
00776                 ensure("3:operator> failed",b_ret);
00777         }
00778 
00779         template<> template<>
00780         void namevalue_object_t::test<26>()
00781         {
00782                 LLNameValue nValue1(" SecondLife STRING RW SIM 33333");
00783                 LLNameValue nValue2(" Virtual STRING RW SIM 33333");
00784                 bool b_ret = (nValue1 != nValue2) ? 1 : 0;
00785                 ensure("1:operator!= failed",!b_ret);   
00786 
00787                 LLNameValue nValue3(" SecondLife F32 RW SIM 11111");
00788                 LLNameValue nValue4(" Virtual F32 RW SIM 22222");
00789                 b_ret = (nValue3 != nValue4) ? 1 : 0;
00790                 ensure("2:operator!= failed",b_ret);
00791 
00792         }
00793         
00794 
00795         template<> template<>
00796         void namevalue_object_t::test<27>()
00797         {
00798                 LLNameValue nValue1(" SecondLife F32 RW SIM 33333");
00799                 LLNameValue nValue2("Virtual");
00800                 nValue2 = -nValue1;
00801                 ensure_equals("1:operator unary- failed",*nValue2.getF32(), -33333.f);
00802 
00803                 LLNameValue nValue3(" SecondLife U32 RW SIM 11111");
00804                 LLNameValue nValue4("Virtual S32");
00805                 nValue4 = -nValue3;
00806                 ensure_equals("2:operator unary- failed",*nValue4.getS32(), -11111);
00807 
00808                 LLNameValue nValue5(" SecondLife VEC3 RW SIM <1, 1, 1>");
00809                 LLNameValue nValue6("Virtual VEC3");
00810                 LLVector3 vec(-1, -1, -1);
00811                 nValue6 = -nValue5;
00812                 ensure_equals("3:operator unary- failed",*nValue6.getVec3(), vec);
00813         }       
00814 
00815         template<> template<>
00816         void namevalue_object_t::test<28>()
00817         {
00818                 LLNameValue nValue("SecondLife", "This is a test", "ASSET", "R", "S", NameValueCallbackFunction, (void**) this);
00819 
00820                 ensure("getAsset failed", (0 == strcmp(nValue.getAsset(),"This is a test")));
00821                 // this should not have updated as it is read only.
00822                 nValue.setAsset("New Value should not be updated");
00823                 ensure("setAsset on ReadOnly failed", (0 == strcmp(nValue.getAsset(),"This is a test")));
00824 
00825                 LLNameValue nValue1("SecondLife", "1234", "U32", "R", "S", NameValueCallbackFunction, (void**) this);
00826                 // this should not have updated as it is read only.
00827                 nValue1.setU32(4567);
00828                 ensure("setU32 on ReadOnly failed", *nValue1.getU32() == 1234);
00829 
00830                 LLNameValue nValue2("SecondLife", "1234", "S32", "R", "S", NameValueCallbackFunction, (void**) this);
00831                 // this should not have updated as it is read only.
00832                 nValue2.setS32(4567);
00833                 ensure("setS32 on ReadOnly failed", *nValue2.getS32() == 1234);
00834 
00835                 LLNameValue nValue3("SecondLife", "1234", "F32", "R", "S", NameValueCallbackFunction, (void**) this);
00836                 // this should not have updated as it is read only.
00837                 nValue3.setF32(4567);
00838                 ensure("setF32 on ReadOnly failed", *nValue3.getF32() == 1234);
00839                 nValue3 = nValue3 * 2;
00840                 ensure("setF32 on ReadOnly failed", *nValue3.getF32() == 1234);
00841 
00842                 LLNameValue nValue4("SecondLife", "<1,2,3>", "VEC3", "R", "S", NameValueCallbackFunction, (void**) this);
00843                 // this should not have updated as it is read only.
00844                 LLVector3 vec(4,5,6);
00845                 nValue3.setVec3(vec);
00846                 LLVector3 vec1(1,2,3);
00847                 ensure("setVec3 on ReadOnly failed", *nValue4.getVec3() == vec1);
00848 
00849                 // cant test for U64 as no set64 exists nor any operators support U64 type
00850         }         
00851 }

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