Script UTC test cases 93/42093/1
authorNick Holland <nick.holland@partner.samsung.com>
Tue, 23 Jun 2015 07:36:46 +0000 (08:36 +0100)
committerNick Holland <nick.holland@partner.samsung.com>
Tue, 23 Jun 2015 07:37:14 +0000 (08:37 +0100)
Change-Id: I225ed158c15d6bd3f620e78266a5e8b99c8495c2

15 files changed:
automated-tests/src/dali-toolkit/CMakeLists.txt
automated-tests/src/dali-toolkit/utc-Dali-Script.cpp [new file with mode: 0644]
dali-toolkit/devel-api/scripting/script-plugin.h
dali-toolkit/devel-api/scripting/script.cpp
dali-toolkit/devel-api/scripting/script.h
dali-toolkit/internal/scripting/script-impl.cpp
dali-toolkit/internal/scripting/script-impl.h
dali-toolkit/internal/scripting/script-plugin-proxy.cpp
dali-toolkit/internal/scripting/script-plugin-proxy.h
plugins/dali-script-v8/src/dali-script-v8.cpp
plugins/dali-script-v8/src/dali-script-v8.h
plugins/dali-script-v8/src/dali-wrapper.cpp
plugins/dali-script-v8/src/dali-wrapper.h
plugins/dali-script-v8/src/module-loader/module-loader.cpp
plugins/dali-script-v8/src/module-loader/module-loader.h

index 803d2ed..b96b37b 100644 (file)
@@ -25,6 +25,7 @@ SET(TC_SOURCES
    utc-Dali-OverlayEffect.cpp
    utc-Dali-PageTurnEffect.cpp
    utc-Dali-PageTurnView.cpp
+   utc-Dali-Script.cpp
    utc-Dali-ScrollBar.cpp
    utc-Dali-ScrollView.cpp
    utc-Dali-ShadowView.cpp
diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Script.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Script.cpp
new file mode 100644 (file)
index 0000000..00bf7ae
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <iostream>
+#include <stdlib.h>
+#include <dali-toolkit-test-suite-utils.h>
+#include <dali-toolkit/dali-toolkit.h>
+#include <dali-toolkit/devel-api/scripting/script.h>
+
+using namespace Dali;
+using namespace Dali::Toolkit;
+
+void dali_script_startup(void)
+{
+  test_return_value = TET_UNDEF;
+}
+
+void dali_script_cleanup(void)
+{
+  test_return_value = TET_PASS;
+}
+
+int UtcDaliScriptExecuteFileN(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" UtcDaliScriptExecuteFileN");
+
+  Script script = Script::New();
+
+  bool ok = script.ExecuteFile("non-existing file");
+
+  DALI_TEST_CHECK( !ok );
+
+  END_TEST;
+}
index 428d82f..f3e049b 100644 (file)
@@ -66,15 +66,18 @@ public:
    * Exec buffer contents as a script
    * @param buffer script file contents
    * @param filename a nominal name for the buffer contents.
-   * (NB filename extension may be used to disambiguate script language)
+   * filename extension may be used to disambiguate script language
+   * @return true on success, false on failure
+   *
    */
-  virtual void ExecuteBuffer(const std::string& buffer, const std::string& filename) = 0;
+  virtual bool ExecuteBuffer(const std::string& buffer, const std::string& filename) = 0;
 
   /**
    * Exec file as a script
    * @param filename the filename to read and execute
+   * @return true on success, false on failure
    */
-  virtual void ExecuteFile(const std::string& filename) = 0;
+  virtual bool ExecuteFile(const std::string& filename) = 0;
 
 }; // class ScriptPlugin
 
index fb846f9..7fdf5e4 100644 (file)
@@ -46,9 +46,9 @@ Script::Script(Internal::Script *impl)
 {
 }
 
-void Script::ExecuteFile( const std::string &filename )
+bool Script::ExecuteFile( const std::string &filename )
 {
-  GetImpl(*this).ExecuteFile( filename );
+  return GetImpl(*this).ExecuteFile( filename );
 }
 
 } // namespace Toolkit
index e49a0d7..8eed33b 100644 (file)
@@ -75,8 +75,10 @@ public:
    * Executes the contents of filename in a scripted environment.
    * @pre A Dali Application object exists
    * @param filename A filename of a script file to execute
