forked from enlightenment/efl
Fixed tests
This commit is contained in:
parent
9f8624603d
commit
1d4145c273
|
@ -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@
|
tests_eina_js_libeina_js_iterator_la_DEPENDENCIES = @USE_EINA_INTERNAL_LIBS@ @USE_EINA_JS_INTERNAL_LIBS@ @USE_EO_INTERNAL_LIBS@
|
||||||
|
|
||||||
else
|
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
|
check_PROGRAMS += tests/eina_js/eina_js_suite
|
||||||
TESTS += 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_CXXFLAGS = $(EINA_JS_TEST_CXXFLAGS)
|
||||||
tests_eina_js_eina_js_suite_LDADD = \
|
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@
|
@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_CXXFLAGS = $(EINA_JS_TEST_CXXFLAGS)
|
||||||
# tests_eina_js_eina_js_value_LDADD = @CHECK_LIBS@ @USE_EINA_JS_LIBS@ @USE_EINA_LIBS@ @USE_EO_LIBS@
|
# tests_eina_js_eina_js_value_LDADD = @CHECK_LIBS@ @USE_EINA_JS_LIBS@ @USE_EINA_LIBS@ @USE_EO_LIBS@
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
#include <Eina.h>
|
#include <Eina.h>
|
||||||
#include <Eina.hh>
|
#include <Eina.hh>
|
||||||
|
@ -28,6 +29,7 @@ bool ExecuteString(v8::Isolate* isolate,
|
||||||
v8::ScriptOrigin origin(name);
|
v8::ScriptOrigin origin(name);
|
||||||
v8::Handle<v8::Script> script = v8::Script::Compile(source, &origin);
|
v8::Handle<v8::Script> script = v8::Script::Compile(source, &origin);
|
||||||
if (script.IsEmpty()) {
|
if (script.IsEmpty()) {
|
||||||
|
std::cerr << "Compilation failed" << std::endl;
|
||||||
std::abort();
|
std::abort();
|
||||||
// Print errors that happened during compilation.
|
// Print errors that happened during compilation.
|
||||||
// if (report_exceptions)
|
// if (report_exceptions)
|
||||||
|
@ -36,14 +38,19 @@ bool ExecuteString(v8::Isolate* isolate,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
std::cerr << "Compilation succesful" << std::endl;
|
||||||
v8::Handle<v8::Value> result = script->Run();
|
v8::Handle<v8::Value> result = script->Run();
|
||||||
if (result.IsEmpty()) {
|
if (result.IsEmpty()) {
|
||||||
std::cout << "Failed with exception thrown" << std::endl;
|
std::cout << "Failed with exception thrown" << std::endl;
|
||||||
assert(try_catch.HasCaught());
|
//assert(try_catch.HasCaught());
|
||||||
std::abort();
|
//std::abort();
|
||||||
// Print errors that happened during execution.
|
// Print errors that happened during execution.
|
||||||
// if (report_exceptions)
|
// if (report_exceptions)
|
||||||
// ReportException(isolate, &try_catch);
|
// 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;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
assert(!try_catch.HasCaught());
|
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 void eina_container_register(v8::Handle<v8::Object> global, v8::Isolate* isolate);
|
||||||
EAPI v8::Handle<v8::FunctionTemplate> get_list_instance_template();
|
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
|
#ifndef HAVE_NODEJS
|
||||||
|
|
||||||
int main(int, char*[])
|
int main(int, char*[])
|
||||||
|
@ -97,21 +129,10 @@ int main(int, char*[])
|
||||||
efl::eina::js::compatibility_handle_scope handle_scope(isolate);
|
efl::eina::js::compatibility_handle_scope handle_scope(isolate);
|
||||||
v8::Handle<v8::Context> context;
|
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.
|
// Create a template for the global object.
|
||||||
v8::Handle<v8::ObjectTemplate> global = efl::eina::js::compatibility_new<v8::ObjectTemplate>(isolate);
|
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);
|
context = efl::eina::js::compatibility_new<v8::Context>(isolate, nullptr, global);
|
||||||
eina_container_register(context->Global(), isolate);
|
|
||||||
}
|
}
|
||||||
if (context.IsEmpty()) {
|
if (context.IsEmpty()) {
|
||||||
fprintf(stderr, "Error creating context\n");
|
fprintf(stderr, "Error creating context\n");
|
||||||
|
@ -119,19 +140,49 @@ int main(int, char*[])
|
||||||
}
|
}
|
||||||
context->Enter();
|
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.
|
// Enter the execution environment before evaluating any code.
|
||||||
v8::Context::Scope context_scope(context);
|
v8::Context::Scope context_scope(context);
|
||||||
v8::Local<v8::String> name(efl::eina::js::compatibility_new<v8::String>
|
v8::Local<v8::String> name(efl::eina::js::compatibility_new<v8::String>
|
||||||
(nullptr, "(shell)"));
|
(nullptr, "(shell)"));
|
||||||
|
|
||||||
v8::Handle<v8::Value> a[] = {efl::eina::js::compatibility_new<v8::External>(isolate, &raw_list)};
|
std::cerr << __LINE__ << std::endl;
|
||||||
context->Global()->Set(efl::eina::js::compatibility_new<v8::String>(isolate, "raw_list")
|
v8::Handle<v8::Object> exports = efl::eina::js::compatibility_new<v8::Object>(isolate);
|
||||||
, get_list_instance_template()->GetFunction()->NewInstance(1, a));
|
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());
|
efl::eina::js::compatibility_handle_scope handle_scope(v8::Isolate::GetCurrent());
|
||||||
|
std::cerr << __LINE__ << std::endl;
|
||||||
ExecuteString(v8::Isolate::GetCurrent(),
|
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);
|
name);
|
||||||
|
std::cerr << __LINE__ << std::endl;
|
||||||
}
|
}
|
||||||
context->Exit();
|
context->Exit();
|
||||||
}
|
}
|
||||||
|
@ -141,38 +192,21 @@ int main(int, char*[])
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
efl::eina::ptr_list<int> list;
|
|
||||||
efl::eina::js::range_eina_list<int> raw_list;
|
|
||||||
|
|
||||||
void init(v8::Handle<v8::Object> exports)
|
void init(v8::Handle<v8::Object> exports)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
eina_init();
|
eina_init();
|
||||||
eo_init();
|
eo_init();
|
||||||
|
|
||||||
|
test_setup(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 << "registered" << std::endl;
|
std::cerr << "registered" << std::endl;
|
||||||
}
|
}
|
||||||
catch(...)
|
catch(...)
|
||||||
{
|
{
|
||||||
std::cerr << "Error" << std::endl;
|
std::cerr << "Error" << std::endl;
|
||||||
|
std::abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,24 @@
|
||||||
#!/usr/bin/env node
|
#!/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);
|
suite = require(process.env.EINA_SUITE_PATH);
|
||||||
assert = require('assert');
|
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) {
|
// container tests
|
||||||
console.log(index + ': ' + val);
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log("teste");
|
console.log("teste");
|
||||||
var l1 = suite.raw_list;
|
var l1 = suite.raw_list;
|
||||||
|
@ -51,3 +60,24 @@ assert (s2[0] == l1[1]);
|
||||||
assert (s2[1] == l1[2]);
|
assert (s2[1] == l1[2]);
|
||||||
|
|
||||||
console.log ("Test execution with success");
|
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');
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue