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 803d2ed7794d27c8ac8966bc48ae42ed565c87a8..b96b37bc0a7c2140d735411e9d01e09dcf04b16f 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 428d82f24503c9328875d5081e6c24b9e657e39b..f3e049b46051d08b03c388fb2df01adda861f79e 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 fb846f9d977245046275ffea0970a505f4ca03cb..7fdf5e42bd4a05167e1ac3e06af945990562030c 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 e49a0d7703b7193886b0a1387be9495e53203228..8eed33ba9b0ff3a8381d19ba97fe4ced17e08e09 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 8b08f992925b8e05801b61c4c25a7dce1043e7b0..a84ee70bdb0b0f6da3d4f3f263a18df4b0038d3e 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 c8d9c6d1710fd28aa1931ea22534ba66cdc51ef9..e8677b32857162db3d7634a881856f9d9b86c496 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 1e0a6c2b863fc5b4d7bafd77cad4e7f43d5e89d5..0af37111553ad1980b3d4c7b8db7230429c6ea58 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 05da08f4137f147219b4c693ab41a5fbf9ffd663..2c359c7f1205a74c842b0e5b0da7c97c4d1c46e4 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 4467b0ada4605755db5b28aa4c93fedff3c729b9..dc7641b2c6a55557ba6f09d7f3e2ba819b9a62d2 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 53896126dd2a0babf5c6f57997ba1610b5c671a0..61d265be161fa73611a27e063ce48e7760f87cba 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 09205d76f6ab5a2144d24672de9eea2a1b61a63b..93c85fceacba1b03c0bc2936cf08204001c79b99 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 27d4fd31aa94faedc0d158d82ad834bc601dcb23..e576f4ba8af6876071fd580edbd4b91156b328b6 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 39b23d261f00310b029903186dd66920730a794b..d475c9088a561f7bb293c18bfcca8009592bc7c7 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 00f36255b1c6373704af62be6df1abad97220fef..085f33febd1a0bb4a78d9676ad66df23f603bbf2 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,