Refactor of tests suits 81/154081/1
authorLukasz Wlazly <l.wlazly@partner.samsung.com>
Fri, 6 Oct 2017 09:52:14 +0000 (11:52 +0200)
committerLukasz Wlazly <l.wlazly@partner.samsung.com>
Fri, 6 Oct 2017 10:12:16 +0000 (12:12 +0200)
1. Change all "asserts" into "expects".
2. Usage of ecore::Timer in ConfigurationTests

Change-Id: I0cce58be91ba38c88cf095978ecfc748bff449c3

tests/no-ui-scenarios/DBusTests.cpp
tests/no-ui-scenarios/OptionalTests.cpp
tests/no-ui-scenarios/TranslationsTests.cpp
tests/ui-scenarios/ActivityProcessingTests.cpp
tests/ui-scenarios/ConfigurationTests.hpp
tests/ui-scenarios/FooTests.cpp [deleted file]
tests/ui-scenarios/FooTests.hpp [deleted file]
tests/ui-scenarios/MenuBuilderTests.cpp
tests/ui-scenarios/main.cpp

index 09c6b43..d9e41b9 100644 (file)
@@ -38,12 +38,9 @@ protected:
                if (init) {
                        init = false;
                        auto z = ecore_init();
-                       ASSERT_EQ(z, 1);
+                       EXPECT_EQ(z, 1);
                        ecore_event_init();
                        eldbus_init();
-                       // DBus::setDebugPrinter([](const char *txt, size_t s) {
-                       //      std::cerr << txt << std::endl;
-                       // });
                }
        }
        void cancelAll()
@@ -264,7 +261,7 @@ TEST_F(DBusTest, sendAndReceiveAsyncInt)
                }
        }, 7, 0);
        runTestInMainLoop(1.0f);
-       ASSERT_TRUE(success);
+       EXPECT_TRUE(success);
 
        db.method<int(int, int)>("ftest").asyncCall([ = ](DBus::ValueOrError<int> val) {
                EXPECT_FALSE(val);
@@ -276,7 +273,7 @@ TEST_F(DBusTest, sendAndReceiveAsyncInt)
                }
        }, 17, 1);
        runTestInMainLoop(1.0f);
-       ASSERT_TRUE(success);
+       EXPECT_TRUE(success);
 
        db.method<int(int, int)>("ftest").asyncCall([ = ](DBus::ValueOrError<int> val) {
                EXPECT_TRUE(val);
@@ -288,7 +285,7 @@ TEST_F(DBusTest, sendAndReceiveAsyncInt)
                }
        }, 27, 2);
        runTestInMainLoop(1.0f);
-       ASSERT_TRUE(success);
+       EXPECT_TRUE(success);
 
        db.method<int(int, int)>("ftest").asyncCall([ = ](DBus::ValueOrError<int> val) {
                EXPECT_FALSE(val);
@@ -300,7 +297,7 @@ TEST_F(DBusTest, sendAndReceiveAsyncInt)
                }
        }, 37, 3);
        runTestInMainLoop(1.0f);
-       ASSERT_TRUE(success);
+       EXPECT_TRUE(success);
 }
 
 // calls asynchronously a method. checks, std::vector marshalls property.
@@ -480,7 +477,7 @@ TEST_F(DBusTest, sendAndReceiveFallbackProperty)
                        }
                });
                runTestInMainLoop(1.0f);
-               ASSERT_TRUE(success);
+               EXPECT_TRUE(success);
        }
 }
 
@@ -537,8 +534,8 @@ TEST_F(DBusTest, synchronousCall)
        auto connection = DBus::getDBusConnectionByType(DBus::ConnectionType::SYSTEM);
        DBus::DBusClient db{testBusName, syncPathName, syncInterfaceName, connection};
        auto r = db.method<int(int, int)>("add").call(10, 55);
-       ASSERT_TRUE(r);
-       ASSERT_EQ(std::get<0>(r), 10 + 55);
+       EXPECT_TRUE(r);
+       EXPECT_EQ(std::get<0>(r), 10 + 55);
 }
 
 // Calls method on external process synchronously, expect error
