forked from enlightenment/efl
eolian-js: Added test for constructing Evas.Box
This commit is contained in:
parent
b09976f264
commit
6f3c04593a
31
configure.ac
31
configure.ac
|
@ -1163,6 +1163,37 @@ EFL_INTERNAL_DEPEND_PKG([EOLIAN], [eina])
|
|||
EFL_LIB_END([Eolian])
|
||||
#### End of Eolian
|
||||
|
||||
EFL_LIB_START([Eolian_Js])
|
||||
|
||||
### Default values
|
||||
|
||||
### Additional options to configure
|
||||
#EFL_ADD_FEATURE([EOLIAN_JS], [cxx], [${have_cxx11}])
|
||||
EFL_DEPEND_PKG([EOLIAN_JS], [V8], [v8 >= 3.25.28])
|
||||
|
||||
### Checks for programs
|
||||
|
||||
### Checks for libraries
|
||||
EFL_INTERNAL_DEPEND_PKG([EOLIAN_JS], [eina])
|
||||
|
||||
### Checks for header files
|
||||
|
||||
### Checks for types
|
||||
|
||||
### Checks for structures
|
||||
|
||||
### Checks for compiler characteristics
|
||||
|
||||
### Checks for linker characteristics
|
||||
|
||||
### Checks for library functions
|
||||
|
||||
### Check availability
|
||||
|
||||
EFL_LIB_END([Eolian_Js])
|
||||
#### End of Eolian
|
||||
|
||||
|
||||
EFL_LIB_START([Eolian_Cxx])
|
||||
### Default values
|
||||
|
||||
|
|
|
@ -72,7 +72,8 @@ tests_eina_js_eina_js_suite_CXXFLAGS = -I$(top_builddir)/src/lib/efl \
|
|||
@EO_CXX_CFLAGS@ \
|
||||
@EO_CFLAGS@ \
|
||||
@EINA_JS_CFLAGS@
|
||||
tests_eina_js_eina_js_suite_LDADD = @CHECK_LIBS@ @USE_EINA_JS_LIBS@ @USE_EINA_LIBS@ @USE_EO_LIBS@
|
||||
tests_eina_js_eina_js_suite_LDADD = \
|
||||
@CHECK_LIBS@ @USE_EO_LIBS@ @USE_EINA_LIBS@ @USE_EOLIAN_LIBS@ @USE_EOLIAN_JS_LIBS@ @USE_EINA_JS_LIBS@
|
||||
tests_eina_js_eina_js_suite_DEPENDENCIES = @USE_EINA_INTERNAL_LIBS@ @USE_EINA_JS_INTERNAL_LIBS@ @USE_EO_INTERNAL_LIBS@
|
||||
|
||||
endif
|
||||
|
|
|
@ -20,13 +20,13 @@ include Makefile_Eolian_Js_Helper.am
|
|||
|
||||
### Library
|
||||
|
||||
lib_LTLIBRARIES += bindings/eolian_js/libeolian_js.la
|
||||
lib_LTLIBRARIES += lib/eolian_js/libeolian_js.la
|
||||
|
||||
bindings_eolian_js_libeolian_js_la_SOURCES =\
|
||||
lib_eolian_js_libeolian_js_la_SOURCES =\
|
||||
bindings/eolian_js/main.cc \
|
||||
$(generated_evas_canvas_js_bindings)
|
||||
|
||||
bindings_eolian_js_libeolian_js_la_CPPFLAGS = -I$(top_builddir)/src/lib/efl \
|
||||
lib_eolian_js_libeolian_js_la_CPPFLAGS = -I$(top_builddir)/src/lib/efl \
|
||||
@EINA_CFLAGS@ @EO_JS_CFLAGS@ @EO_CFLAGS@ @EVAS_CFLAGS@ \
|
||||
-I$(top_builddir)/src/lib/evas/canvas \
|
||||
-DPACKAGE_BIN_DIR=\"$(bindir)\" \
|
||||
|
@ -34,48 +34,45 @@ bindings_eolian_js_libeolian_js_la_CPPFLAGS = -I$(top_builddir)/src/lib/efl \
|
|||
-DPACKAGE_DATA_DIR=\"$(datadir)/eolian_js\" \
|
||||
@VALGRIND_CFLAGS@
|
||||
|
||||
bindings_eolian_js_libeolian_js_la_LIBADD = @EINA_LIBS@ @DL_LIBS@
|
||||
bindings_eolian_js_libeolian_js_la_DEPENDENCIES = @EINA_INTERNAL_LIBS@ @DL_INTERNAL_LIBS@
|
||||
bindings_eolian_js_libeolian_js_la_LDFLAGS = @EFL_LTLIBRARY_FLAGS@
|
||||
lib_eolian_js_libeolian_js_la_LIBADD = @EINA_LIBS@ @DL_LIBS@
|
||||
lib_eolian_js_libeolian_js_la_DEPENDENCIES = @EINA_INTERNAL_LIBS@ @DL_INTERNAL_LIBS@
|
||||
lib_eolian_js_libeolian_js_la_LDFLAGS = @EFL_LTLIBRARY_FLAGS@
|
||||
|
||||
### Unit tests
|
||||
|
||||
if EFL_ENABLE_TESTS
|
||||
|
||||
# check_PROGRAMS += tests/eolian_cxx/eolian_cxx_suite
|
||||
# TESTS += tests/eolian_cxx/eolian_cxx_suite
|
||||
check_PROGRAMS += tests/eolian_js/eolian_js_suite
|
||||
TESTS += tests/eolian_js/eolian_js_suite
|
||||
|
||||
# tests_eolian_cxx_eolian_cxx_suite_SOURCES = \
|
||||
# tests/eolian_cxx/eolian_cxx_suite.cc \
|
||||
# tests/eolian_cxx/eolian_cxx_test_parse.cc \
|
||||
# tests/eolian_cxx/callback.c \
|
||||
# tests/eolian_cxx/eolian_cxx_test_callback.cc \
|
||||
# tests/eolian_cxx/eolian_cxx_test_generate.cc
|
||||
tests_eolian_js_eolian_js_suite_SOURCES = \
|
||||
tests/eolian_js/eolian_js_suite.cc \
|
||||
tests/eolian_js/eolian_js_test_parse.cc
|
||||
|
||||
# tests/eolian_cxx/tests_eolian_cxx_eolian_cxx_suite-eolian_cxx_test_callback.$(OBJEXT): tests/eolian_cxx/callback.eo.hh
|
||||
#tests/eolian_cxx/tests_eolian_cxx_eolian_cxx_suite-eolian_cxx_test_callback.$(OBJEXT): tests/eolian_cxx/callback.eo.hh
|
||||
|
||||
# tests/eolian_cxx/tests_eolian_cxx_eolian_cxx_suite-callback.$(OBJEXT): tests/eolian_cxx/callback.eo.c tests/eolian_cxx/callback.eo.h
|
||||
#tests/eolian_cxx/tests_eolian_cxx_eolian_cxx_suite-callback.$(OBJEXT): tests/eolian_cxx/callback.eo.c tests/eolian_cxx/callback.eo.h
|
||||
|
||||
# CLEANFILES += tests/eolian_cxx/callback.eo.hh tests/eolian_cxx/callback.eo.c tests/eolian_cxx/callback.eo.h
|
||||
#CLEANFILES += tests/eolian_cxx/callback.eo.hh tests/eolian_cxx/callback.eo.c tests/eolian_cxx/callback.eo.h
|
||||
|
||||
# tests_eolian_cxx_eolian_cxx_suite_CXXFLAGS = \
|
||||
# -I$(top_builddir)/src/lib/efl \
|
||||
# -I$(top_srcdir)/src/bin/eolian_cxx \
|
||||
# -I$(top_builddir)/src/tests/eolian_cxx \
|
||||
# -DTESTS_WD=\"`pwd`\" \
|
||||
# -DTESTS_SRC_DIR=\"$(top_srcdir)/src/tests/eolian_cxx\" \
|
||||
# -DPACKAGE_BUILD_DIR=\"$(abs_top_builddir)/src/tests/eolian_cxx\" \
|
||||
# -DPACKAGE_DATA_DIR=\"$(datadir)/eolian_cxx\" \
|
||||
# -DTESTS_BUILD_DIR=\"$(top_builddir)/src/tests/eolian_cxx\" \
|
||||
# @CHECK_CFLAGS@ @EOLIAN_CXX_CFLAGS@ @EINA_CXX_CFLAGS@ \
|
||||
# @EOLIAN_CFLAGS@ @EINA_CFLAGS@ @EO_CFLAGS@ @ECORE_CFLAGS@ \
|
||||
# @EO_CXX_CFLAGS@
|
||||
tests_eolian_js_eolian_js_suite_CXXFLAGS = \
|
||||
-I$(top_builddir)/src/lib/efl \
|
||||
-I$(top_srcdir)/src/bin/eolian_js \
|
||||
-I$(top_builddir)/src/tests/eolian_js \
|
||||
-DTESTS_WD=\"`pwd`\" \
|
||||
-DTESTS_SRC_DIR=\"$(top_srcdir)/src/tests/eolian_js\" \
|
||||
-DPACKAGE_BUILD_DIR=\"$(abs_top_builddir)/src/tests/eolian_js\" \
|
||||
-DPACKAGE_DATA_DIR=\"$(datadir)/eolian_js\" \
|
||||
-DTESTS_BUILD_DIR=\"$(top_builddir)/src/tests/eolian_js\" \
|
||||
@CHECK_CFLAGS@ @EOLIAN_CXX_CFLAGS@ @EO_JS_CFLAGS@ @EINA_JS_CFLAGS@ \
|
||||
@EOLIAN_CFLAGS@ @EINA_CFLAGS@ @EO_CFLAGS@ @ECORE_CFLAGS@ @EINA_CXX_CFLAGS@ \
|
||||
@EO_JS_CFLAGS@ @EO_CXX_CFLAGS@
|
||||
|
||||
# tests_eolian_cxx_eolian_cxx_suite_CFLAGS = ${tests_eolian_cxx_eolian_cxx_suite_CXXFLAGS}
|
||||
# tests_eolian_cxx_eolian_cxx_suite_CPPFLAGS = ${tests_eolian_cxx_eolian_cxx_suite_CXXFLAGS}
|
||||
# tests_eolian_cxx_eolian_cxx_suite_LDADD = \
|
||||
# @CHECK_LIBS@ @USE_EO_LIBS@ @USE_EINA_LIBS@ @USE_EOLIAN_LIBS@
|
||||
# tests_eolian_cxx_eolian_cxx_suite_DEPENDENCIES = @USE_EOLIAN_INTERNAL_LIBS@
|
||||
tests_eolian_js_eolian_js_suite_CFLAGS = ${tests_eolian_js_eolian_js_suite_CXXFLAGS}
|
||||
tests_eolian_js_eolian_js_suite_CPPFLAGS = ${tests_eolian_js_eolian_js_suite_CXXFLAGS}
|
||||
tests_eolian_js_eolian_js_suite_LDADD = \
|
||||
@CHECK_LIBS@ @USE_EO_LIBS@ @USE_EINA_LIBS@ @USE_EOLIAN_LIBS@ @USE_EOLIAN_JS_LIBS@ @USE_EINA_JS_LIBS@
|
||||
tests_eolian_js_eolian_js_suite_DEPENDENCIES = @USE_EOLIAN_JS_INTERNAL_LIBS@ @USE_EOLIAN_INTERNAL_LIBS@ @USE_EINA_JS_INTERNAL_LIBS@
|
||||
|
||||
endif
|
||||
|
||||
|
|
|
@ -145,8 +145,8 @@ int main(int argc, char** argv)
|
|||
print_lower_case_namespace(klass, os);
|
||||
os << " {\n";
|
||||
|
||||
os << "void register_" << lower_case_class_name
|
||||
<< "(v8::Handle<v8::ObjectTemplate> /*global*/, v8::Isolate* isolate)\n";
|
||||
os << "EAPI void register_" << lower_case_class_name
|
||||
<< "(v8::Handle<v8::Object> global, v8::Isolate* isolate)\n";
|
||||
os << "{\n";
|
||||
os << " v8::Handle<v8::FunctionTemplate> constructor = v8::FunctionTemplate::New\n";
|
||||
os << " (isolate, efl::eo::js::constructor, efl::eo::js::constructor_data(isolate, ";
|
||||
|
@ -174,14 +174,14 @@ int main(int argc, char** argv)
|
|||
<< eolian_function_full_c_name_get(function) << ")));\n";
|
||||
}
|
||||
|
||||
os << " global->Set(v8::String::NewFromUtf8(isolate, \""
|
||||
<< class_name << "\")"
|
||||
<< ", constructor->GetFunction());\n";
|
||||
|
||||
os << "}\n";
|
||||
|
||||
for(std::size_t i = 0, j = namespace_size(klass); i != j; ++i)
|
||||
os << "}";
|
||||
os << "\n";
|
||||
|
||||
//std::vector<Eolian_Function const*> functions;
|
||||
|
||||
|
||||
os << "\n#endif\n\n";
|
||||
}
|
||||
|
|
|
@ -9,10 +9,13 @@
|
|||
|
||||
#include <functional>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace efl { namespace eo { namespace js {
|
||||
|
||||
inline void constructor(v8::FunctionCallbackInfo<v8::Value> const& args)
|
||||
{
|
||||
std::cout << "Constructor ! " << std::endl;
|
||||
if(args.IsConstructCall())
|
||||
{
|
||||
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
// #include <stdio.h>
|
||||
// #include <stdlib.h>
|
||||
// #include <check.h>
|
||||
// #include <cassert>
|
||||
|
||||
// void eolian_js_test_parse(TCase* tc);
|
||||
|
||||
// typedef struct _Eolian_Js_Test_Case Eolian_Js_Test_Case;
|
||||
// struct _Eolian_Js_Test_Case
|
||||
// {
|
||||
// const char *test_case;
|
||||
// void (*build)(TCase *tc);
|
||||
// };
|
||||
|
||||
// static const Eolian_Js_Test_Case etc[] = {
|
||||
// { "Eolian-Js Parsing", eolian_js_test_parse },
|
||||
// { NULL, NULL }
|
||||
// };
|
||||
|
||||
// static void
|
||||
// _list_tests(void)
|
||||
// {
|
||||
// const Eolian_Js_Test_Case *itr;
|
||||
|
||||
// itr = etc;
|
||||
// fputs("Available Test Cases:\n", stderr);
|
||||
// for (; itr->test_case; itr++)
|
||||
// fprintf(stderr, "\t%s\n", itr->test_case);
|
||||
// }
|
||||
|
||||
// static bool
|
||||
// _use_test(int argc, const char **argv, const char *test_case)
|
||||
// {
|
||||
// if (argc < 1)
|
||||
// return 1;
|
||||
|
||||
// for (; argc > 0; argc--, argv++)
|
||||
// if (strcmp(test_case, *argv) == 0)
|
||||
// return 1;
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
// Suite *
|
||||
// eolian_js_build_suite(int argc, const char **argv)
|
||||
// {
|
||||
// TCase *tc;
|
||||
// Suite *s;
|
||||
// int i;
|
||||
|
||||
// s = suite_create("Eolian Js");
|
||||
|
||||
// for (i = 0; etc[i].test_case; ++i)
|
||||
// {
|
||||
// if (!_use_test(argc, argv, etc[i].test_case))
|
||||
// continue;
|
||||
|
||||
// tc = tcase_create(etc[i].test_case);
|
||||
// tcase_set_timeout(tc, 0);
|
||||
|
||||
// etc[i].build(tc);
|
||||
// suite_add_tcase(s, tc);
|
||||
// }
|
||||
|
||||
// return s;
|
||||
// }
|
||||
|
||||
// int main(int argc, char* argv[])
|
||||
// {
|
||||
// Suite *s;
|
||||
// SRunner *sr;
|
||||
// int i, failed_count;
|
||||
|
||||
// for (i = 1; i < argc; i++)
|
||||
// if ((strcmp(argv[i], "-h") == 0) ||
|
||||
// (strcmp(argv[i], "--help") == 0))
|
||||
// {
|
||||
// fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n",
|
||||
// argv[0]);
|
||||
// _list_tests();
|
||||
// return 0;
|
||||
// }
|
||||
// else if ((strcmp(argv[i], "-l") == 0) ||
|
||||
// (strcmp(argv[i], "--list") == 0))
|
||||
// {
|
||||
// _list_tests();
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
// putenv(const_cast<char*>("EFL_RUN_IN_TREE=1"));
|
||||
|
||||
// s = eolian_js_build_suite(argc - 1, (const char **)argv + 1);
|
||||
// sr = srunner_create(s);
|
||||
|
||||
// srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml");
|
||||
|
||||
// srunner_run_all(sr, CK_ENV);
|
||||
// failed_count = srunner_ntests_failed(sr);
|
||||
// srunner_free(sr);
|
||||
|
||||
// return (failed_count == 0) ? 0 : 255;
|
||||
// }
|
|
@ -0,0 +1,167 @@
|
|||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <Eo_Js.hh>
|
||||
#include <Eina.hh>
|
||||
#include <Eo.hh>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <cassert>
|
||||
#include <tuple>
|
||||
|
||||
#include <v8-platform.h>
|
||||
|
||||
namespace v8 {
|
||||
namespace platform {
|
||||
|
||||
/**
|
||||
* Returns a new instance of the default v8::Platform implementation.
|
||||
*
|
||||
* The caller will take ownership of the returned pointer. |thread_pool_size|
|
||||
* is the number of worker threads to allocate for background jobs. If a value
|
||||
* of zero is passed, a suitable default based on the current number of
|
||||
* processors online will be chosen.
|
||||
*/
|
||||
v8::Platform* CreateDefaultPlatform(int thread_pool_size = 0);
|
||||
|
||||
|
||||
/**
|
||||
* Pumps the message loop for the given isolate.
|
||||
*
|
||||
* The caller has to make sure that this is called from the right thread.
|
||||
* Returns true if a task was executed, and false otherwise. This call does
|
||||
* not block if no task is pending. The |platform| has to be created using
|
||||
* |CreateDefaultPlatform|.
|
||||
*/
|
||||
bool PumpMessageLoop(v8::Platform* platform, v8::Isolate* isolate);
|
||||
|
||||
|
||||
} // namespace platform
|
||||
} // namespace v8
|
||||
|
||||
namespace evas {
|
||||
EAPI void register_box(v8::Handle<v8::Object> global, v8::Isolate* isolate);
|
||||
}
|
||||
|
||||
static const char script[] =
|
||||
"function assert(condition, message) {\n"
|
||||
" if (!condition) {\n"
|
||||
" print(\"Assertion failed \", message);\n"
|
||||
" throw message || \"Assertion failed\";\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"print(\"teste\");\n"
|
||||
"x = new Box();\n"
|
||||
;
|
||||
|
||||
const char* ToCString(const v8::String::Utf8Value& value) {
|
||||
return *value ? *value : "<string conversion failed>";
|
||||
}
|
||||
|
||||
// Executes a string within the current v8 context.
|
||||
bool ExecuteString(v8::Isolate* isolate,
|
||||
v8::Handle<v8::String> source,
|
||||
v8::Handle<v8::Value> name)
|
||||
{
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
v8::TryCatch try_catch;
|
||||
v8::ScriptOrigin origin(name);
|
||||
v8::Handle<v8::Script> script = v8::Script::Compile(source, &origin);
|
||||
if (script.IsEmpty()) {
|
||||
std::abort();
|
||||
// Print errors that happened during compilation.
|
||||
// if (report_exceptions)
|
||||
// ReportException(isolate, &try_catch);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
v8::Handle<v8::Value> result = script->Run();
|
||||
if (result.IsEmpty()) {
|
||||
std::cout << "Failed with exception thrown" << std::endl;
|
||||
assert(try_catch.HasCaught());
|
||||
std::abort();
|
||||
// Print errors that happened during execution.
|
||||
// if (report_exceptions)
|
||||
// ReportException(isolate, &try_catch);
|
||||
return false;
|
||||
} else {
|
||||
assert(!try_catch.HasCaught());
|
||||
// if (print_result && !result->IsUndefined()) {
|
||||
// // If all went well and the result wasn't undefined then print
|
||||
// // the returned value.
|
||||
// v8::String::Utf8Value str(result);
|
||||
// const char* cstr = ToCString(str);
|
||||
// printf("%s\n", cstr);
|
||||
// }
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Print(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
||||
bool first = true;
|
||||
for (int i = 0; i < args.Length(); i++) {
|
||||
v8::HandleScope handle_scope(args.GetIsolate());
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
printf(" ");
|
||||
}
|
||||
v8::String::Utf8Value str(args[i]);
|
||||
const char* cstr = ToCString(str);
|
||||
printf("%s", cstr);
|
||||
}
|
||||
printf("\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
efl::eina::eina_init eina_init;
|
||||
efl::eo::eo_init eo_init;
|
||||
|
||||
v8::V8::InitializeICU();
|
||||
v8::V8::Initialize();
|
||||
v8::V8::SetFlagsFromCommandLine(&argc, const_cast<char**>(argv), true);
|
||||
|
||||
v8::Isolate* isolate = v8::Isolate::New();
|
||||
|
||||
v8::Isolate::Scope isolate_scope(isolate);
|
||||
|
||||
assert(isolate != 0);
|
||||
|
||||
v8::Handle<v8::Context> context;
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
|
||||
{
|
||||
// Create a template for the global object.
|
||||
v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate);
|
||||
// Bind the global 'print' function to the C++ Print callback.
|
||||
global->Set(v8::String::NewFromUtf8(isolate, "print"),
|
||||
v8::FunctionTemplate::New(isolate, Print));
|
||||
|
||||
context = v8::Context::New(isolate, NULL, global);
|
||||
|
||||
}
|
||||
if (context.IsEmpty()) {
|
||||
fprintf(stderr, "Error creating context\n");
|
||||
}
|
||||
context->Enter();
|
||||
{
|
||||
// Enter the execution environment before evaluating any code.
|
||||
v8::Context::Scope context_scope(context);
|
||||
v8::Local<v8::String> name(v8::String::NewFromUtf8(context->GetIsolate(), "(shell)"));
|
||||
|
||||
evas::register_box(context->Global(), isolate);
|
||||
|
||||
v8::HandleScope handle_scope(context->GetIsolate());
|
||||
ExecuteString(context->GetIsolate(),
|
||||
v8::String::NewFromUtf8(context->GetIsolate(), script),
|
||||
name);
|
||||
}
|
||||
context->Exit();
|
||||
}
|
Loading…
Reference in New Issue