From 7e59c62c2057a3ab60224275008e06c6eb8b271e Mon Sep 17 00:00:00 2001 From: Ammaev Timur Date: Sat, 30 Nov 2024 17:04:14 +0300 Subject: [PATCH] Improve tests --- Source/Vault.cpp | 8 +++----- Tests/VaultUnitTest.cpp | 5 +++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Source/Vault.cpp b/Source/Vault.cpp index e704229..c6cef1e 100644 --- a/Source/Vault.cpp +++ b/Source/Vault.cpp @@ -163,11 +163,6 @@ namespace mvlt if (ds.GetDataType() == paramsIt.second.GetDataType()) { paramsIt.second.SetDataToRecord(paramsIt.first, newData); - - // If key in record template and key tipy match type in param - res.IsOperationSuccess = true; - res.SavedType = paramsIt.second.GetDataType(); - res.ResultCode = VaultOperationResultCode::Success; } else { // If the type in param not match type in record template @@ -233,6 +228,9 @@ namespace mvlt vaultRecordAddersIt.second(newData); vaultRecordRef.SetRecord(newData, this); + + res.IsOperationSuccess = true; + res.ResultCode = VaultOperationResultCode::Success; } } else delete newData; diff --git a/Tests/VaultUnitTest.cpp b/Tests/VaultUnitTest.cpp index cf2984c..b93a333 100644 --- a/Tests/VaultUnitTest.cpp +++ b/Tests/VaultUnitTest.cpp @@ -216,7 +216,7 @@ void Vault_CreateRecord_Test() TEST_ASSERT(vlt.CreateRecord({ {"A", 1}, {"D", 1} }).ResultCode == VaultOperationResultCode::WrongKey, "Failed to create record"); TEST_ASSERT(vlt.CreateRecord({ {"A", 1}, {"A", 'a'} }).ResultCode == VaultOperationResultCode::WrongType, "Failed to create record"); - // Third method overload + // Second method overload VaultRecordRef vrr1, vrr2; vlt.CreateRecord(vrr1, {{"A", 100}}); vlt.GetRecord("A", 100, vrr2); @@ -227,7 +227,8 @@ void Vault_CreateRecord_Test() vlt.AddKey("B", -1); vlt.AddUniqueKey("C", {[](std::size_t counter, const VaultRecordRef& vrf) -> int { return static_cast(counter); }}); - vlt.CreateRecord(vrr1, {{"A", 1}, {"B", 1}, {"C", 1}}); + TEST_ASSERT(vlt.CreateRecord(vrr1, {{"A", 1}, {"B", 1}, {"C", 1}}).ResultCode == VaultOperationResultCode::Success, "Unique key adding failed!"); + vlt.CreateRecord(vrr1, {{"A", 2}, {"B", 1}, {"C", 2}}); vlt.CreateRecord(vrr1, {{"A", 3}, {"B", 1}, {"C", 3}});