@@ -547,8 +544,8 @@ TEST_F(DBusTest, synchronousCallExpectError)
        auto connection = DBus::getDBusConnectionByType(DBus::ConnectionType::SYSTEM);
        DBus::DBusClient db{testBusName, syncPathName, syncInterfaceName, connection};
        auto r = db.method<int(int, int)>("add").call(-10, 55);
-       ASSERT_FALSE(r);
-       ASSERT_EQ(r.getError().message, "org.freedesktop.DBus.Error.Failed: negative");
+       EXPECT_FALSE(r);
+       EXPECT_EQ(r.getError().message, "org.freedesktop.DBus.Error.Failed: negative");
 }
 
 // Calls method 'call' on external process asynchronously,
@@ -576,8 +573,8 @@ TEST_F(DBusTest, recursiveCall)
        }, server.getBusName(), "/ptesttest", "itest.itest2", "setReply", 111);
 
        runTestInMainLoop(1.0f);
-       ASSERT_TRUE(success);
-       ASSERT_EQ(calledValue, 111);
+       EXPECT_TRUE(success);
+       EXPECT_EQ(calledValue, 111);
 }
 
 // Calls method 'emitS' on external process asynchronously,
@@ -602,8 +599,8 @@ TEST_F(DBusTest, recursiveSignal)
        }, 10);
 
        runTestInMainLoop(1.0f);
-       ASSERT_TRUE(success);
-       ASSERT_EQ(realValue, 20);
+       EXPECT_TRUE(success);
+       EXPECT_EQ(realValue, 20);
 }
 
 std::pair<std::vector<std::unique_ptr<DBus::DBusClient>>, std::vector<std::unique_ptr<DBus::DBusServer>>>
index 817f002..74f1852 100644 (file)
@@ -115,7 +115,7 @@ TEST_F(OptionalTestsFixture, ValueStorageChecking)
 TEST_F(OptionalTestsFixture, ConstructorChecking_FromValue)
 {
        Optional<int> a{5};
-       ASSERT_TRUE(a);
+       EXPECT_TRUE(a);
        EXPECT_EQ(*a, 5);
 }
 
@@ -124,7 +124,7 @@ TEST_F(OptionalTestsFixture, ConstructorChecking_FromTypeWithoutCast)
        auto u = AA {};
        Optional<ClassWithCounters> a{u};
        EXPECT_EQ(u.value, 10);
-       ASSERT_TRUE(a);
+       EXPECT_TRUE(a);
        EXPECT_EQ(a->value, 10);
        SetExpects(1, 0, 0);
 }
@@ -133,8 +133,8 @@ TEST_F(OptionalTestsFixture, CopyConstructorChecking_FromEmptyOptional)
 {
        auto original = Optional<ClassWithCounters> {};
        auto copy = original;
-       ASSERT_FALSE(original);
-       ASSERT_FALSE(copy);
+       EXPECT_FALSE(original);
+       EXPECT_FALSE(copy);
        SetExpects(0, 0, 0);
 }
 
@@ -142,9 +142,9 @@ TEST_F(OptionalTestsFixture, CopyConstructorChecking_FromValidOptional)
 {
        auto original = Optional<ClassWithCounters> {5};
        auto copy { original };
-       ASSERT_TRUE(original);
+       EXPECT_TRUE(original);
        EXPECT_EQ(*original, 5);
-       ASSERT_TRUE(copy);
+       EXPECT_TRUE(copy);
        EXPECT_EQ(*copy, 5);
        SetExpects(2, 0, 0);
 }
@@ -153,8 +153,8 @@ TEST_F(OptionalTestsFixture, MoveConstructorChecking_FromEmptyOptional)
 {
        auto original = Optional<ClassWithCounters> {};
        auto copy{std::move(original)};
-       ASSERT_FALSE(original);
-       ASSERT_FALSE(copy);
+       EXPECT_FALSE(original);
+       EXPECT_FALSE(copy);
        SetExpects(0, 0, 0);
 }
 
