Architecture changes required modifications of way the integration tests are executed.
This patch:
1. changes default values of properties in SwitchInteractionManager
2. overrides 'detach' method of Subject in CompositeSwitchProvider
3. adds some nullptr verifications
4. introduces invokation of ecore main loop to tests what enables using ecore timers during them
Change-Id: Id2fbbba163117bf9c415639d96223c5f758182a5
}
}
+void CompositeSwitchProvider::detach(const Observer<Switch> *observer, const Switch *item)
+{
+ for (auto &p : providers)
+ p->detach(observer, item);
+}
+
std::shared_ptr<SwitchProvider> CompositeSwitchProvider::getProviderById(const std::string &id) const
{
for (auto &provider : providers) {
std::shared_ptr<SwitchProvider> getProviderById(const std::string &id) const;
void attach(std::weak_ptr<Observer<Switch>> observer, std::shared_ptr<Condition<Switch>> cond) override;
+ void detach(const Observer<Switch> *observer, const Switch *item) override;
private:
std::vector<std::shared_ptr<SwitchProvider>> providers;
}))
return nullptr;
- INFO("Found: %s, %s, %s", item->getSwitchId().c_str(), item->getUserName().c_str(), item->getActivityType().c_str());
+ if (!item) {
+ DEBUG("No item found");
+ return nullptr;
+ }
+ INFO("Found: %s, %s, %s", item->getSwitchId().c_str(), item->getUserName().c_str(), item->getActivityType().c_str());
return item;
}
std::shared_ptr<SwitchConfigurationItem> SQLiteConfiguration::constructItem(int argc, char **argv, char **azColName)
{
- ASSERT(argc == SwitchConfigurationItemFields::Count, "Fields number does not match the one in SwitchConfigurationItem");
+ if (argc != SwitchConfigurationItemFields::Count) {
+ ERROR("Fields number does not match the one in SwitchConfigurationItem");
+ return nullptr;
+ }
auto item = std::make_shared<SwitchConfigurationItem>();
observers.emplace_back(std::move(observer), std::move(cond));
}
- void detach(const Observer<T> *observer, const T *item)
+ virtual void detach(const Observer<T> *observer, const T *item)
{
for (auto it = observers.begin(); it != observers.end(); ++it) {
auto tempObserver = it->first.lock();
currentSwitch = sw;
notifyMethod = method;
minimalSwitchInteractionTimer = ecore_timer_add(minimalSwitchInteractionTime, minimalSwitchInteractionTimeCb, this);
+ isActiveInteraction = true;
DEBUG("switch: %s", currentSwitch->getId()->getGlobalId().c_str());
+ DEBUG("minimalSwitchInteractionTimer %s for %lf s", minimalSwitchInteractionTimer ? "set" : "unset", minimalSwitchInteractionTime);
}
void SwitchInteractionManager::stopInteraction(const std::shared_ptr<Switch> &sw)
{
- if (!isActiveInteraction())
+ if (!isActiveInteraction)
return;
if (!currentSwitch || !sw || currentSwitch->getId()->getGlobalId() != sw->getId()->getGlobalId())
: minimalSwitchInteractionTime(0.0), switchInteractionInterval(0.0), notificationRepetitionInterval(0.0),
minimalSwitchInteractionTimer(nullptr), switchInteractionIntervalTimer(nullptr), notificationRepetitionIntervalTimer(nullptr)
{
- minimalSwitchInteractionTimeHandler = VConfSingleton::instance().registerAndGet<double>(VCONF_PREFIX "TAP_DURATION_VALUE", 1.0, [this](int x) {
+ minimalSwitchInteractionTimeHandler = VConfSingleton::instance().registerAndGet<double>(VCONF_PREFIX "TAP_DURATION_VALUE", 0.0, [this](int x) {
minimalSwitchInteractionTime = x;
});
- switchInteractionIntervalHandler = VConfSingleton::instance().registerAndGet<double>(VCONF_PREFIX "SGL_IACTION_INT_VALUE", 3.0, [this](int x) {
+ switchInteractionIntervalHandler = VConfSingleton::instance().registerAndGet<double>(VCONF_PREFIX "SGL_IACTION_INT_VALUE", 0.0, [this](int x) {
switchInteractionInterval = x;
});
- notificationRepetitionIntervalHandler = VConfSingleton::instance().registerAndGet<double>(VCONF_PREFIX "AUTO_MOVE_INT_VALUE", 2.0, [this](int x) {
+ notificationRepetitionIntervalHandler = VConfSingleton::instance().registerAndGet<double>(VCONF_PREFIX "AUTO_MOVE_INT_VALUE", 0.0, [this](int x) {
notificationRepetitionInterval = x;
});
}
void SwitchInteractionManager::uncoditionallyStopInteraction()
{
- deleteAndClearTimer(minimalSwitchInteractionTimer);
- deleteAndClearTimer(notificationRepetitionIntervalTimer);
+ isActiveInteraction = false;
if (!switchInteractionIntervalTimer) {
DEBUG("interval timer set");
switchInteractionIntervalTimer = ecore_timer_add(switchInteractionInterval, switchInteractionIntervalCb, this);
}
-
- currentSwitch = nullptr;
- notifyMethod = nullptr;
}
void SwitchInteractionManager::deleteAndClearTimer(Ecore_Timer *&timer)
timer = nullptr;
}
-bool SwitchInteractionManager::isActiveInteraction()
-{
- return minimalSwitchInteractionTimer || notificationRepetitionIntervalTimer;
-}
-
Eina_Bool SwitchInteractionManager::minimalSwitchInteractionTimeCb(void *data)
{
auto im = static_cast<SwitchInteractionManager *>(data);
void SwitchInteractionManager::afterMinimalInteractionTime()
{
- DEBUG("invoked: %s", currentSwitch->getId()->getGlobalId().c_str());
+ DEBUG("invoked, switch: %s", currentSwitch->getId()->getGlobalId().c_str());
minimalSwitchInteractionTimer = nullptr;
notifyMethod();
if (notificationRepetitionInterval != 0.0)
notificationRepetitionIntervalTimer = ecore_timer_add(notificationRepetitionInterval, notificationRepetitionIntervalCb, this);
- else
- ecore_timer_add(switchInteractionInterval, switchInteractionIntervalCb, this);
+
+ currentSwitch = nullptr;
+ notifyMethod = nullptr;
}
void SwitchInteractionManager::afterInteractionInterval()
void uncoditionallyStopInteraction();
void deleteAndClearTimer(Ecore_Timer *&timer);
- bool isActiveInteraction();
+ bool isActiveInteraction = false;
static Eina_Bool minimalSwitchInteractionTimeCb(void *data);
static Eina_Bool switchInteractionIntervalCb(void *data);
void SwitchManager::update(const std::shared_ptr<SwitchConfigurationItem> &item)
{
+ DEBUG("notified with item: %s", item->getSwitchId().c_str());
+
switch (item->getChangeType()) {
case ChangeType::ADD: {
auto sw = switchProvider->findSwitchById(item->getSwitchId());
DEBUG("notified with: %s", sw->getId()->getGlobalId().c_str());
auto confItem = configuration->findBySwitchId(sw->getId()->getGlobalId());
+ if (!confItem)
+ return;
+
auto activityType = confItem->getActivityType();
auto request = std::make_shared<ActivityChangeRequest>(activityType, nullptr);
changeActivity(request);
ASSERT_NE(activity, nullptr);
EXPECT_EQ(activity->getType(), "TWO_STEP_PROCESS_ACTIVITY");
- simulateKeyDown(keyMappedToTwoStepProcessActivity_);
+ simulateKeyPress(keyMappedToTwoStepProcessActivity_);
+ runMainLoop();
auto isEmpty = switchManager_->getActivities().empty();
EXPECT_EQ(isEmpty, true);
}
ASSERT_NE(activity, nullptr);
EXPECT_EQ(activity->getType(), "TWO_STEP_PROCESS_ACTIVITY");
- simulateKeyDown(keyMappedToThreeStepProcessActivity_);
+ simulateKeyPress(keyMappedToThreeStepProcessActivity_);
+ runMainLoop();
EXPECT_EQ(switchManager_->getActivities().size(), 2u);
activity = switchManager_->getActivities().top();
ASSERT_NE(activity, nullptr);
EXPECT_EQ(activity->getType(), "THREE_STEP_PROCESS_ACTIVITY");
- simulateKeyDown(keyMappedToThreeStepProcessActivity_);
+ simulateKeyPress(keyMappedToThreeStepProcessActivity_);
+ runMainLoop();
EXPECT_EQ(switchManager_->getActivities().size(), 2u);
activity = switchManager_->getActivities().top();
+
ASSERT_NE(activity, nullptr);
EXPECT_EQ(activity->getType(), "THREE_STEP_PROCESS_ACTIVITY");
- simulateKeyDown(keyMappedToThreeStepProcessActivity_);
+ simulateKeyPress(keyMappedToThreeStepProcessActivity_);
+ runMainLoop();
EXPECT_EQ(switchManager_->getActivities().size(), 1u);
activity = switchManager_->getActivities().top();
ASSERT_NE(activity, nullptr);
void initialEnvironmentExpect()
{
- simulateKeyDown(keyMappedToTwoStepProcessActivity_);
+ simulateKeyPress(keyMappedToTwoStepProcessActivity_);
+ runMainLoop();
EXPECT_EQ(switchManager_->updatedWithSwitch, 1);
}
configuration_->add(item_);
auto switchManager = SwitchManager::create<SwitchManager_ConfigurationTests>(switchProvider_, configuration_, activityFactory_);
- simulateKeyDown(key_);
+ simulateKeyPress(key_);
+ runMainLoop();
EXPECT_EQ(switchManager->updatedWithSwitch, 1);
- EXPECT_EQ(switchManager->receivedItem->getId()->getGlobalId(), switchId_);
+
+ if (switchManager->receivedItem)
+ EXPECT_EQ(switchManager->receivedItem->getId()->getGlobalId(), switchId_);
}
/*
{
auto switchManager = SwitchManager::create<SwitchManager_ConfigurationTests>(switchProvider_, configuration_, activityFactory_);
configuration_->add(item_);
- simulateKeyDown(key_);
+ simulateKeyPress(key_);
+ runMainLoop();
EXPECT_EQ(switchManager->updatedWithSwitch, 1);
- EXPECT_EQ(switchManager->receivedItem->getId()->getGlobalId(), switchId_);
+
+ if (switchManager->receivedItem)
+ EXPECT_EQ(switchManager->receivedItem->getId()->getGlobalId(), switchId_);
}
/*
configuration_->add(item_);
auto switchManager = SwitchManager::create<SwitchManager_ConfigurationTests>(switchProvider_, configuration_, activityFactory_);
configuration_->remove(switchId_);
- simulateKeyDown(key_);
+ simulateKeyPress(key_);
+ runMainLoop();
EXPECT_EQ(switchManager->updatedWithSwitch, 0);
}
auto newActivityType = "SCAN_OFF";
auto newItem = std::make_shared<SwitchConfigurationItem>(switch_->getId()->getGlobalId(), newActivityType);
configuration_->update(newItem);
- simulateKeyDown(key_);
+ simulateKeyPress(key_);
+ runMainLoop();
EXPECT_EQ(switchManager->updatedWithSwitch, 1);
- EXPECT_EQ(switchManager->receivedItem->getId()->getGlobalId(), switchId_);
+
+ if (switchManager->receivedItem)
+ EXPECT_EQ(switchManager->receivedItem->getId()->getGlobalId(), switchId_);
}
int main(int argc, char **argv)
ecore_event_shutdown();
ecore_shutdown();
return r;
-}
\ No newline at end of file
+}
item_ = std::make_shared<SwitchConfigurationItem>(switch_->getId()->getGlobalId(), activityType_);
}
- void simulateKeyDown(const std::string &key)
+ void simulateKeyPress(const std::string &key)
{
- Ecore_Event_Key *event = (Ecore_Event_Key *)malloc(sizeof(Ecore_Event_Key));
+ Ecore_Event_Key *eventDown = (Ecore_Event_Key *)malloc(sizeof(Ecore_Event_Key));
+ Ecore_Event_Key *eventUp = (Ecore_Event_Key *)malloc(sizeof(Ecore_Event_Key));
- if (!event) {
+ if (!eventDown || !eventUp) {
ERROR("Memory allocation error");
return;
}
- event->key = key.c_str();
- EXPECT_TRUE(ecore_event_add(ECORE_EVENT_KEY_DOWN, event, NULL, NULL));
- ecore_main_loop_iterate();
+ eventDown->key = key.c_str();
+ eventUp->key = key.c_str();
+
+ EXPECT_TRUE(ecore_event_add(ECORE_EVENT_KEY_DOWN, eventDown, NULL, NULL));
+ EXPECT_TRUE(ecore_event_add(ECORE_EVENT_KEY_UP, eventUp, NULL, NULL));
+ }
+
+ void runMainLoop()
+ {
+ EXPECT_TRUE(ecore_timer_add(estimatedTimeRequiredToSafelyPassingThroughTests_, mainLoopQuitCb, nullptr));
+ ecore_main_loop_begin();
+ }
+
+ static Eina_Bool mainLoopQuitCb(void *)
+ {
+ ecore_main_loop_quit();
+ return ECORE_CALLBACK_CANCEL;
}
protected:
std::string key_ = "Down";
std::string switchId_ = "AccessoriesSwitchProvider_Down";
std::string activityType_ = "TWO_STEP_PROCESS_ACTIVITY";
+ double estimatedTimeRequiredToSafelyPassingThroughTests_ = 1.0;
};
class SwitchManager_ConfigurationTests : public SwitchManager