1/* Copyright JS Foundation and other contributors, http://js.foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/**
17 * Unit test for jerry-ext/autorelease.
18 */
19
20#include "jerryscript.h"
21#include "jerryscript-ext/autorelease.h"
22#include "test-common.h"
23
24static int native_free_cb_call_count;
25
26static void
27native_free_cb (void *native_p)
28{
29  ++native_free_cb_call_count;
30  (void) native_p;
31} /* native_free_cb */
32
33static const jerry_object_native_info_t native_info =
34{
35  .free_cb = native_free_cb,
36};
37
38static jerry_value_t
39create_object (void)
40{
41  jerry_value_t obj = jerry_create_object ();
42  jerry_set_object_native_pointer (obj, NULL, &native_info);
43  return obj;
44} /* create_object */
45
46static void
47test_autorelease_val (void)
48{
49  JERRYX_AR_VALUE_T obj = create_object ();
50  (void) obj;
51} /* test_autorelease_val */
52
53int
54main (void)
55{
56  jerry_init (JERRY_INIT_EMPTY);
57
58  native_free_cb_call_count = 0;
59  test_autorelease_val ();
60  jerry_gc (JERRY_GC_PRESSURE_HIGH);
61  TEST_ASSERT (native_free_cb_call_count == 1);
62
63  jerry_cleanup ();
64} /* main */
65