fix tts line issue 10/206110/4
authorRadoslaw Cybulski <r.cybulski@partner.samsung.com>
Tue, 14 May 2019 09:47:36 +0000 (11:47 +0200)
committerRadoslaw Cybulski <r.cybulski@partner.samsung.com>
Thu, 16 May 2019 09:31:20 +0000 (11:31 +0200)
Change-Id: I6cc8bd0a463e82a8b812d1d48066ce9770e62ac5

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

index 7bf09aa..6d1e2d2 100644 (file)
@@ -922,10 +922,10 @@ protected:
        bool success = false;
 };
 
-class DlogTTS : public PredicateWaitInterface
+class WaitDlog : public PredicateWaitInterface
 {
 public:
-       DlogTTS(BatchExecutor *executor, std::chrono::milliseconds timeout, std::string pattern)
+       WaitDlog(BatchExecutor *executor, std::chrono::milliseconds timeout, std::string pattern)
                : PredicateWaitInterface(executor, timeout)
        {
                {
@@ -956,7 +956,7 @@ private:
 class WaitTTS : public PredicateWaitInterface
 {
 public:
-       WaitTTS(BatchExecutor *executor, std::chrono::milliseconds timeout, std::string pattern)
+       WaitTTS(BatchExecutor *executor, std::chrono::milliseconds timeout, std::string pattern, bool exact)
                : PredicateWaitInterface(executor, timeout)
        {
                this->pattern = pattern;
@@ -964,6 +964,9 @@ public:
                        auto h = self->ttsInfo.lock();
                        if (!pattern.empty())
                                h->searchLine = std::move(pattern);
+                       else
+                               h->searchLine = {};
+                       h->exact = exact;
                        h->mode = BatchExecutor::TTSInfo::Mode::search;
                }
        }
@@ -1034,16 +1037,16 @@ private:
 void BatchExecutor::insertWaits()
 {
        auto dlogTTS = [&](std::string pattern, double timeout) -> EvaluationValue {
-               auto impl = std::make_shared<DlogTTS>(this, std::chrono::milliseconds{ static_cast<size_t>(timeout * 1000) }, std::move(pattern));
+               auto impl = std::make_shared<WaitDlog>(this, std::chrono::milliseconds{ static_cast<size_t>(timeout * 1000) }, std::move(pattern));
                return EvaluationValue{ impl };
        };
        variables["dlog"] = EvaluationValueFunction{ std::move(dlogTTS), { { "pattern" }, { "timeout", 5.0 } } };
 
-       auto waitTTS = [&](std::string pattern, double timeout) -> EvaluationValue {
-               auto impl = std::make_shared<WaitTTS>(this, std::chrono::milliseconds{ static_cast<size_t>(timeout * 1000) }, std::move(pattern));
+       auto waitTTS = [&](std::string pattern, double timeout, bool exact) -> EvaluationValue {
+               auto impl = std::make_shared<WaitTTS>(this, std::chrono::milliseconds{ static_cast<size_t>(timeout * 1000) }, std::move(pattern), exact);
                return EvaluationValue{ impl };
        };
-       variables["tts"] = EvaluationValueFunction{ std::move(waitTTS), { { "pattern", "" }, { "timeout", 5.0 } } };
+       variables["tts"] = EvaluationValueFunction{ std::move(waitTTS), { { "pattern", "" }, { "timeout", 5.0 }, { "exact", true } } };
 
        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));
@@ -1340,15 +1343,18 @@ static void threadFunc(StatPtr result, std::unique_ptr<BatchExecutor> exec, std:
                                if (!h->searchLine) {
                                        h->mode = BatchExecutor::TTSInfo::Mode::found;
                                } else {
-                                       if (txt.find("(tts_speak_do)") != std::string::npos) {
-                                               auto z = txt.rfind(", text ");
+                                       if (txt.find("(send_chunk_to_tts)") != std::string::npos) {
+                                               static const auto prefix = std::string{ "Passing TEXT: " };
+                                               static const auto postfix = std::string{ " to TTS" };
+
+                                               auto z = txt.find(prefix);
                                                if (z != std::string::npos) {
-                                                       z += 7;
-                                                       auto z2 = txt.rfind("))");
-                                                       if (z2 != std::string::npos) {
+                                                       z += prefix.size();
+                                                       auto z2 = txt.rfind(postfix);
+                                                       if (z2 != std::string::npos && z2 > z) {
                                                                auto sub = txt.substr(z, z2 - z);
                                                                exec->outputStream() << "TTS: '" << sub << "'\n";
-                                                               if (sub.find(*h->searchLine) != std::string::npos) {
+                                                               if ((h->exact && sub == *h->searchLine) || (!h->exact && sub.find(*h->searchLine) != std::string::npos)) {
                                                                        h->mode = BatchExecutor::TTSInfo::Mode::found;
                                                                }
                                                        }
index 98703a9..43d76a2 100644 (file)
@@ -70,6 +70,7 @@ public:
        };
        struct TTSInfo {
                Optional<std::string> searchLine;
+               bool exact = false;
                enum class Mode { ignore, search, found };
                Mode mode = Mode::ignore;
        };