summaryrefslogtreecommitdiff
path: root/src/tests/efl_js
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2014-09-01 15:08:49 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2015-12-23 23:59:40 -0200
commita3db1dddd3ba67c81118f7f2c0bc753dc8aac551 (patch)
tree233ee1be7bfa299bff560207135d20940c4e411f /src/tests/efl_js
parent1a3cb45f1cc7fdf8d481879e6bd7349d9cb0b3fa (diff)
efl-js: JavaScript Eolian binding
To configure efl sources with bindings to use in nodejs add ––with-js=nodejs in configure flags to generate node files $ configure --with-js=nodejs and compile normally with: $ make $ make install To use, you have to require efl: efl = require('efl') The bindings is divided in two parts: generated and manually written. The generation uses the Eolian library for parsing Eo files and generate C++ code that is compiled against V8 interpreter library to create a efl.node file that can be required in a node.js instance. @feature
Diffstat (limited to 'src/tests/efl_js')
-rw-r--r--src/tests/efl_js/benchmark_js_suite.cc7
-rwxr-xr-xsrc/tests/efl_js/benchmark_js_suite.js205
-rw-r--r--src/tests/efl_js/benchmark_object.eo24
-rw-r--r--src/tests/efl_js/benchmark_object_impl.cc110
-rw-r--r--src/tests/efl_js/ecore_js_suite.cc7
-rwxr-xr-xsrc/tests/efl_js/ecore_js_suite.js352
-rw-r--r--src/tests/efl_js/eina_js_containers_suite.cc7
-rwxr-xr-xsrc/tests/efl_js/eina_js_containers_suite.js552
-rw-r--r--src/tests/efl_js/eina_js_suite.cc7
-rwxr-xr-xsrc/tests/efl_js/eina_js_suite.js360
-rw-r--r--src/tests/efl_js/eio_js_suite.cc7
-rwxr-xr-xsrc/tests/efl_js/eio_js_suite.js89
-rw-r--r--src/tests/efl_js/eldbus_js_suite.cc7
-rwxr-xr-xsrc/tests/efl_js/eldbus_js_suite.js114
-rw-r--r--src/tests/efl_js/ethumb_js_suite.cc7
-rwxr-xr-xsrc/tests/efl_js/ethumb_js_suite.js93
-rw-r--r--src/tests/efl_js/suite_runner.hh147
-rw-r--r--src/tests/efl_js/testproj/hello.project9
-rw-r--r--src/tests/efl_js/testproj/hello.txt1
-rw-r--r--src/tests/efl_js/testproj/main.js5
-rw-r--r--src/tests/efl_js/timer.js33
21 files changed, 2143 insertions, 0 deletions
diff --git a/src/tests/efl_js/benchmark_js_suite.cc b/src/tests/efl_js/benchmark_js_suite.cc
new file mode 100644
index 0000000000..c7583f2b3e
--- /dev/null
+++ b/src/tests/efl_js/benchmark_js_suite.cc
@@ -0,0 +1,7 @@
1
2#include "suite_runner.hh"
3
4int main(int, char*[])
5{
6 return run_script(TESTS_SRC_DIR "/ecore_js_suite.js", nullptr);
7}
diff --git a/src/tests/efl_js/benchmark_js_suite.js b/src/tests/efl_js/benchmark_js_suite.js
new file mode 100755
index 0000000000..b3a5d7c86c
--- /dev/null
+++ b/src/tests/efl_js/benchmark_js_suite.js
@@ -0,0 +1,205 @@
1#!/usr/bin/env node
2
3// Preamble
4function assert(condition, message) {
5 if (!condition) {
6 print("Assertion failed ", message);
7 throw new Error(message || "Assertion failed");
8 }
9}
10
11if(typeof process !== 'undefined')
12{
13 console.log('running from nodejs');
14 console.log('path', process.env.NODE_PATH);
15
16 efl = require('efl');
17 assert(efl != null, "could not load efl node module");
18
19 // Setup output aliases
20 print = console.log;
21 print_error = function() {
22 if (process.argv.indexOf("--supress-errors") == -1)
23 console.error.apply(null, arguments);
24 };
25 print_info = function() {
26 if (process.argv.indexOf("--verbose") != -1)
27 console.info.apply(null, arguments);
28 };
29 exit = efl.ecore_mainloop_quit;
30}
31else
32{
33 assert = function(test, message) { if (test !== true) throw message; };
34 print('running from libv8')
35 //FIXME Add levels to v8 tests
36 print_error = print
37 print_info = print
38 exit = function() {}
39}
40
41// Global flag for suite success //
42suite_success = true;
43// Global test summary
44suite_ok = 0;
45suite_fail = []; // Will store the name of the failures
46
47// Basic test function //
48function start_test(test_name, test_func) {
49 print("[ RUN ] eina_js_suite: " + test_name);
50 var test_result = true;
51 try {
52 test_func();
53 } catch (e) {
54 suite_success = false;
55 test_result = false;
56 print_error("Error: ", e, e.stack);
57 }
58 print("[ " + (test_result ? "PASS" : "FAIL") + " ] eina_js_suite: " + test_name);
59 if (test_result)
60 suite_ok += 1;
61 else
62 suite_fail.push(test_name);
63}
64// end Preamble
65if (typeof process != "undefined")
66{
67 benchmark = require('benchmark_object');
68 assert(benchmark != null, "could not load benchmark_object.node");
69 Benchmark_Object = benchmark.BenchmarkObject;
70 benchmark_emptyarg = benchmark.benchmark_emptyarg;
71 benchmark_onearg = benchmark.benchmark_onearg;
72 benchmark_twoarg = benchmark.benchmark_twoarg;
73 benchmark_tenarg = benchmark.benchmark_tenarg;
74 benchmark_onecomplexarg = benchmark.benchmark_onecomplexarg;
75 benchmark_tencomplexarg = benchmark.benchmark_tencomplexarg;
76}
77else
78{
79 Benchmark_Object = suite.Benchmark_Object;
80}
81
82start_test("empty function", function(){
83 object = new Benchmark_Object(null);
84
85 for(i = 0; i != 10; i++)
86 {
87 object.emptyarg();
88 }
89
90 time = process.hrtime();
91 for(i = 0; i != 20000; i++)
92 {
93 object.emptyarg();
94 }
95 time = process.hrtime(time);
96 console.log('JS empty function %d', time[0]*1000000000 + time[1]);
97 benchmark_emptyarg();
98});
99
100start_test("onearg function", function(){
101 object = new Benchmark_Object(null);
102 for(i = 0; i != 10; i++)
103 {
104 object.onearg(1);
105 }
106
107 time = process.hrtime();
108 for(i = 0; i != 20000; i++)
109 {
110 object.onearg(1);
111 }
112 time = process.hrtime(time);
113 console.log('JS onearg function %d', time[0]*1000000000 + time[1]);
114
115 benchmark_onearg();
116});
117
118start_test("twoarg function", function(){
119 object = new Benchmark_Object(null);
120 for(i = 0; i != 10; i++)
121 {
122 object.twoarg(1, 2);
123 }
124
125 time = process.hrtime();
126 for(i = 0; i != 20000; i++)
127 {
128 object.twoarg(1, 2);
129 }
130 time = process.hrtime(time);
131 console.log('JS twoarg function %d', time[0]*1000000000 + time[1]);
132
133 benchmark_twoarg();
134});
135
136start_test("tenarg function", function(){
137 object = new Benchmark_Object(null);
138 for(i = 0; i != 10; i++)
139 {
140 object.tenarg(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
141 }
142
143 time = process.hrtime();
144 for(i = 0; i != 20000; i++)
145 {
146 object.tenarg(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
147 }
148 time = process.hrtime(time);
149 console.log('JS tenarg function %d', time[0]*1000000000 + time[1]);
150 benchmark_tenarg();
151});
152
153start_test("onecomplexarg function", function(){
154 object = new Benchmark_Object(null);
155 list = new efl.List('int')
156 for(i = 0; i != 10; i++)
157 {
158 object.onecomplexarg(list);
159 }
160
161 time = process.hrtime();
162 for(i = 0; i != 20000; i++)
163 {
164 object.onecomplexarg(list);
165 }
166 time = process.hrtime(time);
167 console.log('JS onecomplexarg function %d', time[0]*1000000000 + time[1]);
168 benchmark_onecomplexarg();
169});
170
171start_test("tencomplexarg function", function(){
172 object = new Benchmark_Object(null);
173 list = new efl.List('int')
174 for(i = 0; i != 10; i++)
175 {
176 object.tencomplexarg(list, list, list, list, list, list, list, list, list, list);
177 }
178
179 time = process.hrtime();
180 for(i = 0; i != 20000; i++)
181 {
182 object.tencomplexarg(list, list, list, list, list, list, list, list, list, list);
183 }
184 time = process.hrtime(time);
185 console.log('JS tencomplexarg function %d', time[0]*1000000000 + time[1]);
186 benchmark_tencomplexarg();
187});
188
189// footer
190
191if (!suite_success) {
192 print ("[ Total tests run: %s ]", suite_ok + suite_fail.length);
193 print ("[ Total successful: %s ]", suite_ok);
194 print ("[ Total failures: %s ]", suite_fail.length);
195 print ("[ Tests failed: ]");
196 for (var i = 0; i < suite_fail.length; i++) {
197 print ("[ %s]", suite_fail[i]);
198 };
199 assert(false, "[ Test suite fail ]");
200} else {
201 print ("[ Test execution with success ]");
202 print ("[ Total tests run: %s ]", suite_ok);
203}
204
205exit();
diff --git a/src/tests/efl_js/benchmark_object.eo b/src/tests/efl_js/benchmark_object.eo
new file mode 100644
index 0000000000..34dd142039
--- /dev/null
+++ b/src/tests/efl_js/benchmark_object.eo
@@ -0,0 +1,24 @@
1class Benchmark_Object (Eo.Base)
2{
3 legacy_prefix: null;
4 data: null;
5 methods {
6 emptyarg {
7 }
8 onearg {
9 params { one: int; }
10 }
11 twoarg {
12 params { one: int; two: int; }
13 }
14 tenarg {
15 params { one: int; two: int; three: int; four: int; five: int; six: int; seven: int; eight: int; nine: int; ten: int; }
16 }
17 onecomplexarg {
18 params { one: list<int>*; }
19 }
20 tencomplexarg {
21 params { one: list<int>*; two: list<int>*; three: list<int>*; four: list<int>*; five: list<int>*; six: list<int>*; seven: list<int>*; eight: list<int>*; nine: list<int>*; ten: list<int>*; }
22 }
23 }
24}
diff --git a/src/tests/efl_js/benchmark_object_impl.cc b/src/tests/efl_js/benchmark_object_impl.cc
new file mode 100644
index 0000000000..538c31b2ce
--- /dev/null
+++ b/src/tests/efl_js/benchmark_object_impl.cc
@@ -0,0 +1,110 @@
1#ifdef HAVE_CONFIG_H
2#include <config.h>
3#endif
4
5#include <Eo.h>
6#include <Ecore.h>
7
8#include <stdlib.h>
9
10extern "C" {
11#include "benchmark_object.eo.h"
12
13void _benchmark_object_emptyarg(Eo*, void*)
14{
15}
16void _benchmark_object_onearg(Eo*, void*, int)
17{
18}
19void _benchmark_object_twoarg(Eo*, void*, int, int)
20{
21}
22void _benchmark_object_tenarg(Eo*, void*, int, int, int, int, int, int, int, int, int, int)
23{
24}
25void _benchmark_object_onecomplexarg(Eo*, void*, Eina_List*)
26{
27}
28void _benchmark_object_tencomplexarg(Eo*, void*, Eina_List*, Eina_List*, Eina_List*, Eina_List*, Eina_List*, Eina_List*, Eina_List*, Eina_List*, Eina_List*, Eina_List*)
29{
30}
31
32#include "benchmark_object.eo.c"
33}
34
35#include "benchmark_object.eo.js.cc"
36
37#ifdef HAVE_NODEJS
38namespace {
39using efl::eina::js::compatibility_return_type;
40using efl::eina::js::compatibility_callback_info_type;
41using efl::eina::js::compatibility_return;
42using efl::eina::js::compatibility_new;
43
44#define JS_BENCHMARK_ARGS0(v)
45#define JS_BENCHMARK_ARGS1(v) v
46#define JS_BENCHMARK_ARGS2(v) v,v
47#define JS_BENCHMARK_ARGS10(v) v,v,v,v,v,v,v,v,v,v
48#define JS_BENCHMARK_FUNC(name, number, v) \
49 compatibility_return_type js_benchmark_object_##name##arg(compatibility_callback_info_type) \
50 { \
51 Eina_Counter* counter = eina_counter_new("counter"); \
52 Eo* object = eo_add(BENCHMARK_OBJECT_CLASS, NULL); \
53 Eina_List* l = NULL; \
54 (void)l; \
55 /* Warm */ \
56 for(int i = 0; i != 10; i++) \
57 { \
58 eo_do(object, benchmark_object_##name##arg(JS_BENCHMARK_ARGS##number(v))); \
59 } \
60 /* Real loop */ \
61 eina_counter_start(counter); \
62 for(int i = 0; i != 20000; i++) \
63 { \
64 eo_do(object, benchmark_object_##name##arg(JS_BENCHMARK_ARGS##number(v))); \
65 } \
66 eina_counter_stop(counter, 20000); \
67 fprintf(stderr, "%s", eina_counter_dump(counter)); \
68 eo_del(object); \
69 return compatibility_return(); \
70 }
71
72JS_BENCHMARK_FUNC(empty, 0, 1)
73JS_BENCHMARK_FUNC(one, 1, 1)
74JS_BENCHMARK_FUNC(two, 2, 1)
75JS_BENCHMARK_FUNC(ten, 10, 1)
76JS_BENCHMARK_FUNC(onecomplex, 1, l)
77JS_BENCHMARK_FUNC(tencomplex, 10, l)
78
79
80void benchmark_object_module_init(v8::Handle<v8::Object> exports)
81{
82 fprintf(stderr, "test suite eolian_js_module_init\n"); fflush(stderr);
83 try
84 {
85 eina_init();
86 eo_init();
87 register_benchmark_object(exports, v8::Isolate::GetCurrent());
88#define JS_BENCHMARK_EXPORT(name) \
89 exports->Set(compatibility_new<v8::String>(nullptr, "benchmark_" #name "arg") \
90 , compatibility_new<v8::FunctionTemplate>(nullptr, &js_benchmark_object_##name##arg)->GetFunction());
91 JS_BENCHMARK_EXPORT(empty)
92 JS_BENCHMARK_EXPORT(one)
93 JS_BENCHMARK_EXPORT(two)
94 JS_BENCHMARK_EXPORT(ten)
95 JS_BENCHMARK_EXPORT(onecomplex)
96 JS_BENCHMARK_EXPORT(tencomplex)
97 }
98 catch(...)
99 {
100 std::cerr << "Error" << std::endl;
101 std::abort();
102 }
103}
104
105}
106
107#include <eina_js_node.hh>
108
109NODE_MODULE(benchmark_object, ::benchmark_object_module_init)
110#endif
diff --git a/src/tests/efl_js/ecore_js_suite.cc b/src/tests/efl_js/ecore_js_suite.cc
new file mode 100644
index 0000000000..c7583f2b3e
--- /dev/null
+++ b/src/tests/efl_js/ecore_js_suite.cc
@@ -0,0 +1,7 @@
1
2#include "suite_runner.hh"
3
4int main(int, char*[])
5{
6 return run_script(TESTS_SRC_DIR "/ecore_js_suite.js", nullptr);
7}
diff --git a/src/tests/efl_js/ecore_js_suite.js b/src/tests/efl_js/ecore_js_suite.js
new file mode 100755
index 0000000000..8534304c1b
--- /dev/null
+++ b/src/tests/efl_js/ecore_js_suite.js
@@ -0,0 +1,352 @@
1#!/usr/bin/env node
2
3// Preamble
4function assert(condition, message) {
5 if (!condition) {
6 print("Assertion failed ", message);
7 throw new Error(message || "Assertion failed");
8 }
9}
10
11if(typeof process !== 'undefined')
12{
13 console.log('running from nodejs');
14 console.log('path', process.env.NODE_PATH);
15 console.log("teste1");
16
17 efl = require('efl');
18 assert(efl != null, "could not load efl node module");
19
20 // Setup output aliases
21 print = console.log;
22 print_error = function() {
23 if (process.argv.indexOf("--supress-errors") == -1)
24 console.error.apply(null, arguments);
25 };
26 print_info = function() {
27 if (process.argv.indexOf("--verbose") != -1)
28 console.info.apply(null, arguments);
29 };
30 exit = efl.ecore_mainloop_quit;
31}
32else
33{
34 assert = function(test, message) { if (test !== true) throw message; };
35 print('running from libv8')
36 //FIXME Add levels to v8 tests
37 print_error = print
38 print_info = print
39 exit = function() {}
40}
41
42// Global flag for suite success //
43suite_success = true;
44// Global test summary
45suite_ok = 0;
46suite_fail = []; // Will store the name of the failures
47
48// Basic test function //
49function start_test(test_name, test_func) {
50 print("[ RUN ] ecore_js_suite: " + test_name);
51 var test_result = true;
52 try {
53 test_func();
54 } catch (e) {
55 suite_success = false;
56 test_result = false;
57 print_error("Error: ", e, e.stack);
58 }
59 print("[ " + (test_result ? "PASS" : "FAIL") + " ] ecore_js_suite: " + test_name);
60 if (test_result)
61 suite_ok += 1;
62 else
63 suite_fail.push(test_name);
64}
65// end Preamble
66
67// ecore preamble
68function abs(n) {
69 if (n < 0)
70 return n * -1;
71 return n;
72}
73var TOLERANCE = 0.0001;
74// end ecore preamble
75
76start_test("timers", function () {
77 var p = 2.5;
78 efl.ecore_timer_precision_set(p);
79 assert(abs(efl.ecore_timer_precision_get() - p) < TOLERANCE);
80
81 p = 0.5;
82 efl.ecore_timer_precision_set(p);
83 assert(abs(efl.ecore_timer_precision_get() - p) < TOLERANCE);
84
85 var ncalls = 0;
86
87 captured = false;
88 efl.ecore_timer_add(1, function() {
89 print_info('ecore_timer_add handler');
90 ++ncalls;
91 if (ncalls != 4)
92 return true;
93
94 captured = true;
95 efl.ecore_job_add(efl.ecore_mainloop_quit);
96 return false;
97 });
98
99 efl.ecore_mainloop_begin();
100 assert(captured);
101
102 ncalls = 0;
103 captured = false;
104
105 efl.ecore_timer_loop_add(1, function() {
106 ++ncalls;
107 if (ncalls != 4)
108 return true;
109
110 captured = true;
111 efl.ecore_job_add(efl.ecore_mainloop_quit);
112 return false;
113 });
114
115 efl.ecore_mainloop_begin();
116 assert(captured);
117
118 captured = false;
119
120 var timer = efl.ecore_timer_add(1, function() {
121 captured = true;
122 return false;
123 });
124
125 assert(timer.freeze_get() === false);
126
127 timer.freeze();
128
129 assert(timer.freeze_get() === true);
130
131 timer.thaw();
132
133 assert(timer.freeze_get() === false);
134
135 timer.del();
136
137 efl.ecore_timer_add(2, function() {
138 efl.ecore_job_add(efl.ecore_mainloop_quit);
139 return false;
140 });
141
142 efl.ecore_mainloop_begin();
143 assert(captured === false);
144});
145
146// Ecore event
147start_test("ecore event", function () {
148 var myevent = efl.ecore_event_type_new();
149
150 captured = [0, 0, 0]
151
152 var handler1 = efl.ecore_event_handler_add(myevent, function(event) {
153 assert(efl.ecore_event_current_type_get() === myevent);
154 assert(event === myevent);
155 captured[0] += 1;
156 return efl.ECORE_CALLBACK_PASS_ON;
157 });
158
159 var handler2 = efl.ecore_event_handler_add(myevent, function(event) {
160 assert(efl.ecore_event_current_type_get() === myevent);
161 assert(event === myevent);
162 captured[1] += 1;
163 return efl.ECORE_CALLBACK_DONE;
164 });
165
166 var handler3 = efl.ecore_event_handler_add(myevent, function(event) {
167 assert(efl.ecore_event_current_type_get() === myevent);
168 assert(event === myevent);
169 captured[2] += 1;
170 return efl.ECORE_CALLBACK_DONE;
171 });
172
173 efl.ecore_timer_add(1, function() {
174 efl.ecore_event_add(myevent);
175 assert(captured[0] === 0 && captured[1] === 0 && captured[2] === 0);
176 efl.ecore_timer_add(1, function() {
177 assert(captured[0] === 1 && captured[1] === 1 && captured[2] === 0);
178 handler1.del();
179 efl.ecore_event_add(myevent);
180 efl.ecore_event_add(myevent);
181 efl.ecore_event_add(myevent).del();
182 efl.ecore_timer_add(1, function() {
183 assert(captured[0] === 1 && captured[1] === 3 && captured[2] === 0);
184 efl.ecore_mainloop_quit();
185 });
186 });
187 });
188
189 efl.ecore_mainloop_begin();
190
191 efl.ecore_event_add(myevent);
192 efl.ecore_event_add(myevent);
193 efl.ecore_event_add(myevent);
194
195 var filter = efl.ecore_event_filter_add(function() {
196 return {count: 0};
197 }, function(loop_data, event) {
198 assert(event === myevent);
199 var c = loop_data.count;
200 ++loop_data.count;
201 return c != 0;
202 }, function(loop_data) {});
203
204 efl.ecore_timer_add(1, efl.ecore_mainloop_quit);
205 efl.ecore_mainloop_begin();
206 assert(captured[1] === 5);
207 filter.del();
208
209 efl.ecore_event_add(myevent);
210 efl.ecore_event_add(myevent);
211 efl.ecore_event_add(myevent);
212
213 efl.ecore_timer_add(1, efl.ecore_mainloop_quit);
214 efl.ecore_mainloop_begin();
215 assert(captured[1] === 8);
216
217 handler2.del();
218 handler3.del();
219});
220
221 // Ecore job
222start_test("ecore jobs", function () {
223 captured = false;
224
225 efl.ecore_job_add(function() {
226 captured = true;
227 efl.ecore_mainloop_quit();
228 });
229
230 assert(captured === false);
231 efl.ecore_mainloop_begin();
232 assert(captured === true);
233
234 captured = false;
235 var job = efl.ecore_job_add(function() {
236 captured = true;
237 });
238 efl.ecore_job_add(efl.ecore_mainloop_quit);
239 job.del();
240 efl.ecore_mainloop_begin();
241 assert(captured === false);
242});
243
244start_test("ecore idle", function () {
245 // Ecore idle
246 var counter = 1;
247 captured = [0, 0, 0, 0, 0];
248
249 efl.ecore_idler_add(function() {
250 print_info('ecore idle handler 1');
251 captured[0] = counter;
252 counter += 1;
253 efl.ecore_job_add(function() { print_info('ecore job handler 1'); });
254 return efl.ECORE_CALLBACK_DONE;
255 });
256
257 print_info('ecore idle 1');
258
259 efl.ecore_idle_enterer_add(function() {
260 print_info('ecore idle handler 2');
261 captured[1] = counter;
262 counter += 1;
263 return efl.ECORE_CALLBACK_DONE;
264 });
265
266 print_info('ecore idle 2');
267
268 efl.ecore_idle_enterer_add(function() {
269 print_info('ecore idle handler 3');
270 captured[2] = counter;
271 counter += 1;
272 return efl.ECORE_CALLBACK_DONE;
273 });
274
275 print_info('ecore idle 3');
276
277 efl.ecore_idle_enterer_before_add(function() {
278 print_info('ecore idle handler 4');
279 captured[3] = counter;
280 counter += 1;
281 return efl.ECORE_CALLBACK_DONE;
282 });
283
284 print_info('ecore idle 4');
285
286 efl.ecore_idle_exiter_add(function() {
287 print_info('ecore idle handler 5');
288 captured[4] = counter;
289 counter += 1;
290 efl.ecore_mainloop_quit();
291 return efl.ECORE_CALLBACK_DONE;
292 });
293
294 print_info('ecore idle 5');
295
296 efl.ecore_mainloop_begin();
297
298 print_info('ecore idle 6');
299
300 assert(captured[0] === 4, "ecore_idler_add test");
301 assert(captured[1] === 2, "ecore_idle_enterer_add test");
302 assert(captured[2] === 3, "ecore_idle_enterer_add test two");
303 assert(captured[3] === 1, "ecore_idle_enterer_before_add test");
304 assert(captured[4] === 5, "ecore_idle_exiter_add test");
305});
306
307// Ecore animator
308start_test("ecore animator", function () {
309 efl.ecore_animator_frametime_set(1);
310 assert(efl.ecore_animator_frametime_get() === 1);
311 efl.ecore_animator_frametime_set(1 / 50);
312 assert(efl.ecore_animator_frametime_get() === (1 / 50));
313
314 assert(efl.ecore_animator_pos_map(0.5, efl.ECORE_POS_MAP_LINEAR, 0, 0)
315 === 0.5);
316
317 efl.ecore_animator_source_set(efl.ECORE_ANIMATOR_SOURCE_CUSTOM);
318});
319
320// Ecore poller
321start_test("ecore poller", function () {
322 efl.ecore_poller_poll_interval_set(efl.ECORE_POLLER_CORE, 42);
323 assert(efl.ecore_poller_poll_interval_get(efl.ECORE_POLLER_CORE) === 42);
324 efl.ecore_poller_poll_interval_set(efl.ECORE_POLLER_CORE, 2);
325 assert(efl.ecore_poller_poll_interval_get(efl.ECORE_POLLER_CORE) === 2);
326});
327
328start_test("ecore throttle", function () {
329 // Ecore throttle
330
331 efl.ecore_throttle_adjust(3);
332 assert(efl.ecore_throttle_get() === 3);
333 efl.ecore_throttle_adjust(-3);
334 assert(efl.ecore_throttle_get() === 0);
335});
336
337// footer
338if (!suite_success) {
339 print ("[ Total tests run: %s ]", suite_ok + suite_fail.length);
340 print ("[ Total successful: %s ]", suite_ok);
341 print ("[ Total failures: %s ]", suite_fail.length);
342 print ("[ Tests failed: ]");
343 for (var i = 0; i < suite_fail.length; i++) {
344 print ("[ %s]", suite_fail[i]);
345 };
346 assert(false, "[ Test suite fail ]");
347} else {
348 print ("[ Test execution with success ]");
349 print ("[ Total tests run: %s ]", suite_ok);
350}
351
352exit();
diff --git a/src/tests/efl_js/eina_js_containers_suite.cc b/src/tests/efl_js/eina_js_containers_suite.cc
new file mode 100644
index 0000000000..5455b9438a
--- /dev/null
+++ b/src/tests/efl_js/eina_js_containers_suite.cc
@@ -0,0 +1,7 @@
1
2#include "suite_runner.hh"
3
4int main(int, char*[])
5{
6 return run_script(TESTS_SRC_DIR "/eina_js_containers_suite.js", nullptr);
7}
diff --git a/src/tests/efl_js/eina_js_containers_suite.js b/src/tests/efl_js/eina_js_containers_suite.js
new file mode 100755
index 0000000000..f4f6bf314e
--- /dev/null
+++ b/src/tests/efl_js/eina_js_containers_suite.js
@@ -0,0 +1,552 @@
1#!/usr/bin/env node
2
3// Preamble
4function assert(condition, message) {
5 if (!condition) {
6 print("Assertion failed ", message);
7 throw new Error(message || "Assertion failed");
8 }
9}
10
11if(typeof process !== 'undefined')
12{
13 console.log('running from nodejs');
14 console.log('path', process.env.NODE_PATH);
15 console.log("teste1");
16
17 efl = require('efl');
18 assert(efl != null, "could not load efl node module");
19
20 // Setup output aliases
21 print = console.log;
22 print_error = function() {
23 if (process.argv.indexOf("--supress-errors") == -1)
24 console.error.apply(null, arguments);
25 };
26 print_info = function() {
27 if (process.argv.indexOf("--verbose") != -1)
28 console.info.apply(null, arguments);
29 };
30 exit = efl.ecore_mainloop_quit;
31}
32else
33{
34 assert = function(test, message) { if (test !== true) throw message; };
35 print('running from libv8')
36 //FIXME Add levels to v8 tests
37 print_error = print
38 print_info = print
39 exit = function() {}
40}
41
42// Global flag for suite success //
43suite_success = true;
44// Global test summary
45suite_ok = 0;
46suite_fail = []; // Will store the name of the failures
47
48// Basic test function //
49function start_test(test_name, test_func) {
50 print("[ RUN ] eina_js_suite: " + test_name);
51 var test_result = true;
52 try {
53 test_func();
54 } catch (e) {
55 suite_success = false;
56 test_result = false;
57 print_error("Error: ", e, e.stack);
58 }
59 print("[ " + (test_result ? "PASS" : "FAIL") + " ] eina_js_suite: " + test_name);
60 if (test_result)
61 suite_ok += 1;
62 else
63 suite_fail.push(test_name);
64}
65// end Preamble
66
67start_test("container_test default list should have size zero", function(){
68 var container = new efl.List;
69 assert (container.length == 0);
70});
71
72start_test("container test default Array should have size zero", function(){
73 var container = new efl.Array;
74 assert (container.length == 0);
75});
76
77start_test("container_test empty list access should return undefined", function(){
78 var empty_l = new efl.List;
79 assert (typeof empty_l[0] === "undefined");
80 assert (typeof empty_l[1] === "undefined");
81});
82
83start_test("container_test empty Array access should return undefined", function(){
84 var empty_l = new efl.Array;
85 assert (typeof empty_l[0] === "undefined");
86 assert (typeof empty_l[1] === "undefined");
87});
88
89start_test("container_test empty list indexOf should return -1", function(){
90 var empty_l = new efl.List;
91 assert(empty_l.indexOf(0) == -1);
92 assert(empty_l.indexOf(42) == -1);
93});
94
95start_test("container_test empty Array indexOf should return -1", function(){
96 var empty_l = new efl.Array;
97 assert(empty_l.indexOf(0) == -1);
98 assert(empty_l.indexOf(42) == -1);
99});
100
101start_test("container_test List indexOf should not break with wrong type", function(){
102 container_indexof_wrong_type(efl.List);
103});
104
105start_test("container_test Array indexOf should not break with wrong type", function(){
106 container_indexof_wrong_type(efl.Array);
107});
108
109function container_indexof_wrong_type(T) {
110 var x = new T("int");
111 var raised = false;
112 try {
113 x.indexOf("float")
114 } catch (err) {
115 raised = true;
116 }
117
118 assert(!raised, "container index of should not break with wrong types");
119}
120
121start_test("container_test list[0] = x on empty list", function(){
122 var empty_l = new efl.List;
123 assert(empty_l.length == 0);
124 empty_l[0] = 42;
125 assert(empty_l.length == 1);
126 assert(empty_l[0] == 42);
127});
128
129start_test("container_test array[0] = x on empty Array", function(){
130 var empty_l = new efl.Array;
131 assert(empty_l.length == 0);
132 empty_l[0] = 42;
133 assert(empty_l.length == 1);
134 assert(empty_l[0] == 42);
135});
136
137start_test("container_test out of bounds x[i] setter should resize list", function(){
138 container_out_of_bound_setter(efl.List);
139});
140
141start_test("container_test out of bounds x[i] setter should resize Array", function(){
142 container_out_of_bound_setter(efl.Array);
143});
144
145function container_out_of_bound_setter(T1) {
146 var empty_l = new T1;
147 assert(empty_l.length == 0);
148 empty_l[9] = 1;
149 assert(empty_l.length == 10);
150 for (var i = 0; i < 9; i++) {
151 assert(empty_l[i] == 0);
152 };
153 assert(empty_l[9] == 1);
154}
155
156start_test("container_test push items should increase list length", function(){
157 container_push_length(efl.List);
158});
159
160start_test("container_test push items should increase Array length", function(){
161 container_push_length(efl.Array);
162});
163
164function container_push_length(T1) {
165 var l1 = new T1;
166 print_info("l1 ", l1.toString());
167 l1.push(1);
168 assert (l1.length == 1);
169 l1.push(2);
170 assert (l1.length == 2);
171 l1.push(3);
172 assert (l1.length == 3);
173}
174
175start_test("container_test list simple push and access valid items", function(){
176 container_push_access_valid(efl.List);
177});
178
179start_test("container_test Array simple push and access valid items", function(){
180 container_push_access_valid(efl.Array);
181});
182
183function container_push_access_valid(T1) {
184 var l1 = new T1;
185 l1.push(1);
186 l1.push(2);
187 assert (l1[0] == 1);
188 assert (l1[1] == 2);
189}
190
191start_test("container_test list simple push and access items out of bounds", function(){
192 container_push_out_of_bounds(efl.List);
193});
194
195start_test("container_test Array simple push and access items out of bounds", function(){
196 container_push_out_of_bounds(efl.Array);
197});
198
199function container_push_out_of_bounds(T1) {
200 var l1 = new T1;
201 l1.push(1);
202 l1.push(2);
203 assert (typeof l1[3] === "undefined");
204 assert (typeof l1[42] === "undefined");
205}
206
207start_test("container_test list push and pop", function() {
208 container_push_pop(efl.List);
209});
210
211start_test("container_test Array push and pop", function() {
212 container_push_pop(efl.Array);
213});
214
215function container_push_pop(T1) {
216 var l1 = new T1;
217
218 assert(typeof l1.pop() === "undefined", "pop on empty container should return undefined");
219
220 l1.push(1);
221 l1.push(2);
222 assert(l1.length == 2);
223 assert(l1.pop() == 2, "Pop should return last element");
224 assert(l1.length == 1, "Pop should decrease list length");
225 assert(l1.pop() == 1, "Pop should return last element even if it's the only element");
226 assert(l1.length == 0, "Pop on single element list should leave it empty");
227}
228
229start_test("container_test list simple push and indexOf valid elements", function(){
230 container_push_indexof_valid(efl.List)
231});
232
233start_test("container_test Array simple push and indexOf valid elements", function(){
234 container_push_indexof_valid(efl.Array)
235});
236
237function container_push_indexof_valid(T1) {
238 var l1 = new T1;
239 l1.push(1);
240 l1.push(2);
241 assert(l1.indexOf(1) == 0);
242 assert(l1.indexOf(2) == 1);
243}
244
245start_test("container_test list simple push and indexOf elements out of bounds", function(){
246 container_push_indexof_out_of_bounds(efl.List);
247});
248
249start_test("container_test list simple push and indexOf elements out of bounds", function(){
250 container_push_indexof_out_of_bounds(efl.Array);
251});
252
253function container_push_indexof_out_of_bounds(T1) {
254 var l1 = new T1;
255 l1.push(1);
256 l1.push(2);
257 assert(l1.indexOf(3) == -1);
258 assert(l1.indexOf(44) == -1);
259}
260
261start_test("container_test list concat filled + empty shouldn't change length", function(){
262 container_filled_concat_empty_length(efl.List);
263});
264
265start_test("container_test array concat filled + empty shouldn't change length", function(){
266 container_filled_concat_empty_length(efl.Array);
267});
268
269function container_filled_concat_empty_length(T1) {
270 var empty_l = new T1;
271 var l1 = new T1;
272 l1.push(1);
273 l1.push(2);
274 l1.push(3);
275 var cle = l1.concat(empty_l);
276 assert (cle.length == 3);
277}
278
279start_test("container_test list concat empty + filled shouldn't change length", function(){
280 container_empty_concat_filled_length(efl.List);
281});
282
283start_test("container_test array concat empty + filled shouldn't change length", function(){
284 container_empty_concat_filled_length(efl.Array);
285});
286
287function container_empty_concat_filled_length(T1) {
288 var empty_l = new T1;
289 var l1 = new T1;
290 l1.push(1);
291 l1.push(2);
292 l1.push(3);
293 var cel = empty_l.concat(l1);
294 assert (cel.length == 3);
295}
296
297start_test("container_test concat two valid lists", function(){
298 container_concat_two_valid_containers(efl.List, efl.List);
299});
300
301start_test("container_test concat two valid arrays", function(){
302 container_concat_two_valid_containers(efl.Array, efl.Array);
303});
304
305function container_concat_two_valid_containers(T1, T2) {
306 l1 = new T1;
307 l1.push(1);
308 l1.push(2);
309 l1.push(3);
310 l2 = new T2;
311 l2.push(1);
312 l2.push(2);
313 l2.push(3);
314 var c = l1.concat(l2);
315
316 assert (c.length == (l1.length + l2.length));
317 assert (c[0] == l1[0]);
318 assert (c[1] == l1[1]);
319 assert (c[2] == l1[2]);
320 assert (c[3] == l2[0]);
321 assert (c[4] == l2[1]);
322 assert (c[5] == l2[2]);
323 assert (c.indexOf(c[0]) == 0);
324 assert (c.indexOf(c[1]) == 1);
325 assert (c.indexOf(c[2]) == 2);
326 assert (c.indexOf(c[3]) == 0);
327 assert (c.indexOf(c[4]) == 1);
328 assert (c.indexOf(c[5]) == 2);
329 assert (c.lastIndexOf(c[0]) == 3);
330 assert (c.lastIndexOf(c[1]) == 4);
331 assert (c.lastIndexOf(c[2]) == 5);
332 assert (c.lastIndexOf(c[3]) == 3);
333 assert (c.lastIndexOf(c[4]) == 4);
334 assert (c.lastIndexOf(c[5]) == 5);
335}
336
337start_test("container_test concat different types", function() {
338 container_concat_diff_types(efl.Array, efl.List);
339 container_concat_diff_types(efl.List, efl.Array);
340});
341
342function container_concat_diff_types(T1, T2) {
343 var l1 = new T1;
344 var l2 = new T2;
345 var raised = false;
346
347 try {
348 l1.concat(l2);
349 assert(false, "Should raise exception after concatenating two different types.")
350 } catch (err) {
351 raised = true;
352 assert(err.name == "TypeError", "Exception should be TypeError.");
353 }
354
355 assert(raised, "Exception was not raised after concatenating different types.");
356}
357
358start_test("container_test toString list", function(){
359 container_to_string(efl.List);
360});
361
362start_test("container_test toString array", function(){
363 container_to_string(efl.Array);
364});
365
366function container_to_string(T) {
367 var x = new T("int");
368
369 assert("" == x.toString(), "toString empty container");
370
371 x.push(1);
372 assert("1" == x.toString(), "toString single element");
373
374 x.push(2);
375 assert("1,2" == x.toString(), "toString two elements");
376
377 x.push(100);
378 assert("1,2,100" == x.toString(), "toString three elements");
379}
380
381start_test("container_test join list", function(){
382 container_join(efl.List);
383});
384
385start_test("container_test join Array", function(){
386 container_join(efl.Array);
387});
388
389function container_join(T) {
390 var x = new T("int");
391 var ref = new Array;
392
393 assert(ref.join() == x.join(), "default join on empty containers");
394 assert(ref.join(':') == x.join(':'), "arg join on empty containers");
395
396 x.push(42);
397 ref.push(42);
398
399 assert(ref.join() == x.join(), "default join on single-element containers");
400 assert(ref.join(':') == x.join(':'), "arg join on single-element containers");
401
402 x.push(314);
403 ref.push(314);
404
405 assert(ref.join() == x.join(), "default join on multiple-element containers");
406 assert(ref.join(':') == x.join(':'), "arg join on multiple-element containers");
407}
408
409start_test("container_test join wrong arguments", function(){
410
411});
412
413function container_join_wrong_type(T1, T2) {
414 var l1 = new T1("int");
415 var raised = false;
416
417 try {
418 l1.join({});
419 assert(false, "Should raise exception after trying to join with wrong argument type.");
420 } catch (err) {
421 raised = true;
422 assert(err.name == "TypeError", "Exception should be TypeError.");
423 }
424
425 assert(raised, "Exception was not raised after join with wrong argument type.");
426}
427
428start_test("container_test slice list simple", function () {
429 container_slice_simple(efl.List);
430});
431
432start_test("container_test slice Array simple", function () {
433 container_slice_simple(efl.Array);
434});
435
436function container_slice_simple(T1) {
437 l1 = new T1;
438 l1.push(1);
439 l1.push(2);
440 l1.push(3);
441
442 var s1 = l1.slice(1, 3);
443 assert (s1.length == 2);
444 assert (s1[0] == l1[1]);
445 assert (s1[1] == l1[2]);
446}
447
448start_test("container_test slice list single argument", function() {
449 container_slice_single_arg(efl.List);
450});
451
452start_test("container_test slice Array single argument", function() {
453 container_slice_single_arg(efl.Array);
454});
455
456function container_slice_single_arg(T1) {
457 l1 = new T1;
458 l1.push(0);
459 l1.push(1);
460 l1.push(2);
461 l1.push(3);
462 l1.push(4);
463
464 var s1 = l1.slice(1);
465 assert(s1.length == (l1.length - 1));
466 assert(s1[0] == l1[1]);
467 assert(s1[1] == l1[2]);
468 assert(s1[2] == l1[3]);
469 assert(s1[3] == l1[4]);
470}
471
472start_test("container_test slice list no arguments", function() {
473 container_slice_no_args(efl.List);
474});
475
476start_test("container_test slice Array no arguments", function() {
477 container_slice_no_args(efl.Array);
478});
479
480function container_slice_no_args(T1) {
481 l1 = new T1;
482 l1.push(0);
483 l1.push(1);
484 l1.push(2);
485 l1.push(3);
486 l1.push(4);
487
488 var s1 = l1.slice();
489 assert(s1.length == l1.length);
490 assert(s1[0] == l1[0]);
491 assert(s1[1] == l1[1]);
492 assert(s1[2] == l1[2]);
493 assert(s1[3] == l1[3]);
494 assert(s1[4] == l1[4]);
495}
496
497start_test("container test list of strings", function(){
498 container_test_generic(new efl.List("string"), ["The", "quick", "brown", "fox"]);
499});
500
501start_test("container test array of strings", function(){
502 container_test_generic(new efl.Array("string"), ["The", "quick", "brown", "fox"]);
503});
504
505start_test("container test list of floats", function(){
506 container_test_generic(new efl.List("float"), [3.42, 3.14, 1.22, 0.0]);
507});
508
509start_test("container test Array of floats", function(){
510 container_test_generic(new efl.Array("float"), [3.42, 3.14, 1.22, 0.0]);
511});
512
513start_test("container test list of bools", function(){
514 container_test_generic(new efl.List("bool"), [true, false, false, false]);
515});
516
517start_test("container test array of bools", function(){
518 container_test_generic(new efl.Array("bool"), [true, false, false, false]);
519});
520
521function container_test_generic(list, js_ref_list) {
522 assert(list.length == 0);
523 list.push(js_ref_list[0]);
524 list.push(js_ref_list[1]);
525 list.push(js_ref_list[2]);
526 list.push(js_ref_list[3]);
527
528 assert(list.indexOf(js_ref_list[0]) == 0, "First pushed element has index 0");
529 assert(list.indexOf(js_ref_list[1]) == 1, "Second pushed element has index 1");
530 assert(list.lastIndexOf(js_ref_list[0]) == 0, "First element is unique, so its lastIndexOf should be 0");
531
532 assert(list.toString() == js_ref_list.toString(), "toString must be equal to JS.")
533 assert(list.pop() == js_ref_list[3], "Pop should return the last list element");
534}
535
536// footer
537
538if (!suite_success) {
539 print ("[ Total tests run: %s ]", suite_ok + suite_fail.length);
540 print ("[ Total successful: %s ]", suite_ok);
541 print ("[ Total failures: %s ]", suite_fail.length);
542 print ("[ Tests failed: ]");
543 for (var i = 0; i < suite_fail.length; i++) {
544 print ("[ %s]", suite_fail[i]);
545 };
546 assert(false, "[ Test suite fail ]");
547} else {
548 print ("[ Test execution with success ]");
549 print ("[ Total tests run: %s ]", suite_ok);
550}
551
552exit();
diff --git a/src/tests/efl_js/eina_js_suite.cc b/src/tests/efl_js/eina_js_suite.cc
new file mode 100644
index 0000000000..68345b5068
--- /dev/null
+++ b/src/tests/efl_js/eina_js_suite.cc
@@ -0,0 +1,7 @@
1
2#include "suite_runner.hh"
3
4int main(int, char*[])
5{
6 return run_script(TESTS_SRC_DIR "/eina_js_suite.js", nullptr);
7}
diff --git a/src/tests/efl_js/eina_js_suite.js b/src/tests/efl_js/eina_js_suite.js
new file mode 100755
index 0000000000..811e1f6756
--- /dev/null
+++ b/src/tests/efl_js/eina_js_suite.js
@@ -0,0 +1,360 @@
1#!/usr/bin/env node
2
3// Preamble
4function assert(condition, message) {
5 if (!condition) {
6 print("Assertion failed ", message);
7 throw new Error(message || "Assertion failed");
8 }
9}
10
11if(typeof process !== 'undefined')
12{
13 console.log('running from nodejs');
14 console.log('path', process.env.NODE_PATH);
15 console.log("teste1");
16
17 efl = require('efl');
18 assert(efl != null, "could not load efl node module");
19
20 // Setup output aliases
21 print = console.log;
22 print_error = function() {
23 if (process.argv.indexOf("--supress-errors") == -1)
24 console.error.apply(null, arguments);
25 };
26 print_info = function() {
27 if (process.argv.indexOf("--verbose") != -1)
28 console.info.apply(null, arguments);
29 };
30 exit = efl.ecore_mainloop_quit;
31}
32else
33{
34 assert = function(test, message) { if (test !== true) throw message; };
35 print('running from libv8')
36 //FIXME Add levels to v8 tests
37 print_error = print
38 print_info = print
39 exit = function() {}
40}
41
42// Global flag for suite success //
43suite_success = true;
44// Global test summary
45suite_ok = 0;
46suite_fail = []; // Will store the name of the failures
47
48// Basic test function //
49function start_test(test_name, test_func) {
50 print("[ RUN ] eina_js_suite: " + test_name);
51 var test_result = true;
52 try {
53 test_func();
54 } catch (e) {
55 suite_success = false;
56 test_result = false;
57 print_error("Error: ", e, e.stack);
58 }
59 print("[ " + (test_result ? "PASS" : "FAIL") + " ] eina_js_suite: " + test_name);
60 if (test_result)
61 suite_ok += 1;
62 else
63 suite_fail.push(test_name);
64}
65
66function array_equal(a, b) {
67 if (a === b) return true;
68 if (a == null || b == null) return false;
69 if (a.length != b.length) return false;
70
71 for (var i = 0; i < a.length; ++i) {
72 if (a[i] !== b[i]
73 && (Object.prototype.toString.call(a[i]) === '[object Array]'
74 && Object.prototype.toString.call(b[i] === '[object Array]')
75 && !array_equal(a[i], b[i])))
76 return false;
77 }
78 return true;
79}
80// end Preamble
81
82// eina Preamble
83// Functions to get the line in NodeJS and V8
84Object.defineProperty(global, '__stack', {
85get: function() {
86 var orig = Error.prepareStackTrace;
87 Error.prepareStackTrace = function(_, stack) {
88 return stack;
89 };
90 var err = new Error;
91 Error.captureStackTrace(err, arguments.callee);
92 var stack = err.stack;
93 Error.prepareStackTrace = orig;
94 return stack;
95 }
96});
97
98Object.defineProperty(global, '__line', {
99get: function() {
100 return __stack[1].getLineNumber();
101 }
102});
103
104Object.defineProperty(global, '__function', {
105get: function() {
106 return __stack[1].getFunctionName();
107 }
108});
109// end eina Preamble
110
111// value tests
112start_test("value tests int get test", function () {
113 print_info("x");
114
115 var my_value = new efl.value(1);
116 print_info("x");
117 var wrapped = my_value.get();
118 print_info("x");
119 assert(typeof(wrapped) === 'number', 'typeof wrapped is not number');
120 print_info("x");
121 assert(wrapped === 1, 'wrapped should be 1');
122 print_info("x");
123});
124
125start_test("value tests int set test", function(){
126 var my_value = new efl.value(1);
127 var wrapped = my_value.get();
128 my_value.set(2);
129 print_info("x");
130 assert(wrapped === 1, 'Setting a value should not change a previous wrapped result');
131 print_info("x");
132 wrapped = my_value.get();
133 print_info("x");
134 assert(typeof(wrapped) === 'number', 'wrapped value after setting to number should be a number');
135 print_info("x");
136 assert(wrapped === 2, 'wrapped is different from value set');
137 print_info("x");
138});
139
140start_test("value tests int set to bool", function(){
141 var my_value = new efl.value(2);
142 var wrapped = my_value.get();
143 my_value.set(true);
144 print_info("x");
145 assert(wrapped === 2, 'Setting a value should not change a previous wrapped result');
146 print_info("x");
147 wrapped = my_value.get();
148 print_info("x");
149 // boolean is represented as integer in the efl::eina::value layer
150 print_info("x");
151 assert(typeof(wrapped) === 'number', 'value.get from bool value should be a number');
152 print_info("x");
153 assert(wrapped === 1, 'value.get from a true boolean should be 1');
154 print_info("x");
155});
156
157start_test("value tests set value to complex object", function() {
158 var my_value = new efl.value(1);
159 print_info("x");
160 var captured = false;
161 print_info("x");
162 try {
163 print_info("x");
164 my_value.set({type: 'complex object'});
165 print_info("x");
166 } catch(e) {
167 print_info("x");
168 assert(e.code === 'std::bad_cast', 'Trying to set a complex object to a value should raise std::bad_cast');
169 print_info("x");
170 captured = true;
171 print_info("x");
172 }
173 print_info("x");
174 assert(captured === true, 'Trying to set a complex object should raise an exception');
175 print_info("x");
176});
177
178start_test("value tests create value from complex object", function() {
179 print_info("x");
180 var captured = false;
181 print_info("x");
182 try {
183 print_info("x");
184 my_value = new efl.value({type: 'complex object'});
185 print_info("x");
186 } catch(e) {
187 print_info("e.code ", e.code, ' ', typeof e);
188 assert(e.code === 'std::bad_cast', 'Trying to create a value from a complex object should raise std::bad_cast');
189 print_info("x");
190 captured = true;
191 print_info("x");
192 }
193 assert(captured === true, 'Trying to create a value from a complex object should raise an exception');
194});
195// log
196
197start_test("log tests basic", function () {
198 function f1(){ efl.logPrint(efl.LOG_DOMAIN_GLOBAL, efl.LOG_LEVEL_DBG, 'I changed again'); }; f1();
199 efl.logPrint(efl.LOG_DOMAIN_GLOBAL, efl.LOG_LEVEL_CRITICAL, 'Cool to Hate');
200 function f2(){ efl.logPrint(efl.LOG_DOMAIN_GLOBAL, efl.LOG_LEVEL_WARN, 'One Fine Day'); }; f2();
201 function f3(){ efl.logPrint(efl.mydomain, efl.LOG_LEVEL_INFO, 'Never Gonna Find Me'); }; f3();
202});
203
204start_test("log tests domains", function() {
205 var mydomain2 = efl.registerLogDomain('mydomain2', '');
206 efl.setLogDomainRegisteredLevel(mydomain2, efl.LOG_LEVEL_DBG);
207 assert(efl.getLogDomainRegisteredLevel(mydomain2) === efl.LOG_LEVEL_DBG, 'Level set is not LEVEL_DBG');
208 efl.logPrint(mydomain2, efl.LOG_LEVEL_ERR, "The Kids Aren't Alright");
209
210 efl.unregisterLogDomain(mydomain2);
211});
212
213start_test("log tests properties", function() {
214 efl.setLogColorDisable(true);
215 assert(efl.getLogColorDisable() === true, 'getLogColorDisable is false after setting to true');
216 efl.setLogColorDisable(false);
217 assert(efl.getLogColorDisable() === false, 'getLogColorDisable is true after setting to false');
218
219 efl.setLogFileDisable(true);
220 assert(efl.getLogFileDisable() === true, 'getLogFileDisable is false after setting to true');
221 efl.setLogFileDisable(false);
222 assert(efl.getLogFileDisable() === false, 'getLogFileDisable is true after setting to false');
223
224 efl.setLogFunctionDisable(true);
225 assert(efl.getLogFunctionDisable() === true, 'getLogFunctionDisable is false after setting to true');
226 efl.setLogFunctionDisable(false);
227 assert(efl.getLogFunctionDisable() === false, 'getLogFunctionDisable is true after setting to false');
228
229 efl.setLogAbortOnCritical(true);
230 assert(efl.getLogAbortOnCritical() === true, 'getLogAbortOnCritical is false after setting to true');
231 efl.setLogAbortOnCritical(false);
232 assert(efl.getLogAbortOnCritical() === false, 'getLogAbortOnCritical is true after setting to false');
233
234});
235
236start_test("log tests print callback", function() {
237 var entered = false;
238 var line_number = 0;
239
240 // Setup
241 var mydomain = efl.registerLogDomain('mydomain', 'deadbeef');
242 efl.setLogDomainRegisteredLevel(mydomain, efl.LOG_LEVEL_WARN);
243
244 efl.setLogPrintCb(function(domain, color, level, file, func, line, msg) {
245 assert(domain === 'mydomain', 'log print callback incorrect domain');
246 assert(color === 'deadbeef', 'log print callback incorrect color');
247 assert(level === efl.LOG_LEVEL_WARN, 'log print callback incorrect level');
248 assert(function(){ var components = file.split('/'); return components[components.length - 1]; }() === 'eina_js_suite.js'
249 , 'log print callback incorrect file');
250 assert(func === 'f4', 'log print callback incorrect func');
251 assert(line === line_number, 'log print callback incorrect line');
252 assert(msg === 'What Happened To You', 'log print callback incorrect message');
253 entered = true;
254 });
255
256 function f4() {
257 line_number = __line + 1;
258 efl.logPrint(mydomain, efl.LOG_LEVEL_WARN, 'What Happened To You');
259 };
260 f4();
261 assert(entered === true, 'log_print callback was not called');
262
263});
264
265start_test("log tests levels", function(){
266 efl.setLogLevel(efl.LOG_LEVEL_DBG);
267 assert(efl.getLogLevel() === efl.LOG_LEVEL_DBG, 'log level was not DBG');
268 assert(efl.checkLogLevel(efl.LOG_LEVEL_INFO) === true, 'log level INFO was not accepted when DBG level set');
269 efl.setLogLevel(efl.LOG_LEVEL_CRITICAL);
270 assert(efl.getLogLevel() === efl.LOG_LEVEL_CRITICAL, 'log level was not CRITICAL');
271 assert(efl.checkLogLevel(efl.LOG_LEVEL_INFO) === false, 'log level INFO was accepted when CRITICAL level set');
272
273 assert(efl.getLogAbortOnCritical() === false, 'log abort on critical get should not be true');
274 efl.setLogAbortOnCritical(true);
275 assert(efl.getLogAbortOnCritical() === true, 'log abort on critical should be true');
276
277 efl.setLogAbortOnCriticalLevel(efl.LOG_LEVEL_CRITICAL);
278 assert(efl.getLogAbortOnCriticalLevel() == efl.LOG_LEVEL_CRITICAL, 'log critical trigger level is not CRITICAL');
279 efl.setLogAbortOnCriticalLevel(efl.LOG_LEVEL_ERR);
280 assert(efl.getLogAbortOnCriticalLevel() == efl.LOG_LEVEL_ERR, 'log critical trigger level is not ERR');
281
282 efl.setLogDomainLevel('mydomain', efl.LOG_LEVEL_WARN);
283 assert(efl.getLogDomainLevel('mydomain') === efl.LOG_LEVEL_WARN, 'log level for mydomain is not WARN');
284 efl.setLogDomainLevel('mydomain', efl.LOG_LEVEL_INFO);
285 assert(efl.getLogDomainLevel('mydomain') === efl.LOG_LEVEL_INFO, 'log level for mydomain is not INFO');
286
287 assert(typeof(efl.LOG_STATE_START) === 'number', 'type of LOG_STATE_START is not number');
288 assert(typeof(efl.LOG_STATE_STOP) === 'number', 'type of LOG_STATE_STOP is not number');
289 assert(typeof(efl.logTiming) === 'function', 'type of log_timing is not function');
290});
291
292start_test("log helper functions", function(){
293 var messages = [
294 [efl.LOG_LEVEL_CRITICAL, "critical"],
295 [efl.LOG_LEVEL_ERR, "error"],
296 [efl.LOG_LEVEL_WARN, "warning"],
297 [efl.LOG_LEVEL_INFO, "info"],
298 [efl.LOG_LEVEL_DBG, "debug"]
299 ];
300 var caught_messages = [];
301
302 efl.setLogLevel(efl.LOG_LEVEL_WARN);
303 efl.setLogAbortOnCritical(false);
304
305 efl.setLogPrintCb(function(domain, color, level, file, func, line, msg) {
306 caught_messages.push([level, msg]);
307 });
308
309 efl.logCritical(messages[0][1]);
310 efl.logError(messages[1][1]);
311 efl.logWarning(messages[2][1]);
312 efl.logInfo(messages[3][1]);
313 efl.logDebug(messages[4][1]);
314
315 assert(array_equal(messages.slice(0, 3), caught_messages), "Must received only the messages above the desired level.");
316});
317
318start_test("log helper wrong type", function(){
319 var raised = false;
320 try {
321 efl.log_info(442);
322 } catch (err) {
323 raised = true;
324 assert(err.name == "TypeError", "Raised exception must be TypeError.");
325 }
326 assert(raised, "Passing anything other than a string must raise TypeError.");
327});
328
329start_test("log color constants", function(){
330 assert(typeof efl.COLOR_LIGHTRED == "string", "efl.COLOR_LIGHTRED must be a string.");
331 assert(typeof efl.COLOR_RED == "string", "efl.COLOR_RED must be a string.");
332 assert(typeof efl.COLOR_LIGHTBLUE == "string", "efl.COLOR_LIGHTBLUE must be a string.");
333 assert(typeof efl.COLOR_BLUE == "string", "efl.COLOR_BLUE must be a string.");
334 assert(typeof efl.COLOR_GREEN == "string", "efl.COLOR_GREEN must be a string.");
335 assert(typeof efl.COLOR_YELLOW == "string", "efl.COLOR_YELLOW must be a string.");
336 assert(typeof efl.COLOR_ORANGE == "string", "efl.COLOR_ORANGE must be a string.");
337 assert(typeof efl.COLOR_WHITE == "string", "efl.COLOR_WHITE must be a string.");
338 assert(typeof efl.COLOR_LIGHTCYAN == "string", "efl.COLOR_LIGHTCYAN must be a string.");
339 assert(typeof efl.COLOR_CYAN == "string", "efl.COLOR_CYAN must be a string.");
340 assert(typeof efl.COLOR_RESET == "string", "efl.COLOR_RESET must be a string.");
341 assert(typeof efl.COLOR_HIGH == "string", "efl.COLOR_HIGH must be a string.");
342});
343
344// footer
345
346if (!suite_success) {
347 print ("[ Total tests run: %s ]", suite_ok + suite_fail.length);
348 print ("[ Total successful: %s ]", suite_ok);
349 print ("[ Total failures: %s ]", suite_fail.length);
350 print ("[ Tests failed: ]");
351 for (var i = 0; i < suite_fail.length; i++) {
352 print ("[ %s]", suite_fail[i]);
353 };
354 assert(false, "[ Test suite fail ]");
355} else {
356 print ("[ Test execution with success ]");
357 print ("[ Total tests run: %s ]", suite_ok);
358}
359
360exit();
diff --git a/src/tests/efl_js/eio_js_suite.cc b/src/tests/efl_js/eio_js_suite.cc
new file mode 100644
index 0000000000..ba2df9d767
--- /dev/null
+++ b/src/tests/efl_js/eio_js_suite.cc
@@ -0,0 +1,7 @@
1
2#include "suite_runner.hh"
3
4int main(int, char*[])
5{
6 return run_script(TESTS_SRC_DIR "/eio_js_suite.js", nullptr);
7}
diff --git a/src/tests/efl_js/eio_js_suite.js b/src/tests/efl_js/eio_js_suite.js
new file mode 100755
index 0000000000..01eb09c171
--- /dev/null
+++ b/src/tests/efl_js/eio_js_suite.js
@@ -0,0 +1,89 @@
1#!/usr/bin/env node
2
3// Preamble
4function assert(condition, message) {
5 if (!condition) {
6 print("Assertion failed ", message);
7 throw new Error(message || "Assertion failed");
8 }
9}
10
11if(typeof process !== 'undefined')
12{
13 console.log('running from nodejs');
14 console.log('path', process.env.NODE_PATH);
15 console.log("teste1");
16
17 efl = require('efl');
18 assert(efl != null, "could not load efl node module");
19
20 // Setup output aliases
21 print = console.log;
22 print_error = function() {
23 if (process.argv.indexOf("--supress-errors") == -1)
24 console.error.apply(null, arguments);
25 };
26 print_info = function() {
27 if (process.argv.indexOf("--verbose") != -1)
28 console.info.apply(null, arguments);
29 };
30 exit = efl.ecore_mainloop_quit;
31}
32else
33{
34 assert = function(test, message) { if (test !== true) throw message; };
35 print('running from libv8')
36 //FIXME Add levels to v8 tests
37 print_error = print
38 print_info = print
39 exit = function() {}
40}
41
42// Global flag for suite success //
43suite_success = true;
44// Global test summary
45suite_ok = 0;
46suite_fail = []; // Will store the name of the failures
47
48// Basic test function //
49function start_test(test_name, test_func) {
50 print("[ RUN ] eio_js_suite: " + test_name);
51 var test_result = true;
52 try {
53 test_func();
54 } catch (e) {
55 suite_success = false;
56 test_result = false;
57 print_error("Error: ", e, e.stack);
58 }
59 print("[ " + (test_result ? "PASS" : "FAIL") + " ] eio_js_suite: " + test_name);
60 if (test_result)
61 suite_ok += 1;
62 else
63 suite_fail.push(test_name);
64}
65// end Preamble
66
67// Eio tests
68start_test('test constants', function () {
69 assert(typeof(efl.EIO_FILE_COPY) === 'number');
70});
71// TODO: more tests
72
73// footer
74
75if (!suite_success) {
76 print ("[ Total tests run: %s ]", suite_ok + suite_fail.length);
77 print ("[ Total successful: %s ]", suite_ok);
78 print ("[ Total failures: %s ]", suite_fail.length);
79 print ("[ Tests failed: ]");
80 for (var i = 0; i < suite_fail.length; i++) {
81 print ("[ %s]", suite_fail[i]);
82 };
83 assert(false, "[ Test suite fail ]");
84} else {
85 print ("[ Test execution with success ]");
86 print ("[ Total tests run: %s ]", suite_ok);
87}
88
89exit();
diff --git a/src/tests/efl_js/eldbus_js_suite.cc b/src/tests/efl_js/eldbus_js_suite.cc
new file mode 100644
index 0000000000..791c0c6c3c
--- /dev/null
+++ b/src/tests/efl_js/eldbus_js_suite.cc
@@ -0,0 +1,7 @@
1
2#include "suite_runner.hh"
3
4int main(int, char*[])
5{
6 return run_script(TESTS_SRC_DIR "/eldbus_js_suite.js", nullptr);
7}
diff --git a/src/tests/efl_js/eldbus_js_suite.js b/src/tests/efl_js/eldbus_js_suite.js
new file mode 100755
index 0000000000..30869072c4
--- /dev/null
+++ b/src/tests/efl_js/eldbus_js_suite.js
@@ -0,0 +1,114 @@
1#!/usr/bin/env node
2
3// Preamble
4function assert(condition, message) {
5 if (!condition) {
6 print("Assertion failed ", message);
7 throw new Error(message || "Assertion failed");
8 }
9}
10
11if(typeof process !== 'undefined')
12{
13 console.log('running from nodejs');
14 console.log('path', process.env.NODE_PATH);
15 console.log("teste1");
16
17 efl = require('efl');
18 assert(efl != null, "could not load efl node module");
19
20 // Setup output aliases
21 print = console.log;
22 print_error = function() {
23 if (process.argv.indexOf("--supress-errors") == -1)
24 console.error.apply(null, arguments);
25 };
26 print_info = function() {
27 if (process.argv.indexOf("--verbose") != -1)
28 console.info.apply(null, arguments);
29 };
30 exit = efl.ecore_mainloop_quit;
31}
32else
33{
34 assert = function(test, message) { if (test !== true) throw message; };
35 print('running from libv8')
36 //FIXME Add levels to v8 tests
37 print_error = print
38 print_info = print
39 exit = function() {}
40}
41
42// Global flag for suite success //
43suite_success = true;
44// Global test summary
45suite_ok = 0;
46suite_fail = []; // Will store the name of the failures
47
48// Basic test function //
49function start_test(test_name, test_func) {
50 print("[ RUN ] eldbus_js_suite: " + test_name);
51 var test_result = true;
52 try {
53 test_func();
54 } catch (e) {
55 suite_success = false;
56 test_result = false;
57 print_error("Error: ", e, e.stack);
58 }
59 print("[ " + (test_result ? "PASS" : "FAIL") + " ] eldbus_js_suite: " + test_name);
60 if (test_result)
61 suite_ok += 1;
62 else
63 suite_fail.push(test_name);
64}
65// end Preamble
66
67// Eldbus core tests
68start_test('test constants', function () {
69 assert(typeof(efl.ELDBUS_FDO_BUS) === 'string');
70 assert(typeof(efl.ELDBUS_FDO_PATH) === 'string');
71 assert(typeof(efl.ELDBUS_FDO_INTERFACE) === 'string');
72 assert(typeof(efl.ELDBUS_FDO_INTERFACE_PROPERTIES) === 'string');
73 assert(typeof(efl.ELDBUS_FDO_INTERFACE_INTROSPECTABLE) === 'string');
74 assert(typeof(efl.ELDBUS_FDO_INTEFACE_PEER) === 'string');
75 assert(typeof(efl.ELDBUS_ERROR_PENDING_CANCELED) === 'string');
76 assert(typeof(efl.ELDBUS_ERROR_PENDING_TIMEOUT) === 'string');
77});
78
79// Eldbus connection tests
80start_test('test connection constants', function () {
81 assert(typeof(efl.ELDBUS_TIMEOUT_INFINITE) === 'number');
82 assert(typeof(efl.ELDBUS_CONNECTION_TYPE_UNKNOWN) === 'number');
83 assert(typeof(efl.ELDBUS_CONNECTION_TYPE_SESSION) === 'number');
84 assert(typeof(efl.ELDBUS_CONNECTION_TYPE_SYSTEM) === 'number');
85 assert(typeof(efl.ELDBUS_CONNECTION_TYPE_STARTER) === 'number');
86 assert(typeof(efl.ELDBUS_CONNECTION_TYPE_ADDRESS) === 'number');
87 assert(typeof(efl.ELDBUS_CONNECTION_TYPE_LAST) === 'number');
88 assert(typeof(efl.ELDBUS_CONNECTION_EVENT_DEL) === 'number');
89 assert(typeof(efl.ELDBUS_CONNECTION_EVENT_DISCONNECTED) === 'number');
90 assert(typeof(efl.ELDBUS_CONNECTION_EVENT_LAST) === 'number');
91});
92// Eldbus connection
93
94// TODO...
95
96// finished tests
97
98// footer
99
100if (!suite_success) {
101 print ("[ Total tests run: %s ]", suite_ok + suite_fail.length);
102 print ("[ Total successful: %s ]", suite_ok);
103 print ("[ Total failures: %s ]", suite_fail.length);
104 print ("[ Tests failed: ]");
105 for (var i = 0; i < suite_fail.length; i++) {
106 print ("[ %s]", suite_fail[i]);
107 };
108 assert(false, "[ Test suite fail ]");
109} else {
110 print ("[ Test execution with success ]");
111 print ("[ Total tests run: %s ]", suite_ok);
112}
113
114exit();
diff --git a/src/tests/efl_js/ethumb_js_suite.cc b/src/tests/efl_js/ethumb_js_suite.cc
new file mode 100644
index 0000000000..5d0149f2ff
--- /dev/null
+++ b/src/tests/efl_js/ethumb_js_suite.cc
@@ -0,0 +1,7 @@
1
2#include "suite_runner.hh"
3
4int main(int, char*[])
5{
6 return run_script(TESTS_SRC_DIR "/ethumb_js_suite.js", nullptr);
7}
diff --git a/src/tests/efl_js/ethumb_js_suite.js b/src/tests/efl_js/ethumb_js_suite.js
new file mode 100755
index 0000000000..5dd78fc493
--- /dev/null
+++ b/src/tests/efl_js/ethumb_js_suite.js
@@ -0,0 +1,93 @@
1#!/usr/bin/env node
2
3// Preamble
4function assert(condition, message) {
5 if (!condition) {
6 print("Assertion failed ", message);
7 throw new Error(message || "Assertion failed");
8 }
9}
10
11if(typeof process !== 'undefined')
12{
13 console.log('running from nodejs');
14 console.log('path', process.env.NODE_PATH);
15 console.log("teste1");
16
17 efl = require('efl');
18 assert(efl != null, "could not load efl node module");
19
20 // Setup output aliases
21 print = console.log;
22 print_error = function() {
23 if (process.argv.indexOf("--supress-errors") == -1)
24 console.error.apply(null, arguments);
25 };
26 print_info = function() {
27 if (process.argv.indexOf("--verbose") != -1)
28 console.info.apply(null, arguments);
29 };
30 exit = efl.ecore_mainloop_quit;
31}
32else
33{
34 assert = function(test, message) { if (test !== true) throw message; };
35 print('running from libv8')
36 //FIXME Add levels to v8 tests
37 print_error = print
38 print_info = print
39 exit = function() {}
40}
41
42// Global flag for suite success //
43suite_success = true;
44// Global test summary
45suite_ok = 0;
46suite_fail = []; // Will store the name of the failures
47
48// Basic test function //
49function start_test(test_name, test_func) {
50 print("[ RUN ] ethumb_js_suite: " + test_name);
51 var test_result = true;
52 try {
53 test_func();
54 } catch (e) {
55 suite_success = false;
56 test_result = false;
57 print_error("Error: ", e, e.stack);
58 }
59 print("[ " + (test_result ? "PASS" : "FAIL") + " ] ethumb_js_suite: " + test_name);
60 if (test_result)
61 suite_ok += 1;
62 else
63 suite_fail.push(test_name);
64}
65// end Preamble
66
67efl.ethumb_client_init();
68
69// Ethumb tests
70
71start_test('dummy test', function () {
72 assert(true);
73});
74
75efl.ethumb_client_shutdown();
76
77// footer
78
79if (!suite_success) {
80 print ("[ Total tests run: %s ]", suite_ok + suite_fail.length);
81 print ("[ Total successful: %s ]", suite_ok);
82 print ("[ Total failures: %s ]", suite_fail.length);
83 print ("[ Tests failed: ]");
84 for (var i = 0; i < suite_fail.length; i++) {
85 print ("[ %s]", suite_fail[i]);
86 };
87 assert(false, "[ Test suite fail ]");
88} else {
89 print ("[ Test execution with success ]");
90 print ("[ Total tests run: %s ]", suite_ok);
91}
92
93exit();
diff --git a/src/tests/efl_js/suite_runner.hh b/src/tests/efl_js/suite_runner.hh
new file mode 100644
index 0000000000..9686ba5e90
--- /dev/null
+++ b/src/tests/efl_js/suite_runner.hh
@@ -0,0 +1,147 @@
1
2#ifdef HAVE_CONFIG_H
3#include <config.h>
4#endif
5
6#include <Eina.hh>
7
8#include <cassert>
9#include <cstdlib>
10#include <fstream>
11
12#include <Eina_Js.hh>
13#include <Efl_Js.hh>
14
15const char* ToCString(const v8::String::Utf8Value& value) {
16 return *value ? *value : "<string conversion failed>";
17}
18
19// Executes a string within the current v8 context.
20void ExecuteString(v8::Isolate* isolate,
21 v8::Handle<v8::String> source,
22 v8::Handle<v8::Value> name)
23{
24 efl::eina::js::compatibility_handle_scope handle_scope(isolate);
25 v8::TryCatch try_catch;
26 v8::ScriptOrigin origin(name);
27 v8::Handle<v8::Script> script = v8::Script::Compile(source, &origin);
28 if (script.IsEmpty()) {
29 std::cerr << "Compilation failed" << std::endl;
30 std::exit(-1);
31 }
32 else
33 {
34 std::cerr << "Compilation succesful" << std::endl;
35 v8::Handle<v8::Value> result = script->Run();
36 if (result.IsEmpty()) {
37 std::cout << "Failed with exception thrown" << std::endl;
38 if(try_catch.HasCaught())
39 {
40 if(!try_catch.Message().IsEmpty() && !try_catch.Message()->Get().IsEmpty())
41 std::cerr << "Exception " << ToCString(v8::String::Utf8Value(try_catch.Message()->Get()))
42 << std::endl;
43 else
44 std::cerr << "Exception without message" << std::endl;
45 }
46 std::exit(-1);
47 }
48 }
49}
50
51efl::eina::js::compatibility_return_type Print(efl::eina::js::compatibility_callback_info_type args)
52{
53 bool first = true;
54 for (int i = 0; i < args.Length(); i++) {
55 efl::eina::js::compatibility_handle_scope handle_scope(args.GetIsolate());
56 if (first) {
57 first = false;
58 } else {
59 printf(" ");
60 }
61 v8::String::Utf8Value str(args[i]);
62 const char* cstr = ToCString(str);
63 printf("%s", cstr);
64 }
65 printf("\n");
66 fflush(stdout);
67 return efl::eina::js::compatibility_return();
68}
69
70std::vector<char> read_script(const char* file)
71{
72 std::vector<char> script;
73 std::ifstream script_file(file);
74 script_file.seekg(0, std::ios::end);
75 std::size_t script_size = script_file.tellg();
76 script_file.seekg(0, std::ios::beg);
77 script.resize(script_size+1);
78 script_file.rdbuf()->sgetn(&script[0], script_size);
79 auto line_break = std::find(script.begin(), script.end(), '\n');
80 assert(line_break != script.end());
81 ++line_break;
82 std::fill(script.begin(), line_break, ' ');
83
84 std::cerr << "program:" << std::endl;
85 std::copy(script.begin(), script.end(), std::ostream_iterator<char>(std::cerr));
86 std::cerr << "end of program" << std::endl;
87
88 return script;
89}
90
91int run_script(const char* file, void(*init)(v8::Handle<v8::Object>))
92{
93 efl::eina::js::compatibility_initialize();
94 v8::Isolate* isolate = efl::eina::js::compatibility_isolate_new();
95 assert(isolate != 0);
96
97 v8::Isolate::Scope isolate_scope(isolate);
98
99 efl::eina::js::compatibility_handle_scope handle_scope(isolate);
100 v8::Handle<v8::Context> context
101 = efl::eina::js::compatibility_new<v8::Context>
102 (isolate, nullptr
103 , efl::eina::js::compatibility_new<v8::ObjectTemplate>(isolate));
104 if (context.IsEmpty()) {
105 fprintf(stderr, "Error creating context\n");
106 return 1;
107 }
108 context->Enter();
109 {
110 // Enter the execution environment before evaluating any code.
111 v8::Context::Scope context_scope(context);
112 v8::Local<v8::Object> global = context->Global();
113
114 global->Set(efl::eina::js::compatibility_new<v8::String>(isolate, "print")
115 , efl::eina::js::compatibility_new<v8::FunctionTemplate>(isolate, & ::Print)
116 ->GetFunction());
117
118 std::cerr << __LINE__ << std::endl;
119 v8::Handle<v8::Object> exports = efl::eina::js::compatibility_new<v8::Object>(isolate);
120 global->Set(efl::eina::js::compatibility_new<v8::String>(isolate, "efl"), exports);
121
122 efl_js::init(exports);
123
124 if(init)
125 {
126 v8::Handle<v8::Object> exports = efl::eina::js::compatibility_new<v8::Object>(isolate);
127 global->Set(efl::eina::js::compatibility_new<v8::String>(isolate, "suite"), exports);
128 init(exports);
129 }
130 std::cerr << __LINE__ << std::endl;
131
132 {
133 efl::eina::js::compatibility_handle_scope handle_scope(v8::Isolate::GetCurrent());
134 std::cerr << __LINE__ << std::endl;
135 std::vector<char> script = read_script(file);
136 v8::Local<v8::String> name(efl::eina::js::compatibility_new<v8::String>
137 (nullptr, file));
138 ExecuteString(v8::Isolate::GetCurrent(),
139 efl::eina::js::compatibility_new<v8::String>
140 (v8::Isolate::GetCurrent(), &script[0]), name);
141 std::cerr << __LINE__ << std::endl;
142 }
143 }
144 context->Exit();
145
146 return 0;
147}
diff --git a/src/tests/efl_js/testproj/hello.project b/src/tests/efl_js/testproj/hello.project
new file mode 100644
index 0000000000..6d094fcf1d
--- /dev/null
+++ b/src/tests/efl_js/testproj/hello.project
@@ -0,0 +1,9 @@
1{
2 "Name": "test-project",
3 "Entry": "main.js",
4 "Version": "0.42",
5 "Sources": [
6 ["main.js", "."],
7 ["hello.txt", "."]
8 ]
9} \ No newline at end of file
diff --git a/src/tests/efl_js/testproj/hello.txt b/src/tests/efl_js/testproj/hello.txt
new file mode 100644
index 0000000000..8fe2a4b5ad
--- /dev/null
+++ b/src/tests/efl_js/testproj/hello.txt
@@ -0,0 +1 @@
The quick brown fox jumps over the lazy dog. \ No newline at end of file
diff --git a/src/tests/efl_js/testproj/main.js b/src/tests/efl_js/testproj/main.js
new file mode 100644
index 0000000000..e9cf00a97d
--- /dev/null
+++ b/src/tests/efl_js/testproj/main.js
@@ -0,0 +1,5 @@
1var fs = require('fs');
2
3text = fs.readFileSync('hello.txt', {encoding: 'utf8'});
4
5console.log(text); \ No newline at end of file
diff --git a/src/tests/efl_js/timer.js b/src/tests/efl_js/timer.js
new file mode 100644
index 0000000000..95c3011080
--- /dev/null
+++ b/src/tests/efl_js/timer.js
@@ -0,0 +1,33 @@
1
2var efl = require('efl');
3
4var loop = new efl.Ecore_Mainloop(null);
5
6var secondsToWait = parseFloat(process.argv[2]);
7
8if (isNaN(secondsToWait))
9 {
10 secondsToWait = 2;
11 }
12
13console.log('Waiting ' + secondsToWait + ' seconds...');
14
15if (false)
16 {
17 var timer = new efl.Timer(null, secondsToWait,
18 function(){
19 console.log("Timer cb called;");
20 loop.quit();
21 }, null);
22 }
23else
24 {
25 setTimeout(function(){
26 console.log("Js callback called;");
27 loop.quit();
28 }, secondsToWait*1000);
29 }
30
31loop.begin();
32
33process.exit(0); \ No newline at end of file