@@ -162,8 +162,8 @@ TEST_F(OptionalTestsFixture, MoveConstructorChecking_FromValidOptional)
 {
        auto original = Optional<ClassWithCounters> {5};
        auto copy{std::move(original)};
-       ASSERT_TRUE(copy);
-       ASSERT_EQ(*copy, 5);
+       EXPECT_TRUE(copy);
+       EXPECT_EQ(*copy, 5);
        SetExpects(2, 0, 0);
 }
 
@@ -187,7 +187,7 @@ TEST_F(OptionalTestsFixture, AssignmentOperatorChecking_SameObjectEmptyOptional)
 {
        auto a = Optional<ClassWithCounters> {};
        a = a;
-       ASSERT_FALSE(a);
+       EXPECT_FALSE(a);
        SetExpects(0, 0, 0);
 }
 
@@ -195,7 +195,7 @@ TEST_F(OptionalTestsFixture, AssignmentOperatorChecking_SameObjectValidOptional)
 {
        auto a = Optional<ClassWithCounters> {5};
        a = a;
-       ASSERT_TRUE(a);
+       EXPECT_TRUE(a);
        EXPECT_EQ(a->value, 5);
        SetExpects(1, 0, 0);
 }
@@ -205,8 +205,8 @@ TEST_F(OptionalTestsFixture, AssignmentOperatorChecking_FromEmptyToValid)
        auto a = Optional<ClassWithCounters> {};
        auto b = Optional<ClassWithCounters> {7};
        b = a;
-       ASSERT_FALSE(a);
-       ASSERT_FALSE(b);
+       EXPECT_FALSE(a);
+       EXPECT_FALSE(b);
        SetExpects(1, 1, 0);
 }
 
@@ -215,9 +215,9 @@ TEST_F(OptionalTestsFixture, AssignmentOperatorChecking_FromValidToValid)
        auto a = Optional<ClassWithCounters> {5};
        auto b = Optional<ClassWithCounters> {7};
        b = a;
-       ASSERT_TRUE(a);
+       EXPECT_TRUE(a);
        EXPECT_EQ(a->value, 5);
-       ASSERT_TRUE(b);
+       EXPECT_TRUE(b);
        EXPECT_EQ(b->value, 5);
        SetExpects(2, 0, 1);
 }
@@ -227,9 +227,9 @@ TEST_F(OptionalTestsFixture, AssignmentOperatorChecking_FromValidToEmpty)
        auto a = Optional<ClassWithCounters> {5};
        auto b = Optional<ClassWithCounters> {};
        b = a;
-       ASSERT_TRUE(a);
+       EXPECT_TRUE(a);
        EXPECT_EQ(a->value, 5);
-       ASSERT_TRUE(b);
+       EXPECT_TRUE(b);
        EXPECT_EQ(b->value, 5);
        SetExpects(2, 0, 0);
 }
@@ -238,7 +238,7 @@ TEST_F(OptionalTestsFixture, AssignmentMoveOperatorChecking_SameObjectEmptyOptio
 {
        auto a = Optional<ClassWithCounters> {};
        a = std::move(a);
-       ASSERT_FALSE(a);
+       EXPECT_FALSE(a);
        SetExpects(0, 0, 0);
 }
 
@@ -246,7 +246,7 @@ TEST_F(OptionalTestsFixture, AssignmentMoveOperatorChecking_SameObjectValidOptio
 {
        auto a = Optional<ClassWithCounters> {5};
        a = std::move(a);
-       ASSERT_TRUE(a);
+       EXPECT_TRUE(a);
        EXPECT_EQ(a->value, 5);
        SetExpects(1, 0, 0);
 }
@@ -256,8 +256,8 @@ TEST_F(OptionalTestsFixture, AssignmentMoveOperatorChecking_FromEmptyToValid)
        auto a = Optional<ClassWithCounters> {};
        auto b = Optional<ClassWithCounters> {7};
        b = std::move(a);
-       ASSERT_FALSE(a);
-       ASSERT_FALSE(b);
+       EXPECT_FALSE(a);
+       EXPECT_FALSE(b);
        SetExpects(1, 1, 0);
 }
 
@@ -266,9 +266,9 @@ TEST_F(OptionalTestsFixture, AssignmentMoveOperatorChecking_FromValidToValid)
        auto a = Optional<ClassWithCounters> {5};
        auto b = Optional<ClassWithCounters> {7};
        b = std::move(a);
-       ASSERT_TRUE(a);
+       EXPECT_TRUE(a);
        EXPECT_EQ(a->value, 5);
-       ASSERT_TRUE(b);
+       EXPECT_TRUE(b);
        EXPECT_EQ(b->value, 5);
        SetExpects(2, 0, 1);
 }
