mirror of
https://github.com/google/pebble.git
synced 2025-07-12 04:35:54 +00:00
Import of the watch repository from Pebble
This commit is contained in:
commit
3b92768480
10334 changed files with 2564465 additions and 0 deletions
831
third_party/jerryscript/tests/unit/test-api.c
vendored
Normal file
831
third_party/jerryscript/tests/unit/test-api.c
vendored
Normal file
|
@ -0,0 +1,831 @@
|
|||
/* Copyright 2015-2016 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2016 University of Szeged.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "jerry-api.h"
|
||||
|
||||
#include "test-common.h"
|
||||
|
||||
const char *test_source = (
|
||||
"function assert (arg) { "
|
||||
" if (!arg) { "
|
||||
" throw Error('Assert failed');"
|
||||
" } "
|
||||
"} "
|
||||
"this.t = 1; "
|
||||
"function f () { "
|
||||
"return this.t; "
|
||||
"} "
|
||||
"this.foo = f; "
|
||||
"this.bar = function (a) { "
|
||||
"return a + t; "
|
||||
"}; "
|
||||
"function A () { "
|
||||
"this.t = 12; "
|
||||
"} "
|
||||
"this.A = A; "
|
||||
"this.a = new A (); "
|
||||
"function call_external () { "
|
||||
" return this.external ('1', true); "
|
||||
"} "
|
||||
"function call_throw_test() { "
|
||||
" var catched = false; "
|
||||
" try { "
|
||||
" this.throw_test(); "
|
||||
" } catch (e) { "
|
||||
" catched = true; "
|
||||
" assert(e.name == 'TypeError'); "
|
||||
" assert(e.message == 'error'); "
|
||||
" } "
|
||||
" assert(catched); "
|
||||
"} "
|
||||
"function throw_reference_error() { "
|
||||
" throw new ReferenceError ();"
|
||||
"} "
|
||||
"p = {'alpha':32, 'bravo':false, 'charlie':{}, 'delta':123.45, 'echo':'foobar'};"
|
||||
"np = {}; Object.defineProperty (np, 'foxtrot', { "
|
||||
"get: function() { throw 'error'; }, enumerable: true }) "
|
||||
);
|
||||
|
||||
bool test_api_is_free_callback_was_called = false;
|
||||
|
||||
static jerry_value_t
|
||||
handler (const jerry_value_t func_obj_val, /**< function object */
|
||||
const jerry_value_t this_val, /**< this value */
|
||||
const jerry_value_t args_p[], /**< arguments list */
|
||||
const jerry_length_t args_cnt) /**< arguments length */
|
||||
{
|
||||
char buffer[32];
|
||||
jerry_size_t sz;
|
||||
|
||||
printf ("ok %u %u %p %u\n",
|
||||
(unsigned int) func_obj_val, (unsigned int) this_val, (void *) args_p, (unsigned int) args_cnt);
|
||||
|
||||
TEST_ASSERT (args_cnt == 2);
|
||||
|
||||
TEST_ASSERT (jerry_value_is_string (args_p[0]));
|
||||
sz = jerry_get_string_size (args_p[0]);
|
||||
TEST_ASSERT (sz == 1);
|
||||
sz = jerry_string_to_char_buffer (args_p[0],
|
||||
(jerry_char_t *) buffer,
|
||||
sz);
|
||||
TEST_ASSERT (sz == 1);
|
||||
TEST_ASSERT (!strncmp (buffer, "1", (size_t) sz));
|
||||
|
||||
TEST_ASSERT (jerry_value_is_boolean (args_p[1]));
|
||||
|
||||
return jerry_create_string ((jerry_char_t *) "string from handler");
|
||||
} /* handler */
|
||||
|
||||
static jerry_value_t
|
||||
handler_throw_test (const jerry_value_t func_obj_val, /**< function object */
|
||||
const jerry_value_t this_val, /**< this value */
|
||||
const jerry_value_t args_p[], /**< arguments list */
|
||||
const jerry_length_t args_cnt) /**< arguments length */
|
||||
{
|
||||
printf ("ok %u %u %p %u\n",
|
||||
(unsigned int) func_obj_val, (unsigned int) this_val, (void *) args_p, (unsigned int) args_cnt);
|
||||
|
||||
return jerry_create_error (JERRY_ERROR_TYPE, (jerry_char_t *) "error");
|
||||
} /* handler_throw_test */
|
||||
|
||||
static void
|
||||
handler_construct_freecb (uintptr_t native_p)
|
||||
{
|
||||
TEST_ASSERT (native_p == (uintptr_t) 0x0012345678abcdefull);
|
||||
printf ("ok object free callback\n");
|
||||
|
||||
test_api_is_free_callback_was_called = true;
|
||||
} /* handler_construct_freecb */
|
||||
|
||||
static jerry_value_t
|
||||
handler_construct (const jerry_value_t func_obj_val, /**< function object */
|
||||
const jerry_value_t this_val, /**< this value */
|
||||
const jerry_value_t args_p[], /**< arguments list */
|
||||
const jerry_length_t args_cnt) /**< arguments length */
|
||||
{
|
||||
printf ("ok construct %u %u %p %u\n",
|
||||
(unsigned int) func_obj_val, (unsigned int) this_val, (void *) args_p, (unsigned int) args_cnt);
|
||||
|
||||
TEST_ASSERT (jerry_value_is_object (this_val));
|
||||
|
||||
TEST_ASSERT (args_cnt == 1);
|
||||
TEST_ASSERT (jerry_value_is_boolean (args_p[0]));
|
||||
TEST_ASSERT (jerry_get_boolean_value (args_p[0]) == true);
|
||||
|
||||
jerry_value_t field_name = jerry_create_string ((jerry_char_t *) "value_field");
|
||||
jerry_set_property (this_val, field_name, args_p[0]);
|
||||
jerry_release_value (field_name);
|
||||
|
||||
jerry_set_object_native_handle (this_val,
|
||||
(uintptr_t) 0x0000000000000000ull,
|
||||
handler_construct_freecb);
|
||||
|
||||
uintptr_t ptr = (uintptr_t) NULL;
|
||||
bool is_ok = jerry_get_object_native_handle (this_val, &ptr);
|
||||
TEST_ASSERT (is_ok && ptr == (uintptr_t) 0x0000000000000000ull);
|
||||
|
||||
/* check if setting handle for second time is handled correctly */
|
||||
jerry_set_object_native_handle (this_val,
|
||||
(uintptr_t) 0x0012345678abcdefull,
|
||||
handler_construct_freecb);
|
||||
|
||||
return jerry_create_boolean (true);
|
||||
} /* handler_construct */
|
||||
|
||||
/**
|
||||
* Extended Magic Strings
|
||||
*/
|
||||
#define JERRY_MAGIC_STRING_ITEMS \
|
||||
JERRY_MAGIC_STRING_DEF (GLOBAL, global) \
|
||||
JERRY_MAGIC_STRING_DEF (CONSOLE, console)
|
||||
|
||||
|
||||
#define JERRY_MAGIC_STRING_DEF(NAME, STRING) \
|
||||
static const char jerry_magic_string_ex_ ## NAME[] = # STRING;
|
||||
|
||||
JERRY_MAGIC_STRING_ITEMS
|
||||
|
||||
#undef JERRY_MAGIC_STRING_DEF
|
||||
|
||||
const jerry_length_t magic_string_lengths[] =
|
||||
{
|
||||
#define JERRY_MAGIC_STRING_DEF(NAME, STRING) \
|
||||
(jerry_length_t) (sizeof (jerry_magic_string_ex_ ## NAME) - 1u),
|
||||
|
||||
JERRY_MAGIC_STRING_ITEMS
|
||||
|
||||
#undef JERRY_MAGIC_STRING_DEF
|
||||
};
|
||||
|
||||
const jerry_char_ptr_t magic_string_items[] =
|
||||
{
|
||||
#define JERRY_MAGIC_STRING_DEF(NAME, STRING) \
|
||||
(const jerry_char_ptr_t) jerry_magic_string_ex_ ## NAME,
|
||||
|
||||
JERRY_MAGIC_STRING_ITEMS
|
||||
|
||||
#undef JERRY_MAGIC_STRING_DEF
|
||||
};
|
||||
|
||||
static bool
|
||||
foreach (const jerry_value_t name, /**< field name */
|
||||
const jerry_value_t value, /**< field value */
|
||||
void *user_data) /**< user data */
|
||||
{
|
||||
char str_buf_p[128];
|
||||
jerry_size_t sz = jerry_string_to_char_buffer (name, (jerry_char_t *) str_buf_p, 128);
|
||||
str_buf_p[sz] = '\0';
|
||||
|
||||
TEST_ASSERT (!strncmp ((const char *) user_data, "user_data", 9));
|
||||
TEST_ASSERT (sz > 0);
|
||||
|
||||
if (!strncmp (str_buf_p, "alpha", (size_t) sz))
|
||||
{
|
||||
TEST_ASSERT (jerry_value_is_number (value));
|
||||
TEST_ASSERT (jerry_get_number_value (value) == 32.0);
|
||||
return true;
|
||||
}
|
||||
else if (!strncmp (str_buf_p, "bravo", (size_t) sz))
|
||||
{
|
||||
TEST_ASSERT (jerry_value_is_boolean (value));
|
||||
TEST_ASSERT (jerry_get_boolean_value (value) == false);
|
||||
return true;
|
||||
}
|
||||
else if (!strncmp (str_buf_p, "charlie", (size_t) sz))
|
||||
{
|
||||
TEST_ASSERT (jerry_value_is_object (value));
|
||||
return true;
|
||||
}
|
||||
else if (!strncmp (str_buf_p, "delta", (size_t) sz))
|
||||
{
|
||||
TEST_ASSERT (jerry_value_is_number (value));
|
||||
TEST_ASSERT (jerry_get_number_value (value) == 123.45);
|
||||
return true;
|
||||
}
|
||||
else if (!strncmp (str_buf_p, "echo", (size_t) sz))
|
||||
{
|
||||
TEST_ASSERT (jerry_value_is_string (value));
|
||||
jerry_size_t echo_sz = jerry_string_to_char_buffer (value,
|
||||
(jerry_char_t *) str_buf_p,
|
||||
128);
|
||||
str_buf_p[echo_sz] = '\0';
|
||||
TEST_ASSERT (!strncmp (str_buf_p, "foobar", (size_t) echo_sz));
|
||||
return true;
|
||||
}
|
||||
|
||||
TEST_ASSERT (false);
|
||||
return false;
|
||||
|
||||
|
||||
} /* foreach */
|
||||
|
||||
static bool
|
||||
foreach_exception (const jerry_value_t name, /**< field name */
|
||||
const jerry_value_t value, /**< field value */
|
||||
void *user_data) /**< user data */
|
||||
{
|
||||
JERRY_UNUSED (value);
|
||||
JERRY_UNUSED (user_data);
|
||||
char str_buf_p[128];
|
||||
jerry_size_t sz = jerry_string_to_char_buffer (name, (jerry_char_t *) str_buf_p, 128);
|
||||
str_buf_p[sz] = '\0';
|
||||
|
||||
if (!strncmp (str_buf_p, "foxtrot", (size_t) sz))
|
||||
{
|
||||
TEST_ASSERT (false);
|
||||
}
|
||||
|
||||
return true;
|
||||
} /* foreach_exception */
|
||||
|
||||
static bool
|
||||
foreach_subset (const jerry_value_t name, /**< field name */
|
||||
const jerry_value_t value, /**< field value */
|
||||
void *user_data) /**< user data */
|
||||
{
|
||||
JERRY_UNUSED (name);
|
||||
JERRY_UNUSED (value);
|
||||
int *count_p = (int *) (user_data);
|
||||
|
||||
if (*count_p == 3)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
(*count_p)++;
|
||||
return true;
|
||||
} /* foreach_subset */
|
||||
|
||||
static jerry_value_t
|
||||
get_property (const jerry_value_t obj_val, /**< object value */
|
||||
const char *str_p) /**< property name */
|
||||
{
|
||||
jerry_value_t prop_name_val = jerry_create_string ((const jerry_char_t *) str_p);
|
||||
jerry_value_t ret_val = jerry_get_property (obj_val, prop_name_val);
|
||||
jerry_release_value (prop_name_val);
|
||||
return ret_val;
|
||||
} /* get_property */
|
||||
|
||||
static jerry_value_t
|
||||
set_property (const jerry_value_t obj_val, /**< object value */
|
||||
const char *str_p, /**< property name */
|
||||
const jerry_value_t val) /**< value to set */
|
||||
{
|
||||
jerry_value_t prop_name_val = jerry_create_string ((const jerry_char_t *) str_p);
|
||||
jerry_value_t ret_val = jerry_set_property (obj_val, prop_name_val, val);
|
||||
jerry_release_value (prop_name_val);
|
||||
return ret_val;
|
||||
} /* set_property */
|
||||
|
||||
static bool
|
||||
test_run_simple (const char *script_p) /**< source code to run */
|
||||
{
|
||||
size_t script_size = strlen (script_p);
|
||||
|
||||
return jerry_run_simple ((const jerry_char_t *) script_p, script_size, JERRY_INIT_EMPTY);
|
||||
} /* test_run_simple */
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
TEST_INIT ();
|
||||
|
||||
bool is_ok;
|
||||
jerry_size_t sz;
|
||||
jerry_value_t val_t, val_foo, val_bar, val_A, val_A_prototype, val_a, val_a_foo, val_value_field, val_p, val_np;
|
||||
jerry_value_t val_call_external;
|
||||
jerry_value_t global_obj_val, obj_val;
|
||||
jerry_value_t external_func_val, external_construct_val;
|
||||
jerry_value_t throw_test_handler_val;
|
||||
jerry_value_t parsed_code_val, proto_val, prim_val;
|
||||
jerry_value_t res, args[2];
|
||||
double number_val;
|
||||
char buffer[32];
|
||||
|
||||
is_ok = test_run_simple ("print ('Hello, World!');");
|
||||
TEST_ASSERT (is_ok);
|
||||
|
||||
is_ok = test_run_simple ("throw 'Hello World';");
|
||||
TEST_ASSERT (!is_ok);
|
||||
|
||||
jerry_init (JERRY_INIT_EMPTY);
|
||||
|
||||
parsed_code_val = jerry_parse ((jerry_char_t *) test_source, strlen (test_source), false);
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (parsed_code_val));
|
||||
|
||||
res = jerry_run (parsed_code_val);
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (res));
|
||||
jerry_release_value (res);
|
||||
jerry_release_value (parsed_code_val);
|
||||
|
||||
global_obj_val = jerry_get_global_object ();
|
||||
|
||||
// Test corner case for jerry_string_to_char_buffer
|
||||
args[0] = jerry_create_string ((jerry_char_t *) "");
|
||||
sz = jerry_get_string_size (args[0]);
|
||||
TEST_ASSERT (sz == 0);
|
||||
jerry_release_value (args[0]);
|
||||
|
||||
// Get global.boo (non-existing field)
|
||||
val_t = get_property (global_obj_val, "boo");
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (val_t));
|
||||
TEST_ASSERT (jerry_value_is_undefined (val_t));
|
||||
|
||||
// Get global.t
|
||||
val_t = get_property (global_obj_val, "t");
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (val_t));
|
||||
TEST_ASSERT (jerry_value_is_number (val_t)
|
||||
&& jerry_get_number_value (val_t) == 1.0);
|
||||
jerry_release_value (val_t);
|
||||
|
||||
// Get global.foo
|
||||
val_foo = get_property (global_obj_val, "foo");
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (val_foo));
|
||||
TEST_ASSERT (jerry_value_is_object (val_foo));
|
||||
|
||||
// Call foo (4, 2)
|
||||
args[0] = jerry_create_number (4);
|
||||
args[1] = jerry_create_number (2);
|
||||
res = jerry_call_function (val_foo, jerry_create_undefined (), args, 2);
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (res));
|
||||
TEST_ASSERT (jerry_value_is_number (res)
|
||||
&& jerry_get_number_value (res) == 1.0);
|
||||
jerry_release_value (res);
|
||||
|
||||
// Get global.bar
|
||||
val_bar = get_property (global_obj_val, "bar");
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (val_bar));
|
||||
TEST_ASSERT (jerry_value_is_object (val_bar));
|
||||
|
||||
// Call bar (4, 2)
|
||||
res = jerry_call_function (val_bar, jerry_create_undefined (), args, 2);
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (res));
|
||||
TEST_ASSERT (jerry_value_is_number (res)
|
||||
&& jerry_get_number_value (res) == 5.0);
|
||||
jerry_release_value (res);
|
||||
jerry_release_value (val_bar);
|
||||
|
||||
// Set global.t = "abcd"
|
||||
jerry_release_value (args[0]);
|
||||
args[0] = jerry_create_string ((jerry_char_t *) "abcd");
|
||||
res = set_property (global_obj_val, "t", args[0]);
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (res));
|
||||
TEST_ASSERT (jerry_get_boolean_value (res));
|
||||
jerry_release_value (res);
|
||||
|
||||
// Call foo (4, 2)
|
||||
res = jerry_call_function (val_foo, jerry_create_undefined (), args, 2);
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (res));
|
||||
TEST_ASSERT (jerry_value_is_string (res));
|
||||
sz = jerry_get_string_size (res);
|
||||
TEST_ASSERT (sz == 4);
|
||||
sz = jerry_string_to_char_buffer (res, (jerry_char_t *) buffer, sz);
|
||||
TEST_ASSERT (sz == 4);
|
||||
jerry_release_value (res);
|
||||
TEST_ASSERT (!strncmp (buffer, "abcd", (size_t) sz));
|
||||
jerry_release_value (args[0]);
|
||||
jerry_release_value (args[1]);
|
||||
|
||||
// Get global.A
|
||||
val_A = get_property (global_obj_val, "A");
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (val_A));
|
||||
TEST_ASSERT (jerry_value_is_object (val_A));
|
||||
|
||||
// Get A.prototype
|
||||
is_ok = jerry_value_is_constructor (val_A);
|
||||
TEST_ASSERT (is_ok);
|
||||
val_A_prototype = get_property (val_A, "prototype");
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (val_A_prototype));
|
||||
TEST_ASSERT (jerry_value_is_object (val_A_prototype));
|
||||
jerry_release_value (val_A);
|
||||
|
||||
// Set A.prototype.foo = global.foo
|
||||
res = set_property (val_A_prototype, "foo", val_foo);
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (res));
|
||||
TEST_ASSERT (jerry_get_boolean_value (res));
|
||||
jerry_release_value (res);
|
||||
jerry_release_value (val_A_prototype);
|
||||
jerry_release_value (val_foo);
|
||||
|
||||
// Get global.a
|
||||
val_a = get_property (global_obj_val, "a");
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (val_a));
|
||||
TEST_ASSERT (jerry_value_is_object (val_a));
|
||||
|
||||
// Get a.t
|
||||
res = get_property (val_a, "t");
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (res));
|
||||
TEST_ASSERT (jerry_value_is_number (res)
|
||||
&& jerry_get_number_value (res) == 12.0);
|
||||
jerry_release_value (res);
|
||||
|
||||
// foreach properties
|
||||
val_p = get_property (global_obj_val, "p");
|
||||
is_ok = jerry_foreach_object_property (val_p, foreach, (void *) "user_data");
|
||||
TEST_ASSERT (is_ok);
|
||||
|
||||
// break foreach at third element
|
||||
int count = 0;
|
||||
is_ok = jerry_foreach_object_property (val_p, foreach_subset, &count);
|
||||
TEST_ASSERT (is_ok);
|
||||
TEST_ASSERT (count == 3);
|
||||
jerry_release_value (val_p);
|
||||
|
||||
// foreach with throw test
|
||||
val_np = get_property (global_obj_val, "np");
|
||||
is_ok = !jerry_foreach_object_property (val_np, foreach_exception, NULL);
|
||||
TEST_ASSERT (is_ok);
|
||||
jerry_release_value (val_np);
|
||||
|
||||
// Get a.foo
|
||||
val_a_foo = get_property (val_a, "foo");
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (val_a_foo));
|
||||
TEST_ASSERT (jerry_value_is_object (val_a_foo));
|
||||
|
||||
// Call a.foo ()
|
||||
res = jerry_call_function (val_a_foo, val_a, NULL, 0);
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (res));
|
||||
TEST_ASSERT (jerry_value_is_number (res)
|
||||
&& jerry_get_number_value (res) == 12.0);
|
||||
jerry_release_value (res);
|
||||
jerry_release_value (val_a_foo);
|
||||
|
||||
jerry_release_value (val_a);
|
||||
|
||||
// Create native handler bound function object and set it to 'external' variable
|
||||
external_func_val = jerry_create_external_function (handler);
|
||||
TEST_ASSERT (jerry_value_is_function (external_func_val)
|
||||
&& jerry_value_is_constructor (external_func_val));
|
||||
|
||||
res = set_property (global_obj_val, "external", external_func_val);
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (res));
|
||||
TEST_ASSERT (jerry_get_boolean_value (res));
|
||||
jerry_release_value (external_func_val);
|
||||
|
||||
// Call 'call_external' function that should call external function created above
|
||||
val_call_external = get_property (global_obj_val, "call_external");
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (val_call_external));
|
||||
TEST_ASSERT (jerry_value_is_object (val_call_external));
|
||||
res = jerry_call_function (val_call_external, global_obj_val, NULL, 0);
|
||||
jerry_release_value (val_call_external);
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (res));
|
||||
TEST_ASSERT (jerry_value_is_string (res));
|
||||
sz = jerry_get_string_size (res);
|
||||
TEST_ASSERT (sz == 19);
|
||||
sz = jerry_string_to_char_buffer (res, (jerry_char_t *) buffer, sz);
|
||||
TEST_ASSERT (sz == 19);
|
||||
jerry_release_value (res);
|
||||
TEST_ASSERT (!strncmp (buffer, "string from handler", (size_t) sz));
|
||||
|
||||
// Create native handler bound function object and set it to 'external_construct' variable
|
||||
external_construct_val = jerry_create_external_function (handler_construct);
|
||||
TEST_ASSERT (jerry_value_is_function (external_construct_val)
|
||||
&& jerry_value_is_constructor (external_construct_val));
|
||||
|
||||
res = set_property (global_obj_val, "external_construct", external_construct_val);
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (res));
|
||||
TEST_ASSERT (jerry_get_boolean_value (res));
|
||||
jerry_release_value (res);
|
||||
|
||||
// Call external function created above, as constructor
|
||||
args[0] = jerry_create_boolean (true);
|
||||
res = jerry_construct_object (external_construct_val, args, 1);
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (res));
|
||||
TEST_ASSERT (jerry_value_is_object (res));
|
||||
val_value_field = get_property (res, "value_field");
|
||||
|
||||
// Get 'value_field' of constructed object
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (val_value_field));
|
||||
TEST_ASSERT (jerry_value_is_boolean (val_value_field)
|
||||
&& jerry_get_boolean_value (val_value_field));
|
||||
jerry_release_value (val_value_field);
|
||||
jerry_release_value (external_construct_val);
|
||||
|
||||
uintptr_t ptr = (uintptr_t) NULL;
|
||||
is_ok = jerry_get_object_native_handle (res, &ptr);
|
||||
TEST_ASSERT (is_ok
|
||||
&& ptr == (uintptr_t) 0x0012345678abcdefull);
|
||||
|
||||
jerry_release_value (res);
|
||||
|
||||
// Test: Throwing exception from native handler.
|
||||
throw_test_handler_val = jerry_create_external_function (handler_throw_test);
|
||||
TEST_ASSERT (jerry_value_is_function (throw_test_handler_val));
|
||||
|
||||
res = set_property (global_obj_val, "throw_test", throw_test_handler_val);
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (res));
|
||||
TEST_ASSERT (jerry_get_boolean_value (res));
|
||||
jerry_release_value (res);
|
||||
jerry_release_value (throw_test_handler_val);
|
||||
|
||||
val_t = get_property (global_obj_val, "call_throw_test");
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (val_t));
|
||||
TEST_ASSERT (jerry_value_is_object (val_t));
|
||||
|
||||
res = jerry_call_function (val_t, global_obj_val, NULL, 0);
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (res));
|
||||
jerry_release_value (val_t);
|
||||
jerry_release_value (res);
|
||||
|
||||
// Test: Unhandled exception in called function
|
||||
val_t = get_property (global_obj_val, "throw_reference_error");
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (val_t));
|
||||
TEST_ASSERT (jerry_value_is_object (val_t));
|
||||
|
||||
res = jerry_call_function (val_t, global_obj_val, NULL, 0);
|
||||
|
||||
TEST_ASSERT (jerry_value_has_error_flag (res));
|
||||
jerry_release_value (val_t);
|
||||
|
||||
// 'res' should contain exception object
|
||||
TEST_ASSERT (jerry_value_is_object (res));
|
||||
jerry_release_value (res);
|
||||
|
||||
// Test: Call of non-function
|
||||
obj_val = jerry_create_object ();
|
||||
res = jerry_call_function (obj_val, global_obj_val, NULL, 0);
|
||||
TEST_ASSERT (jerry_value_has_error_flag (res));
|
||||
|
||||
// 'res' should contain exception object
|
||||
TEST_ASSERT (jerry_value_is_object (res));
|
||||
jerry_release_value (res);
|
||||
|
||||
jerry_release_value (obj_val);
|
||||
|
||||
// Test: Unhandled exception in function called, as constructor
|
||||
val_t = get_property (global_obj_val, "throw_reference_error");
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (val_t));
|
||||
TEST_ASSERT (jerry_value_is_object (val_t));
|
||||
|
||||
res = jerry_construct_object (val_t, NULL, 0);
|
||||
TEST_ASSERT (jerry_value_has_error_flag (res));
|
||||
jerry_release_value (val_t);
|
||||
|
||||
// 'res' should contain exception object
|
||||
TEST_ASSERT (jerry_value_is_object (res));
|
||||
jerry_release_value (res);
|
||||
|
||||
// Test: Call of non-function as constructor
|
||||
obj_val = jerry_create_object ();
|
||||
res = jerry_construct_object (obj_val, NULL, 0);
|
||||
TEST_ASSERT (jerry_value_has_error_flag (res));
|
||||
|
||||
// 'res' should contain exception object
|
||||
TEST_ASSERT (jerry_value_is_object (res));
|
||||
jerry_release_value (res);
|
||||
|
||||
jerry_release_value (obj_val);
|
||||
|
||||
// Test: Array Object API
|
||||
jerry_value_t array_obj_val = jerry_create_array (10);
|
||||
TEST_ASSERT (jerry_value_is_array (array_obj_val));
|
||||
TEST_ASSERT (jerry_get_array_length (array_obj_val) == 10);
|
||||
|
||||
jerry_value_t v_in = jerry_create_number (10.5);
|
||||
jerry_set_property_by_index (array_obj_val, 5, v_in);
|
||||
jerry_value_t v_out = jerry_get_property_by_index (array_obj_val, 5);
|
||||
|
||||
TEST_ASSERT (jerry_value_is_number (v_out)
|
||||
&& jerry_get_number_value (v_out) == 10.5);
|
||||
|
||||
jerry_release_value (v_in);
|
||||
jerry_release_value (v_out);
|
||||
jerry_release_value (array_obj_val);
|
||||
|
||||
// Test: init property descriptor
|
||||
jerry_property_descriptor_t prop_desc;
|
||||
jerry_init_property_descriptor_fields (&prop_desc);
|
||||
TEST_ASSERT (prop_desc.is_value_defined == false);
|
||||
TEST_ASSERT (jerry_value_is_undefined (prop_desc.value));
|
||||
TEST_ASSERT (prop_desc.is_writable_defined == false);
|
||||
TEST_ASSERT (prop_desc.is_writable == false);
|
||||
TEST_ASSERT (prop_desc.is_enumerable_defined == false);
|
||||
TEST_ASSERT (prop_desc.is_enumerable == false);
|
||||
TEST_ASSERT (prop_desc.is_configurable_defined == false);
|
||||
TEST_ASSERT (prop_desc.is_configurable == false);
|
||||
TEST_ASSERT (prop_desc.is_get_defined == false);
|
||||
TEST_ASSERT (jerry_value_is_undefined (prop_desc.getter));
|
||||
TEST_ASSERT (prop_desc.is_set_defined == false);
|
||||
TEST_ASSERT (jerry_value_is_undefined (prop_desc.setter));
|
||||
|
||||
// Test: define own properties
|
||||
jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "my_defined_property");
|
||||
prop_desc.is_value_defined = true;
|
||||
prop_desc.value = jerry_acquire_value (prop_name);
|
||||
res = jerry_define_own_property (global_obj_val, prop_name, &prop_desc);
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (res));
|
||||
TEST_ASSERT (jerry_value_is_boolean (res));
|
||||
TEST_ASSERT (jerry_get_boolean_value (res));
|
||||
jerry_release_value (res);
|
||||
jerry_free_property_descriptor_fields (&prop_desc);
|
||||
|
||||
// Test: get own property descriptor
|
||||
is_ok = jerry_get_own_property_descriptor (global_obj_val, prop_name, &prop_desc);
|
||||
TEST_ASSERT (is_ok);
|
||||
TEST_ASSERT (prop_desc.is_value_defined == true);
|
||||
TEST_ASSERT (jerry_value_is_string (prop_desc.value));
|
||||
TEST_ASSERT (prop_desc.is_writable == false);
|
||||
TEST_ASSERT (prop_desc.is_enumerable == false);
|
||||
TEST_ASSERT (prop_desc.is_configurable == false);
|
||||
TEST_ASSERT (prop_desc.is_get_defined == false);
|
||||
TEST_ASSERT (jerry_value_is_undefined (prop_desc.getter));
|
||||
TEST_ASSERT (prop_desc.is_set_defined == false);
|
||||
TEST_ASSERT (jerry_value_is_undefined (prop_desc.setter));
|
||||
jerry_release_value (prop_name);
|
||||
jerry_free_property_descriptor_fields (&prop_desc);
|
||||
|
||||
// Test: object keys
|
||||
res = jerry_get_object_keys (global_obj_val);
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (res));
|
||||
TEST_ASSERT (jerry_value_is_array (res));
|
||||
jerry_release_value (res);
|
||||
|
||||
// Test: jerry_value_to_primitive
|
||||
obj_val = jerry_eval ((jerry_char_t *) "new String ('hello')", 20, false);
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (obj_val));
|
||||
TEST_ASSERT (jerry_value_is_object (obj_val));
|
||||
TEST_ASSERT (!jerry_value_is_string (obj_val));
|
||||
prim_val = jerry_value_to_primitive (obj_val);
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (prim_val));
|
||||
TEST_ASSERT (jerry_value_is_string (prim_val));
|
||||
jerry_release_value (prim_val);
|
||||
|
||||
// Test: jerry_get_prototype
|
||||
proto_val = jerry_get_prototype (obj_val);
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (proto_val));
|
||||
TEST_ASSERT (jerry_value_is_object (proto_val));
|
||||
jerry_release_value (obj_val);
|
||||
|
||||
// Test: jerry_set_prototype
|
||||
obj_val = jerry_create_object ();
|
||||
res = jerry_set_prototype (obj_val, jerry_create_null ());
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (res));
|
||||
TEST_ASSERT (jerry_value_is_boolean (res));
|
||||
TEST_ASSERT (jerry_get_boolean_value (res));
|
||||
|
||||
res = jerry_set_prototype (obj_val, jerry_create_object ());
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (res));
|
||||
TEST_ASSERT (jerry_value_is_boolean (res));
|
||||
TEST_ASSERT (jerry_get_boolean_value (res));
|
||||
proto_val = jerry_get_prototype (obj_val);
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (proto_val));
|
||||
TEST_ASSERT (jerry_value_is_object (proto_val));
|
||||
jerry_release_value (proto_val);
|
||||
jerry_release_value (obj_val);
|
||||
|
||||
// Test: eval
|
||||
const char *eval_code_src_p = "(function () { return 123; })";
|
||||
val_t = jerry_eval ((jerry_char_t *) eval_code_src_p, strlen (eval_code_src_p), true);
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (val_t));
|
||||
TEST_ASSERT (jerry_value_is_object (val_t));
|
||||
TEST_ASSERT (jerry_value_is_function (val_t));
|
||||
|
||||
res = jerry_call_function (val_t, jerry_create_undefined (), NULL, 0);
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (res));
|
||||
TEST_ASSERT (jerry_value_is_number (res)
|
||||
&& jerry_get_number_value (res) == 123.0);
|
||||
jerry_release_value (res);
|
||||
|
||||
jerry_release_value (val_t);
|
||||
|
||||
// cleanup.
|
||||
jerry_release_value (global_obj_val);
|
||||
|
||||
// Test: run gc.
|
||||
jerry_gc ();
|
||||
|
||||
// Test: number
|
||||
val_t = jerry_create_number (6.25);
|
||||
number_val = jerry_get_number_value (val_t);
|
||||
TEST_ASSERT (number_val * 3 == 18.75);
|
||||
jerry_release_value (val_t);
|
||||
|
||||
val_t = jerry_create_number_infinity (true);
|
||||
number_val = jerry_get_number_value (val_t);
|
||||
TEST_ASSERT (number_val * 3 == number_val && number_val != 0.0);
|
||||
jerry_release_value (val_t);
|
||||
|
||||
val_t = jerry_create_number_nan ();
|
||||
number_val = jerry_get_number_value (val_t);
|
||||
TEST_ASSERT (number_val != number_val);
|
||||
jerry_release_value (val_t);
|
||||
|
||||
jerry_cleanup ();
|
||||
|
||||
TEST_ASSERT (test_api_is_free_callback_was_called);
|
||||
|
||||
// Test: parser error location
|
||||
jerry_init (JERRY_INIT_SHOW_OPCODES);
|
||||
|
||||
const char *parser_err_src_p = "b = 'hello';\nvar a = (;";
|
||||
parsed_code_val = jerry_parse ((jerry_char_t *) parser_err_src_p,
|
||||
strlen (parser_err_src_p),
|
||||
false);
|
||||
TEST_ASSERT (jerry_value_has_error_flag (parsed_code_val));
|
||||
jerry_value_clear_error_flag (&parsed_code_val);
|
||||
jerry_value_t err_str_val = jerry_value_to_string (parsed_code_val);
|
||||
jerry_size_t err_str_size = jerry_get_string_size (err_str_val);
|
||||
jerry_char_t err_str_buf[256];
|
||||
sz = jerry_string_to_char_buffer (err_str_val, err_str_buf, err_str_size);
|
||||
err_str_buf[sz] = 0;
|
||||
|
||||
jerry_release_value (err_str_val);
|
||||
jerry_release_value (parsed_code_val);
|
||||
|
||||
TEST_ASSERT (!strcmp ((char *) err_str_buf,
|
||||
"SyntaxError: Primary expression expected. [line: 2, column: 10]"));
|
||||
jerry_cleanup ();
|
||||
|
||||
// External Magic String
|
||||
jerry_init (JERRY_INIT_SHOW_OPCODES);
|
||||
|
||||
uint32_t num_magic_string_items = (uint32_t) (sizeof (magic_string_items) / sizeof (jerry_char_ptr_t));
|
||||
jerry_register_magic_strings (magic_string_items,
|
||||
num_magic_string_items,
|
||||
magic_string_lengths);
|
||||
|
||||
const char *ms_code_src_p = "var global = {}; var console = [1]; var process = 1;";
|
||||
parsed_code_val = jerry_parse ((jerry_char_t *) ms_code_src_p, strlen (ms_code_src_p), false);
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (parsed_code_val));
|
||||
|
||||
res = jerry_run (parsed_code_val);
|
||||
TEST_ASSERT (!jerry_value_has_error_flag (res));
|
||||
jerry_release_value (res);
|
||||
jerry_release_value (parsed_code_val);
|
||||
|
||||
jerry_cleanup ();
|
||||
|
||||
// Dump / execute snapshot
|
||||
if (true)
|
||||
{
|
||||
static uint8_t global_mode_snapshot_buffer[1024];
|
||||
static uint8_t eval_mode_snapshot_buffer[1024];
|
||||
|
||||
const char *code_to_snapshot_p = "(function () { return 'string from snapshot'; }) ();";
|
||||
|
||||
jerry_init (JERRY_INIT_SHOW_OPCODES);
|
||||
size_t global_mode_snapshot_size = jerry_parse_and_save_snapshot ((jerry_char_t *) code_to_snapshot_p,
|
||||
strlen (code_to_snapshot_p),
|
||||
true,
|
||||
false,
|
||||
global_mode_snapshot_buffer,
|
||||
sizeof (global_mode_snapshot_buffer));
|
||||
TEST_ASSERT (global_mode_snapshot_size != 0);
|
||||
jerry_cleanup ();
|
||||
|
||||
jerry_init (JERRY_INIT_SHOW_OPCODES);
|
||||
size_t eval_mode_snapshot_size = jerry_parse_and_save_snapshot ((jerry_char_t *) code_to_snapshot_p,
|
||||
strlen (code_to_snapshot_p),
|
||||
false,
|
||||
false,
|
||||
eval_mode_snapshot_buffer,
|
||||
sizeof (eval_mode_snapshot_buffer));
|
||||
TEST_ASSERT (eval_mode_snapshot_size != 0);
|
||||
jerry_cleanup ();
|
||||
|
||||
jerry_init (JERRY_INIT_SHOW_OPCODES);
|
||||
|
||||
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));
|
||||
sz = jerry_get_string_size (res);
|
||||
TEST_ASSERT (sz == 20);
|
||||
sz = jerry_string_to_char_buffer (res, (jerry_char_t *) buffer, sz);
|
||||
TEST_ASSERT (sz == 20);
|
||||
jerry_release_value (res);
|
||||
TEST_ASSERT (!strncmp (buffer, "string from snapshot", (size_t) sz));
|
||||
|
||||
res = jerry_exec_snapshot (eval_mode_snapshot_buffer,
|
||||
eval_mode_snapshot_size,
|
||||
false);
|
||||
|
||||
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 *) buffer, sz);
|
||||
TEST_ASSERT (sz == 20);
|
||||
jerry_release_value (res);
|
||||
TEST_ASSERT (!strncmp (buffer, "string from snapshot", (size_t) sz));
|
||||
|
||||
jerry_cleanup ();
|
||||
}
|
||||
|
||||
return 0;
|
||||
} /* main */
|
72
third_party/jerryscript/tests/unit/test-common.h
vendored
Normal file
72
third_party/jerryscript/tests/unit/test-common.h
vendored
Normal file
|
@ -0,0 +1,72 @@
|
|||
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2016 University of Szeged
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TEST_COMMON_H
|
||||
#define TEST_COMMON_H
|
||||
|
||||
#include "jrt.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <setjmp.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
#define TEST_ASSERT(x) \
|
||||
do \
|
||||
{ \
|
||||
if (unlikely (!(x))) \
|
||||
{ \
|
||||
jerry_port_log (JERRY_LOG_LEVEL_ERROR, \
|
||||
"TEST: Assertion '%s' failed at %s(%s):%lu.\n", \
|
||||
#x, \
|
||||
__FILE__, \
|
||||
__func__, \
|
||||
(unsigned long) __LINE__); \
|
||||
jerry_fatal (ERR_FAILED_INTERNAL_ASSERTION); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* Test initialization statement that should be included
|
||||
* at the beginning of main function in every unit test.
|
||||
*/
|
||||
#define TEST_INIT() \
|
||||
do \
|
||||
{ \
|
||||
FILE *f_rnd = fopen ("/dev/urandom", "r"); \
|
||||
\
|
||||
if (f_rnd == NULL) \
|
||||
{ \
|
||||
return 1; \
|
||||
} \
|
||||
\
|
||||
uint32_t seed; \
|
||||
\
|
||||
size_t bytes_read = fread (&seed, 1, sizeof (seed), f_rnd); \
|
||||
\
|
||||
fclose (f_rnd); \
|
||||
\
|
||||
if (bytes_read != sizeof (seed)) \
|
||||
{ \
|
||||
return 1; \
|
||||
} \
|
||||
\
|
||||
srand (seed); \
|
||||
} while (0)
|
||||
|
||||
#endif /* TEST_COMMON_H */
|
175
third_party/jerryscript/tests/unit/test-date-helpers.c
vendored
Normal file
175
third_party/jerryscript/tests/unit/test-date-helpers.c
vendored
Normal file
|
@ -0,0 +1,175 @@
|
|||
/* Copyright 2015-2016 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2015-2016 University of Szeged.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-builtin-helpers.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
|
||||
#include "test-common.h"
|
||||
|
||||
#define MS_PER_DAY ((ecma_number_t) 86400000)
|
||||
#define MS_PER_YEAR ((ecma_number_t) 365 * MS_PER_DAY)
|
||||
#define START_OF_GREGORIAN_CALENDAR ((ecma_number_t) (-1970 * MS_PER_YEAR \
|
||||
- (1970 / 4) * MS_PER_DAY \
|
||||
+ (1970 / 100) * MS_PER_DAY \
|
||||
- (1970 / 400) * MS_PER_DAY \
|
||||
- MS_PER_DAY))
|
||||
|
||||
/**
|
||||
* Unit test's main function.
|
||||
*/
|
||||
int
|
||||
main ()
|
||||
{
|
||||
/* int ecma_date_day (time)*/
|
||||
|
||||
TEST_ASSERT (ecma_date_day (0) == 0);
|
||||
TEST_ASSERT (ecma_date_day (MS_PER_DAY) == 1);
|
||||
|
||||
/* ecma_number_t ecma_date_time_within_day (time) */
|
||||
|
||||
TEST_ASSERT (ecma_date_time_within_day (0) == 0);
|
||||
TEST_ASSERT (ecma_date_time_within_day (42) == 42);
|
||||
TEST_ASSERT (ecma_date_time_within_day (42.51) == 42.51);
|
||||
TEST_ASSERT (ecma_date_time_within_day (MS_PER_DAY + 42) == 42);
|
||||
|
||||
/* int ecma_date_days_in_year (year) */
|
||||
|
||||
TEST_ASSERT (ecma_date_days_in_year (0) == 366);
|
||||
TEST_ASSERT (ecma_date_days_in_year (1600) == 366);
|
||||
TEST_ASSERT (ecma_date_days_in_year (1603) == 365);
|
||||
TEST_ASSERT (ecma_date_days_in_year (1900) == 365);
|
||||
TEST_ASSERT (ecma_date_days_in_year (1970) == 365);
|
||||
TEST_ASSERT (ecma_date_days_in_year (2000) == 366);
|
||||
TEST_ASSERT (ecma_date_days_in_year (2000.45) == 366);
|
||||
TEST_ASSERT (ecma_date_days_in_year (2012) == 366);
|
||||
TEST_ASSERT (ecma_date_days_in_year (2015) == 365);
|
||||
TEST_ASSERT (ecma_date_days_in_year (285616 + 1970) == 365);
|
||||
TEST_ASSERT (ecma_date_days_in_year (-1970) == 365);
|
||||
|
||||
/* int ecma_date_day_from_year (year) */
|
||||
|
||||
TEST_ASSERT (ecma_date_day_from_year (1969) == -365);
|
||||
TEST_ASSERT (ecma_date_day_from_year (1970) == 0);
|
||||
TEST_ASSERT (ecma_date_day_from_year (1971) == 365);
|
||||
TEST_ASSERT (ecma_date_day_from_year (2000) == 10957);
|
||||
|
||||
/* int ecma_date_year_from_time (time) */
|
||||
|
||||
TEST_ASSERT (ecma_date_year_from_time (0) == 1970);
|
||||
TEST_ASSERT (ecma_date_year_from_time (0) == 1970);
|
||||
TEST_ASSERT (ecma_date_year_from_time (MS_PER_DAY) == 1970);
|
||||
TEST_ASSERT (ecma_date_year_from_time ((MS_PER_DAY) * (ecma_number_t) 365 - 1) == 1970);
|
||||
TEST_ASSERT (ecma_date_year_from_time (MS_PER_DAY * (ecma_number_t) 365) == 1971);
|
||||
TEST_ASSERT (ecma_date_year_from_time (MS_PER_DAY * (ecma_number_t) (365 * (2015 - 1970)))
|
||||
== 2014);
|
||||
TEST_ASSERT (ecma_date_year_from_time (MS_PER_DAY * (ecma_number_t) (365.25 * (2015 - 1970)))
|
||||
== 2015);
|
||||
TEST_ASSERT (ecma_date_year_from_time (-MS_PER_YEAR) == 1969);
|
||||
TEST_ASSERT (ecma_date_year_from_time (-1970 * MS_PER_YEAR) == 1);
|
||||
TEST_ASSERT (ecma_date_year_from_time (START_OF_GREGORIAN_CALENDAR) == 0);
|
||||
TEST_ASSERT (ecma_date_year_from_time (START_OF_GREGORIAN_CALENDAR - 1) == -1);
|
||||
TEST_ASSERT (ecma_date_year_from_time (START_OF_GREGORIAN_CALENDAR - 3 * MS_PER_YEAR) == -3);
|
||||
|
||||
/* int ecma_date_day_within_year (time) */
|
||||
|
||||
/* FIXME: Implement */
|
||||
|
||||
/* int ecma_date_month_from_time (time) */
|
||||
|
||||
TEST_ASSERT (ecma_date_month_from_time (START_OF_GREGORIAN_CALENDAR) == 0);
|
||||
TEST_ASSERT (ecma_date_month_from_time (0) == 0);
|
||||
TEST_ASSERT (ecma_date_month_from_time (-MS_PER_DAY) == 11);
|
||||
TEST_ASSERT (ecma_date_month_from_time (31 * MS_PER_DAY) == 1);
|
||||
|
||||
/* int ecma_date_date_from_time (time) */
|
||||
|
||||
TEST_ASSERT (ecma_date_date_from_time (START_OF_GREGORIAN_CALENDAR) == 1);
|
||||
TEST_ASSERT (ecma_date_date_from_time (0) == 1);
|
||||
TEST_ASSERT (ecma_date_date_from_time (-MS_PER_DAY) == 31);
|
||||
TEST_ASSERT (ecma_date_date_from_time (31 * MS_PER_DAY) == 1);
|
||||
|
||||
/* int ecma_date_week_day (ecma_number_t time) */
|
||||
|
||||
/* FIXME: Implement */
|
||||
|
||||
/* ecma_number_t ecma_date_local_tza () */
|
||||
|
||||
/* FIXME: Implement */
|
||||
|
||||
/* ecma_number_t ecma_date_daylight_saving_ta (time) */
|
||||
|
||||
/* FIXME: Implement */
|
||||
|
||||
/* ecma_number_t ecma_date_local_time (time) */
|
||||
|
||||
/* FIXME: Implement */
|
||||
|
||||
/* ecma_number_t ecma_date_utc (time) */
|
||||
|
||||
/* FIXME: Implement */
|
||||
|
||||
/* ecma_number_t ecma_date_hour_from_time (time) */
|
||||
|
||||
TEST_ASSERT (ecma_date_hour_from_time (START_OF_GREGORIAN_CALENDAR) == 0);
|
||||
TEST_ASSERT (ecma_date_hour_from_time (0) == 0);
|
||||
TEST_ASSERT (ecma_date_hour_from_time (-MS_PER_DAY) == 0);
|
||||
TEST_ASSERT (ecma_date_hour_from_time (-1) == 23);
|
||||
|
||||
/* ecma_number_t ecma_date_min_from_time (time) */
|
||||
|
||||
TEST_ASSERT (ecma_date_min_from_time (START_OF_GREGORIAN_CALENDAR) == 0);
|
||||
TEST_ASSERT (ecma_date_min_from_time (0) == 0);
|
||||
TEST_ASSERT (ecma_date_min_from_time (-MS_PER_DAY) == 0);
|
||||
TEST_ASSERT (ecma_date_min_from_time (-1) == 59);
|
||||
|
||||
/* ecma_number_t ecma_date_sec_from_time (time) */
|
||||
|
||||
TEST_ASSERT (ecma_date_sec_from_time (START_OF_GREGORIAN_CALENDAR) == 0);
|
||||
TEST_ASSERT (ecma_date_sec_from_time (0) == 0);
|
||||
TEST_ASSERT (ecma_date_sec_from_time (-MS_PER_DAY) == 0);
|
||||
TEST_ASSERT (ecma_date_sec_from_time (-1) == 59);
|
||||
|
||||
/* ecma_number_t ecma_date_ms_from_time (time) */
|
||||
|
||||
TEST_ASSERT (ecma_date_ms_from_time (START_OF_GREGORIAN_CALENDAR) == 0);
|
||||
TEST_ASSERT (ecma_date_ms_from_time (0) == 0);
|
||||
TEST_ASSERT (ecma_date_ms_from_time (-MS_PER_DAY) == 0);
|
||||
TEST_ASSERT (ecma_date_ms_from_time (-1) == 999);
|
||||
|
||||
/* ecma_number_t ecma_date_make_time (hour, min, sec, ms) */
|
||||
|
||||
/* FIXME: Implement */
|
||||
|
||||
/* ecma_number_t ecma_date_make_day (year, month, date) */
|
||||
|
||||
TEST_ASSERT (ecma_date_make_day (1970, 0, 1) == 0);
|
||||
TEST_ASSERT (ecma_date_make_day (1970, -1, 1) == -31);
|
||||
TEST_ASSERT (ecma_date_make_day (1970, 0, 2.5) == 1);
|
||||
TEST_ASSERT (ecma_date_make_day (1970, 1, 35) == 65);
|
||||
TEST_ASSERT (ecma_date_make_day (1970, 13, 35) == 430);
|
||||
TEST_ASSERT (ecma_date_make_day (2016, 2, 1) == 16861);
|
||||
|
||||
/* ecma_number_t ecma_date_make_date (day, time) */
|
||||
|
||||
/* FIXME: Implement */
|
||||
|
||||
/* ecma_number_t ecma_date_time_clip (year) */
|
||||
|
||||
/* FIXME: Implement */
|
||||
|
||||
return 0;
|
||||
} /* main */
|
119
third_party/jerryscript/tests/unit/test-heap.c
vendored
Normal file
119
third_party/jerryscript/tests/unit/test-heap.c
vendored
Normal file
|
@ -0,0 +1,119 @@
|
|||
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2016 University of Szeged.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "jmem-allocator.h"
|
||||
|
||||
#include "test-common.h"
|
||||
|
||||
// Heap size is 32K
|
||||
#define test_heap_size (32 * 1024)
|
||||
|
||||
// Iterations count
|
||||
#define test_iters (4 * 1024)
|
||||
|
||||
// Subiterations count
|
||||
#define test_sub_iters 32
|
||||
|
||||
// Threshold size of block to allocate
|
||||
#define test_threshold_block_size 8192
|
||||
|
||||
uint8_t *ptrs[test_sub_iters];
|
||||
size_t sizes[test_sub_iters];
|
||||
bool is_one_chunked[test_sub_iters];
|
||||
|
||||
static void
|
||||
test_heap_give_some_memory_back (jmem_free_unused_memory_severity_t severity)
|
||||
{
|
||||
int p;
|
||||
|
||||
if (severity == JMEM_FREE_UNUSED_MEMORY_SEVERITY_LOW)
|
||||
{
|
||||
p = 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
TEST_ASSERT (severity == JMEM_FREE_UNUSED_MEMORY_SEVERITY_HIGH);
|
||||
|
||||
p = 1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < test_sub_iters; i++)
|
||||
{
|
||||
if (rand () % p == 0)
|
||||
{
|
||||
if (ptrs[i] != NULL)
|
||||
{
|
||||
for (size_t k = 0; k < sizes[i]; k++)
|
||||
{
|
||||
TEST_ASSERT (ptrs[i][k] == 0);
|
||||
}
|
||||
|
||||
jmem_heap_free_block (ptrs[i], sizes[i]);
|
||||
ptrs[i] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
} /* test_heap_give_some_memory_back */
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
TEST_INIT ();
|
||||
|
||||
jmem_heap_init ();
|
||||
|
||||
jmem_register_free_unused_memory_callback (test_heap_give_some_memory_back);
|
||||
|
||||
#ifdef JMEM_STATS
|
||||
jmem_heap_stats_print ();
|
||||
#endif /* JMEM_STATS */
|
||||
|
||||
for (uint32_t i = 0; i < test_iters; i++)
|
||||
{
|
||||
for (uint32_t j = 0; j < test_sub_iters; j++)
|
||||
{
|
||||
size_t size = (size_t) rand () % test_threshold_block_size;
|
||||
ptrs[j] = (uint8_t *) jmem_heap_alloc_block (size);
|
||||
sizes[j] = size;
|
||||
|
||||
TEST_ASSERT (sizes[j] == 0 || ptrs[j] != NULL);
|
||||
memset (ptrs[j], 0, sizes[j]);
|
||||
}
|
||||
|
||||
/* jmem_heap_print (true); */
|
||||
|
||||
for (uint32_t j = 0; j < test_sub_iters; j++)
|
||||
{
|
||||
if (ptrs[j] != NULL)
|
||||
{
|
||||
for (size_t k = 0; k < sizes[j]; k++)
|
||||
{
|
||||
TEST_ASSERT (ptrs[j][k] == 0);
|
||||
}
|
||||
|
||||
jmem_heap_free_block (ptrs[j], sizes[j]);
|
||||
|
||||
ptrs[j] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef JMEM_STATS
|
||||
jmem_heap_stats_print ();
|
||||
#endif /* JMEM_STATS */
|
||||
|
||||
return 0;
|
||||
} /* main */
|
94
third_party/jerryscript/tests/unit/test-libm.c
vendored
Normal file
94
third_party/jerryscript/tests/unit/test-libm.c
vendored
Normal file
|
@ -0,0 +1,94 @@
|
|||
/* Copyright 2016 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2016 University of Szeged.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Unit test for jerry-libm
|
||||
*/
|
||||
|
||||
#include "test-common.h"
|
||||
|
||||
static bool passed = true;
|
||||
|
||||
static void
|
||||
check_int (const char *expr, int computed, int expected)
|
||||
{
|
||||
printf ("%s = %d [expected=%d] ", expr, computed, expected);
|
||||
|
||||
bool result = computed == expected;
|
||||
printf ("%s\n", result ? "PASS" : "FAIL");
|
||||
|
||||
passed &= result;
|
||||
} /* check_int */
|
||||
|
||||
typedef union
|
||||
{
|
||||
double value;
|
||||
uint64_t bits64;
|
||||
uint32_t bits32[2];
|
||||
} double_bits_t;
|
||||
|
||||
static void
|
||||
check_double (const char *expr, double computed, double expected)
|
||||
{
|
||||
double_bits_t computed_bits;
|
||||
double_bits_t expected_bits;
|
||||
|
||||
computed_bits.value = computed;
|
||||
expected_bits.value = expected;
|
||||
|
||||
printf ("%s = 0x%08x%08x [expected=0x%08x%08x] ", expr,
|
||||
(unsigned int) computed_bits.bits32[1], (unsigned int) computed_bits.bits32[0],
|
||||
(unsigned int) expected_bits.bits32[1], (unsigned int) expected_bits.bits32[0]);
|
||||
|
||||
bool result;
|
||||
if (isnan (computed) && isnan (expected))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
int64_t diff = (int64_t) (computed_bits.bits64 - expected_bits.bits64);
|
||||
if (diff < 0)
|
||||
{
|
||||
diff = -diff;
|
||||
}
|
||||
|
||||
if (diff <= 1) /* tolerate 1 bit of differene in the last place */
|
||||
{
|
||||
result = true;
|
||||
if (diff != 0)
|
||||
{
|
||||
printf ("APPROX ");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
printf ("%s\n", result ? "PASS" : "FAIL");
|
||||
|
||||
passed &= result;
|
||||
} /* check_double */
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
#define INF INFINITY
|
||||
#include "test-libm.inc.h"
|
||||
|
||||
return passed ? 0 : 1;
|
||||
} /* main */
|
584
third_party/jerryscript/tests/unit/test-libm.inc.h
vendored
Normal file
584
third_party/jerryscript/tests/unit/test-libm.inc.h
vendored
Normal file
|
@ -0,0 +1,584 @@
|
|||
/* Copyright 2016 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2016 University of Szeged.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Generated by tools/gen-test-libm.sh
|
||||
* DO NOT EDIT!!!
|
||||
*/
|
||||
check_double ("acos (0.0)", acos (0.0), 1.57079632679489655800E+00);
|
||||
check_double ("acos (-0.0)", acos (-0.0), 1.57079632679489655800E+00);
|
||||
check_double ("acos (1.0)", acos (1.0), 0.00000000000000000000E+00);
|
||||
check_double ("acos (-1.0)", acos (-1.0), 3.14159265358979311600E+00);
|
||||
check_double ("acos (0.5)", acos (0.5), 1.04719755119659785336E+00);
|
||||
check_double ("acos (-0.5)", acos (-0.5), 2.09439510239319570672E+00);
|
||||
check_double ("acos (INFINITY)", acos (INFINITY), NAN);
|
||||
check_double ("acos (-INFINITY)", acos (-INFINITY), NAN);
|
||||
check_double ("acos (NAN)", acos (NAN), NAN);
|
||||
check_double ("acos (6.9e-18)", acos (6.9e-18), 1.57079632679489655800E+00);
|
||||
check_double ("acos (-6.9e-18)", acos (-6.9e-18), 1.57079632679489655800E+00);
|
||||
check_double ("acos (7.0e-18)", acos (7.0e-18), 1.57079632679489655800E+00);
|
||||
check_double ("acos (-7.0e-18)", acos (-7.0e-18), 1.57079632679489655800E+00);
|
||||
check_double ("acos (7.4e-9)", acos (7.4e-9), 1.57079631939489661185E+00);
|
||||
check_double ("acos (-7.4e-9)", acos (-7.4e-9), 1.57079633419489672619E+00);
|
||||
check_double ("acos (7.5e-9)", acos (7.5e-9), 1.57079631929489660358E+00);
|
||||
check_double ("acos (-7.5e-9)", acos (-7.5e-9), 1.57079633429489651242E+00);
|
||||
check_double ("acos (0.1)", acos (0.1), 1.47062890563333681371E+00);
|
||||
check_double ("acos (-0.1)", acos (-0.1), 1.67096374795645652434E+00);
|
||||
check_double ("acos (0.4)", acos (0.4), 1.15927948072740849561E+00);
|
||||
check_double ("acos (-0.4)", acos (-0.4), 1.98231317286238462039E+00);
|
||||
check_double ("acos (0.6)", acos (0.6), 9.27295218001612298053E-01);
|
||||
check_double ("acos (-0.6)", acos (-0.6), 2.21429743558818081794E+00);
|
||||
check_double ("acos (0.99)", acos (0.99), 1.41539473324427289569E-01);
|
||||
check_double ("acos (-0.99)", acos (-0.99), 3.00005318026536604847E+00);
|
||||
check_double ("acos (1.1)", acos (1.1), NAN);
|
||||
check_double ("acos (-1.1)", acos (-1.1), NAN);
|
||||
check_double ("acos (0.7)", acos (0.7), 7.95398830184143590394E-01);
|
||||
check_double ("asin (0.0)", asin (0.0), 0.00000000000000000000E+00);
|
||||
check_double ("asin (-0.0)", asin (-0.0), -0.00000000000000000000E+00);
|
||||
check_double ("asin (1.0)", asin (1.0), 1.57079632679489655800E+00);
|
||||
check_double ("asin (-1.0)", asin (-1.0), -1.57079632679489655800E+00);
|
||||
check_double ("asin (0.5)", asin (0.5), 5.23598775598298926681E-01);
|
||||
check_double ("asin (-0.5)", asin (-0.5), -5.23598775598298926681E-01);
|
||||
check_double ("asin (0.98)", asin (0.98), 1.37046148447177684737E+00);
|
||||
check_double ("asin (-0.98)", asin (-0.98), -1.37046148447177684737E+00);
|
||||
check_double ("asin (INFINITY)", asin (INFINITY), NAN);
|
||||
check_double ("asin (-INFINITY)", asin (-INFINITY), NAN);
|
||||
check_double ("asin (NAN)", asin (NAN), NAN);
|
||||
check_double ("asin (6.9e-18)", asin (6.9e-18), 6.90000000000000026253E-18);
|
||||
check_double ("asin (-6.9e-18)", asin (-6.9e-18), -6.90000000000000026253E-18);
|
||||
check_double ("asin (7.0e-18)", asin (7.0e-18), 6.99999999999999973042E-18);
|
||||
check_double ("asin (-7.0e-18)", asin (-7.0e-18), -6.99999999999999973042E-18);
|
||||
check_double ("asin (7.4e-9)", asin (7.4e-9), 7.40000000000000008865E-09);
|
||||
check_double ("asin (-7.4e-9)", asin (-7.4e-9), -7.40000000000000008865E-09);
|
||||
check_double ("asin (7.5e-9)", asin (7.5e-9), 7.49999999999999932974E-09);
|
||||
check_double ("asin (-7.5e-9)", asin (-7.5e-9), -7.49999999999999932974E-09);
|
||||
check_double ("asin (0.1)", asin (0.1), 1.00167421161559799803E-01);
|
||||
check_double ("asin (-0.1)", asin (-0.1), -1.00167421161559799803E-01);
|
||||
check_double ("asin (0.4)", asin (0.4), 4.11516846067488062388E-01);
|
||||
check_double ("asin (-0.4)", asin (-0.4), -4.11516846067488062388E-01);
|
||||
check_double ("asin (0.6)", asin (0.6), 6.43501108793284370968E-01);
|
||||
check_double ("asin (-0.6)", asin (-0.6), -6.43501108793284370968E-01);
|
||||
check_double ("asin (0.97)", asin (0.97), 1.32523080927960457132E+00);
|
||||
check_double ("asin (-0.97)", asin (-0.97), -1.32523080927960457132E+00);
|
||||
check_double ("asin (0.99)", asin (0.99), 1.42925685347046926843E+00);
|
||||
check_double ("asin (-0.99)", asin (-0.99), -1.42925685347046926843E+00);
|
||||
check_double ("asin (1.1)", asin (1.1), NAN);
|
||||
check_double ("asin (-1.1)", asin (-1.1), NAN);
|
||||
check_double ("asin (0.7)", asin (0.7), 7.75397496610752967605E-01);
|
||||
check_double ("atan (0.0)", atan (0.0), 0.00000000000000000000E+00);
|
||||
check_double ("atan (-0.0)", atan (-0.0), -0.00000000000000000000E+00);
|
||||
check_double ("atan (7.0 / 16.0)", atan (7.0 / 16.0), 4.12410441597387322776E-01);
|
||||
check_double ("atan (-7.0 / 16.0)", atan (-7.0 / 16.0), -4.12410441597387322776E-01);
|
||||
check_double ("atan (11.0 / 16.0)", atan (11.0 / 16.0), 6.02287346134964152178E-01);
|
||||
check_double ("atan (-11.0 / 16.0)", atan (-11.0 / 16.0), -6.02287346134964152178E-01);
|
||||
check_double ("atan (19.0 / 16.0)", atan (19.0 / 16.0), 8.70903457075652975838E-01);
|
||||
check_double ("atan (-19.0 / 16.0)", atan (-19.0 / 16.0), -8.70903457075652975838E-01);
|
||||
check_double ("atan (39.0 / 16.0)", atan (39.0 / 16.0), 1.18147960496175574718E+00);
|
||||
check_double ("atan (-39.0 / 16.0)", atan (-39.0 / 16.0), -1.18147960496175574718E+00);
|
||||
check_double ("atan (1.0)", atan (1.0), 7.85398163397448278999E-01);
|
||||
check_double ("atan (-1.0)", atan (-1.0), -7.85398163397448278999E-01);
|
||||
check_double ("atan (INFINITY)", atan (INFINITY), 1.57079632679489655800E+00);
|
||||
check_double ("atan (-INFINITY)", atan (-INFINITY), -1.57079632679489655800E+00);
|
||||
check_double ("atan (NAN)", atan (NAN), NAN);
|
||||
check_double ("atan (6.9 / 16.0)", atan (6.9 / 16.0), 4.07152520941509277197E-01);
|
||||
check_double ("atan (-6.9 / 16.0)", atan (-6.9 / 16.0), -4.07152520941509277197E-01);
|
||||
check_double ("atan (7.1 / 16.0)", atan (7.1 / 16.0), 4.17644283240569735849E-01);
|
||||
check_double ("atan (-7.1 / 16.0)", atan (-7.1 / 16.0), -4.17644283240569735849E-01);
|
||||
check_double ("atan (10.9 / 16.0)", atan (10.9 / 16.0), 5.98030920656102416011E-01);
|
||||
check_double ("atan (-10.9 / 16.0)", atan (-10.9 / 16.0), -5.98030920656102416011E-01);
|
||||
check_double ("atan (11.1 / 16.0)", atan (11.1 / 16.0), 6.06519005615576589641E-01);
|
||||
check_double ("atan (-11.1 / 16.0)", atan (-11.1 / 16.0), -6.06519005615576589641E-01);
|
||||
check_double ("atan (18.9 / 16.0)", atan (18.9 / 16.0), 8.68302259886018612534E-01);
|
||||
check_double ("atan (-18.9 / 16.0)", atan (-18.9 / 16.0), -8.68302259886018612534E-01);
|
||||
check_double ("atan (19.1 / 16.0)", atan (19.1 / 16.0), 8.73488683179258762479E-01);
|
||||
check_double ("atan (-19.1 / 16.0)", atan (-19.1 / 16.0), -8.73488683179258762479E-01);
|
||||
check_double ("atan (38.9 / 16.0)", atan (38.9 / 16.0), 1.18057723083411603149E+00);
|
||||
check_double ("atan (-38.9 / 16.0)", atan (-38.9 / 16.0), -1.18057723083411603149E+00);
|
||||
check_double ("atan (39.1 / 16.0)", atan (39.1 / 16.0), 1.18237802686613768799E+00);
|
||||
check_double ("atan (-39.1 / 16.0)", atan (-39.1 / 16.0), -1.18237802686613768799E+00);
|
||||
check_double ("atan (0.99)", atan (0.99), 7.80373080066635860241E-01);
|
||||
check_double ("atan (-0.99)", atan (-0.99), -7.80373080066635860241E-01);
|
||||
check_double ("atan (1.1)", atan (1.1), 8.32981266674431730657E-01);
|
||||
check_double ("atan (-1.1)", atan (-1.1), -8.32981266674431730657E-01);
|
||||
check_double ("atan (7.37e+19)", atan (7.37e+19), 1.57079632679489655800E+00);
|
||||
check_double ("atan (-7.37e+19)", atan (-7.37e+19), -1.57079632679489655800E+00);
|
||||
check_double ("atan (7.38e+19)", atan (7.38e+19), 1.57079632679489655800E+00);
|
||||
check_double ("atan (-7.38e+19)", atan (-7.38e+19), -1.57079632679489655800E+00);
|
||||
check_double ("atan (0.7)", atan (0.7), 6.10725964389208564320E-01);
|
||||
check_double ("atan2 (NAN, NAN)", atan2 (NAN, NAN), NAN);
|
||||
check_double ("atan2 (0.0, NAN)", atan2 (0.0, NAN), NAN);
|
||||
check_double ("atan2 (-0.0, NAN)", atan2 (-0.0, NAN), NAN);
|
||||
check_double ("atan2 (1.0, NAN)", atan2 (1.0, NAN), NAN);
|
||||
check_double ("atan2 (-1.0, NAN)", atan2 (-1.0, NAN), NAN);
|
||||
check_double ("atan2 (INFINITY, NAN)", atan2 (INFINITY, NAN), NAN);
|
||||
check_double ("atan2 (-INFINITY, NAN)", atan2 (-INFINITY, NAN), NAN);
|
||||
check_double ("atan2 (NAN, 0.0)", atan2 (NAN, 0.0), NAN);
|
||||
check_double ("atan2 (NAN, -0.0)", atan2 (NAN, -0.0), NAN);
|
||||
check_double ("atan2 (NAN, 1.0)", atan2 (NAN, 1.0), NAN);
|
||||
check_double ("atan2 (NAN, -1.0)", atan2 (NAN, -1.0), NAN);
|
||||
check_double ("atan2 (NAN, INFINITY)", atan2 (NAN, INFINITY), NAN);
|
||||
check_double ("atan2 (NAN, -INFINITY)", atan2 (NAN, -INFINITY), NAN);
|
||||
check_double ("atan2 (0.0, 0.0)", atan2 (0.0, 0.0), 0.00000000000000000000E+00);
|
||||
check_double ("atan2 (0.0, -0.0)", atan2 (0.0, -0.0), 3.14159265358979311600E+00);
|
||||
check_double ("atan2 (-0.0, 0.0)", atan2 (-0.0, 0.0), -0.00000000000000000000E+00);
|
||||
check_double ("atan2 (-0.0, -0.0)", atan2 (-0.0, -0.0), -3.14159265358979311600E+00);
|
||||
check_double ("atan2 (0.0, 1.0)", atan2 (0.0, 1.0), 0.00000000000000000000E+00);
|
||||
check_double ("atan2 (0.0, -1.0)", atan2 (0.0, -1.0), 3.14159265358979311600E+00);
|
||||
check_double ("atan2 (0.0, INFINITY)", atan2 (0.0, INFINITY), 0.00000000000000000000E+00);
|
||||
check_double ("atan2 (0.0, -INFINITY)", atan2 (0.0, -INFINITY), 3.14159265358979311600E+00);
|
||||
check_double ("atan2 (-0.0, 1.0)", atan2 (-0.0, 1.0), -0.00000000000000000000E+00);
|
||||
check_double ("atan2 (-0.0, -1.0)", atan2 (-0.0, -1.0), -3.14159265358979311600E+00);
|
||||
check_double ("atan2 (-0.0, INFINITY)", atan2 (-0.0, INFINITY), -0.00000000000000000000E+00);
|
||||
check_double ("atan2 (-0.0, -INFINITY)", atan2 (-0.0, -INFINITY), -3.14159265358979311600E+00);
|
||||
check_double ("atan2 (1.0, 0.0)", atan2 (1.0, 0.0), 1.57079632679489655800E+00);
|
||||
check_double ("atan2 (1.0, -0.0)", atan2 (1.0, -0.0), 1.57079632679489655800E+00);
|
||||
check_double ("atan2 (INFINITY, 0.0)", atan2 (INFINITY, 0.0), 1.57079632679489655800E+00);
|
||||
check_double ("atan2 (INFINITY, -0.0)", atan2 (INFINITY, -0.0), 1.57079632679489655800E+00);
|
||||
check_double ("atan2 (-1.0, 0.0)", atan2 (-1.0, 0.0), -1.57079632679489655800E+00);
|
||||
check_double ("atan2 (-1.0, -0.0)", atan2 (-1.0, -0.0), -1.57079632679489655800E+00);
|
||||
check_double ("atan2 (-INFINITY, 0.0)", atan2 (-INFINITY, 0.0), -1.57079632679489655800E+00);
|
||||
check_double ("atan2 (-INFINITY, -0.0)", atan2 (-INFINITY, -0.0), -1.57079632679489655800E+00);
|
||||
check_double ("atan2 (1.0, INFINITY)", atan2 (1.0, INFINITY), 0.00000000000000000000E+00);
|
||||
check_double ("atan2 (-1.0, INFINITY)", atan2 (-1.0, INFINITY), -0.00000000000000000000E+00);
|
||||
check_double ("atan2 (1.0, -INFINITY)", atan2 (1.0, -INFINITY), 3.14159265358979311600E+00);
|
||||
check_double ("atan2 (-1.0, -INFINITY)", atan2 (-1.0, -INFINITY), -3.14159265358979311600E+00);
|
||||
check_double ("atan2 (INFINITY, INFINITY)", atan2 (INFINITY, INFINITY), 7.85398163397448278999E-01);
|
||||
check_double ("atan2 (INFINITY, -INFINITY)", atan2 (INFINITY, -INFINITY), 2.35619449019234483700E+00);
|
||||
check_double ("atan2 (-INFINITY, INFINITY)", atan2 (-INFINITY, INFINITY), -7.85398163397448278999E-01);
|
||||
check_double ("atan2 (-INFINITY, -INFINITY)", atan2 (-INFINITY, -INFINITY), -2.35619449019234483700E+00);
|
||||
check_double ("atan2 (INFINITY, 1.0)", atan2 (INFINITY, 1.0), 1.57079632679489655800E+00);
|
||||
check_double ("atan2 (INFINITY, -1.0)", atan2 (INFINITY, -1.0), 1.57079632679489655800E+00);
|
||||
check_double ("atan2 (-INFINITY, 1.0)", atan2 (-INFINITY, 1.0), -1.57079632679489655800E+00);
|
||||
check_double ("atan2 (-INFINITY, -1.0)", atan2 (-INFINITY, -1.0), -1.57079632679489655800E+00);
|
||||
check_double ("atan2 (0.7, 1.0)", atan2 (0.7, 1.0), 6.10725964389208564320E-01);
|
||||
check_double ("atan2 (-0.7, 1.0)", atan2 (-0.7, 1.0), -6.10725964389208564320E-01);
|
||||
check_double ("atan2 (0.7, -1.0)", atan2 (0.7, -1.0), 2.53086668920058466270E+00);
|
||||
check_double ("atan2 (-0.7, -1.0)", atan2 (-0.7, -1.0), -2.53086668920058466270E+00);
|
||||
check_double ("atan2 (0.4, 0.0003)", atan2 (0.4, 0.0003), 1.57004632693552159672E+00);
|
||||
check_double ("atan2 (1.4, -0.93)", atan2 (1.4, -0.93), 2.15714876682378431383E+00);
|
||||
check_double ("ceil (0.0)", ceil (0.0), 0.00000000000000000000E+00);
|
||||
check_double ("ceil (-0.0)", ceil (-0.0), -0.00000000000000000000E+00);
|
||||
check_double ("ceil (INFINITY)", ceil (INFINITY), INF);
|
||||
check_double ("ceil (-INFINITY)", ceil (-INFINITY), -INF);
|
||||
check_double ("ceil (NAN)", ceil (NAN), NAN);
|
||||
check_double ("ceil (3.14)", ceil (3.14), 4.00000000000000000000E+00);
|
||||
check_double ("ceil (-3.14)", ceil (-3.14), -3.00000000000000000000E+00);
|
||||
check_double ("ceil (3.72e-09)", ceil (3.72e-09), 1.00000000000000000000E+00);
|
||||
check_double ("ceil (-3.72e-09)", ceil (-3.72e-09), -0.00000000000000000000E+00);
|
||||
check_double ("ceil (7.37e+19)", ceil (7.37e+19), 7.37000000000000000000E+19);
|
||||
check_double ("ceil (-7.37e+19)", ceil (-7.37e+19), -7.37000000000000000000E+19);
|
||||
check_double ("exp (0.0)", exp (0.0), 1.00000000000000000000E+00);
|
||||
check_double ("exp (-0.0)", exp (-0.0), 1.00000000000000000000E+00);
|
||||
check_double ("exp (1.0)", exp (1.0), 2.71828182845904509080E+00);
|
||||
check_double ("exp (-1.0)", exp (-1.0), 3.67879441171442334024E-01);
|
||||
check_double ("exp (INFINITY)", exp (INFINITY), INF);
|
||||
check_double ("exp (-INFINITY)", exp (-INFINITY), 0.00000000000000000000E+00);
|
||||
check_double ("exp (NAN)", exp (NAN), NAN);
|
||||
check_double ("exp (7.08e+02)", exp (7.08e+02), 3.02338314427605515848E+307);
|
||||
check_double ("exp (7.10e+02)", exp (7.10e+02), INF);
|
||||
check_double ("exp (-7.40e+02)", exp (-7.40e+02), 4.19955798965059562550E-322);
|
||||
check_double ("exp (-7.50e+02)", exp (-7.50e+02), 0.00000000000000000000E+00);
|
||||
check_double ("exp (0.34)", exp (0.34), 1.40494759056359375116E+00);
|
||||
check_double ("exp (-0.34)", exp (-0.34), 7.11770322762609652933E-01);
|
||||
check_double ("exp (0.35)", exp (0.35), 1.41906754859325712204E+00);
|
||||
check_double ("exp (-0.35)", exp (-0.35), 7.04688089718713439602E-01);
|
||||
check_double ("exp (1.03)", exp (1.03), 2.80106583469907910455E+00);
|
||||
check_double ("exp (-1.03)", exp (-1.03), 3.57006960569147380191E-01);
|
||||
check_double ("exp (1.04)", exp (1.04), 2.82921701435155981130E+00);
|
||||
check_double ("exp (-1.04)", exp (-1.04), 3.53454681958780159157E-01);
|
||||
check_double ("exp (3.72e-09)", exp (3.72e-09), 1.00000000372000008575E+00);
|
||||
check_double ("exp (-3.72e-09)", exp (-3.72e-09), 9.99999996280000025273E-01);
|
||||
check_double ("exp (3.73e-09)", exp (3.73e-09), 1.00000000373000008658E+00);
|
||||
check_double ("exp (-3.73e-09)", exp (-3.73e-09), 9.99999996270000024445E-01);
|
||||
check_double ("exp (2.0)", exp (2.0), 7.38905609893065040694E+00);
|
||||
check_double ("exp (3.0)", exp (3.0), 2.00855369231876679237E+01);
|
||||
check_double ("exp (0.7)", exp (0.7), 2.01375270747047663278E+00);
|
||||
check_double ("exp (38.0)", exp (38.0), 3.18559317571137560000E+16);
|
||||
check_double ("fabs (0.0)", fabs (0.0), 0.00000000000000000000E+00);
|
||||
check_double ("fabs (-0.0)", fabs (-0.0), 0.00000000000000000000E+00);
|
||||
check_double ("fabs (1.0)", fabs (1.0), 1.00000000000000000000E+00);
|
||||
check_double ("fabs (-1.0)", fabs (-1.0), 1.00000000000000000000E+00);
|
||||
check_double ("fabs (INFINITY)", fabs (INFINITY), INF);
|
||||
check_double ("fabs (-INFINITY)", fabs (-INFINITY), INF);
|
||||
check_double ("fabs (NAN)", fabs (NAN), NAN);
|
||||
check_double ("fabs (3.14)", fabs (3.14), 3.14000000000000012434E+00);
|
||||
check_double ("fabs (-3.14)", fabs (-3.14), 3.14000000000000012434E+00);
|
||||
check_double ("fabs (0.7)", fabs (0.7), 6.99999999999999955591E-01);
|
||||
check_double ("fabs (-0.7)", fabs (-0.7), 6.99999999999999955591E-01);
|
||||
check_double ("fabs (3.72e-09)", fabs (3.72e-09), 3.71999999999999997526E-09);
|
||||
check_double ("fabs (-3.72e-09)", fabs (-3.72e-09), 3.71999999999999997526E-09);
|
||||
check_double ("fabs (7.37e+19)", fabs (7.37e+19), 7.37000000000000000000E+19);
|
||||
check_double ("fabs (-7.37e+19)", fabs (-7.37e+19), 7.37000000000000000000E+19);
|
||||
check_double ("floor (0.0)", floor (0.0), 0.00000000000000000000E+00);
|
||||
check_double ("floor (-0.0)", floor (-0.0), -0.00000000000000000000E+00);
|
||||
check_double ("floor (INFINITY)", floor (INFINITY), INF);
|
||||
check_double ("floor (-INFINITY)", floor (-INFINITY), -INF);
|
||||
check_double ("floor (NAN)", floor (NAN), NAN);
|
||||
check_double ("floor (3.14)", floor (3.14), 3.00000000000000000000E+00);
|
||||
check_double ("floor (-3.14)", floor (-3.14), -4.00000000000000000000E+00);
|
||||
check_double ("floor (3.72e-09)", floor (3.72e-09), 0.00000000000000000000E+00);
|
||||
check_double ("floor (-3.72e-09)", floor (-3.72e-09), -1.00000000000000000000E+00);
|
||||
check_double ("floor (7.37e+19)", floor (7.37e+19), 7.37000000000000000000E+19);
|
||||
check_double ("floor (-7.37e+19)", floor (-7.37e+19), -7.37000000000000000000E+19);
|
||||
check_double ("fmod (0.0, 0.0)", fmod (0.0, 0.0), -NAN);
|
||||
check_double ("fmod (0.0, -0.0)", fmod (0.0, -0.0), -NAN);
|
||||
check_double ("fmod (-0.0, 0.0)", fmod (-0.0, 0.0), -NAN);
|
||||
check_double ("fmod (-0.0, -0.0)", fmod (-0.0, -0.0), -NAN);
|
||||
check_double ("fmod (0.0, 3.0)", fmod (0.0, 3.0), 0.00000000000000000000E+00);
|
||||
check_double ("fmod (0.0, -3.0)", fmod (0.0, -3.0), 0.00000000000000000000E+00);
|
||||
check_double ("fmod (-0.0, 3.0)", fmod (-0.0, 3.0), -0.00000000000000000000E+00);
|
||||
check_double ("fmod (-0.0, -3.0)", fmod (-0.0, -3.0), -0.00000000000000000000E+00);
|
||||
check_double ("fmod (0.0, INFINITY)", fmod (0.0, INFINITY), 0.00000000000000000000E+00);
|
||||
check_double ("fmod (0.0, -INFINITY)", fmod (0.0, -INFINITY), 0.00000000000000000000E+00);
|
||||
check_double ("fmod (-0.0, INFINITY)", fmod (-0.0, INFINITY), -0.00000000000000000000E+00);
|
||||
check_double ("fmod (-0.0, -INFINITY)", fmod (-0.0, -INFINITY), -0.00000000000000000000E+00);
|
||||
check_double ("fmod (0.0, NAN)", fmod (0.0, NAN), NAN);
|
||||
check_double ("fmod (-0.0, NAN)", fmod (-0.0, NAN), NAN);
|
||||
check_double ("fmod (3.0, 0.0)", fmod (3.0, 0.0), -NAN);
|
||||
check_double ("fmod (3.0, -0.0)", fmod (3.0, -0.0), -NAN);
|
||||
check_double ("fmod (-3.0, 0.0)", fmod (-3.0, 0.0), -NAN);
|
||||
check_double ("fmod (-3.0, -0.0)", fmod (-3.0, -0.0), -NAN);
|
||||
check_double ("fmod (3.0, 3.0)", fmod (3.0, 3.0), 0.00000000000000000000E+00);
|
||||
check_double ("fmod (3.0, -3.0)", fmod (3.0, -3.0), 0.00000000000000000000E+00);
|
||||
check_double ("fmod (-3.0, 3.0)", fmod (-3.0, 3.0), -0.00000000000000000000E+00);
|
||||
check_double ("fmod (-3.0, -3.0)", fmod (-3.0, -3.0), -0.00000000000000000000E+00);
|
||||
check_double ("fmod (3.0, INFINITY)", fmod (3.0, INFINITY), 3.00000000000000000000E+00);
|
||||
check_double ("fmod (3.0, -INFINITY)", fmod (3.0, -INFINITY), 3.00000000000000000000E+00);
|
||||
check_double ("fmod (-3.0, INFINITY)", fmod (-3.0, INFINITY), -3.00000000000000000000E+00);
|
||||
check_double ("fmod (-3.0, -INFINITY)", fmod (-3.0, -INFINITY), -3.00000000000000000000E+00);
|
||||
check_double ("fmod (3.0, NAN)", fmod (3.0, NAN), NAN);
|
||||
check_double ("fmod (-3.0, NAN)", fmod (-3.0, NAN), NAN);
|
||||
check_double ("fmod (INFINITY, 0.0)", fmod (INFINITY, 0.0), -NAN);
|
||||
check_double ("fmod (INFINITY, -0.0)", fmod (INFINITY, -0.0), -NAN);
|
||||
check_double ("fmod (-INFINITY, 0.0)", fmod (-INFINITY, 0.0), -NAN);
|
||||
check_double ("fmod (-INFINITY, -0.0)", fmod (-INFINITY, -0.0), -NAN);
|
||||
check_double ("fmod (INFINITY, 3.0)", fmod (INFINITY, 3.0), -NAN);
|
||||
check_double ("fmod (INFINITY, -3.0)", fmod (INFINITY, -3.0), -NAN);
|
||||
check_double ("fmod (-INFINITY, 3.0)", fmod (-INFINITY, 3.0), -NAN);
|
||||
check_double ("fmod (-INFINITY, -3.0)", fmod (-INFINITY, -3.0), -NAN);
|
||||
check_double ("fmod (INFINITY, INFINITY)", fmod (INFINITY, INFINITY), -NAN);
|
||||
check_double ("fmod (INFINITY, -INFINITY)", fmod (INFINITY, -INFINITY), -NAN);
|
||||
check_double ("fmod (-INFINITY, INFINITY)", fmod (-INFINITY, INFINITY), -NAN);
|
||||
check_double ("fmod (-INFINITY, -INFINITY)", fmod (-INFINITY, -INFINITY), -NAN);
|
||||
check_double ("fmod (INFINITY, NAN)", fmod (INFINITY, NAN), NAN);
|
||||
check_double ("fmod (-INFINITY, NAN)", fmod (-INFINITY, NAN), NAN);
|
||||
check_double ("fmod (NAN, 0.0)", fmod (NAN, 0.0), NAN);
|
||||
check_double ("fmod (NAN, -0.0)", fmod (NAN, -0.0), NAN);
|
||||
check_double ("fmod (NAN, 3.0)", fmod (NAN, 3.0), NAN);
|
||||
check_double ("fmod (NAN, -3.0)", fmod (NAN, -3.0), NAN);
|
||||
check_double ("fmod (NAN, INFINITY)", fmod (NAN, INFINITY), NAN);
|
||||
check_double ("fmod (NAN, -INFINITY)", fmod (NAN, -INFINITY), NAN);
|
||||
check_double ("fmod (NAN, NAN)", fmod (NAN, NAN), NAN);
|
||||
check_double ("fmod (3.0, 1.0)", fmod (3.0, 1.0), 0.00000000000000000000E+00);
|
||||
check_double ("fmod (3.0, -1.0)", fmod (3.0, -1.0), 0.00000000000000000000E+00);
|
||||
check_double ("fmod (-3.0, 1.0)", fmod (-3.0, 1.0), -0.00000000000000000000E+00);
|
||||
check_double ("fmod (-3.0, -1.0)", fmod (-3.0, -1.0), -0.00000000000000000000E+00);
|
||||
check_double ("fmod (6.5, 2.3)", fmod (6.5, 2.3), 1.90000000000000035527E+00);
|
||||
check_double ("fmod (6.5, -2.3)", fmod (6.5, -2.3), 1.90000000000000035527E+00);
|
||||
check_double ("fmod (-6.5, 2.3)", fmod (-6.5, 2.3), -1.90000000000000035527E+00);
|
||||
check_double ("fmod (-6.5, -2.3)", fmod (-6.5, -2.3), -1.90000000000000035527E+00);
|
||||
check_int ("isnan (0.0)", isnan (0.0), 0);
|
||||
check_int ("isnan (-0.0)", isnan (-0.0), 0);
|
||||
check_int ("isnan (1.0)", isnan (1.0), 0);
|
||||
check_int ("isnan (-1.0)", isnan (-1.0), 0);
|
||||
check_int ("isnan (INFINITY)", isnan (INFINITY), 0);
|
||||
check_int ("isnan (-INFINITY)", isnan (-INFINITY), 0);
|
||||
check_int ("isnan (NAN)", isnan (NAN), 1);
|
||||
check_int ("isnan (3.14)", isnan (3.14), 0);
|
||||
check_int ("isnan (-3.14)", isnan (-3.14), 0);
|
||||
check_int ("isnan (0.7)", isnan (0.7), 0);
|
||||
check_int ("isnan (-0.7)", isnan (-0.7), 0);
|
||||
check_int ("isnan (3.72e-09)", isnan (3.72e-09), 0);
|
||||
check_int ("isnan (-3.72e-09)", isnan (-3.72e-09), 0);
|
||||
check_int ("isnan (7.37e+19)", isnan (7.37e+19), 0);
|
||||
check_int ("isnan (-7.37e+19)", isnan (-7.37e+19), 0);
|
||||
check_double ("log (0.0)", log (0.0), -INF);
|
||||
check_double ("log (-0.0)", log (-0.0), -INF);
|
||||
check_double ("log (1.0)", log (1.0), 0.00000000000000000000E+00);
|
||||
check_double ("log (-1.0)", log (-1.0), NAN);
|
||||
check_double ("log (INFINITY)", log (INFINITY), INF);
|
||||
check_double ("log (-INFINITY)", log (-INFINITY), NAN);
|
||||
check_double ("log (NAN)", log (NAN), NAN);
|
||||
check_double ("log (M_E)", log (M_E), 1.00000000000000000000E+00);
|
||||
check_double ("log (1.0 / M_E)", log (1.0 / M_E), -1.00000000000000000000E+00);
|
||||
check_double ("log (2)", log (2), 6.93147180559945286227E-01);
|
||||
check_double ("log (10)", log (10), 2.30258509299404590109E+00);
|
||||
check_double ("log (0.7)", log (0.7), -3.56674943938732447180E-01);
|
||||
check_double ("log (2.22e-308)", log (2.22e-308), -7.08398701446281847893E+02);
|
||||
check_double ("log (2.23e-308)", log (2.23e-308), -7.08394207056694085622E+02);
|
||||
check_double ("log (0.17)", log (0.17), -1.77195684193187519284E+00);
|
||||
check_double ("log (0.18)", log (0.18), -1.71479842809192661868E+00);
|
||||
check_double ("log (1999.0)", log (1999.0), 7.60040233450039970364E+00);
|
||||
check_double ("log (2000.0)", log (2000.0), 7.60090245954208221235E+00);
|
||||
check_double ("log (2001.0)", log (2001.0), 7.60140233458373337783E+00);
|
||||
check_double ("pow (0.0, 0.0)", pow (0.0, 0.0), 1.00000000000000000000E+00);
|
||||
check_double ("pow (0.0, -0.0)", pow (0.0, -0.0), 1.00000000000000000000E+00);
|
||||
check_double ("pow (-0.0, 0.0)", pow (-0.0, 0.0), 1.00000000000000000000E+00);
|
||||
check_double ("pow (-0.0, -0.0)", pow (-0.0, -0.0), 1.00000000000000000000E+00);
|
||||
check_double ("pow (0.0, 1.0)", pow (0.0, 1.0), 0.00000000000000000000E+00);
|
||||
check_double ("pow (0.0, -1.0)", pow (0.0, -1.0), INF);
|
||||
check_double ("pow (-0.0, 1.0)", pow (-0.0, 1.0), -0.00000000000000000000E+00);
|
||||
check_double ("pow (-0.0, -1.0)", pow (-0.0, -1.0), -INF);
|
||||
check_double ("pow (0.0, INFINITY)", pow (0.0, INFINITY), 0.00000000000000000000E+00);
|
||||
check_double ("pow (0.0, -INFINITY)", pow (0.0, -INFINITY), INF);
|
||||
check_double ("pow (-0.0, INFINITY)", pow (-0.0, INFINITY), 0.00000000000000000000E+00);
|
||||
check_double ("pow (-0.0, -INFINITY)", pow (-0.0, -INFINITY), INF);
|
||||
check_double ("pow (0.0, NAN)", pow (0.0, NAN), NAN);
|
||||
check_double ("pow (-0.0, NAN)", pow (-0.0, NAN), NAN);
|
||||
check_double ("pow (1.0, 0.0)", pow (1.0, 0.0), 1.00000000000000000000E+00);
|
||||
check_double ("pow (1.0, -0.0)", pow (1.0, -0.0), 1.00000000000000000000E+00);
|
||||
check_double ("pow (-1.0, 0.0)", pow (-1.0, 0.0), 1.00000000000000000000E+00);
|
||||
check_double ("pow (-1.0, -0.0)", pow (-1.0, -0.0), 1.00000000000000000000E+00);
|
||||
check_double ("pow (1.0, 1.0)", pow (1.0, 1.0), 1.00000000000000000000E+00);
|
||||
check_double ("pow (1.0, -1.0)", pow (1.0, -1.0), 1.00000000000000000000E+00);
|
||||
check_double ("pow (-1.0, 1.0)", pow (-1.0, 1.0), -1.00000000000000000000E+00);
|
||||
check_double ("pow (-1.0, -1.0)", pow (-1.0, -1.0), -1.00000000000000000000E+00);
|
||||
check_double ("pow (1.0, INFINITY)", pow (1.0, INFINITY), 1.00000000000000000000E+00);
|
||||
check_double ("pow (1.0, -INFINITY)", pow (1.0, -INFINITY), 1.00000000000000000000E+00);
|
||||
check_double ("pow (-1.0, INFINITY)", pow (-1.0, INFINITY), 1.00000000000000000000E+00);
|
||||
check_double ("pow (-1.0, -INFINITY)", pow (-1.0, -INFINITY), 1.00000000000000000000E+00);
|
||||
check_double ("pow (1.0, NAN)", pow (1.0, NAN), 1.00000000000000000000E+00);
|
||||
check_double ("pow (-1.0, NAN)", pow (-1.0, NAN), NAN);
|
||||
check_double ("pow (INFINITY, 0.0)", pow (INFINITY, 0.0), 1.00000000000000000000E+00);
|
||||
check_double ("pow (INFINITY, -0.0)", pow (INFINITY, -0.0), 1.00000000000000000000E+00);
|
||||
check_double ("pow (-INFINITY, 0.0)", pow (-INFINITY, 0.0), 1.00000000000000000000E+00);
|
||||
check_double ("pow (-INFINITY, -0.0)", pow (-INFINITY, -0.0), 1.00000000000000000000E+00);
|
||||
check_double ("pow (INFINITY, 1.0)", pow (INFINITY, 1.0), INF);
|
||||
check_double ("pow (INFINITY, -1.0)", pow (INFINITY, -1.0), 0.00000000000000000000E+00);
|
||||
check_double ("pow (-INFINITY, 1.0)", pow (-INFINITY, 1.0), -INF);
|
||||
check_double ("pow (-INFINITY, -1.0)", pow (-INFINITY, -1.0), -0.00000000000000000000E+00);
|
||||
check_double ("pow (INFINITY, INFINITY)", pow (INFINITY, INFINITY), INF);
|
||||
check_double ("pow (INFINITY, -INFINITY)", pow (INFINITY, -INFINITY), 0.00000000000000000000E+00);
|
||||
check_double ("pow (-INFINITY, INFINITY)", pow (-INFINITY, INFINITY), INF);
|
||||
check_double ("pow (-INFINITY, -INFINITY)", pow (-INFINITY, -INFINITY), 0.00000000000000000000E+00);
|
||||
check_double ("pow (INFINITY, NAN)", pow (INFINITY, NAN), NAN);
|
||||
check_double ("pow (-INFINITY, NAN)", pow (-INFINITY, NAN), NAN);
|
||||
check_double ("pow (NAN, 0.0)", pow (NAN, 0.0), 1.00000000000000000000E+00);
|
||||
check_double ("pow (NAN, -0.0)", pow (NAN, -0.0), 1.00000000000000000000E+00);
|
||||
check_double ("pow (NAN, 1.0)", pow (NAN, 1.0), NAN);
|
||||
check_double ("pow (NAN, -1.0)", pow (NAN, -1.0), NAN);
|
||||
check_double ("pow (NAN, INFINITY)", pow (NAN, INFINITY), NAN);
|
||||
check_double ("pow (NAN, -INFINITY)", pow (NAN, -INFINITY), NAN);
|
||||
check_double ("pow (NAN, NAN)", pow (NAN, NAN), NAN);
|
||||
check_double ("pow (0.9, INFINITY)", pow (0.9, INFINITY), 0.00000000000000000000E+00);
|
||||
check_double ("pow (0.9, -INFINITY)", pow (0.9, -INFINITY), INF);
|
||||
check_double ("pow (-0.9, INFINITY)", pow (-0.9, INFINITY), 0.00000000000000000000E+00);
|
||||
check_double ("pow (-0.9, -INFINITY)", pow (-0.9, -INFINITY), INF);
|
||||
check_double ("pow (1.1, INFINITY)", pow (1.1, INFINITY), INF);
|
||||
check_double ("pow (1.1, -INFINITY)", pow (1.1, -INFINITY), 0.00000000000000000000E+00);
|
||||
check_double ("pow (-1.1, INFINITY)", pow (-1.1, INFINITY), INF);
|
||||
check_double ("pow (-1.1, -INFINITY)", pow (-1.1, -INFINITY), 0.00000000000000000000E+00);
|
||||
check_double ("pow (0.0, 2.0)", pow (0.0, 2.0), 0.00000000000000000000E+00);
|
||||
check_double ("pow (0.0, -2.0)", pow (0.0, -2.0), INF);
|
||||
check_double ("pow (-0.0, 2.0)", pow (-0.0, 2.0), 0.00000000000000000000E+00);
|
||||
check_double ("pow (-0.0, -2.0)", pow (-0.0, -2.0), INF);
|
||||
check_double ("pow (0.0, 3.0)", pow (0.0, 3.0), 0.00000000000000000000E+00);
|
||||
check_double ("pow (0.0, -3.0)", pow (0.0, -3.0), INF);
|
||||
check_double ("pow (-0.0, 3.0)", pow (-0.0, 3.0), -0.00000000000000000000E+00);
|
||||
check_double ("pow (-0.0, -3.0)", pow (-0.0, -3.0), -INF);
|
||||
check_double ("pow (0.0, 3.14)", pow (0.0, 3.14), 0.00000000000000000000E+00);
|
||||
check_double ("pow (0.0, -3.14)", pow (0.0, -3.14), INF);
|
||||
check_double ("pow (-0.0, 3.14)", pow (-0.0, 3.14), 0.00000000000000000000E+00);
|
||||
check_double ("pow (-0.0, -3.14)", pow (-0.0, -3.14), INF);
|
||||
check_double ("pow (1.0, 3.14)", pow (1.0, 3.14), 1.00000000000000000000E+00);
|
||||
check_double ("pow (1.0, -3.14)", pow (1.0, -3.14), 1.00000000000000000000E+00);
|
||||
check_double ("pow (-1.0, 3.14)", pow (-1.0, 3.14), -NAN);
|
||||
check_double ("pow (-1.0, -3.14)", pow (-1.0, -3.14), -NAN);
|
||||
check_double ("pow (3.14, 0.0)", pow (3.14, 0.0), 1.00000000000000000000E+00);
|
||||
check_double ("pow (3.14, -0.0)", pow (3.14, -0.0), 1.00000000000000000000E+00);
|
||||
check_double ("pow (-3.14, 0.0)", pow (-3.14, 0.0), 1.00000000000000000000E+00);
|
||||
check_double ("pow (-3.14, -0.0)", pow (-3.14, -0.0), 1.00000000000000000000E+00);
|
||||
check_double ("pow (3.14, 1.0)", pow (3.14, 1.0), 3.14000000000000012434E+00);
|
||||
check_double ("pow (3.14, -1.0)", pow (3.14, -1.0), 3.18471337579617819191E-01);
|
||||
check_double ("pow (-3.14, 1.0)", pow (-3.14, 1.0), -3.14000000000000012434E+00);
|
||||
check_double ("pow (-3.14, -1.0)", pow (-3.14, -1.0), -3.18471337579617819191E-01);
|
||||
check_double ("pow (3.14, 2.0)", pow (3.14, 2.0), 9.85960000000000036380E+00);
|
||||
check_double ("pow (3.14, -2.0)", pow (3.14, -2.0), 1.01423992859750899953E-01);
|
||||
check_double ("pow (-3.14, 2.0)", pow (-3.14, 2.0), 9.85960000000000036380E+00);
|
||||
check_double ("pow (-3.14, -2.0)", pow (-3.14, -2.0), 1.01423992859750899953E-01);
|
||||
check_double ("pow (3.14, 3.0)", pow (3.14, 3.0), 3.09591440000000019950E+01);
|
||||
check_double ("pow (3.14, -3.0)", pow (3.14, -3.0), 3.23006346687104775595E-02);
|
||||
check_double ("pow (-3.14, 3.0)", pow (-3.14, 3.0), -3.09591440000000019950E+01);
|
||||
check_double ("pow (-3.14, -3.0)", pow (-3.14, -3.0), -3.23006346687104775595E-02);
|
||||
check_double ("pow (3.14, 3.14)", pow (3.14, 3.14), 3.63378388801747078674E+01);
|
||||
check_double ("pow (3.14, -3.14)", pow (3.14, -3.14), 2.75195231972252124519E-02);
|
||||
check_double ("pow (-3.14, 3.14)", pow (-3.14, 3.14), -NAN);
|
||||
check_double ("pow (-3.14, -3.14)", pow (-3.14, -3.14), -NAN);
|
||||
check_double ("pow (INFINITY, 2.0)", pow (INFINITY, 2.0), INF);
|
||||
check_double ("pow (INFINITY, -2.0)", pow (INFINITY, -2.0), 0.00000000000000000000E+00);
|
||||
check_double ("pow (-INFINITY, 2.0)", pow (-INFINITY, 2.0), INF);
|
||||
check_double ("pow (-INFINITY, -2.0)", pow (-INFINITY, -2.0), 0.00000000000000000000E+00);
|
||||
check_double ("pow (INFINITY, 3.0)", pow (INFINITY, 3.0), INF);
|
||||
check_double ("pow (INFINITY, -3.0)", pow (INFINITY, -3.0), 0.00000000000000000000E+00);
|
||||
check_double ("pow (-INFINITY, 3.0)", pow (-INFINITY, 3.0), -INF);
|
||||
check_double ("pow (-INFINITY, -3.0)", pow (-INFINITY, -3.0), -0.00000000000000000000E+00);
|
||||
check_double ("pow (INFINITY, 3.14)", pow (INFINITY, 3.14), INF);
|
||||
check_double ("pow (INFINITY, -3.14)", pow (INFINITY, -3.14), 0.00000000000000000000E+00);
|
||||
check_double ("pow (-INFINITY, 3.14)", pow (-INFINITY, 3.14), INF);
|
||||
check_double ("pow (-INFINITY, -3.14)", pow (-INFINITY, -3.14), 0.00000000000000000000E+00);
|
||||
check_double ("pow (0.7, 1.2)", pow (0.7, 1.2), 6.51804940566386381562E-01);
|
||||
check_double ("sqrt (0.0)", sqrt (0.0), 0.00000000000000000000E+00);
|
||||
check_double ("sqrt (-0.0)", sqrt (-0.0), -0.00000000000000000000E+00);
|
||||
check_double ("sqrt (1.0)", sqrt (1.0), 1.00000000000000000000E+00);
|
||||
check_double ("sqrt (-1.0)", sqrt (-1.0), -NAN);
|
||||
check_double ("sqrt (INFINITY)", sqrt (INFINITY), INF);
|
||||
check_double ("sqrt (-INFINITY)", sqrt (-INFINITY), -NAN);
|
||||
check_double ("sqrt (NAN)", sqrt (NAN), NAN);
|
||||
check_double ("sqrt (0.7)", sqrt (0.7), 8.36660026534075562665E-01);
|
||||
check_double ("sqrt (2)", sqrt (2), 1.41421356237309514547E+00);
|
||||
check_double ("sqrt (10)", sqrt (10), 3.16227766016837952279E+00);
|
||||
check_double ("sqrt (2.22e-308)", sqrt (2.22e-308), 1.48996644257513405066E-154);
|
||||
check_double ("sqrt (2.23e-308)", sqrt (2.23e-308), 1.49331845230680803391E-154);
|
||||
check_double ("sqrt (3.72e-09)", sqrt (3.72e-09), 6.09918027279076225416E-05);
|
||||
check_double ("sqrt (7.37e+19)", sqrt (7.37e+19), 8.58487041253390121460E+09);
|
||||
check_double ("sqrt (2209)", sqrt (2209), 4.70000000000000000000E+01);
|
||||
check_double ("sqrt (4)", sqrt (4), 2.00000000000000000000E+00);
|
||||
check_double ("sqrt (0.25)", sqrt (0.25), 5.00000000000000000000E-01);
|
||||
check_double ("sqrt (6642.25)", sqrt (6642.25), 8.15000000000000000000E+01);
|
||||
check_double ("sqrt (15239.9025)", sqrt (15239.9025), 1.23450000000000002842E+02);
|
||||
check_double ("sin (0.0)", sin (0.0), 0.00000000000000000000E+00);
|
||||
check_double ("sin (-0.0)", sin (-0.0), -0.00000000000000000000E+00);
|
||||
check_double ("sin (1.0)", sin (1.0), 8.41470984807896504876E-01);
|
||||
check_double ("sin (-1.0)", sin (-1.0), -8.41470984807896504876E-01);
|
||||
check_double ("sin (INFINITY)", sin (INFINITY), -NAN);
|
||||
check_double ("sin (-INFINITY)", sin (-INFINITY), -NAN);
|
||||
check_double ("sin (NAN)", sin (NAN), NAN);
|
||||
check_double ("sin (M_PI)", sin (M_PI), 1.22464679914735320717E-16);
|
||||
check_double ("sin (-M_PI)", sin (-M_PI), -1.22464679914735320717E-16);
|
||||
check_double ("sin (2.0 * M_PI)", sin (2.0 * M_PI), -2.44929359829470641435E-16);
|
||||
check_double ("sin (-2.0 * M_PI)", sin (-2.0 * M_PI), 2.44929359829470641435E-16);
|
||||
check_double ("sin (M_PI / 2.0)", sin (M_PI / 2.0), 1.00000000000000000000E+00);
|
||||
check_double ("sin (-M_PI / 2.0)", sin (-M_PI / 2.0), -1.00000000000000000000E+00);
|
||||
check_double ("sin (M_PI / 3.0)", sin (M_PI / 3.0), 8.66025403784438596588E-01);
|
||||
check_double ("sin (-M_PI / 3.0)", sin (-M_PI / 3.0), -8.66025403784438596588E-01);
|
||||
check_double ("sin (M_PI / 4.0)", sin (M_PI / 4.0), 7.07106781186547461715E-01);
|
||||
check_double ("sin (-M_PI / 4.0)", sin (-M_PI / 4.0), -7.07106781186547461715E-01);
|
||||
check_double ("sin (M_PI / 6.0)", sin (M_PI / 6.0), 4.99999999999999944489E-01);
|
||||
check_double ("sin (-M_PI / 6.0)", sin (-M_PI / 6.0), -4.99999999999999944489E-01);
|
||||
check_double ("sin (M_PI * 2.0 / 3.0)", sin (M_PI * 2.0 / 3.0), 8.66025403784438707611E-01);
|
||||
check_double ("sin (-M_PI * 2.0 / 3.0)", sin (-M_PI * 2.0 / 3.0), -8.66025403784438707611E-01);
|
||||
check_double ("sin (M_PI * 5.0 / 6.0)", sin (M_PI * 5.0 / 6.0), 4.99999999999999944489E-01);
|
||||
check_double ("sin (-M_PI * 5.0 / 6.0)", sin (-M_PI * 5.0 / 6.0), -4.99999999999999944489E-01);
|
||||
check_double ("sin (6.9e-18)", sin (6.9e-18), 6.90000000000000026253E-18);
|
||||
check_double ("sin (-6.9e-18)", sin (-6.9e-18), -6.90000000000000026253E-18);
|
||||
check_double ("sin (7.0e-18)", sin (7.0e-18), 6.99999999999999973042E-18);
|
||||
check_double ("sin (-7.0e-18)", sin (-7.0e-18), -6.99999999999999973042E-18);
|
||||
check_double ("sin (7.4e-9)", sin (7.4e-9), 7.40000000000000008865E-09);
|
||||
check_double ("sin (-7.4e-9)", sin (-7.4e-9), -7.40000000000000008865E-09);
|
||||
check_double ("sin (7.5e-9)", sin (7.5e-9), 7.49999999999999932974E-09);
|
||||
check_double ("sin (-7.5e-9)", sin (-7.5e-9), -7.49999999999999932974E-09);
|
||||
check_double ("sin (0.2)", sin (0.2), 1.98669330795061216399E-01);
|
||||
check_double ("sin (-0.2)", sin (-0.2), -1.98669330795061216399E-01);
|
||||
check_double ("sin (0.4)", sin (0.4), 3.89418342308650522465E-01);
|
||||
check_double ("sin (-0.4)", sin (-0.4), -3.89418342308650522465E-01);
|
||||
check_double ("sin (0.7)", sin (0.7), 6.44217687237691016833E-01);
|
||||
check_double ("sin (-0.7)", sin (-0.7), -6.44217687237691016833E-01);
|
||||
check_double ("sin (0.8)", sin (0.8), 7.17356090899522791382E-01);
|
||||
check_double ("sin (-0.8)", sin (-0.8), -7.17356090899522791382E-01);
|
||||
check_double ("sin (3.0)", sin (3.0), 1.41120008059867213523E-01);
|
||||
check_double ("sin (-3.0)", sin (-3.0), -1.41120008059867213523E-01);
|
||||
check_double ("sin (4.0)", sin (4.0), -7.56802495307928202450E-01);
|
||||
check_double ("sin (-4.0)", sin (-4.0), 7.56802495307928202450E-01);
|
||||
check_double ("sin (6.0)", sin (6.0), -2.79415498198925860152E-01);
|
||||
check_double ("sin (-6.0)", sin (-6.0), 2.79415498198925860152E-01);
|
||||
check_double ("sin (7.0)", sin (7.0), 6.56986598718789061024E-01);
|
||||
check_double ("sin (-7.0)", sin (-7.0), -6.56986598718789061024E-01);
|
||||
check_double ("cos (0.0)", cos (0.0), 1.00000000000000000000E+00);
|
||||
check_double ("cos (-0.0)", cos (-0.0), 1.00000000000000000000E+00);
|
||||
check_double ("cos (1.0)", cos (1.0), 5.40302305868139765010E-01);
|
||||
check_double ("cos (-1.0)", cos (-1.0), 5.40302305868139765010E-01);
|
||||
check_double ("cos (INFINITY)", cos (INFINITY), -NAN);
|
||||
check_double ("cos (-INFINITY)", cos (-INFINITY), -NAN);
|
||||
check_double ("cos (NAN)", cos (NAN), NAN);
|
||||
check_double ("cos (M_PI)", cos (M_PI), -1.00000000000000000000E+00);
|
||||
check_double ("cos (-M_PI)", cos (-M_PI), -1.00000000000000000000E+00);
|
||||
check_double ("cos (2.0 * M_PI)", cos (2.0 * M_PI), 1.00000000000000000000E+00);
|
||||
check_double ("cos (-2.0 * M_PI)", cos (-2.0 * M_PI), 1.00000000000000000000E+00);
|
||||
check_double ("cos (M_PI / 2.0)", cos (M_PI / 2.0), 6.12323399573676603587E-17);
|
||||
check_double ("cos (-M_PI / 2.0)", cos (-M_PI / 2.0), 6.12323399573676603587E-17);
|
||||
check_double ("cos (M_PI / 3.0)", cos (M_PI / 3.0), 5.00000000000000111022E-01);
|
||||
check_double ("cos (-M_PI / 3.0)", cos (-M_PI / 3.0), 5.00000000000000111022E-01);
|
||||
check_double ("cos (M_PI / 4.0)", cos (M_PI / 4.0), 7.07106781186547572737E-01);
|
||||
check_double ("cos (-M_PI / 4.0)", cos (-M_PI / 4.0), 7.07106781186547572737E-01);
|
||||
check_double ("cos (M_PI / 6.0)", cos (M_PI / 6.0), 8.66025403784438707611E-01);
|
||||
check_double ("cos (-M_PI / 6.0)", cos (-M_PI / 6.0), 8.66025403784438707611E-01);
|
||||
check_double ("cos (M_PI * 2.0 / 3.0)", cos (M_PI * 2.0 / 3.0), -4.99999999999999777955E-01);
|
||||
check_double ("cos (-M_PI * 2.0 / 3.0)", cos (-M_PI * 2.0 / 3.0), -4.99999999999999777955E-01);
|
||||
check_double ("cos (M_PI * 5.0 / 6.0)", cos (M_PI * 5.0 / 6.0), -8.66025403784438707611E-01);
|
||||
check_double ("cos (-M_PI * 5.0 / 6.0)", cos (-M_PI * 5.0 / 6.0), -8.66025403784438707611E-01);
|
||||
check_double ("cos (6.9e-18)", cos (6.9e-18), 1.00000000000000000000E+00);
|
||||
check_double ("cos (-6.9e-18)", cos (-6.9e-18), 1.00000000000000000000E+00);
|
||||
check_double ("cos (7.0e-18)", cos (7.0e-18), 1.00000000000000000000E+00);
|
||||
check_double ("cos (-7.0e-18)", cos (-7.0e-18), 1.00000000000000000000E+00);
|
||||
check_double ("cos (7.4e-9)", cos (7.4e-9), 1.00000000000000000000E+00);
|
||||
check_double ("cos (-7.4e-9)", cos (-7.4e-9), 1.00000000000000000000E+00);
|
||||
check_double ("cos (7.5e-9)", cos (7.5e-9), 1.00000000000000000000E+00);
|
||||
check_double ("cos (-7.5e-9)", cos (-7.5e-9), 1.00000000000000000000E+00);
|
||||
check_double ("cos (0.2)", cos (0.2), 9.80066577841241626246E-01);
|
||||
check_double ("cos (-0.2)", cos (-0.2), 9.80066577841241626246E-01);
|
||||
check_double ("cos (0.4)", cos (0.4), 9.21060994002885102816E-01);
|
||||
check_double ("cos (-0.4)", cos (-0.4), 9.21060994002885102816E-01);
|
||||
check_double ("cos (0.7)", cos (0.7), 7.64842187284488495003E-01);
|
||||
check_double ("cos (-0.7)", cos (-0.7), 7.64842187284488495003E-01);
|
||||
check_double ("cos (0.8)", cos (0.8), 6.96706709347165387136E-01);
|
||||
check_double ("cos (-0.8)", cos (-0.8), 6.96706709347165387136E-01);
|
||||
check_double ("cos (3.0)", cos (3.0), -9.89992496600445415211E-01);
|
||||
check_double ("cos (-3.0)", cos (-3.0), -9.89992496600445415211E-01);
|
||||
check_double ("cos (4.0)", cos (4.0), -6.53643620863611940486E-01);
|
||||
check_double ("cos (-4.0)", cos (-4.0), -6.53643620863611940486E-01);
|
||||
check_double ("cos (6.0)", cos (6.0), 9.60170286650365967240E-01);
|
||||
check_double ("cos (-6.0)", cos (-6.0), 9.60170286650365967240E-01);
|
||||
check_double ("cos (7.0)", cos (7.0), 7.53902254343304600859E-01);
|
||||
check_double ("cos (-7.0)", cos (-7.0), 7.53902254343304600859E-01);
|
||||
check_double ("tan (0.0)", tan (0.0), 0.00000000000000000000E+00);
|
||||
check_double ("tan (-0.0)", tan (-0.0), -0.00000000000000000000E+00);
|
||||
check_double ("tan (1.0)", tan (1.0), 1.55740772465490229237E+00);
|
||||
check_double ("tan (-1.0)", tan (-1.0), -1.55740772465490229237E+00);
|
||||
check_double ("tan (INFINITY)", tan (INFINITY), -NAN);
|
||||
check_double ("tan (-INFINITY)", tan (-INFINITY), -NAN);
|
||||
check_double ("tan (NAN)", tan (NAN), NAN);
|
||||
check_double ("tan (M_PI)", tan (M_PI), -1.22464679914735320717E-16);
|
||||
check_double ("tan (-M_PI)", tan (-M_PI), 1.22464679914735320717E-16);
|
||||
check_double ("tan (2.0 * M_PI)", tan (2.0 * M_PI), -2.44929359829470641435E-16);
|
||||
check_double ("tan (-2.0 * M_PI)", tan (-2.0 * M_PI), 2.44929359829470641435E-16);
|
||||
check_double ("tan (M_PI / 2.0)", tan (M_PI / 2.0), 1.63312393531953700000E+16);
|
||||
check_double ("tan (-M_PI / 2.0)", tan (-M_PI / 2.0), -1.63312393531953700000E+16);
|
||||
check_double ("tan (M_PI / 3.0)", tan (M_PI / 3.0), 1.73205080756887674909E+00);
|
||||
check_double ("tan (-M_PI / 3.0)", tan (-M_PI / 3.0), -1.73205080756887674909E+00);
|
||||
check_double ("tan (M_PI / 4.0)", tan (M_PI / 4.0), 9.99999999999999888978E-01);
|
||||
check_double ("tan (-M_PI / 4.0)", tan (-M_PI / 4.0), -9.99999999999999888978E-01);
|
||||
check_double ("tan (M_PI / 6.0)", tan (M_PI / 6.0), 5.77350269189625731059E-01);
|
||||
check_double ("tan (-M_PI / 6.0)", tan (-M_PI / 6.0), -5.77350269189625731059E-01);
|
||||
check_double ("tan (M_PI * 2.0 / 3.0)", tan (M_PI * 2.0 / 3.0), -1.73205080756887830340E+00);
|
||||
check_double ("tan (-M_PI * 2.0 / 3.0)", tan (-M_PI * 2.0 / 3.0), 1.73205080756887830340E+00);
|
||||
check_double ("tan (M_PI * 5.0 / 6.0)", tan (M_PI * 5.0 / 6.0), -5.77350269189625731059E-01);
|
||||
check_double ("tan (-M_PI * 5.0 / 6.0)", tan (-M_PI * 5.0 / 6.0), 5.77350269189625731059E-01);
|
||||
check_double ("tan (3.7e-9)", tan (3.7e-9), 3.70000000000000004433E-09);
|
||||
check_double ("tan (-3.7e-9)", tan (-3.7e-9), -3.70000000000000004433E-09);
|
||||
check_double ("tan (3.8e-9)", tan (3.8e-9), 3.80000000000000011259E-09);
|
||||
check_double ("tan (-3.8e-9)", tan (-3.8e-9), -3.80000000000000011259E-09);
|
||||
check_double ("tan (0.6)", tan (0.6), 6.84136808341692326252E-01);
|
||||
check_double ("tan (-0.6)", tan (-0.6), -6.84136808341692326252E-01);
|
||||
check_double ("tan (0.7)", tan (0.7), 8.42288380463079411342E-01);
|
||||
check_double ("tan (-0.7)", tan (-0.7), -8.42288380463079411342E-01);
|
||||
check_double ("tan (3.0)", tan (3.0), -1.42546543074277803909E-01);
|
||||
check_double ("tan (-3.0)", tan (-3.0), 1.42546543074277803909E-01);
|
||||
check_double ("tan (4.0)", tan (4.0), 1.15782128234957748525E+00);
|
||||
check_double ("tan (-4.0)", tan (-4.0), -1.15782128234957748525E+00);
|
||||
check_double ("tan (6.0)", tan (6.0), -2.91006191384749146600E-01);
|
||||
check_double ("tan (-6.0)", tan (-6.0), 2.91006191384749146600E-01);
|
||||
check_double ("tan (7.0)", tan (7.0), 8.71447982724318781500E-01);
|
||||
check_double ("tan (-7.0)", tan (-7.0), -8.71447982724318781500E-01);
|
80
third_party/jerryscript/tests/unit/test-lit-char-helpers.c
vendored
Normal file
80
third_party/jerryscript/tests/unit/test-lit-char-helpers.c
vendored
Normal file
|
@ -0,0 +1,80 @@
|
|||
/* Copyright 2015-2016 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-helpers.h"
|
||||
#include "lit-strings.h"
|
||||
#include "ecma-init-finalize.h"
|
||||
#include "lit-char-helpers.h"
|
||||
#include "js-parser-internal.h"
|
||||
|
||||
#include "test-common.h"
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
TEST_INIT ();
|
||||
|
||||
jmem_init ();
|
||||
ecma_init ();
|
||||
|
||||
const uint8_t _1_byte_long1[] = "\\u007F";
|
||||
const uint8_t _1_byte_long2[] = "\\u0000";
|
||||
const uint8_t _1_byte_long3[] = "\\u0065";
|
||||
|
||||
const uint8_t _2_byte_long1[] = "\\u008F";
|
||||
const uint8_t _2_byte_long2[] = "\\u00FF";
|
||||
const uint8_t _2_byte_long3[] = "\\u07FF";
|
||||
|
||||
const uint8_t _3_byte_long1[] = "\\u08FF";
|
||||
const uint8_t _3_byte_long2[] = "\\u0FFF";
|
||||
const uint8_t _3_byte_long3[] = "\\uFFFF";
|
||||
|
||||
size_t length;
|
||||
|
||||
// test 1-byte-long unicode sequences
|
||||
length = lit_char_get_utf8_length (lexer_hex_to_character (0, _1_byte_long1 + 2, 4));
|
||||
TEST_ASSERT (length == 1);
|
||||
|
||||
length = lit_char_get_utf8_length (lexer_hex_to_character (0, _1_byte_long2 + 2, 4));
|
||||
TEST_ASSERT (length == 1);
|
||||
|
||||
length = lit_char_get_utf8_length (lexer_hex_to_character (0, _1_byte_long3 + 2, 4));
|
||||
TEST_ASSERT (length == 1);
|
||||
|
||||
// test 2-byte-long unicode sequences
|
||||
length = lit_char_get_utf8_length (lexer_hex_to_character (0, _2_byte_long1 + 2, 4));
|
||||
TEST_ASSERT (length == 2);
|
||||
|
||||
length = lit_char_get_utf8_length (lexer_hex_to_character (0, _2_byte_long2 + 2, 4));
|
||||
TEST_ASSERT (length == 2);
|
||||
|
||||
length = lit_char_get_utf8_length (lexer_hex_to_character (0, _2_byte_long3 + 2, 4));
|
||||
TEST_ASSERT (length == 2);
|
||||
|
||||
// test 3-byte-long unicode sequences
|
||||
length = lit_char_get_utf8_length (lexer_hex_to_character (0, _3_byte_long1 + 2, 4));
|
||||
TEST_ASSERT (length != 2);
|
||||
|
||||
length = lit_char_get_utf8_length (lexer_hex_to_character (0, _3_byte_long2 + 2, 4));
|
||||
TEST_ASSERT (length == 3);
|
||||
|
||||
length = lit_char_get_utf8_length (lexer_hex_to_character (0, _3_byte_long3 + 2, 4));
|
||||
TEST_ASSERT (length == 3);
|
||||
|
||||
ecma_finalize ();
|
||||
jmem_finalize ();
|
||||
|
||||
return 0;
|
||||
} /* main */
|
134
third_party/jerryscript/tests/unit/test-literal-storage.c
vendored
Normal file
134
third_party/jerryscript/tests/unit/test-literal-storage.c
vendored
Normal file
|
@ -0,0 +1,134 @@
|
|||
/* Copyright 2015-2016 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2016 University of Szeged
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-literal-storage.h"
|
||||
#include "test-common.h"
|
||||
|
||||
// Iterations count
|
||||
#define test_iters 64
|
||||
|
||||
// Subiterations count
|
||||
#define test_sub_iters 64
|
||||
|
||||
// Max characters in a string
|
||||
#define max_characters_in_string 256
|
||||
|
||||
static void
|
||||
generate_string (lit_utf8_byte_t *str, lit_utf8_size_t len)
|
||||
{
|
||||
static const lit_utf8_byte_t bytes[] = "!@#$%^&*()_+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789";
|
||||
static const lit_utf8_size_t length = (lit_utf8_size_t) (sizeof (bytes) - 1);
|
||||
for (lit_utf8_size_t i = 0; i < len; ++i)
|
||||
{
|
||||
str[i] = bytes[(unsigned long) rand () % length];
|
||||
}
|
||||
} /* generate_string */
|
||||
|
||||
static ecma_number_t
|
||||
generate_number ()
|
||||
{
|
||||
ecma_number_t num = ((ecma_number_t) rand () / 32767.0);
|
||||
if (rand () % 2)
|
||||
{
|
||||
num = -num;
|
||||
}
|
||||
int power = rand () % 30;
|
||||
while (power-- > 0)
|
||||
{
|
||||
num *= 10;
|
||||
}
|
||||
return num;
|
||||
} /* generate_number */
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
TEST_INIT ();
|
||||
|
||||
const lit_utf8_byte_t *ptrs[test_sub_iters];
|
||||
ecma_number_t numbers[test_sub_iters];
|
||||
lit_utf8_byte_t strings[test_sub_iters][max_characters_in_string + 1];
|
||||
lit_utf8_size_t lengths[test_sub_iters];
|
||||
|
||||
jmem_init ();
|
||||
|
||||
for (uint32_t i = 0; i < test_iters; i++)
|
||||
{
|
||||
memset (numbers, 0, sizeof (ecma_number_t) * test_sub_iters);
|
||||
memset (lengths, 0, sizeof (lit_utf8_size_t) * test_sub_iters);
|
||||
memset (ptrs, 0, sizeof (lit_utf8_byte_t *) * test_sub_iters);
|
||||
|
||||
for (uint32_t j = 0; j < test_sub_iters; j++)
|
||||
{
|
||||
int type = rand () % 3;
|
||||
if (type == 0)
|
||||
{
|
||||
lengths[j] = (lit_utf8_size_t) (rand () % max_characters_in_string + 1);
|
||||
generate_string (strings[j], lengths[j]);
|
||||
ecma_find_or_create_literal_string (strings[j], lengths[j]);
|
||||
strings[j][lengths[j]] = '\0';
|
||||
ptrs[j] = strings[j];
|
||||
TEST_ASSERT (ptrs[j]);
|
||||
}
|
||||
else if (type == 1)
|
||||
{
|
||||
lit_magic_string_id_t msi = (lit_magic_string_id_t) (rand () % LIT_MAGIC_STRING__COUNT);
|
||||
ptrs[j] = lit_get_magic_string_utf8 (msi);
|
||||
TEST_ASSERT (ptrs[j]);
|
||||
lengths[j] = (lit_utf8_size_t) lit_zt_utf8_string_size (ptrs[j]);
|
||||
ecma_find_or_create_literal_string (ptrs[j], lengths[j]);
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_number_t num = generate_number ();
|
||||
lengths[j] = ecma_number_to_utf8_string (num, strings[j], max_characters_in_string);
|
||||
ecma_find_or_create_literal_number (num);
|
||||
}
|
||||
}
|
||||
|
||||
// Add empty string
|
||||
ecma_find_or_create_literal_string (NULL, 0);
|
||||
|
||||
for (uint32_t j = 0; j < test_sub_iters; j++)
|
||||
{
|
||||
jmem_cpointer_t lit1;
|
||||
jmem_cpointer_t lit2;
|
||||
if (ptrs[j])
|
||||
{
|
||||
lit1 = ecma_find_or_create_literal_string (ptrs[j], lengths[j]);
|
||||
lit2 = ecma_find_or_create_literal_string (ptrs[j], lengths[j]);
|
||||
TEST_ASSERT (lit1 == lit2);
|
||||
}
|
||||
else
|
||||
{
|
||||
lit1 = ecma_find_or_create_literal_number (numbers[j]);
|
||||
lit2 = ecma_find_or_create_literal_number (numbers[j]);
|
||||
TEST_ASSERT (lit1 == lit2);
|
||||
}
|
||||
TEST_ASSERT (lit1);
|
||||
TEST_ASSERT (lit2);
|
||||
TEST_ASSERT (lit1 == lit2);
|
||||
}
|
||||
|
||||
// Check empty string exists
|
||||
TEST_ASSERT (ecma_find_or_create_literal_string (NULL, 0) != JMEM_CP_NULL);
|
||||
}
|
||||
|
||||
ecma_finalize_lit_storage ();
|
||||
jmem_finalize ();
|
||||
return 0;
|
||||
} /* main */
|
81
third_party/jerryscript/tests/unit/test-longjmp.c
vendored
Normal file
81
third_party/jerryscript/tests/unit/test-longjmp.c
vendored
Normal file
|
@ -0,0 +1,81 @@
|
|||
/* Copyright 2015-2016 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "test-common.h"
|
||||
|
||||
#define TEST_MAX_DEPTH 10
|
||||
#define TEST_ITERATIONS_NUM 256
|
||||
|
||||
jmp_buf buffers[TEST_MAX_DEPTH];
|
||||
|
||||
static void
|
||||
test_setjmp_longjmp (volatile int depth)
|
||||
{
|
||||
if (depth != TEST_MAX_DEPTH)
|
||||
{
|
||||
int a = 1, b = 2, c = 3;
|
||||
|
||||
int array[256];
|
||||
for (int i = 0; i < 256; i++)
|
||||
{
|
||||
array[i] = i;
|
||||
}
|
||||
|
||||
(void) a;
|
||||
(void) b;
|
||||
(void) c;
|
||||
(void) array;
|
||||
|
||||
int k = setjmp (buffers[depth]);
|
||||
|
||||
if (k == 0)
|
||||
{
|
||||
test_setjmp_longjmp (depth + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
TEST_ASSERT (k == depth + 1);
|
||||
|
||||
TEST_ASSERT (a == 1);
|
||||
TEST_ASSERT (b == 2);
|
||||
TEST_ASSERT (c == 3);
|
||||
|
||||
for (int i = 0; i < 256; i++)
|
||||
{
|
||||
TEST_ASSERT (array[i] == i);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int t = rand () % depth;
|
||||
TEST_ASSERT (t >= 0 && t < depth);
|
||||
|
||||
longjmp (buffers[t], t + 1);
|
||||
}
|
||||
} /* test_setjmp_longjmp */
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
TEST_INIT ();
|
||||
|
||||
for (int i = 0; i < TEST_ITERATIONS_NUM; i++)
|
||||
{
|
||||
test_setjmp_longjmp (0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
} /* main */
|
108
third_party/jerryscript/tests/unit/test-number-to-integer.c
vendored
Normal file
108
third_party/jerryscript/tests/unit/test-number-to-integer.c
vendored
Normal file
|
@ -0,0 +1,108 @@
|
|||
/* Copyright 2015-2016 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
|
||||
#include "test-common.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ecma_number_t num;
|
||||
uint32_t uint32_num;
|
||||
} uint32_test_case_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ecma_number_t num;
|
||||
int32_t int32_num;
|
||||
} int32_test_case_t;
|
||||
|
||||
/**
|
||||
* Unit test's main function.
|
||||
*/
|
||||
int
|
||||
main ()
|
||||
{
|
||||
TEST_INIT ();
|
||||
|
||||
const uint32_test_case_t test_cases_uint32[] =
|
||||
{
|
||||
#define TEST_CASE(num, uint32) { num, uint32 }
|
||||
TEST_CASE (1.0, 1),
|
||||
TEST_CASE (0.0, 0),
|
||||
TEST_CASE (ecma_number_negate (0.0), 0),
|
||||
TEST_CASE (NAN, 0),
|
||||
TEST_CASE (-NAN, 0),
|
||||
TEST_CASE (INFINITY, 0),
|
||||
TEST_CASE (-INFINITY, 0),
|
||||
TEST_CASE (0.1, 0),
|
||||
TEST_CASE (-0.1, 0),
|
||||
TEST_CASE (1.1, 1),
|
||||
TEST_CASE (-1.1, 4294967295),
|
||||
TEST_CASE (4294967295, 4294967295),
|
||||
TEST_CASE (-4294967295, 1),
|
||||
TEST_CASE (4294967296, 0),
|
||||
TEST_CASE (-4294967296, 0),
|
||||
TEST_CASE (4294967297, 1),
|
||||
TEST_CASE (-4294967297, 4294967295)
|
||||
#undef TEST_CASE
|
||||
};
|
||||
|
||||
for (uint32_t i = 0;
|
||||
i < sizeof (test_cases_uint32) / sizeof (test_cases_uint32[0]);
|
||||
i++)
|
||||
{
|
||||
TEST_ASSERT (ecma_number_to_uint32 (test_cases_uint32[i].num) == test_cases_uint32[i].uint32_num);
|
||||
}
|
||||
|
||||
int32_test_case_t test_cases_int32[] =
|
||||
{
|
||||
#define TEST_CASE(num, int32) { num, int32 }
|
||||
TEST_CASE (1.0, 1),
|
||||
TEST_CASE (0.0, 0),
|
||||
TEST_CASE (ecma_number_negate (0.0), 0),
|
||||
TEST_CASE (NAN, 0),
|
||||
TEST_CASE (-NAN, 0),
|
||||
TEST_CASE (INFINITY, 0),
|
||||
TEST_CASE (-INFINITY, 0),
|
||||
TEST_CASE (0.1, 0),
|
||||
TEST_CASE (-0.1, 0),
|
||||
TEST_CASE (1.1, 1),
|
||||
TEST_CASE (-1.1, -1),
|
||||
TEST_CASE (4294967295, -1),
|
||||
TEST_CASE (-4294967295, 1),
|
||||
TEST_CASE (4294967296, 0),
|
||||
TEST_CASE (-4294967296, 0),
|
||||
TEST_CASE (4294967297, 1),
|
||||
TEST_CASE (-4294967297, -1),
|
||||
TEST_CASE (2147483648, -2147483648),
|
||||
TEST_CASE (-2147483648, -2147483648),
|
||||
TEST_CASE (2147483647, 2147483647),
|
||||
TEST_CASE (-2147483647, -2147483647),
|
||||
TEST_CASE (-2147483649, 2147483647),
|
||||
TEST_CASE (2147483649, -2147483647)
|
||||
#undef TEST_CASE
|
||||
};
|
||||
|
||||
for (uint32_t i = 0;
|
||||
i < sizeof (test_cases_int32) / sizeof (test_cases_int32[0]);
|
||||
i++)
|
||||
{
|
||||
TEST_ASSERT (ecma_number_to_int32 (test_cases_int32[i].num) == test_cases_int32[i].int32_num);
|
||||
}
|
||||
|
||||
return 0;
|
||||
} /* main */
|
74
third_party/jerryscript/tests/unit/test-number-to-string.c
vendored
Normal file
74
third_party/jerryscript/tests/unit/test-number-to-string.c
vendored
Normal file
|
@ -0,0 +1,74 @@
|
|||
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
|
||||
#include "test-common.h"
|
||||
|
||||
/**
|
||||
* Unit test's main function.
|
||||
*/
|
||||
int
|
||||
main ()
|
||||
{
|
||||
TEST_INIT ();
|
||||
|
||||
const lit_utf8_byte_t *strings[] =
|
||||
{
|
||||
(const lit_utf8_byte_t *) "1",
|
||||
(const lit_utf8_byte_t *) "0.5",
|
||||
(const lit_utf8_byte_t *) "12345",
|
||||
(const lit_utf8_byte_t *) "12345.123",
|
||||
(const lit_utf8_byte_t *) "1e-45",
|
||||
(const lit_utf8_byte_t *) "-2.5e+38",
|
||||
(const lit_utf8_byte_t *) "NaN",
|
||||
(const lit_utf8_byte_t *) "Infinity",
|
||||
(const lit_utf8_byte_t *) "-Infinity",
|
||||
(const lit_utf8_byte_t *) "0",
|
||||
(const lit_utf8_byte_t *) "0",
|
||||
};
|
||||
|
||||
const ecma_number_t nums[] =
|
||||
{
|
||||
(ecma_number_t) 1.0,
|
||||
(ecma_number_t) 0.5,
|
||||
(ecma_number_t) 12345.0,
|
||||
(ecma_number_t) 12345.123,
|
||||
(ecma_number_t) 1.0e-45,
|
||||
(ecma_number_t) -2.5e+38,
|
||||
(ecma_number_t) NAN,
|
||||
(ecma_number_t) INFINITY,
|
||||
(ecma_number_t) -INFINITY,
|
||||
(ecma_number_t) +0.0,
|
||||
(ecma_number_t) -0.0
|
||||
};
|
||||
|
||||
for (uint32_t i = 0;
|
||||
i < sizeof (nums) / sizeof (nums[0]);
|
||||
i++)
|
||||
{
|
||||
lit_utf8_byte_t str[64];
|
||||
|
||||
lit_utf8_size_t str_size = ecma_number_to_utf8_string (nums[i], str, sizeof (str));
|
||||
|
||||
if (strncmp ((char *) str, (char *) strings[i], str_size) != 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
} /* main */
|
89
third_party/jerryscript/tests/unit/test-poolman.c
vendored
Normal file
89
third_party/jerryscript/tests/unit/test-poolman.c
vendored
Normal file
|
@ -0,0 +1,89 @@
|
|||
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2016 University of Szeged.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Unit test for pool manager.
|
||||
*/
|
||||
|
||||
#define JERRY_MEM_POOL_INTERNAL
|
||||
|
||||
#include "jmem-allocator.h"
|
||||
#include "jmem-poolman.h"
|
||||
|
||||
#include "test-common.h"
|
||||
|
||||
// Iterations count
|
||||
const uint32_t test_iters = 1024;
|
||||
|
||||
// Subiterations count
|
||||
#define TEST_MAX_SUB_ITERS 1024
|
||||
#define TEST_CHUNK_SIZE 8
|
||||
|
||||
uint8_t *ptrs[TEST_MAX_SUB_ITERS];
|
||||
uint8_t data[TEST_MAX_SUB_ITERS][TEST_CHUNK_SIZE];
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
TEST_INIT ();
|
||||
|
||||
jmem_init ();
|
||||
|
||||
for (uint32_t i = 0; i < test_iters; i++)
|
||||
{
|
||||
const size_t subiters = ((size_t) rand () % TEST_MAX_SUB_ITERS) + 1;
|
||||
|
||||
for (size_t j = 0; j < subiters; j++)
|
||||
{
|
||||
ptrs[j] = (uint8_t *) jmem_pools_alloc (TEST_CHUNK_SIZE);
|
||||
|
||||
if (ptrs[j] != NULL)
|
||||
{
|
||||
for (size_t k = 0; k < TEST_CHUNK_SIZE; k++)
|
||||
{
|
||||
ptrs[j][k] = (uint8_t) (rand () % 256);
|
||||
}
|
||||
|
||||
memcpy (data[j], ptrs[j], TEST_CHUNK_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
/* jmem_heap_print (false); */
|
||||
|
||||
for (size_t j = 0; j < subiters; j++)
|
||||
{
|
||||
if (rand () % 256 == 0)
|
||||
{
|
||||
jmem_pools_collect_empty ();
|
||||
}
|
||||
|
||||
if (ptrs[j] != NULL)
|
||||
{
|
||||
TEST_ASSERT (!memcmp (data[j], ptrs[j], TEST_CHUNK_SIZE));
|
||||
|
||||
jmem_pools_free (ptrs[j], TEST_CHUNK_SIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef JMEM_STATS
|
||||
jmem_pools_stats_print ();
|
||||
#endif /* JMEM_STATS */
|
||||
|
||||
jmem_finalize ();
|
||||
|
||||
return 0;
|
||||
} /* main */
|
90
third_party/jerryscript/tests/unit/test-string-to-number.c
vendored
Normal file
90
third_party/jerryscript/tests/unit/test-string-to-number.c
vendored
Normal file
|
@ -0,0 +1,90 @@
|
|||
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2016 University of Szeged.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "jerry-api.h"
|
||||
|
||||
#include "test-common.h"
|
||||
|
||||
/**
|
||||
* Unit test's main function.
|
||||
*/
|
||||
int
|
||||
main ()
|
||||
{
|
||||
TEST_INIT ();
|
||||
|
||||
const jerry_char_t *strings[] =
|
||||
{
|
||||
(const jerry_char_t *) "1",
|
||||
(const jerry_char_t *) "0.5",
|
||||
(const jerry_char_t *) "12345",
|
||||
(const jerry_char_t *) "1e-45",
|
||||
(const jerry_char_t *) "-2.5e+38",
|
||||
(const jerry_char_t *) "-2.5e38",
|
||||
(const jerry_char_t *) "- 2.5e+38",
|
||||
(const jerry_char_t *) "-2 .5e+38",
|
||||
(const jerry_char_t *) "-2. 5e+38",
|
||||
(const jerry_char_t *) "-2.5e+ 38",
|
||||
(const jerry_char_t *) "-2.5 e+38",
|
||||
(const jerry_char_t *) "-2.5e +38",
|
||||
(const jerry_char_t *) "NaN",
|
||||
(const jerry_char_t *) "abc",
|
||||
(const jerry_char_t *) " Infinity ",
|
||||
(const jerry_char_t *) "-Infinity",
|
||||
(const jerry_char_t *) "0",
|
||||
(const jerry_char_t *) "0",
|
||||
};
|
||||
|
||||
const ecma_number_t nums[] =
|
||||
{
|
||||
(ecma_number_t) 1.0,
|
||||
(ecma_number_t) 0.5,
|
||||
(ecma_number_t) 12345.0,
|
||||
(ecma_number_t) 1.0e-45,
|
||||
(ecma_number_t) -2.5e+38,
|
||||
(ecma_number_t) -2.5e+38,
|
||||
(ecma_number_t) NAN,
|
||||
(ecma_number_t) NAN,
|
||||
(ecma_number_t) NAN,
|
||||
(ecma_number_t) NAN,
|
||||
(ecma_number_t) NAN,
|
||||
(ecma_number_t) NAN,
|
||||
(ecma_number_t) NAN,
|
||||
(ecma_number_t) NAN,
|
||||
(ecma_number_t) INFINITY,
|
||||
(ecma_number_t) -INFINITY,
|
||||
(ecma_number_t) +0.0,
|
||||
(ecma_number_t) -0.0
|
||||
};
|
||||
|
||||
for (uint32_t i = 0;
|
||||
i < sizeof (nums) / sizeof (nums[0]);
|
||||
i++)
|
||||
{
|
||||
ecma_number_t num = ecma_utf8_string_to_number (strings[i], lit_zt_utf8_string_size (strings[i]));
|
||||
|
||||
if (num != nums[i]
|
||||
&& (!ecma_number_is_nan (num)
|
||||
|| !ecma_number_is_nan (nums[i])))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
} /* main */
|
223
third_party/jerryscript/tests/unit/test-strings.c
vendored
Normal file
223
third_party/jerryscript/tests/unit/test-strings.c
vendored
Normal file
|
@ -0,0 +1,223 @@
|
|||
/* Copyright 2015-2016 Samsung Electronics Co., Ltd.
|
||||
* Copyright 2016 University of Szeged.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecma-helpers.h"
|
||||
#include "lit-strings.h"
|
||||
#include "ecma-init-finalize.h"
|
||||
|
||||
#include "test-common.h"
|
||||
|
||||
// Iterations count
|
||||
#define test_iters (1024)
|
||||
|
||||
// Sub iterations count
|
||||
#define test_subiters (128)
|
||||
|
||||
// Max bytes in string
|
||||
#define max_bytes_in_string (16 * 1024)
|
||||
#define max_code_units_in_string (max_bytes_in_string)
|
||||
|
||||
typedef enum
|
||||
{
|
||||
CESU8_ANY_SIZE,
|
||||
CESU8_ONE_BYTE,
|
||||
CESU8_TWO_BYTES,
|
||||
CESU8_THREE_BYTES,
|
||||
} utf8_char_size;
|
||||
|
||||
static lit_utf8_size_t
|
||||
generate_cesu8_char (utf8_char_size char_size,
|
||||
lit_utf8_byte_t *buf)
|
||||
{
|
||||
TEST_ASSERT (char_size >= 0 && char_size <= LIT_CESU8_MAX_BYTES_IN_CODE_UNIT);
|
||||
lit_code_point_t code_point = (lit_code_point_t) rand ();
|
||||
|
||||
if (char_size == 1)
|
||||
{
|
||||
code_point %= LIT_UTF8_1_BYTE_CODE_POINT_MAX;
|
||||
}
|
||||
else if (char_size == 2)
|
||||
{
|
||||
code_point = LIT_UTF8_2_BYTE_CODE_POINT_MIN + code_point % (LIT_UTF8_2_BYTE_CODE_POINT_MAX -
|
||||
LIT_UTF8_2_BYTE_CODE_POINT_MIN);
|
||||
}
|
||||
else if (char_size == 3)
|
||||
{
|
||||
code_point = LIT_UTF8_3_BYTE_CODE_POINT_MIN + code_point % (LIT_UTF8_3_BYTE_CODE_POINT_MAX -
|
||||
LIT_UTF8_3_BYTE_CODE_POINT_MIN);
|
||||
}
|
||||
else
|
||||
{
|
||||
code_point %= LIT_UTF8_3_BYTE_CODE_POINT_MAX;
|
||||
}
|
||||
|
||||
if (code_point >= LIT_UTF16_HIGH_SURROGATE_MIN
|
||||
&& code_point <= LIT_UTF16_LOW_SURROGATE_MAX)
|
||||
{
|
||||
code_point = LIT_UTF16_HIGH_SURROGATE_MIN - 1;
|
||||
}
|
||||
|
||||
return lit_code_unit_to_utf8 ((ecma_char_t) code_point, buf);
|
||||
} /* generate_cesu8_char */
|
||||
|
||||
static ecma_length_t
|
||||
generate_cesu8_string (lit_utf8_byte_t *buf_p,
|
||||
lit_utf8_size_t buf_size)
|
||||
{
|
||||
ecma_length_t length = 0;
|
||||
|
||||
lit_utf8_size_t size = 0;
|
||||
while (size < buf_size)
|
||||
{
|
||||
const utf8_char_size char_size = (((buf_size - size) > LIT_CESU8_MAX_BYTES_IN_CODE_UNIT)
|
||||
? CESU8_ANY_SIZE
|
||||
: (utf8_char_size) (buf_size - size));
|
||||
|
||||
lit_utf8_size_t bytes_generated = generate_cesu8_char (char_size, buf_p);
|
||||
|
||||
TEST_ASSERT (lit_is_cesu8_string_valid (buf_p, bytes_generated));
|
||||
|
||||
size += bytes_generated;
|
||||
buf_p += bytes_generated;
|
||||
length++;
|
||||
}
|
||||
|
||||
TEST_ASSERT (size == buf_size);
|
||||
|
||||
return length;
|
||||
} /* generate_cesu8_string */
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
TEST_INIT ();
|
||||
|
||||
jmem_init ();
|
||||
ecma_init ();
|
||||
|
||||
lit_utf8_byte_t cesu8_string[max_bytes_in_string];
|
||||
ecma_char_t code_units[max_code_units_in_string];
|
||||
const lit_utf8_byte_t *saved_positions[max_code_units_in_string];
|
||||
|
||||
for (int i = 0; i < test_iters; i++)
|
||||
{
|
||||
lit_utf8_size_t cesu8_string_size = (i == 0) ? 0 : (lit_utf8_size_t) (rand () % max_bytes_in_string);
|
||||
ecma_length_t length = generate_cesu8_string (cesu8_string, cesu8_string_size);
|
||||
|
||||
ecma_string_t *char_collection_string_p = ecma_new_ecma_string_from_utf8 (cesu8_string, cesu8_string_size);
|
||||
ecma_length_t char_collection_len = ecma_string_get_length (char_collection_string_p);
|
||||
TEST_ASSERT (char_collection_len == length);
|
||||
ecma_deref_ecma_string (char_collection_string_p);
|
||||
|
||||
TEST_ASSERT (lit_utf8_string_length (cesu8_string, cesu8_string_size) == length);
|
||||
|
||||
const lit_utf8_byte_t *curr_p = cesu8_string;
|
||||
const lit_utf8_byte_t *end_p = cesu8_string + cesu8_string_size;
|
||||
|
||||
ecma_length_t calculated_length = 0;
|
||||
ecma_length_t code_units_count = 0;
|
||||
|
||||
while (curr_p < end_p)
|
||||
{
|
||||
code_units[code_units_count] = lit_utf8_peek_next (curr_p);
|
||||
saved_positions[code_units_count] = curr_p;
|
||||
code_units_count++;
|
||||
calculated_length++;
|
||||
|
||||
lit_utf8_incr (&curr_p);
|
||||
}
|
||||
|
||||
TEST_ASSERT (length == calculated_length);
|
||||
|
||||
if (code_units_count > 0)
|
||||
{
|
||||
for (int j = 0; j < test_subiters; j++)
|
||||
{
|
||||
ecma_length_t index = (ecma_length_t) rand () % code_units_count;
|
||||
curr_p = saved_positions[index];
|
||||
TEST_ASSERT (lit_utf8_peek_next (curr_p) == code_units[index]);
|
||||
}
|
||||
}
|
||||
|
||||
curr_p = (lit_utf8_byte_t *) end_p;
|
||||
while (curr_p > cesu8_string)
|
||||
{
|
||||
TEST_ASSERT (code_units_count > 0);
|
||||
calculated_length--;
|
||||
TEST_ASSERT (code_units[calculated_length] == lit_utf8_peek_prev (curr_p));
|
||||
lit_utf8_decr (&curr_p);
|
||||
}
|
||||
|
||||
TEST_ASSERT (calculated_length == 0);
|
||||
|
||||
while (curr_p < end_p)
|
||||
{
|
||||
ecma_char_t code_unit = lit_utf8_read_next (&curr_p);
|
||||
TEST_ASSERT (code_unit == code_units[calculated_length]);
|
||||
calculated_length++;
|
||||
}
|
||||
|
||||
TEST_ASSERT (length == calculated_length);
|
||||
|
||||
while (curr_p > cesu8_string)
|
||||
{
|
||||
TEST_ASSERT (code_units_count > 0);
|
||||
calculated_length--;
|
||||
TEST_ASSERT (code_units[calculated_length] == lit_utf8_read_prev (&curr_p));
|
||||
}
|
||||
|
||||
TEST_ASSERT (calculated_length == 0);
|
||||
}
|
||||
|
||||
/* Overlong-encoded code point */
|
||||
lit_utf8_byte_t invalid_cesu8_string_1[] = {0xC0, 0x82};
|
||||
TEST_ASSERT (!lit_is_cesu8_string_valid (invalid_cesu8_string_1, sizeof (invalid_cesu8_string_1)));
|
||||
|
||||
/* Overlong-encoded code point */
|
||||
lit_utf8_byte_t invalid_cesu8_string_2[] = {0xE0, 0x80, 0x81};
|
||||
TEST_ASSERT (!lit_is_cesu8_string_valid (invalid_cesu8_string_2, sizeof (invalid_cesu8_string_2)));
|
||||
|
||||
/* Pair of surrogates: 0xD901 0xDFF0 which encode Unicode character 0x507F0 */
|
||||
lit_utf8_byte_t invalid_cesu8_string_3[] = {0xED, 0xA4, 0x81, 0xED, 0xBF, 0xB0};
|
||||
TEST_ASSERT (lit_is_cesu8_string_valid (invalid_cesu8_string_3, sizeof (invalid_cesu8_string_3)));
|
||||
|
||||
/* Isolated high surrogate 0xD901 */
|
||||
lit_utf8_byte_t valid_utf8_string_1[] = {0xED, 0xA4, 0x81};
|
||||
TEST_ASSERT (lit_is_cesu8_string_valid (valid_utf8_string_1, sizeof (valid_utf8_string_1)));
|
||||
|
||||
lit_utf8_byte_t res_buf[3];
|
||||
lit_utf8_size_t res_size;
|
||||
|
||||
res_size = lit_code_unit_to_utf8 (0x73, res_buf);
|
||||
TEST_ASSERT (res_size == 1);
|
||||
TEST_ASSERT (res_buf[0] == 0x73);
|
||||
|
||||
res_size = lit_code_unit_to_utf8 (0x41A, res_buf);
|
||||
TEST_ASSERT (res_size == 2);
|
||||
TEST_ASSERT (res_buf[0] == 0xD0);
|
||||
TEST_ASSERT (res_buf[1] == 0x9A);
|
||||
|
||||
res_size = lit_code_unit_to_utf8 (0xD7FF, res_buf);
|
||||
TEST_ASSERT (res_size == 3);
|
||||
TEST_ASSERT (res_buf[0] == 0xED);
|
||||
TEST_ASSERT (res_buf[1] == 0x9F);
|
||||
TEST_ASSERT (res_buf[2] == 0xBF);
|
||||
|
||||
ecma_finalize ();
|
||||
jmem_finalize ();
|
||||
|
||||
return 0;
|
||||
} /* main */
|
Loading…
Add table
Add a link
Reference in a new issue