Index: src/libchcore/Tests/TestsTModificationTracker.cpp =================================================================== diff -u --- src/libchcore/Tests/TestsTModificationTracker.cpp (revision 0) +++ src/libchcore/Tests/TestsTModificationTracker.cpp (revision 87f7271b86103cc66243554a91af0c0654f55f45) @@ -0,0 +1,128 @@ +#include "stdafx.h" +#include "gtest/gtest.h" +#include "gmock/gmock.h" +#include "../TModificationTracker.h" +#include "../TString.h" + +using namespace chcore; + +TEST(TModificationTrackerTests, DefaultConstructor) +{ + TModificationTracker tracker; + + EXPECT_TRUE(tracker.IsModified()); + EXPECT_EQ(TString(), tracker); + EXPECT_FALSE(tracker.IsAdded()); +} + +TEST(TModificationTrackerTests, ValueConstructor_NotAdded) +{ + TModificationTracker tracker(L"SomeString", false); + + EXPECT_EQ(TString(L"SomeString"), tracker); + EXPECT_TRUE(tracker.IsModified()); + EXPECT_FALSE(tracker.IsAdded()); +} + +TEST(TModificationTrackerTests, ValueConstructor_Added) +{ + TModificationTracker tracker(L"SomeString", true); + + EXPECT_EQ(TString(L"SomeString"), tracker); + EXPECT_TRUE(tracker.IsModified()); + EXPECT_TRUE(tracker.IsAdded()); +} + +TEST(TModificationTrackerTests, CopyConstructor_NotAdded) +{ + TModificationTracker tracker(L"SomeString", false); + TModificationTracker tracker2(tracker); + + EXPECT_EQ(TString(L"SomeString"), tracker2); + EXPECT_TRUE(tracker2.IsModified()); + EXPECT_FALSE(tracker2.IsAdded()); +} + +TEST(TModificationTrackerTests, CopyConstructor_Added) +{ + TModificationTracker tracker(L"SomeString", true); + TModificationTracker tracker2(tracker); + + EXPECT_EQ(TString(L"SomeString"), tracker2); + EXPECT_TRUE(tracker2.IsModified()); + EXPECT_TRUE(tracker2.IsAdded()); +} + +/////////////////////////////////////////////////////////////////////////// +TEST(TModificationTrackerTests, AssignmentOperator_ModificationTracker_NotAdded) +{ + TModificationTracker tracker(L"SomeString", false); + TModificationTracker tracker2; + + tracker2 = tracker; + + EXPECT_EQ(TString(L"SomeString"), tracker2); + EXPECT_TRUE(tracker2.IsModified()); + EXPECT_FALSE(tracker2.IsAdded()); +} + +TEST(TModificationTrackerTests, AssignmentOperator_ModificationTracker_Added) +{ + TModificationTracker tracker(L"SomeString", true); + TModificationTracker tracker2; + + tracker2 = tracker; + + EXPECT_EQ(TString(L"SomeString"), tracker2); + EXPECT_TRUE(tracker2.IsModified()); + EXPECT_TRUE(tracker2.IsAdded()); +} + +TEST(TModificationTrackerTests, AssignmentOperator_ValueModified) +{ + TModificationTracker tracker(L"SomeString", false); + tracker.ClearModifications(); + + tracker = L"OtherString"; + + EXPECT_EQ(TString(L"OtherString"), tracker); + EXPECT_TRUE(tracker.IsModified()); + EXPECT_FALSE(tracker.IsAdded()); +} + +TEST(TModificationTrackerTests, AssignmentOperator_ValueNotModified) +{ + TModificationTracker tracker(L"SomeString", false); + tracker.ClearModifications(); + + tracker = L"SomeString"; + + EXPECT_EQ(TString(L"SomeString"), tracker); + EXPECT_FALSE(tracker.IsModified()); + EXPECT_FALSE(tracker.IsAdded()); +} + +/////////////////////////////////////////////////////////////////////////// +TEST(TModificationTrackerTests, Modify) +{ + TModificationTracker tracker(L"SomeString", false); + tracker.ClearModifications(); + + tracker.Modify() = L"SomeString"; + + EXPECT_EQ(TString(L"SomeString"), tracker); + EXPECT_TRUE(tracker.IsModified()); + EXPECT_FALSE(tracker.IsAdded()); +} + +/////////////////////////////////////////////////////////////////////////// +TEST(TModificationTrackerTests, IsModified_IsAdded_ClearModifications) +{ + TModificationTracker tracker(L"SomeString", true); + EXPECT_TRUE(tracker.IsModified()); + EXPECT_TRUE(tracker.IsAdded()); + + tracker.ClearModifications(); + EXPECT_FALSE(tracker.IsModified()); + EXPECT_FALSE(tracker.IsAdded()); +} Index: src/libchcore/Tests/TestsTSharedModificationTracker.cpp =================================================================== diff -u --- src/libchcore/Tests/TestsTSharedModificationTracker.cpp (revision 0) +++ src/libchcore/Tests/TestsTSharedModificationTracker.cpp (revision 87f7271b86103cc66243554a91af0c0654f55f45) @@ -0,0 +1,193 @@ +#include "stdafx.h" +#include "gtest/gtest.h" +#include "gmock/gmock.h" +#include "../TSharedModificationTracker.h" +#include +#include "../TString.h" + +using namespace chcore; + +TEST(TSharedModificationTrackerTests, DefaultConstructor) +{ + enum { eMyElement, eLast }; + std::bitset setBits; + TSharedModificationTracker, eMyElement> tracker(setBits); + + EXPECT_EQ(true, tracker.IsModified()); + EXPECT_EQ(true, setBits[eMyElement]); + EXPECT_EQ(TString(), tracker); +} + +TEST(TSharedModificationTrackerTests, AlmostCopyConstructor_Modified) +{ + enum + { + eMyElement, eLast + }; + std::bitset setBits; + TSharedModificationTracker, eMyElement> tracker(setBits); + + std::bitset setBits2; + TSharedModificationTracker, eMyElement> tracker2(tracker, setBits2); + + EXPECT_EQ(true, tracker2.IsModified()); + EXPECT_EQ(true, setBits2[eMyElement]); + EXPECT_EQ(TString(), tracker2); +} + +TEST(TSharedModificationTrackerTests, AlmostCopyConstructor_Modified_WithValue) +{ + enum + { + eMyElement, eLast + }; + + std::bitset setBits; + TSharedModificationTracker, eMyElement> tracker(setBits); + tracker = L"SomeString"; + + std::bitset setBits2; + TSharedModificationTracker, eMyElement> tracker2(tracker, setBits2); + + EXPECT_EQ(true, tracker2.IsModified()); + EXPECT_EQ(true, setBits2[eMyElement]); + EXPECT_EQ(TString(L"SomeString"), tracker2); +} + +TEST(TSharedModificationTrackerTests, AlmostCopyConstructor_Unmodified) +{ + enum + { + eMyElement, eLast + }; + std::bitset setBits; + TSharedModificationTracker, eMyElement> tracker(setBits); + tracker.MarkAsUnmodified(); + + std::bitset setBits2; + TSharedModificationTracker, eMyElement> tracker2(tracker, setBits2); + + EXPECT_EQ(false, tracker2.IsModified()); + EXPECT_EQ(false, setBits2[eMyElement]); +} + +TEST(TSharedModificationTrackerTests, AlmostCopyConstructor_Unmodified_WithValue) +{ + enum + { + eMyElement, eLast + }; + std::bitset setBits; + TSharedModificationTracker, eMyElement> tracker(setBits); + tracker = L"SomeString"; + tracker.MarkAsUnmodified(); + + std::bitset setBits2; + TSharedModificationTracker, eMyElement> tracker2(tracker, setBits2); + + EXPECT_EQ(false, tracker2.IsModified()); + EXPECT_EQ(false, setBits2[eMyElement]); + EXPECT_EQ(TString(L"SomeString"), tracker2); +} + +TEST(TSharedModificationTrackerTests, ConstructorWithValue) +{ + enum + { + eMyElement, eLast + }; + std::bitset setBits; + TSharedModificationTracker, eMyElement> tracker(setBits, L"SomeString"); + + EXPECT_EQ(true, tracker.IsModified()); + EXPECT_EQ(true, setBits[eMyElement]); + EXPECT_EQ(TString(L"SomeString"), tracker); +} + +/////////////////////////////////////////////////////////////////////////// +TEST(TSharedModificationTrackerTests, AssignmentOperator_SharedTracker) +{ + enum + { + eMyElement, eLast + }; + std::bitset setBits; + TSharedModificationTracker, eMyElement> tracker(setBits, L"SomeString"); + + std::bitset setBits2; + TSharedModificationTracker, eMyElement> tracker2(setBits2); + tracker2 = tracker; + + EXPECT_EQ(true, tracker2.IsModified()); + EXPECT_EQ(true, setBits2[eMyElement]); + EXPECT_EQ(TString(L"SomeString"), tracker2); +} + +TEST(TSharedModificationTrackerTests, AssignmentOperator_OtherValue_ModifiesValue) +{ + enum + { + eMyElement, eLast + }; + std::bitset setBits; + TSharedModificationTracker, eMyElement> tracker(setBits); + + tracker = L"SomeString"; + + EXPECT_EQ(true, tracker.IsModified()); + EXPECT_EQ(true, setBits[eMyElement]); + EXPECT_EQ(TString(L"SomeString"), tracker); +} + +TEST(TSharedModificationTrackerTests, AssignmentOperator_OtherValue_DoesNotModifyValue) +{ + enum + { + eMyElement, eLast + }; + std::bitset setBits; + TSharedModificationTracker, eMyElement> tracker(setBits); + + tracker = L"SomeString"; + + EXPECT_EQ(true, tracker.IsModified()); + EXPECT_EQ(true, setBits[eMyElement]); + EXPECT_EQ(TString(L"SomeString"), tracker); +} + +/////////////////////////////////////////////////////////////////////////// +TEST(TSharedModificationTrackerTests, Modify) +{ + enum + { + eMyElement, eLast + }; + std::bitset setBits; + TSharedModificationTracker, eMyElement> tracker(setBits, L"SomeString"); + tracker.MarkAsUnmodified(); + + tracker.Modify() = L"OtherString"; + + EXPECT_EQ(true, tracker.IsModified()); + EXPECT_EQ(true, setBits[eMyElement]); + EXPECT_EQ(TString(L"OtherString"), tracker); +} + +/////////////////////////////////////////////////////////////////////////// +TEST(TSharedModificationTrackerTests, MarkAsModified_MarkAsUnmodified) +{ + enum + { + eMyElement, eLast + }; + std::bitset setBits; + TSharedModificationTracker, eMyElement> tracker(setBits, L"SomeString"); + + EXPECT_EQ(true, tracker.IsModified()); + + tracker.MarkAsUnmodified(); + EXPECT_EQ(false, tracker.IsModified()); + + tracker.MarkAsModified(); + EXPECT_EQ(true, tracker.IsModified()); +}