Add flick left / right / up / down and taps to batch mode 30/205130/7
authorRadoslaw Cybulski <r.cybulski@partner.samsung.com>
Mon, 29 Apr 2019 09:51:40 +0000 (11:51 +0200)
committerRadoslaw Cybulski <r.cybulski@partner.samsung.com>
Thu, 16 May 2019 09:31:20 +0000 (11:31 +0200)
Change-Id: Ifff9053df5ca63156d02cebb53aa755b606c9b13

src/batch/BatchRunner.cpp
src/batch/EvaluationValue.hpp

index fadd378..c8b43c9 100644 (file)
@@ -534,6 +534,54 @@ void BatchExecutor::insertMethods()
                                }), std::move(roles), std::move(states));
                        }, monitor);
                }, { { "name" }, { "roles", EvaluationValueSet() }, { "states", EvaluationValueSet() } } };
+
+       auto generateTapFunction = [&](size_t tapCount) {
+               Optional<EvaluationValue> defValue;
+               if (tapCount > 1)
+                       defValue = EvaluationValuePoint{ 300, 300 };
+               return EvaluationValueFunction{ [ &, tapCount](EvaluationValue target) -> EvaluationValue {
+                               auto root = getVisibleRoot();
+                               if (!root) throw EvaluationFailure{} << "no visible root (context changed didn't happen)";
+                               ASSERT(root->getObject());
+                               auto dest = target.convertToUIElement();
+
+                               auto sleep_until = std::chrono::high_resolution_clock::now() + std::chrono::milliseconds{ 400 };
+                               for (auto i = 0u; i < tapCount; ++i)
+                               {
+                                       executeOnMainThread([&]() {
+                                               auto coord = dest->getScanningCoordinates();
+                                               auto res = utils::generateTapGesture(coord.x, coord.y, 0.0f);
+                                               if (!res)
+                                                       throw EvaluationFailure{} << "failed to execute " << tapCount << " tap gesture, " << res.getError().message;
+                                       });
+                               }
+                               std::this_thread::sleep_until(sleep_until);
+
+                               return EvaluationValue{};
+                       }, { { "target" } } };
+       };
+       variables["TAP"] = generateTapFunction(1);
+       variables["DOUBLE_TAP"] = generateTapFunction(2);
+       variables["TRIPLE_TAP"] = generateTapFunction(3);
+
+       auto generateFlickFunction = [&](int x0, int y0, int x1, int y1) {
+               return EvaluationValueFunction{ [ &, x0, y0, x1, y1]() -> EvaluationValue {
+                               auto root = getVisibleRoot();
+                               if (!root) throw EvaluationFailure{} << "no visible root (context changed didn't happen)";
+                               ASSERT(root->getObject());
+
+                               executeOnMainThread([&]()
+                               {
+                                       utils::generateDragGesture(x0, y0, x1, y1, 10, 0.0);
+                               });
+                               std::this_thread::sleep_for(std::chrono::milliseconds{ 150 });
+                               return EvaluationValue{};
+                       }, { } };
+       };
+       variables["FLICK_RIGHT"] = generateFlickFunction(200, 200, 400, 200);
+       variables["FLICK_LEFT"] = generateFlickFunction(400, 200, 200, 200);
+       variables["FLICK_UP"] = generateFlickFunction(300, 400, 300, 200);
+       variables["FLICK_DOWN"] = generateFlickFunction(300, 200, 300, 400);
 }
 
 class PredicateWaitInterface : public EvaluationValueWaitInterface
@@ -657,18 +705,20 @@ void BatchExecutor::insertWaits()
                auto impl = std::make_shared<WaitTTS>(this, std::chrono::milliseconds{ static_cast<size_t>(timeout * 1000) }, std::move(pattern));
                return EvaluationValue{ impl };
        };
-       variables["tts"] = EvaluationValueFunction{ std::move(waitTTS), { { "pattern", "" }, { "timeout", 3.0 } } };
+       variables["tts"] = EvaluationValueFunction{ std::move(waitTTS), { { "pattern", "" }, { "timeout", 5.0 } } };
 
        auto waitGui = [&](std::string name, double timeout) -> EvaluationValue {
                auto impl = std::make_shared<WaitGui>(this, std::chrono::milliseconds{ static_cast<size_t>(timeout * 1000) }, std::move(name));
                return EvaluationValue{ impl };
        };
-       variables["gui"] = EvaluationValueFunction{ std::move(waitGui), { { "name", "" }, { "timeout", 3.0 } } };
+       variables["gui"] = EvaluationValueFunction{ std::move(waitGui), { { "name", "" }, { "timeout", 5.0 } } };
 }
 
 void BatchExecutor::insertActivities()
 {
        for (auto activityName : ActivityFactory::getInstance()->getAllActivityTypes()) {
+               if (variables.find(activityName) != variables.end())
+                       continue;
                variables[activityName] = [ = ](EvaluationValueFunction::Args args) -> EvaluationValue {
                        auto activity = executeOnMainThread([&]()
                        {
index 3dcecc8..ba20b00 100644 (file)
@@ -442,15 +442,8 @@ public:
        class Arg
        {
        public:
-               Arg(std::string name) : name(std::move(name))
-               {
-                       ASSERT(!this->name.empty());
-               }
-               Arg(const char *name) : name(name)
-               {
-                       ASSERT(!this->name.empty());
-               }
-               Arg(std::string name, EvaluationValue val) : name(std::move(name)), defaultValue(std::move(val)) { }
+               template <typename T> Arg(T &&name, Optional<EvaluationValue> val = Optional<EvaluationValue> {}) :
+                       name(std::forward<T>(name)), defaultValue(std::move(val)) { }
 
                std::string getName() const
                {