fix for failed DOUBLE_TAP without arguments 83/206483/2
authorRadoslaw Cybulski <r.cybulski@partner.samsung.com>
Mon, 20 May 2019 11:24:07 +0000 (13:24 +0200)
committerRadoslaw Cybulski <r.cybulski@partner.samsung.com>
Mon, 20 May 2019 11:47:07 +0000 (13:47 +0200)
Change-Id: Idd6617392c79930d53d55da3c26eb8335bafba10

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

index c3f74f88c8e2935bda7a5dd13ff7ccf4aaffba43..4eb9e2ee51a5a797dc1ecef6125588770f309705 100644 (file)
@@ -349,8 +349,10 @@ void BatchExecutor::findByName(const std::vector<AtspiAccessiblePtr> &elems, std
                        if (!name) {
                                if (!exec->error)
                                        exec->error = name.getError();
-                       } else if (std::get<0>(name) == exec->requestedName) {
-                               exec->foundElements.push_back(e);
+                       } else {
+                               if (std::get<0>(name) == exec->requestedName) {
+                                       exec->foundElements.push_back(e);
+                               }
                        }
                });
        }
@@ -379,11 +381,11 @@ void BatchExecutor::makeUIElement(AtspiAccessiblePtr src, std::function<void(DBu
 {
        auto atspi = Singleton<UniversalSwitch>::instance().getAtspi();
        atspi->getComponentInterface(src, [src, callback = std::move(callback)](DBus::ValueOrError<AtspiComponentPtr> comp) {
+               auto atspi = Singleton<UniversalSwitch>::instance().getAtspi();
                if (!comp) {
                        callback(comp.getError());
                        return;
                }
-               auto atspi = Singleton<UniversalSwitch>::instance().getAtspi();
                atspi->getScreenPosition(std::get<0>(comp), [src, callback = std::move(callback)](DBus::ValueOrError<Rectangle> pos) {
                        if (!pos) {
                                callback(pos.getError());
@@ -902,21 +904,30 @@ void BatchExecutor::insertMethods()
        auto generateTapFunction = [&](size_t tapCount) {
                Optional<EvaluationValue> defValue;
                if (tapCount > 1)
-                       defValue = EvaluationValuePoint{ 300, 300 };
+                       defValue = EvaluationValue{};
                return EvaluationValueFunction{ [ &, tapCount](EvaluationValue target, EvaluationValue fingers) -> EvaluationValue {
                                auto root = getVisibleRoot();
                                if (!root) throw EvaluationFailure{} << "no visible root (context changed didn't happen)";
                                ASSERT(root->getObject());
-                               if (target.isString())
-                               {
-                                       target = this->convertToUIElement(target.convertToString());
-                               }
-                               auto dest = target.convertToUIElement();
-                               auto coord = getUIElementPosition(dest).getCenterPoint();
-                               auto fingerCount = fingers.convertToInteger();
+
+                               const auto fingerCount = fingers.convertToInteger();
                                if (fingerCount <= 0 || fingerCount > 3)
                                        throw EvaluationFailure{} << "invalid finger count (must be between 1 and 3)";
 
+                               auto coord = Point{ 300, 300 };
+                               if (!target.isEmpty())
+                               {
+                                       if (target.isString()) {
+                                               target = this->convertToUIElement(target.convertToString());
+                                       }
+                                       auto dest = target.convertToUIElement();
+                                       coord = getUIElementPosition(dest).getCenterPoint();
+                               } else
+                               {
+                                       if (tapCount == 1)
+                                               throw EvaluationFailure{} << "no target value passed (you need target to do single tap)";
+                               }
+
                                auto sleep_until = std::chrono::high_resolution_clock::now() + std::chrono::milliseconds{ 400 };
                                for (auto i = 0u; i < tapCount; ++i)
                                {
index 4881976097a42a2cd43365a0f26c50ff770be023..93a36a7262467ec16129d791806889db6f56f25b 100644 (file)
@@ -32,6 +32,11 @@ EvaluationValue::EvaluationValue(EvaluationValuePtr v) : value(std::move(v))
 {
 }
 
+bool EvaluationValue::isEmpty() const
+{
+       return value->isEmpty();
+}
+
 void EvaluationValue::convertTo(int &v) const
 {
        EvaluationValueInteger tmp = {};
index b16799edc27f5d34215e7d99ab2b5eb7ec3d4ff6..e4bfcb9cd50b8bc3835fa48a680bdc587b600be5 100644 (file)
@@ -215,6 +215,7 @@ public:
        Q(Iterator)
 #undef Q
 
+       bool isEmpty() const;
        std::string typeName() const;
        bool operator == (const EvaluationValue &) const;
        bool operator != (const EvaluationValue &) const;