Registers activities as callables in batch mode 60/164560/43
authorRadoslaw Cybulski <r.cybulski@partner.samsung.com>
Tue, 19 Dec 2017 15:58:18 +0000 (16:58 +0100)
committerRadoslaw Cybulski <r.cybulski@partner.samsung.com>
Thu, 18 Jan 2018 12:29:38 +0000 (13:29 +0100)
Registers all activities, which override
getRequiredNumberOfArgumentsIfAllowedInTesting function to return
required number of arguments.

Change-Id: I59d63f14d7746ff3217a324088301917645edc52

src/batch/BatchRunner.cpp

index a04ee01..61e64ea 100644 (file)
@@ -20,6 +20,8 @@
 #include "Parser.hpp"
 #include "EvaluationContext.hpp"
 #include "Evaluator.hpp"
+#include "../ActivityFactory.hpp"
+#include "../Observer.hpp"
 #include "../UIElement.hpp"
 #include "../NavigationInterface.hpp"
 
@@ -120,6 +122,39 @@ struct TestExecutor : ExecutorInterface {
                                return result;
                        }
                };
+               for (auto activityName : ActivityFactory::getInstance()->getAllActivityTypes()) {
+                       variables[activityName] = EvaluationValue::FunctionType::Type{
+                               [ = ](EvaluationContext & ec, std::vector<EvaluationValue> args) -> EvaluationValue {
+                                       executeOnMainThread([&]()
+                                       {
+                                               DEBUG("calling activity %s", activityName.c_str());
+                                               auto activity = ActivityFactory::getInstance()->createActivity(activityName);
+                                               if (!activity)
+                                                       throw EvaluationFailure{} << "failed to construct '" << activityName << "' activity";
+                                               auto numOfArgs = activity->getRequiredNumberOfArgumentsIfAllowedInBatchProcessing();
+                                               if (!numOfArgs)
+                                                       throw EvaluationFailure{} << "activity '" << activityName << "' is not supported";
+                                               if (*numOfArgs != args.size())
+                                                       throw EvaluationFailure{} << "invalid number of arguments for activity '" << activityName <<
+                                                                                                         "', got " << args.size() << ", expected " << *numOfArgs;
+                                               auto activityObserver = std::dynamic_pointer_cast<Observer<UIElement>>(activity);
+                                               for (size_t i = 0; i < args.size(); ++i) {
+                                                       ASSERT(activityObserver);
+                                                       auto uiElement = detail::ConvertTo<std::shared_ptr<UIElement>>::convert(ec, std::move(args[i]));
+                                                       if (!uiElement)
+                                                               throw EvaluationFailure{} << "can't convert argument " << (i + 1) <<
+                                                                                                                 " of kind " << EvaluationValue::toString(args[i].kind()) << " to UIElement";
+                                                       activityObserver->update(std::move(uiElement));
+                                               }
+                                               activity->process({});
+                                               if (!activity->isCompleted())
+                                                       throw EvaluationFailure{} << "not enough arguments for activity '" << activityName << "'";
+                                               DEBUG("calling activity %s done", activityName.c_str());
+                                       });
+                                       return {};
+                               } };
+               }
+
                auto nav = Singleton<UniversalSwitch>::instance().getNavigationInterface();
                this->navigationContext = nav->getCurrentNavigationContext();
                this->root = nav->getCurrentVisibleRoot();