20
20
static bool test_context_data1_new_called = false;
21
21
static bool test_context_data2_new_called = false;
22
22
static bool test_context_data3_new_called = false;
23
+ static bool test_context_data4_new_called = false;
23
24
static bool test_context_data1_free_called = false;
24
25
static bool test_context_data2_free_called = false;
26
+ static bool test_context_data4_free_called = false;
25
27
static bool test_context_data1_finalize_called = false;
28
+ static bool test_context_data4_finalize_called = false;
26
29
27
30
/* Context item 1 */
28
31
const char * string1 = "item1" ;
@@ -84,13 +87,12 @@ static const jerry_context_data_manager_t manager2 =
84
87
};
85
88
86
89
/* Context item 3 */
87
- const char * string3 = "item3" ;
88
90
89
91
static void
90
92
test_context_data3_new (void * user_data_p )
91
93
{
94
+ JERRY_UNUSED (user_data_p );
92
95
test_context_data3_new_called = true;
93
- * ((const char * * ) user_data_p ) = string3 ;
94
96
} /* test_context_data3_new */
95
97
96
98
static const jerry_context_data_manager_t manager3 =
@@ -102,6 +104,41 @@ static const jerry_context_data_manager_t manager3 =
102
104
.bytes_needed = 0 ,
103
105
};
104
106
107
+ /* Context item 4 */
108
+
109
+ static void
110
+ test_context_data4_new (void * user_data_p )
111
+ {
112
+ test_context_data4_new_called = true;
113
+ TEST_ASSERT (user_data_p == NULL );
114
+ } /* test_context_data4_new */
115
+
116
+
117
+ static void
118
+ test_context_data4_free (void * user_data_p )
119
+ {
120
+ test_context_data4_free_called = true;
121
+ TEST_ASSERT (user_data_p == NULL );
122
+ TEST_ASSERT (!test_context_data4_finalize_called );
123
+ } /* test_context_data4_free */
124
+
125
+ static void
126
+ test_context_data4_finalize (void * user_data_p )
127
+ {
128
+ TEST_ASSERT (!test_context_data4_finalize_called );
129
+ test_context_data4_finalize_called = true;
130
+ TEST_ASSERT (user_data_p == NULL );
131
+ } /* test_context_data4_finalize */
132
+
133
+ static const jerry_context_data_manager_t manager4 =
134
+ {
135
+ .init_cb = test_context_data4_new ,
136
+ .deinit_cb = test_context_data4_free ,
137
+ .finalize_cb = test_context_data4_finalize ,
138
+ .bytes_needed = 0
139
+ };
140
+
141
+
105
142
int
106
143
main (void )
107
144
{
@@ -111,19 +148,26 @@ main (void)
111
148
112
149
TEST_ASSERT (!strcmp (* ((const char * * ) jerry_get_context_data (& manager1 )), "item1" ));
113
150
TEST_ASSERT (!strcmp (* ((const char * * ) jerry_get_context_data (& manager2 )), "item2" ));
114
- TEST_ASSERT (!strcmp (* ((const char * * ) jerry_get_context_data (& manager3 )), "item3" ));
151
+ TEST_ASSERT (jerry_get_context_data (& manager3 ) == NULL );
152
+ TEST_ASSERT (jerry_get_context_data (& manager4 ) == NULL );
115
153
116
154
TEST_ASSERT (test_context_data1_new_called );
117
155
TEST_ASSERT (test_context_data2_new_called );
118
156
TEST_ASSERT (test_context_data3_new_called );
157
+ TEST_ASSERT (test_context_data4_new_called );
119
158
120
159
TEST_ASSERT (!test_context_data1_free_called );
121
160
TEST_ASSERT (!test_context_data2_free_called );
161
+ TEST_ASSERT (!test_context_data4_free_called );
122
162
123
163
jerry_cleanup ();
124
164
125
165
TEST_ASSERT (test_context_data1_free_called );
126
166
TEST_ASSERT (test_context_data2_free_called );
167
+ TEST_ASSERT (test_context_data4_free_called );
168
+
169
+ TEST_ASSERT (test_context_data1_finalize_called );
170
+ TEST_ASSERT (test_context_data4_finalize_called );
127
171
128
172
return 0 ;
129
173
} /* main */
0 commit comments