[jerryx/arg]add jerryx_arg_utf8_string (#2133)

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
This commit is contained in:
Zidong Jiang
2018-01-08 17:17:40 +08:00
committed by Zoltan Herczeg
parent 290bc22f0c
commit 4e7a9d2d53
5 changed files with 212 additions and 22 deletions
+27
View File
@@ -563,6 +563,31 @@ test_validator_array2_handler (const jerry_value_t func_obj_val __attribute__((u
return jerry_create_undefined ();
} /* test_validator_array2_handler */
static void
test_utf8_string (void)
{
/* test string: 'str: {DESERET CAPITAL LETTER LONG I}' */
jerry_value_t str = jerry_create_string ((jerry_char_t *) "\x73\x74\x72\x3a \xed\xa0\x81\xed\xb0\x80");
char expect_utf8_buf[] = "\x73\x74\x72\x3a \xf0\x90\x90\x80";
size_t buf_len = strlen (expect_utf8_buf);
char buf[buf_len+1];
jerryx_arg_t mapping[] =
{
jerryx_arg_utf8_string (buf, (uint32_t) buf_len + 1, JERRYX_ARG_COERCE, JERRYX_ARG_REQUIRED),
};
jerry_value_t is_ok = jerryx_arg_transform_args (&str,
1,
mapping,
ARRAY_SIZE (mapping));
TEST_ASSERT (!jerry_value_has_error_flag (is_ok));
TEST_ASSERT (!strcmp (buf, expect_utf8_buf));
jerry_release_value (str);
} /* test_utf8_string */
static jerry_value_t
create_object_a_handler (const jerry_value_t func_obj_val __attribute__((unused)), /**< function object */
const jerry_value_t this_val, /**< this value */
@@ -620,6 +645,8 @@ main (void)
{
jerry_init (JERRY_INIT_EMPTY);
test_utf8_string ();
register_js_function ("test_validator1", test_validator1_handler);
register_js_function ("test_validator2", test_validator2_handler);
register_js_function ("test_validator_int1", test_validator_int1_handler);