aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortkeri <kertamjozs@gmail.com>2018-01-08 09:44:50 +0100
committerZoltan Herczeg <zherczeg.u-szeged@partner.samsung.com>2018-01-08 09:44:50 +0100
commite0e6aa031902422dd5a2f36d3c1f3c8fb9839e76 (patch)
treeb5b779c8936cb0808bd3abd4af7a0b85fee68c97
parentd6df000fe57ab37f655d9159a304b840cb3320bd (diff)
Add new snapshot execution test cases (#2160)
Add new function to avoid code duplication. Add two new test cases to jerry_exec_snapshot function: * test enable copy byte-code with global mode * test enable copy byte-code with eval mode JerryScript-DCO-1.0-Signed-off-by: Tamas Keri tkeri@inf.u-szeged.hu
-rw-r--r--tests/unit-core/test-snapshot.c61
1 files changed, 34 insertions, 27 deletions
diff --git a/tests/unit-core/test-snapshot.c b/tests/unit-core/test-snapshot.c
index 66fdb6eb..8ed1228d 100644
--- a/tests/unit-core/test-snapshot.c
+++ b/tests/unit-core/test-snapshot.c
@@ -79,6 +79,28 @@ static void test_function_snapshot (void)
jerry_cleanup ();
} /* test_function_snapshot */
+static void test_exec_snapshot (uint32_t *snapshot_p, size_t snapshot_size, bool copy_bytecode)
+{
+ char string_data[32];
+
+ jerry_init (JERRY_INIT_EMPTY);
+
+ jerry_value_t res = jerry_exec_snapshot (snapshot_p,
+ snapshot_size,
+ copy_bytecode);
+
+ TEST_ASSERT (!jerry_value_has_error_flag (res));
+ TEST_ASSERT (jerry_value_is_string (res));
+ jerry_size_t sz = jerry_get_string_size (res);
+ TEST_ASSERT (sz == 20);
+ sz = jerry_string_to_char_buffer (res, (jerry_char_t *) string_data, sz);
+ TEST_ASSERT (sz == 20);
+ jerry_release_value (res);
+ TEST_ASSERT (!strncmp (string_data, "string from snapshot", (size_t) sz));
+
+ jerry_cleanup ();
+} /* test_exec_snapshot */
+
int
main (void)
{
@@ -90,7 +112,6 @@ main (void)
{
static uint32_t global_mode_snapshot_buffer[SNAPSHOT_BUFFER_SIZE];
static uint32_t eval_mode_snapshot_buffer[SNAPSHOT_BUFFER_SIZE];
- char string_data[32];
const char *code_to_snapshot_p = "(function () { return 'string from snapshot'; }) ();";
@@ -114,35 +135,21 @@ main (void)
TEST_ASSERT (eval_mode_snapshot_size != 0);
jerry_cleanup ();
- jerry_init (JERRY_INIT_EMPTY);
-
- jerry_value_t res = jerry_exec_snapshot (global_mode_snapshot_buffer,
- global_mode_snapshot_size,
- false);
-
- TEST_ASSERT (!jerry_value_has_error_flag (res));
- TEST_ASSERT (jerry_value_is_string (res));
- jerry_size_t sz = jerry_get_string_size (res);
- TEST_ASSERT (sz == 20);
- sz = jerry_string_to_char_buffer (res, (jerry_char_t *) string_data, sz);
- TEST_ASSERT (sz == 20);
- jerry_release_value (res);
- TEST_ASSERT (!strncmp (string_data, "string from snapshot", (size_t) sz));
+ test_exec_snapshot (global_mode_snapshot_buffer,
+ global_mode_snapshot_size,
+ false);
- res = jerry_exec_snapshot (eval_mode_snapshot_buffer,
- eval_mode_snapshot_size,
- false);
+ test_exec_snapshot (global_mode_snapshot_buffer,
+ global_mode_snapshot_size,
+ true);
- TEST_ASSERT (!jerry_value_has_error_flag (res));
- TEST_ASSERT (jerry_value_is_string (res));
- sz = jerry_get_string_size (res);
- TEST_ASSERT (sz == 20);
- sz = jerry_string_to_char_buffer (res, (jerry_char_t *) string_data, sz);
- TEST_ASSERT (sz == 20);
- jerry_release_value (res);
- TEST_ASSERT (!strncmp (string_data, "string from snapshot", (size_t) sz));
+ test_exec_snapshot (eval_mode_snapshot_buffer,
+ eval_mode_snapshot_size,
+ false);
- jerry_cleanup ();
+ test_exec_snapshot (eval_mode_snapshot_buffer,
+ eval_mode_snapshot_size,
+ true);
}
/* Merge snapshot */