2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
20 * @date 09/13/2011 08:31:09 AM
28 #include <dpl/log/log.h>
29 #include <dpl/assert.h>
30 #include <JavaScriptCore/JavaScript.h>
31 #include <Commons/WrtWrapper/WrtWrappersMgr.h>
32 #include <WidgetDB/WidgetDBMgr.h>
33 #include <WidgetDB/IWidgetDB.h>
36 using namespace WrtDeviceApis;
37 //using namespace WrtDeviceApis::Commons;
38 //using namespace WrtDeviceApis::CommonsJavaScript;
40 namespace WrtPlugins {
47 DPL::Event::ControllerEventHandler<FinishEvent>::Touch();
50 void Test::run(double timeout) {
51 PostTimedEvent(FinishEvent(), timeout);
54 void Test::setEvaluator(JSObjectRef evaluator) {
55 m_evaluator = evaluator;
58 void Test::setContext(JSContextRef context) {
62 void Test::OnEventReceived(const FinishEvent& event) {
65 Result result = Result::Success;
66 if (m_evaluator && m_context) {
67 JSValueRef eval = JSObjectCallAsFunction(m_context,
74 if (JSValueIsBoolean(m_context, eval)) {
75 if (!JSValueToBoolean(m_context, eval)) {
76 result = Result::Fail;
80 LogError("Evaluator returned value of wrong type.");
81 result = Result::Exception;
85 LogError("Evaluator did not return any value.");
86 result = Result::Exception;
91 FILE* output = fdopen(4, "w");
93 Commons::IWrtWrapperPtr wrt =
94 Commons::WrtWrappersMgr::getInstance().getWrtWrapper(m_context);
95 WidgetDB::Api::IWidgetDBPtr widgetDB =
96 WidgetDB::Api::getWidgetDB(wrt->getWidgetId());
101 widgetDB->getConfigValue(
102 WidgetDB::Api::ConfigAttribute::NAME).c_str(),
103 resultToString(result).c_str());
106 LogInfo("Output descriptor not created.");
109 pid_t pid = getpid();
110 LogDebug("Sending SIGINT to " << pid);
111 if (kill(pid, SIGINT) != 0) {
112 LogError("Sending SIGINT failed.");
116 std::string Test::resultToString(Result result) {
118 case Result::Success: return "OK";
119 case Result::Fail: return "FAIL";
120 case Result::Exception: return "EXCEPTION";
122 Assert(false && "Unsupported result type.");