From 8bbb15566e1025fe5784190fa0f594cc837c2673 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Gl=C3=B6ckner?= Date: Thu, 31 Mar 2016 10:40:02 +0200 Subject: Removed unused features and fixed tests --- src/syncedsettings.h | 12 ------ test/syncedsettings.cc | 109 ++++++++++++++++++++++++++++++++++--------------- 2 files changed, 76 insertions(+), 45 deletions(-) diff --git a/src/syncedsettings.h b/src/syncedsettings.h index b72229e..aa43cc0 100644 --- a/src/syncedsettings.h +++ b/src/syncedsettings.h @@ -60,18 +60,6 @@ public: { } - Group(T const& data) - : mutex{} - , data{data} - { - } - - Group(T&& data) - : mutex{} - , data{std::move(data)} - { - } - Group(Group const& other) : mutex{} , data{} diff --git a/test/syncedsettings.cc b/test/syncedsettings.cc index a04c870..7de7c42 100644 --- a/test/syncedsettings.cc +++ b/test/syncedsettings.cc @@ -34,8 +34,6 @@ class SyncedSettingsTest CPPUNIT_TEST_SUITE(SyncedSettingsTest); CPPUNIT_TEST(groupCanBeDefaultInitialized); CPPUNIT_TEST(groupDataCanBeCopied); - CPPUNIT_TEST(groupCanBeCreatedByReference); - CPPUNIT_TEST(groupCanBeCreatedByRvalueReference); CPPUNIT_TEST(accessorCanGetFields); CPPUNIT_TEST(accessorCanSetFields); @@ -44,6 +42,8 @@ class SyncedSettingsTest CPPUNIT_TEST(groupHasMoveCtor); CPPUNIT_TEST(groupHasCopyAssignOp); CPPUNIT_TEST(groupHasMoveAssignOp); + + CPPUNIT_TEST(mimicRealUse); CPPUNIT_TEST_SUITE_END(); private: @@ -66,18 +66,14 @@ class SyncedSettingsTest (TestData)data; // copies } - void groupCanBeCreatedByReference() { - TestData tmp{3.f, false, "hello"}; - Group data{tmp}; - TestData copy = data; - CPPUNIT_ASSERT_EQUAL(copy.foo, 3.f); - CPPUNIT_ASSERT_EQUAL(copy.bar, false); - CPPUNIT_ASSERT_EQUAL(copy.msg, std::string{"hello"}); - } - - void groupCanBeCreatedByRvalueReference() { - TestData tmp{3.f, false, "hello"}; - Group data{std::move(tmp)}; + void accessorCanSetFields() { + Group data; + { + Accessor a{data}; + a.data.foo = 3.f; + a.data.bar = false; + a.data.msg = "hello"; + } TestData copy = data; CPPUNIT_ASSERT_EQUAL(copy.foo, 3.f); CPPUNIT_ASSERT_EQUAL(copy.bar, false); @@ -85,26 +81,22 @@ class SyncedSettingsTest } void accessorCanGetFields() { - TestData tmp{3.f, false, "hello"}; - Group data{tmp}; - Accessor a{data}; - CPPUNIT_ASSERT_EQUAL(a.data.foo, 3.f); - CPPUNIT_ASSERT_EQUAL(a.data.bar, false); - CPPUNIT_ASSERT_EQUAL(a.data.msg, std::string{"hello"}); - } - - void accessorCanSetFields() { Group data; - Accessor a{data}; - a.data.foo = 3.f; - a.data.bar = false; - a.data.msg = "hello"; - TestData copy = data; - CPPUNIT_ASSERT_EQUAL(copy.foo, 3.f); - CPPUNIT_ASSERT_EQUAL(copy.bar, false); - CPPUNIT_ASSERT_EQUAL(copy.msg, std::string{"hello"}); + { + Accessor a{data}; + a.data.foo = 3.f; + a.data.bar = false; + a.data.msg = "hello"; + } + // now read + { + Accessor a{data}; + CPPUNIT_ASSERT_EQUAL(a.data.foo, 3.f); + CPPUNIT_ASSERT_EQUAL(a.data.bar, false); + CPPUNIT_ASSERT_EQUAL(a.data.msg, std::string{"hello"}); + } } - + void groupHasCopyCtor() { Group tmp; { @@ -165,7 +157,58 @@ class SyncedSettingsTest CPPUNIT_ASSERT_EQUAL(copy.msg, std::string{"hello"}); } - // todo: further testing + void mimicRealUse() { + struct Settings { + struct Foo { + int a, b; + bool enabled; + }; + struct Bar { + float a, b; + bool enabled; + }; + struct Idk { + std::string label; + float bla; + }; + + Group foo; + Group bar; + Group idk; + }; + + Settings s; + + // set some settings + { + Accessor tmp{s.foo}; + tmp.data.enabled = true; + tmp.data.a = 3; + } + { + Accessor tmp{s.bar}; + tmp.data.enabled = false; + tmp.data.a = 0.f; + tmp.data.b = 0.f; + } + { + Accessor tmp{s.idk}; + tmp.data.label = "hello world"; + tmp.data.bla = 3.14f; + } + + // read some settings + { + Accessor tmp{s.foo}; + if (tmp.data.enabled) { + // do some while locked + } + } + Settings::Bar copy = s.bar; + if (copy.enabled) { + // do some stuff without locking + } + } }; // Registers the fixture into the 'registry' -- cgit v1.2.3