diff options
author | Felipe Magno de Almeida <felipe@expertisesolutions.com.br> | 2015-01-11 13:35:47 -0200 |
---|---|---|
committer | Felipe Magno de Almeida <felipe@expertisesolutions.com.br> | 2015-01-11 13:35:47 -0200 |
commit | 1d4145c2733d383287a2ec95a5d4cc78ecfdc0d3 (patch) | |
tree | 2975097c87aee299d8c7ee5fd722fbb2816f6bbb | |
parent | 9f8624603d0d1c79406c43ab539f69de7cb56519 (diff) | |
download | efl-1d4145c2733d383287a2ec95a5d4cc78ecfdc0d3.tar.gz |
Fixed tests
-rw-r--r-- | src/Makefile_Eina_Js.am | 4 | ||||
-rw-r--r-- | src/tests/eina_js/eina_js_suite.cc | 108 | ||||
-rwxr-xr-x | src/tests/eina_js/eina_js_suite.js | 44 |
3 files changed, 109 insertions, 47 deletions
diff --git a/src/Makefile_Eina_Js.am b/src/Makefile_Eina_Js.am index 80289514fa..1d8a408e55 100644 --- a/src/Makefile_Eina_Js.am +++ b/src/Makefile_Eina_Js.am @@ -140,8 +140,6 @@ tests_eina_js_libeina_js_iterator_la_LIBADD = @CHECK_LIBS@ @USE_EINA_JS_LIBS@ @U tests_eina_js_libeina_js_iterator_la_DEPENDENCIES = @USE_EINA_INTERNAL_LIBS@ @USE_EINA_JS_INTERNAL_LIBS@ @USE_EO_INTERNAL_LIBS@ else -AM_TESTS_ENVIRONMENT = EINA_SUITE_PATH='$(abs_srcdir)/tests/eina_js/eina_js_suite.js'; export EINA_SUITE_PATH; - check_PROGRAMS += tests/eina_js/eina_js_suite TESTS += tests/eina_js/eina_js_suite @@ -166,7 +164,7 @@ tests/eina_js/eina_js_suite.cc tests_eina_js_eina_js_suite_CXXFLAGS = $(EINA_JS_TEST_CXXFLAGS) tests_eina_js_eina_js_suite_LDADD = \ @CHECK_LIBS@ @USE_EO_LIBS@ @USE_EINA_LIBS@ @USE_EOLIAN_LIBS@ @USE_EINA_JS_LIBS@ @EINA_JS_LIBS@ -tests_eina_js_eina_js_suite_DEPENDENCIES = @USE_EINA_INTERNAL_LIBS@ @USE_EINA_JS_INTERNAL_LIBS@ @USE_EO_INTERNAL_LIBS@ +tests_eina_js_eina_js_suite_DEPENDENCIES = @USE_EINA_INTERNAL_LIBS@ @USE_EINA_JS_INTERNAL_LIBS@ @USE_EO_INTERNAL_LIBS@ tests/eina_js/eina_js_suite.js # tests_eina_js_eina_js_value_CXXFLAGS = $(EINA_JS_TEST_CXXFLAGS) # tests_eina_js_eina_js_value_LDADD = @CHECK_LIBS@ @USE_EINA_JS_LIBS@ @USE_EINA_LIBS@ @USE_EO_LIBS@ diff --git a/src/tests/eina_js/eina_js_suite.cc b/src/tests/eina_js/eina_js_suite.cc index 762f35f09f..cfcf528f19 100644 --- a/src/tests/eina_js/eina_js_suite.cc +++ b/src/tests/eina_js/eina_js_suite.cc @@ -7,6 +7,7 @@ #include <cassert> #include <cstdlib> +#include <fstream> #include <Eina.h> #include <Eina.hh> @@ -28,6 +29,7 @@ bool ExecuteString(v8::Isolate* isolate, v8::ScriptOrigin origin(name); v8::Handle<v8::Script> script = v8::Script::Compile(source, &origin); if (script.IsEmpty()) { + std::cerr << "Compilation failed" << std::endl; std::abort(); // Print errors that happened during compilation. // if (report_exceptions) @@ -36,14 +38,19 @@ bool ExecuteString(v8::Isolate* isolate, } else { + std::cerr << "Compilation succesful" << std::endl; v8::Handle<v8::Value> result = script->Run(); if (result.IsEmpty()) { std::cout << "Failed with exception thrown" << std::endl; - assert(try_catch.HasCaught()); - std::abort(); + //assert(try_catch.HasCaught()); + //std::abort(); // Print errors that happened during execution. // if (report_exceptions) // ReportException(isolate, &try_catch); + if(try_catch.HasCaught()) + std::cerr << "Exception " << ToCString(v8::String::Utf8Value(try_catch.Message()->Get())) + << std::endl; + std::abort(); return false; } else { assert(!try_catch.HasCaught()); @@ -81,6 +88,31 @@ efl::eina::js::compatibility_return_type Print(efl::eina::js::compatibility_call EAPI void eina_container_register(v8::Handle<v8::Object> global, v8::Isolate* isolate); EAPI v8::Handle<v8::FunctionTemplate> get_list_instance_template(); +efl::eina::ptr_list<int> list; +efl::eina::js::range_eina_list<int> raw_list; + +void test_setup(v8::Handle<v8::Object> exports) +{ + std::cerr << __LINE__ << std::endl; + list.push_back(new int(5)); + list.push_back(new int(10)); + list.push_back(new int(15)); + std::cerr << __LINE__ << std::endl; + + raw_list = efl::eina::js::range_eina_list<int>(list.native_handle()); + + std::cerr << __LINE__ << std::endl; + eina_container_register(exports, v8::Isolate::GetCurrent()); + std::cerr << __LINE__ << std::endl; + + v8::Handle<v8::Value> a[] = {efl::eina::js::compatibility_new<v8::External>(nullptr, &raw_list)}; + std::cerr << __LINE__ << std::endl; + exports->Set(efl::eina::js::compatibility_new<v8::String>(nullptr, "raw_list") + , get_list_instance_template()->GetFunction()->NewInstance(1, a)); + std::cerr << __LINE__ << std::endl; + +} + #ifndef HAVE_NODEJS int main(int, char*[]) @@ -97,21 +129,10 @@ int main(int, char*[]) efl::eina::js::compatibility_handle_scope handle_scope(isolate); v8::Handle<v8::Context> context; - efl::eina::ptr_list<int> list; - list.push_back(new int(5)); - list.push_back(new int(10)); - list.push_back(new int(15)); - - efl::eina::js::range_eina_list<int> raw_list(list.native_handle()); { // Create a template for the global object. v8::Handle<v8::ObjectTemplate> global = efl::eina::js::compatibility_new<v8::ObjectTemplate>(isolate); - // Bind the global 'print' function to the C++ Print callback. - global->Set(efl::eina::js::compatibility_new<v8::String>(isolate, "print"), - efl::eina::js::compatibility_new<v8::FunctionTemplate>(isolate, Print)); - context = efl::eina::js::compatibility_new<v8::Context>(isolate, nullptr, global); - eina_container_register(context->Global(), isolate); } if (context.IsEmpty()) { fprintf(stderr, "Error creating context\n"); @@ -119,19 +140,49 @@ int main(int, char*[]) } context->Enter(); { + std::vector<char> script; + { + std::ifstream script_file(TESTS_SRC_DIR "/eina_js_suite.js"); + script_file.seekg(0, std::ios::end); + std::size_t script_size = script_file.tellg(); + script_file.seekg(0, std::ios::beg); + script.resize(script_size+1); + script_file.rdbuf()->sgetn(&script[0], script_size); + auto line_break = std::find(script.begin(), script.end(), '\n'); + assert(line_break != script.end()); + ++line_break; + std::fill(script.begin(), line_break, ' '); + + std::cerr << "program:" << std::endl; + std::copy(script.begin(), script.end(), std::ostream_iterator<char>(std::cerr)); + std::cerr << "end of program" << std::endl; + } + + // Enter the execution environment before evaluating any code. v8::Context::Scope context_scope(context); v8::Local<v8::String> name(efl::eina::js::compatibility_new<v8::String> (nullptr, "(shell)")); - v8::Handle<v8::Value> a[] = {efl::eina::js::compatibility_new<v8::External>(isolate, &raw_list)}; - context->Global()->Set(efl::eina::js::compatibility_new<v8::String>(isolate, "raw_list") - , get_list_instance_template()->GetFunction()->NewInstance(1, a)); + std::cerr << __LINE__ << std::endl; + v8::Handle<v8::Object> exports = efl::eina::js::compatibility_new<v8::Object>(isolate); + context->Global()->Set(efl::eina::js::compatibility_new<v8::String>(isolate, "suite"), exports); + test_setup(exports); + std::cerr << __LINE__ << std::endl; + + v8::Handle<v8::Object> console = efl::eina::js::compatibility_new<v8::Object>(isolate); + context->Global()->Set(efl::eina::js::compatibility_new<v8::String>(isolate, "console"), console); + console->Set(efl::eina::js::compatibility_new<v8::String>(isolate, "log") + , efl::eina::js::compatibility_new<v8::FunctionTemplate>(isolate, & ::Print) + ->GetFunction()); + efl::eina::js::compatibility_handle_scope handle_scope(v8::Isolate::GetCurrent()); + std::cerr << __LINE__ << std::endl; ExecuteString(v8::Isolate::GetCurrent(), - efl::eina::js::compatibility_new<v8::String>(v8::Isolate::GetCurrent(), script), + efl::eina::js::compatibility_new<v8::String>(v8::Isolate::GetCurrent(), &script[0]), name); + std::cerr << __LINE__ << std::endl; } context->Exit(); } @@ -141,38 +192,21 @@ int main(int, char*[]) namespace { -efl::eina::ptr_list<int> list; -efl::eina::js::range_eina_list<int> raw_list; - void init(v8::Handle<v8::Object> exports) { try { eina_init(); eo_init(); - - std::cerr << __LINE__ << std::endl; - list.push_back(new int(5)); - list.push_back(new int(10)); - list.push_back(new int(15)); - std::cerr << __LINE__ << std::endl; - - raw_list = efl::eina::js::range_eina_list<int>(list.native_handle()); - - std::cerr << __LINE__ << std::endl; - eina_container_register(exports, v8::Isolate::GetCurrent()); - std::cerr << __LINE__ << std::endl; - - v8::Handle<v8::Value> a[] = {efl::eina::js::compatibility_new<v8::External>(nullptr, &raw_list)}; - std::cerr << __LINE__ << std::endl; - exports->Set(efl::eina::js::compatibility_new<v8::String>(nullptr, "raw_list") - , get_list_instance_template()->GetFunction()->NewInstance(1, a)); + test_setup(exports); + std::cerr << "registered" << std::endl; } catch(...) { std::cerr << "Error" << std::endl; + std::abort(); } } diff --git a/src/tests/eina_js/eina_js_suite.js b/src/tests/eina_js/eina_js_suite.js index 9c2d55e02c..02429249de 100755 --- a/src/tests/eina_js/eina_js_suite.js +++ b/src/tests/eina_js/eina_js_suite.js @@ -1,15 +1,24 @@ #!/usr/bin/env node -console.log('path ', process.env.EINA_SUITE_PATH); +var suite; +var assert; -console.log("teste1"); +if(typeof process !== 'undefined') +{ + console.log('running from nodejs'); + console.log('path ', process.env.EINA_SUITE_PATH); + console.log("teste1"); -var suite = require(process.env.EINA_SUITE_PATH); -assert = require('assert'); + suite = require(process.env.EINA_SUITE_PATH); + assert = require('assert'); +} +else +{ + assert = function(test, message) { if (test !== true) throw message; }; + console.log('running from libv8') +} -process.argv.forEach(function (val, index, array) { - console.log(index + ': ' + val); -}); +// container tests console.log("teste"); var l1 = suite.raw_list; @@ -51,3 +60,24 @@ assert (s2[0] == l1[1]); assert (s2[1] == l1[2]); console.log ("Test execution with success"); + +// error tests + +var captured = false; +try { + clear_eina_error(); +} catch(e) { + captured = true; +} +assert(captured === false, '#1'); + +captured = false; +try { + set_eina_error(); +} catch(e) { + assert(e.code === 'Eina_Error', '#2'); + assert(e.value === 'foobar', '#3'); + captured = true; +} +assert(captured === true, '#4'); + |