void ChatHandler::ChangeSelectedNPC(const uint16 &index, const uint32 Value, const uint32 max, const uint32 min) { wowWData data; if(!TestValue(Value, max, min)) return; Unit * pUnit = getSelectedNPC(); if(pUnit!=NULL) { pUnit->setUpdateValue(index , Value); DatabaseInterface *dbi = Database::getSingleton().createDatabaseInterface( ); /* sprintf((char*)buf, "DELETE FROM creatures WHERE id=%u", pUnit->getGUID()); dbi->doQuery((char*)buf); dbi->saveCreature(pUnit); */ dbi->updateCreature(pUnit); Database::getSingleton( ).removeDatabaseInterface(dbi); pUnit->UpdateObject(); FillMessageData(&data, 0x09, m_pClient,(uint8*)"NPC updated."); m_pClient->SendMsg( &data ); } return; }
//UINT32 void ChatHandler::ChangeSelectedChar(const uint16 &index, const uint32 Value, const uint32 max, const uint32 min, char * nom) { if(!TestValue(Value, max, min)) return; Character * pChar = getSelectedChar(); if(pChar!=NULL) { pChar->setUpdateValue(index , Value); Message(pChar, nom, Value); } return; }
static void DeleteTest() { static char pathBuffer[STR_SIZE] = { 0 }; snprintf(pathBuffer, STR_SIZE, "%s/deleteTest/", TestRootDir); le_cfg_IteratorRef_t iterRef = le_cfg_CreateWriteTxn(pathBuffer); le_cfg_SetString(iterRef, "valueA", "aNewValue"); le_cfg_SetString(iterRef, "valueB", "aNewValue"); le_cfg_SetString(iterRef, "valueC", "aNewValue"); TestValue(iterRef, "valueA", "aNewValue"); TestValue(iterRef, "valueB", "aNewValue"); TestValue(iterRef, "valueC", "aNewValue"); le_cfg_CommitTxn(iterRef); iterRef = le_cfg_CreateWriteTxn(pathBuffer); le_cfg_DeleteNode(iterRef, "valueB"); TestValue(iterRef, "valueA", "aNewValue"); TestValue(iterRef, "valueB", ""); TestValue(iterRef, "valueC", "aNewValue"); le_cfg_CommitTxn(iterRef); iterRef = le_cfg_CreateReadTxn(pathBuffer); TestValue(iterRef, "valueA", "aNewValue"); TestValue(iterRef, "valueB", ""); TestValue(iterRef, "valueC", "aNewValue"); DumpTree(iterRef, 0); le_cfg_CancelTxn(iterRef); }
//UINT32 void ChatHandler::ChangeSelectedCharMsg(const uint16 &index, const uint32 Value, const uint32 max, const uint32 min, char * nom) { wowWData data; if(!TestValue(Value, max, min)) return; Character * pChar = getSelectedChar(); if(pChar!=NULL) { data.Initialise( 12, index ); data << pChar->getUpdateValue( OBJECT_FIELD_GUID ); data << pChar->getUpdateValue( OBJECT_FIELD_GUID + 1 ); data << Value; pChar->SendMessageToSet( &data, true ); Message(pChar, nom, Value); } return; }
//------------------------- TH1* KVRandomizor::FillHisto2D(Int_t ntimes) //------------------------- { TH2* h1 = new TH2F( Form("histo%dD", fNd), Form("histo%dD", fNd), (fMax[0] - fMin[0]) * 100, fMin[0], fMax[0], (fMax[1] - fMin[1]) * 100, fMin[1], fMax[1] ); for (Int_t ii = 0; ii < ntimes; ii += 1) { fNtest += 1; Double_t* pos = GetPosition(); if (TestValue(ComputeValue(pos))) { h1->Fill(pos[0], pos[1]); } else { ii -= 1; } delete [] pos; } return h1; }
int main (int argc, char const * argv []) { TestValue (LILengthVec2 (LIMakeVec2 (3, 4)), 5); TestValue (LILengthVec3 (LIMakeVec3 (3, 4, -5)), 7.071067812); TestValue (LILengthVec4 (LIMakeVec4 (3, 4, -5, 6)), 9.273618495); TestValue (LIDistanceVec2 (LIMakeVec2 (3, 4), LIMakeVec2 (-5, -2)), 10); TestValue (LIDistanceVec3 (LIMakeVec3 (3, 4, -5), LIMakeVec3 (-5, -2, 7)), 15.62049935); TestValue (LIDistanceVec4 (LIMakeVec4 (3, 4, -5, 6), LIMakeVec4 (-5, -2, 7, -8)), 20.97617696); TestVec2 (LINormalizeMultVec2 (LIMakeVec2 (3, 4), -1.2), LIMultVec2 (LIMakeVec2 (0.6, 0.8), -1.2)); TestVec3 (LINormalizeMultVec3 (LIMakeVec3 (3, 4, 5), -1.2), LIMultVec3 (LIMakeVec3 (0.4242640687, 0.5656854249, 0.7071067812), -1.2)); TestVec4 (LINormalizeMultVec4 (LIMakeVec4 (3, 4, 5, 6), -1.2), LIMultVec4 (LIMakeVec4 (0.3234983196, 0.4313310928, 0.539163866, 0.6469966393), -1.2)); TestVec2 (LINormalizeVec2 (LIMakeVec2 (3, 4)), LIMakeVec2 (0.6, 0.8)); TestVec3 (LINormalizeVec3 (LIMakeVec3 (3, 4, 5)), LIMakeVec3 (0.4242640687, 0.5656854249, 0.7071067812)); TestVec4 (LINormalizeVec4 (LIMakeVec4 (3, 4, 5, 6)), LIMakeVec4 (0.3234983196, 0.4313310928, 0.539163866, 0.6469966393)); return STATUS_PASS; }
/** Simple test cases for key value pair code */ void TestKeyValuePairs() { bool bSuccess = true; TArray<uint8> TestData; TestData.Add((uint8)200); typedef FOnlineKeyValuePairs<FName, FVariantData> TestDataType; TestDataType TestKeyValuePairs; // Test Templates TestKeyValuePairs.Add(TEXT("INTValue"), FVariantData(512)); TestKeyValuePairs.Add(TEXT("FLOATValue"), FVariantData(512.0f)); TestKeyValuePairs.Add(TEXT("QWORDValue"), FVariantData((uint64)512)); TestKeyValuePairs.Add(TEXT("DOUBLEValue"), FVariantData(512000.0)); TestKeyValuePairs.Add(TEXT("STRINGValue"), FVariantData(TEXT("This Is A Test!"))); TestKeyValuePairs.Add(TEXT("BLOBValue"), FVariantData(TestData)); UE_LOG(LogOnline, Display, TEXT("ConstIterator")); for (TestDataType::TConstIterator It(TestKeyValuePairs); It; ++It) { UE_LOG(LogOnline, Display, TEXT("%s = %s"), *It.Key().ToString(), *It.Value().ToString()); } UE_LOG(LogOnline, Display, TEXT("Iterator")); for (TestDataType::TIterator It(TestKeyValuePairs); It; ++It) { UE_LOG(LogOnline, Display, TEXT("Iterator %s = %s"), *It.Key().ToString(), *It.Value().ToString()); } UE_LOG(LogOnline, Display, TEXT("Finding all elements")); if (TestKeyValuePairs.Find(TEXT("INTValue")) == NULL) { bSuccess = false; } if (TestKeyValuePairs.Find(TEXT("FLOATValue")) == NULL) { bSuccess = false; } if (TestKeyValuePairs.Find(TEXT("QWORDValue")) == NULL) { bSuccess = false; } if (TestKeyValuePairs.Find(TEXT("DOUBLEValue")) == NULL) { bSuccess = false; } if (TestKeyValuePairs.Find(TEXT("STRINGValue")) == NULL) { bSuccess = false; } if (TestKeyValuePairs.Find(TEXT("BLOBValue")) == NULL) { bSuccess = false; } if (!bSuccess) { UE_LOG(LogOnline, Display, TEXT("Not all elements found!")); } TestKeyValuePairs.Remove(TEXT("INTValue")); TestKeyValuePairs.Remove(TEXT("BLOBValue")); UE_LOG(LogOnline, Display, TEXT("Iterator AFTER removing int32 and Blob elements")); for (TestDataType::TIterator It(TestKeyValuePairs); It; ++It) { UE_LOG(LogOnline, Display, TEXT("Iterator %s = %s"), *It.Key().ToString(), *It.Value().ToString()); } TestKeyValuePairs.Empty(); UE_LOG(LogOnline, Display, TEXT("Iterator AFTER emptying structure")); for (TestDataType::TIterator It(TestKeyValuePairs); It; ++It) { UE_LOG(LogOnline, Display, TEXT("Iterator %s = %s"), *It.Key().ToString(), *It.Value().ToString()); } bSuccess = TestKeyValuePairs.Num() == 0 ? true : false; // Test basic variant data type functionality FVariantData OrigKeyValuePair; FVariantData CopyValue; { // Test int32 int32 OutValue = 0; int32 TestValue = 5; OrigKeyValuePair.SetValue(TestValue); OrigKeyValuePair.GetValue(OutValue); bSuccess = bSuccess && (OutValue == TestValue); CopyValue = OrigKeyValuePair; UE_LOG(LogOnline, Display, TEXT("int32 Test %s == %s"), *OrigKeyValuePair.ToString(), *CopyValue.ToString()); OrigKeyValuePair.Increment<int32,EOnlineKeyValuePairDataType::Int32>((int32)1); UE_LOG(LogOnline, Display, TEXT("+1 Now is %s"), *OrigKeyValuePair.ToString()); OrigKeyValuePair.Decrement<int32,EOnlineKeyValuePairDataType::Int32>((int32)1); UE_LOG(LogOnline, Display, TEXT("-1 Now is %s"), *OrigKeyValuePair.ToString()); bSuccess = bSuccess && (OrigKeyValuePair == CopyValue); bSuccess = bSuccess && OrigKeyValuePair.FromString(TEXT("5")); UE_LOG(LogOnline, Display, TEXT("int32 Test %s == %s"), *OrigKeyValuePair.ToString(), *CopyValue.ToString()); } { // Test float float OutValue = 0.0f; float TestValue = 5.0f; OrigKeyValuePair.SetValue(TestValue); OrigKeyValuePair.GetValue(OutValue); bSuccess = bSuccess && (OutValue == TestValue); CopyValue = OrigKeyValuePair; UE_LOG(LogOnline, Display, TEXT("float Test %s == %s"), *OrigKeyValuePair.ToString(), *CopyValue.ToString()); OrigKeyValuePair.Increment<float,EOnlineKeyValuePairDataType::Float>(1.0f); UE_LOG(LogOnline, Display, TEXT("+1 Now is %s"), *OrigKeyValuePair.ToString()); OrigKeyValuePair.Decrement<float,EOnlineKeyValuePairDataType::Float>(1.0f); UE_LOG(LogOnline, Display, TEXT("-1 Now is %s"), *OrigKeyValuePair.ToString()); bSuccess = bSuccess && (OrigKeyValuePair == CopyValue); bSuccess = bSuccess && OrigKeyValuePair.FromString(TEXT("5.0")); UE_LOG(LogOnline, Display, TEXT("float Test %s == %s"), *OrigKeyValuePair.ToString(), *CopyValue.ToString()); } { // Test double double OutValue = 0.0; double TestValue = 5.0; OrigKeyValuePair.SetValue(TestValue); OrigKeyValuePair.GetValue(OutValue); bSuccess = bSuccess && (OutValue == TestValue); CopyValue = OrigKeyValuePair; UE_LOG(LogOnline, Display, TEXT("double Test %s == %s"), *OrigKeyValuePair.ToString(), *CopyValue.ToString()); OrigKeyValuePair.Increment<double,EOnlineKeyValuePairDataType::Double>(1.0); UE_LOG(LogOnline, Display, TEXT("+1 Now is %s"), *OrigKeyValuePair.ToString()); OrigKeyValuePair.Decrement<double,EOnlineKeyValuePairDataType::Double>(1.0); UE_LOG(LogOnline, Display, TEXT("-1 Now is %s"), *OrigKeyValuePair.ToString()); bSuccess = bSuccess && (OrigKeyValuePair == CopyValue); bSuccess = bSuccess && OrigKeyValuePair.FromString(TEXT("5.0")); UE_LOG(LogOnline, Display, TEXT("double Test %s == %s"), *OrigKeyValuePair.ToString(), *CopyValue.ToString()); } { // Test uint64 uint64 OutValue = 0; uint64 TestValue = 524288; OrigKeyValuePair.SetValue(TestValue); OrigKeyValuePair.GetValue(OutValue); bSuccess = bSuccess && (OutValue == TestValue); CopyValue = OrigKeyValuePair; UE_LOG(LogOnline, Display, TEXT("uint64 Test %s == %s"), *OrigKeyValuePair.ToString(), *CopyValue.ToString()); OrigKeyValuePair.Increment<uint64,EOnlineKeyValuePairDataType::Int64>(1.0); UE_LOG(LogOnline, Display, TEXT("+1 Now is %s"), *OrigKeyValuePair.ToString()); OrigKeyValuePair.Decrement<uint64,EOnlineKeyValuePairDataType::Int64>(1.0); UE_LOG(LogOnline, Display, TEXT("-1 Now is %s"), *OrigKeyValuePair.ToString()); bSuccess = bSuccess && (OrigKeyValuePair == CopyValue); bSuccess = bSuccess && OrigKeyValuePair.FromString(TEXT("524288")); UE_LOG(LogOnline, Display, TEXT("uint64 Test %s == %s"), *OrigKeyValuePair.ToString(), *CopyValue.ToString()); } { // Test String FString OutValue; FString TestValue(TEXT("This is a test!")); OrigKeyValuePair.SetValue(TestValue); OrigKeyValuePair.GetValue(OutValue); bSuccess = bSuccess && (OutValue == TestValue); CopyValue = OrigKeyValuePair; bSuccess = bSuccess && (OrigKeyValuePair == CopyValue); UE_LOG(LogOnline, Display, TEXT("STRING Test %s == %s"), *OrigKeyValuePair.ToString(), *CopyValue.ToString()); } { // Test Blob TArray<uint8> OutValue; TArray<uint8> TestValue; for (int32 i=0; i<512; i++) { TestValue.Add(FMath::Rand() % 255); } OrigKeyValuePair.SetValue(TestValue); OrigKeyValuePair.GetValue(OutValue); bSuccess = bSuccess && (OutValue == TestValue); CopyValue = OrigKeyValuePair; bSuccess = bSuccess && (OrigKeyValuePair == CopyValue); UE_LOG(LogOnline, Display, TEXT("BLOB Test %s == %s"), *OrigKeyValuePair.ToString(), *CopyValue.ToString()); } UE_LOG(LogOnline, Warning, TEXT("KeyValuePairTest: %s!"), bSuccess ? TEXT("PASSED") : TEXT("FAILED")); }