+   * @return true on success, false on failure
+   *
    */
-  void ExecuteFile( const std::string& filename );
+  bool ExecuteFile( const std::string& filename );
 
 private:
 
index 8b08f99..a84ee70 100644 (file)
@@ -36,14 +36,6 @@ namespace
 const char* PLUGIN_FILE = "libdali-script-plugin-v8.so";
 }
 
-void Script::ExecuteFile( const std::string& filename )
-{
-  if( mPlugin )
-  {
-    mPlugin->ExecuteFile(filename);
-  }
-}
-
 Script::Script(void) : mPlugin(NULL)
 {
   ScriptPluginProxy *plugin = new ScriptPluginProxy( PLUGIN_FILE );
@@ -66,6 +58,15 @@ Script::Script(void) : mPlugin(NULL)
 
 }
 
+bool Script::ExecuteFile( const std::string& filename )
+{
+  if( mPlugin )
+  {
+    return mPlugin->ExecuteFile(filename);
+  }
+  return false;
+}
+
 Script::~Script()
 {
   if( mPlugin )
index c8d9c6d..e8677b3 100644 (file)
@@ -51,7 +51,7 @@ public:
   /**
    * @copydoc Toolkit::Script::ExecuteFile
    */
-  void ExecuteFile( const std::string& filename );
+  bool ExecuteFile( const std::string& filename );
 
 protected:
 
index 1e0a6c2..0af3711 100644 (file)
@@ -57,20 +57,22 @@ void ScriptPluginProxy::SetFlags(const std::string& flags)
   }
 }
 
-void ScriptPluginProxy::ExecuteBuffer(const std::string &buffer, const std::string &filename)
+bool ScriptPluginProxy::ExecuteBuffer(const std::string &buffer, const std::string &filename)
 {
   if( mIsInitialized )
   {
-    mScriptingPlugin->ExecuteBuffer( buffer, filename );
+    return mScriptingPlugin->ExecuteBuffer( buffer, filename );
   }
+  return false;
 }
 
-void ScriptPluginProxy::ExecuteFile(const std::string &filename)
+bool ScriptPluginProxy::ExecuteFile(const std::string &filename)
 {
   if( mIsInitialized )
   {
-    mScriptingPlugin->ExecuteFile( filename );
+    return mScriptingPlugin->ExecuteFile( filename );
   }
+  return false;
 }
 
 bool ScriptPluginProxy::IsInitialized() const
@@ -78,7 +80,6 @@ bool ScriptPluginProxy::IsInitialized() const
   return mIsInitialized;
 };
 
-
 void ScriptPluginProxy::Initialize()
 {
   if( mIsInitialized )
index 05da08f..2c359c7 100644 (file)
@@ -56,18 +56,21 @@ public:
   virtual void SetFlags( const std::string& flags );
 
   /**
-   *  @brief Exececute the buffer contents as a script
+   * @brief Exececute the buffer contents as a script
    * @param [in] buffer script file contents
    * @param [in] filename a nominal name for the buffer contents.
-   * (NB filename extension may be used to disambiguate script language)
+   * @note filename extension may be used to disambiguate script language
+   * @return true on success, false on failure
+   *
    */
-  virtual void ExecuteBuffer( const std::string& buffer, const std::string& filename );
+  virtual bool ExecuteBuffer( const std::string& buffer, const std::string& filename );
 
   /**
    * @brief  execture the file as a script
    * @param [in] filename the filename to read and execute
+   * @return true on success, false on failure
    */
-  virtual void ExecuteFile( const std::string& fileName );
+  virtual bool ExecuteFile( const std::string& fileName );
 
   /**
    * @brief check if the plugin is initialized
index 4467b0a..dc7641b 100644 (file)
@@ -56,16 +56,14 @@ void DaliScriptV8::SetFlags(const std::string& s)
   DaliWrapper::Get().SetFlagsFromString(s);
 }
 
-void DaliScriptV8::ExecuteBuffer(const std::string& buffer, const std::string& filename)
+bool DaliScriptV8::ExecuteBuffer(const std::string& buffer, const std::string& filename)
 {
-  DaliWrapper::Get().ExecuteBuffer(buffer, filename);
+  return DaliWrapper::Get().ExecuteBuffer(buffer, filename);
 }
 
-void DaliScriptV8::ExecuteFile(const std::string& filename)
+bool DaliScriptV8::ExecuteFile(const std::string& filename)
 {
-
-
-  DaliWrapper::Get().ExecuteFile( filename );
+  return DaliWrapper::Get().ExecuteFile( filename );
 }
 
 }  // namespace V8Plugin
index 5389612..61d265b 100644 (file)
@@ -55,12 +55,12 @@ public: // ScriptV8Plugin overrides
   /**
    * @copydoc Dali::Toolkit::ScriptPlugin::ExecuteBuffer()
    */
-  virtual void ExecuteBuffer(const std::string& buffer, const std::string& filename);
+  virtual bool ExecuteBuffer(const std::string& buffer, const std::string& filename);
 
   /**
    * @copydoc Dali::Toolkit::ScriptPlugin::ExecuteFile()
    */
-  virtual void ExecuteFile(const std::string& fileName);
+  virtual bool ExecuteFile(const std::string& fileName);
 
 
 };