@@ -311,15 +311,15 @@ TEST_F(OptionalTestsFixture, EnumClearingFailure)
 {
        enum class A { a };
        Optional<A> opt { A::a };
-       ASSERT_TRUE(opt);
+       EXPECT_TRUE(opt);
        opt = {};
-       ASSERT_FALSE(opt);
+       EXPECT_FALSE(opt);
 }
 
 TEST_F(OptionalTestsFixture, IntClearingFailure)
 {
        Optional<int> opt { 1 };
-       ASSERT_TRUE(opt);
+       EXPECT_TRUE(opt);
        opt = {};
-       ASSERT_FALSE(opt);
+       EXPECT_FALSE(opt);
 }
index 0b05e2b..5d34732 100644 (file)
@@ -2,7 +2,6 @@
 #include "Singleton.hpp"
 
 #include <gtest/gtest.h>
-#include <string>
 
 TEST(Translations, testTranslations)
 {
@@ -12,4 +11,4 @@ TEST(Translations, testTranslations)
        textdomain(PROJECT_NAME);
        setlocale(LC_ALL, "en_US.UTF-8");
        EXPECT_EQ(menuItem->getName(), "Tap");
-}
\ No newline at end of file
+}
index 5156291..a19a696 100644 (file)
@@ -1,8 +1,6 @@
 #include "ActivityProcessingTests.hpp"
 #include "ActivityFactory.hpp"
 
-#include <cassert>
-
 /*
    This test verifies, if auto-registration of activity types in ActivityFactory was performed on application bootstrap.
 */
