From 77f68c9091e95d1797ff243cd73f1cd9997d106d Mon Sep 17 00:00:00 2001 From: Lukasz Wlazly Date: Fri, 6 Oct 2017 11:52:14 +0200 Subject: [PATCH] Refactor of tests suits 1. Change all "asserts" into "expects". 2. Usage of ecore::Timer in ConfigurationTests Change-Id: I0cce58be91ba38c88cf095978ecfc748bff449c3 --- tests/no-ui-scenarios/DBusTests.cpp | 31 +++++++------- tests/no-ui-scenarios/OptionalTests.cpp | 56 +++++++++++++------------- tests/no-ui-scenarios/TranslationsTests.cpp | 3 +- tests/ui-scenarios/ActivityProcessingTests.cpp | 33 ++++++++------- tests/ui-scenarios/ConfigurationTests.hpp | 40 +++++------------- tests/ui-scenarios/FooTests.cpp | 7 ---- tests/ui-scenarios/FooTests.hpp | 22 ---------- tests/ui-scenarios/MenuBuilderTests.cpp | 4 +- tests/ui-scenarios/main.cpp | 7 ++-- 9 files changed, 79 insertions(+), 124 deletions(-) delete mode 100644 tests/ui-scenarios/FooTests.cpp delete mode 100644 tests/ui-scenarios/FooTests.hpp diff --git a/tests/no-ui-scenarios/DBusTests.cpp b/tests/no-ui-scenarios/DBusTests.cpp index 09c6b43..d9e41b9 100644 --- a/tests/no-ui-scenarios/DBusTests.cpp +++ b/tests/no-ui-scenarios/DBusTests.cpp @@ -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("ftest").asyncCall([ = ](DBus::ValueOrError 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("ftest").asyncCall([ = ](DBus::ValueOrError 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("ftest").asyncCall([ = ](DBus::ValueOrError 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("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("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>> diff --git a/tests/no-ui-scenarios/OptionalTests.cpp b/tests/no-ui-scenarios/OptionalTests.cpp index 817f002..74f1852 100644 --- a/tests/no-ui-scenarios/OptionalTests.cpp +++ b/tests/no-ui-scenarios/OptionalTests.cpp @@ -115,7 +115,7 @@ TEST_F(OptionalTestsFixture, ValueStorageChecking) TEST_F(OptionalTestsFixture, ConstructorChecking_FromValue) { Optional 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 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 {}; 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 {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 {}; 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 {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 {}; a = a; - ASSERT_FALSE(a); + EXPECT_FALSE(a); SetExpects(0, 0, 0); } @@ -195,7 +195,7 @@ TEST_F(OptionalTestsFixture, AssignmentOperatorChecking_SameObjectValidOptional) { auto a = Optional {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 {}; auto b = Optional {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 {5}; auto b = Optional {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 {5}; auto b = Optional {}; 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 {}; 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 {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 {}; auto b = Optional {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 {5}; auto b = Optional {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 opt { A::a }; - ASSERT_TRUE(opt); + EXPECT_TRUE(opt); opt = {}; - ASSERT_FALSE(opt); + EXPECT_FALSE(opt); } TEST_F(OptionalTestsFixture, IntClearingFailure) { Optional opt { 1 }; - ASSERT_TRUE(opt); + EXPECT_TRUE(opt); opt = {}; - ASSERT_FALSE(opt); + EXPECT_FALSE(opt); } diff --git a/tests/no-ui-scenarios/TranslationsTests.cpp b/tests/no-ui-scenarios/TranslationsTests.cpp index 0b05e2b..5d34732 100644 --- a/tests/no-ui-scenarios/TranslationsTests.cpp +++ b/tests/no-ui-scenarios/TranslationsTests.cpp @@ -2,7 +2,6 @@ #include "Singleton.hpp" #include -#include 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 +} diff --git a/tests/ui-scenarios/ActivityProcessingTests.cpp b/tests/ui-scenarios/ActivityProcessingTests.cpp index 5156291..a19a696 100644 --- a/tests/ui-scenarios/ActivityProcessingTests.cpp +++ b/tests/ui-scenarios/ActivityProcessingTests.cpp @@ -1,8 +1,6 @@ #include "ActivityProcessingTests.hpp" #include "ActivityFactory.hpp" -#include - /* 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"); } diff --git a/tests/ui-scenarios/ConfigurationTests.hpp b/tests/ui-scenarios/ConfigurationTests.hpp index efef650..50bf7e9 100644 --- a/tests/ui-scenarios/ConfigurationTests.hpp +++ b/tests/ui-scenarios/ConfigurationTests.hpp @@ -11,7 +11,7 @@ #include "SwitchManager.hpp" #include "ActivityFactory.hpp" #include "utils.hpp" -#include "dbusLocators.hpp" +#include "ecore.hpp" #include @@ -54,8 +54,6 @@ public: void SetUp() { - dbusClient = std::make_unique(dbusLocators::accessibilityEMod::BUS, dbusLocators::accessibilityEMod::OBJ_PATH, dbusLocators::accessibilityEMod::INTERFACE, DBus::ConnectionType::SYSTEM); - dbusClient->method(dbusLocators::accessibilityEMod::ACCESSORIES_SP_ENABLED).call(true); auto SQLiteConfig = std::make_shared(true); SQLiteConfig->clearTable(); configuration_ = SQLiteConfig; @@ -74,48 +72,32 @@ public: item_ = std::make_shared(switch_->getId()->getGlobalId(), activityType_); } - void TearDown() - { - dbusClient->method(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(data); - utils::EventGenerator::generateKeyPress(key); - return ECORE_CALLBACK_CANCEL; - } - protected: std::shared_ptr configuration_; std::shared_ptr switchProvider_; std::shared_ptr activityFactory_; std::shared_ptr switch_; std::shared_ptr item_; - std::unique_ptr 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 index 72d76e2..0000000 --- a/tests/ui-scenarios/FooTests.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "FooTests.hpp" -#include "UniversalSwitchLog.hpp" - -TEST_F(FooFixture, Foo) -{ - auto window = std::make_shared(); -} diff --git a/tests/ui-scenarios/FooTests.hpp b/tests/ui-scenarios/FooTests.hpp deleted file mode 100644 index 27f6373..0000000 --- a/tests/ui-scenarios/FooTests.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef FOO_TESTS_HPP -#define FOO_TESTS_HPP - -#include "Window.hpp" - -#include - -#include - -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 diff --git a/tests/ui-scenarios/MenuBuilderTests.cpp b/tests/ui-scenarios/MenuBuilderTests.cpp index 4bf0613..321395c 100644 --- a/tests/ui-scenarios/MenuBuilderTests.cpp +++ b/tests/ui-scenarios/MenuBuilderTests.cpp @@ -89,7 +89,7 @@ public: //This test will check content of menu, with each item in default state. auto actualMenuItems = Singleton::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 +} diff --git a/tests/ui-scenarios/main.cpp b/tests/ui-scenarios/main.cpp index ef3d545..702ce70 100644 --- a/tests/ui-scenarios/main.cpp +++ b/tests/ui-scenarios/main.cpp @@ -1,7 +1,6 @@ #include "UniversalSwitchLog.hpp" -#include "FooTests.hpp" - +#include #include #include #include @@ -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; } -- 2.7.4