index 09205d7..93c85fc 100644 (file)
@@ -143,16 +143,16 @@ void DaliWrapper::Shutdown()
   }
 }
 
-void DaliWrapper::ExecuteBuffer(const std::string &sourceCode, const std::string &sourceFileName)
+bool DaliWrapper::ExecuteBuffer(const std::string &sourceCode, const std::string &sourceFileName)
 {
-  mModuleLoader.ExecuteScript( mIsolate,  sourceCode, sourceFileName );
+  return mModuleLoader.ExecuteScript( mIsolate,  sourceCode, sourceFileName );
 }
 
-void DaliWrapper::ExecuteFile( const std::string& sourceFileName )
+bool DaliWrapper::ExecuteFile( const std::string& sourceFileName )
 {
   DALI_LOG_INFO( gLogExecuteFilter, Debug::Verbose, "Executing source file %s \n",sourceFileName.c_str() );
 
-  mModuleLoader.ExecuteScriptFromFile( mIsolate,  sourceFileName );
+  return mModuleLoader.ExecuteScriptFromFile( mIsolate,  sourceFileName );
 }
 
 GarbageCollectorInterface& DaliWrapper::GetDaliGarbageCollector()
index 27d4fd3..e576f4b 100644 (file)
@@ -101,16 +101,18 @@ public:
    *
    * @param[in] sourceCode The buffer containing javascript to execute
    * @param[in] sourceFileName Filename associated with the buffer (for error tracing)
+   * @return true on success, false on failure
    */
-  void ExecuteBuffer(const std::string &sourceCode, const std::string &sourceFileName);
+  bool ExecuteBuffer(const std::string &sourceCode, const std::string &sourceFileName);
 
 
   /**
    * Excute the buffer in the v8 context
    *
    * @param[in] sourceFileName Filename associated with the buffer (for error tracing)
+   * @return true on success, false on failure
    */
-  void ExecuteFile( const std::string& sourceFileName);
+  bool ExecuteFile( const std::string& sourceFileName);
 
 
   /**
index 39b23d2..d475c90 100644 (file)
@@ -97,6 +97,11 @@ bool ModuleLoader::ExecuteScriptFromFile( v8::Isolate* isolate,
 
   V8Utils::GetFileContents( fileName, contents );
 
+  if( contents.empty() )
+  {
+    return false;
+  }
+
   return ExecuteScript( isolate, contents, fileName );
 }
 
index 00f3625..085f33f 100644 (file)
@@ -77,6 +77,8 @@ public:
   /**
    * Execute a script from a file
    * @param[in] fileName file name
+   * @return true on success, false on failure
+   *
    */
   bool ExecuteScriptFromFile( v8::Isolate* isolate, const std::string& fileName );
 
@@ -85,6 +87,7 @@ public:
    * Execute a script
    * @param[in] sourceCode source code to run
    * @param[in] sourceFileName source file name
+   * @return true on success, false on failure
    */
   bool ExecuteScript( v8::Isolate* isolate,
                       const std::string& sourceCode,