@@ -20,8 +18,10 @@ TEST_F(ActivityProcessingFixture, ActivityNotFullyProcessed)
 {
        initialEnvironmentExpect();
        auto activity = switchManager_->getActivities().top();
-       ASSERT_NE(activity, nullptr);
-       EXPECT_EQ(activity->getType(), "TWO_STEP_PROCESS_ACTIVITY");
+
+       EXPECT_NE(activity, nullptr);
+       if (activity)
+               EXPECT_EQ(activity->getType(), "TWO_STEP_PROCESS_ACTIVITY");
 }
 
 /*
@@ -32,8 +32,9 @@ TEST_F(ActivityProcessingFixture, ActivityReady)
 {
        initialEnvironmentExpect();
        auto activity = switchManager_->getActivities().top();
-       ASSERT_NE(activity, nullptr);
-       EXPECT_EQ(activity->getType(), "TWO_STEP_PROCESS_ACTIVITY");
+       EXPECT_NE(activity, nullptr);
+       if (activity)
+               EXPECT_EQ(activity->getType(), "TWO_STEP_PROCESS_ACTIVITY");
 
        simulateKeyPress(keyMappedToTwoStepProcessActivity_);
        auto isEmpty = switchManager_->getActivities().empty();
@@ -48,25 +49,29 @@ TEST_F(ActivityProcessingFixture, ActivityAbandoned)
 {
        initialEnvironmentExpect();
        auto activity = switchManager_->getActivities().top();
-       ASSERT_NE(activity, nullptr);
-       EXPECT_EQ(activity->getType(), "TWO_STEP_PROCESS_ACTIVITY");
+       EXPECT_NE(activity, nullptr);
+       if (activity)
+               EXPECT_EQ(activity->getType(), "TWO_STEP_PROCESS_ACTIVITY");
 
        simulateKeyPress(keyMappedToThreeStepProcessActivity_);
        EXPECT_EQ(switchManager_->getActivities().size(), 2u);
        activity = switchManager_->getActivities().top();
-       ASSERT_NE(activity, nullptr);
-       EXPECT_EQ(activity->getType(), "THREE_STEP_PROCESS_ACTIVITY");
+       EXPECT_NE(activity, nullptr);
+       if (activity)
+               EXPECT_EQ(activity->getType(), "THREE_STEP_PROCESS_ACTIVITY");
 
        simulateKeyPress(keyMappedToThreeStepProcessActivity_);
        EXPECT_EQ(switchManager_->getActivities().size(), 2u);
        activity = switchManager_->getActivities().top();
 
-       ASSERT_NE(activity, nullptr);
-       EXPECT_EQ(activity->getType(), "THREE_STEP_PROCESS_ACTIVITY");
+       EXPECT_NE(activity, nullptr);
+       if (activity)
+               EXPECT_EQ(activity->getType(), "THREE_STEP_PROCESS_ACTIVITY");
 
        simulateKeyPress(keyMappedToThreeStepProcessActivity_);
        EXPECT_EQ(switchManager_->getActivities().size(), 1u);
        activity = switchManager_->getActivities().top();
-       ASSERT_NE(activity, nullptr);
-       EXPECT_EQ(activity->getType(), "TWO_STEP_PROCESS_ACTIVITY");
+       EXPECT_NE(activity, nullptr);
+       if (activity)
+               EXPECT_EQ(activity->getType(), "TWO_STEP_PROCESS_ACTIVITY");
 }
index efef650..50bf7e9 100644 (file)
@@ -11,7 +11,7 @@
 #include "SwitchManager.hpp"
 #include "ActivityFactory.hpp"
 #include "utils.hpp"
-#include "dbusLocators.hpp"
+#include "ecore.hpp"
 
 #include <memory>
 
@@ -54,8 +54,6 @@ public:
 
        void SetUp()
        {
-               dbusClient = std::make_unique<DBus::DBusClient>(dbusLocators::accessibilityEMod::BUS, dbusLocators::accessibilityEMod::OBJ_PATH, dbusLocators::accessibilityEMod::INTERFACE, DBus::ConnectionType::SYSTEM);
-               dbusClient->method<void(bool)>(dbusLocators::accessibilityEMod::ACCESSORIES_SP_ENABLED).call(true);
                auto SQLiteConfig = std::make_shared<SQLiteConfiguration>(true);
                SQLiteConfig->clearTable();
                configuration_ = SQLiteConfig;
@@ -74,48 +72,32 @@ public:
                item_ = std::make_shared<SwitchConfigurationItem>(switch_->getId()->getGlobalId(), activityType_);
        }
 
-       void TearDown()
-       {
-               dbusClient->method<void(bool)>(dbusLocators::accessibilityEMod::ACCESSORIES_SP_ENABLED).call(false);
-       }
-
        void simulateKeyPress(const std::string &key)
        {
-               EXPECT_TRUE(ecore_timer_add(SMALL_DELAY_, addEventCb, key.c_str()));
-               runMainLoop();
-       }
-
-       void runMainLoop()
-       {
-               EXPECT_TRUE(ecore_timer_add(ESTIMATED_TIME_REQUIRED_TO_SAFELY_PASSING_THROUGH_TESTS_, mainLoopQuitCb, nullptr));
+               eventTimer.reset(SMALL_DELAY_, [&key]() {
+                       utils::EventGenerator::generateKeyPress(key);
+                       return ecore::TimerRepetitionPolicy::cancel;
+               });
+               mainloopTimer.reset(ESTIMATED_TIME_REQUIRED_TO_SAFELY_PASSING_THROUGH_TESTS_, []() {
+                       ecore_main_loop_quit();
+                       return ecore::TimerRepetitionPolicy::cancel;
+               });
                ecore_main_loop_begin();
        }
 
-       static Eina_Bool mainLoopQuitCb(void *)
-       {
-               ecore_main_loop_quit();
-               return ECORE_CALLBACK_CANCEL;
-       }
-
-       static Eina_Bool addEventCb(void *data)
-       {
-               auto key = static_cast<const char *>(data);
-               utils::EventGenerator::generateKeyPress(key);
-               return ECORE_CALLBACK_CANCEL;
-       }
-
 protected:
        std::shared_ptr<Configuration> configuration_;
        std::shared_ptr<CompositeSwitchProvider> switchProvider_;
        std::shared_ptr<ActivityFactory> activityFactory_;
        std::shared_ptr<Switch> switch_;
        std::shared_ptr<SwitchConfigurationItem> item_;
-       std::unique_ptr<DBus::DBusClient> dbusClient;
        std::string key_ = "Down";
        std::string switchId_ = "AccessoriesSwitchProvider_Down";
        std::string activityType_ = "TWO_STEP_PROCESS_ACTIVITY";
        static constexpr double ESTIMATED_TIME_REQUIRED_TO_SAFELY_PASSING_THROUGH_TESTS_ = 1.0;
        static constexpr double SMALL_DELAY_ = 0.1;
+       ecore::Timer eventTimer;
+       ecore::Timer mainloopTimer;
 };
 
 class SwitchManager_ConfigurationTests : public SwitchManager
diff --git a/tests/ui-scenarios/FooTests.cpp b/tests/ui-scenarios/FooTests.cpp
deleted file mode 100644 (file)
index 72d76e2..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#include "FooTests.hpp"
-#include "UniversalSwitchLog.hpp"
-
-TEST_F(FooFixture, Foo)
-{
-       auto window = std::make_shared<Window>();
-}
diff --git a/tests/ui-scenarios/FooTests.hpp b/tests/ui-scenarios/FooTests.hpp
deleted file mode 100644 (file)
index 27f6373..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-#ifndef FOO_TESTS_HPP
-#define FOO_TESTS_HPP
-
-#include "Window.hpp"
-
-#include <cmock/cmock.h>
-
-#include <memory>
-
-using ::testing::StrictMock;
-using ::testing::DoAll;
-using ::testing::Invoke;
-using ::testing::Return;
-using ::testing::SetArgPointee;
-using ::testing::StrEq;
-using ::testing::_;
-
-class FooFixture : public ::testing::Test
-{
-};
-
-#endif // FOO_TESTS_HPP
index 4bf0613..321395c 100644 (file)
@@ -89,7 +89,7 @@ public:
                //This test will check content of menu, with each item in default state.
                auto actualMenuItems = Singleton<MenuBuilder>::instance().build(menuName);
 
-               ASSERT_EQ(actualMenuItems.size(), expectedMenuItemsNames.size());
+               EXPECT_EQ(actualMenuItems.size(), expectedMenuItemsNames.size());
 
                for (auto ii = 0u; ii < actualMenuItems.size(); ++ii) {
                        EXPECT_EQ(actualMenuItems[ii]->getName(), expectedMenuItemsNames[ii]);
@@ -362,4 +362,4 @@ TEST_F(MenuBuilderTest, testMenuItemsStates)
        auto turnOnOffSound = actualMenuItems[5];
        testVconfBoolTypeMenuItemStates(turnOnOffSound.get(), VCONF_KEY_FEEDBACK_SOUND_ENABLED,
        {"IDS_TURN_ON_SOUND", "IDS_TURN_OFF_SOUND"});
-}
\ No newline at end of file
+}
index ef3d545..702ce70 100644 (file)
@@ -1,7 +1,6 @@
 #include "UniversalSwitchLog.hpp"
 
-#include "FooTests.hpp"
-
+#include <cmock/cmock.h>
 #include <tizen.h>
 #include <app.h>
 #include <Elementary.h>
@@ -23,7 +22,9 @@ bool app_create(void *data)
 {
        DEBUG("App create");
        int r = RUN_ALL_TESTS();
-       ASSERT(r == 0, "RUN_ALL_TESTS() failed");
+       if (r != 0)
+               ERROR("RUN_ALL_TESTS() failed");
+
        ui_app_exit();
        return true;
 }