Skip to content

Commit 3e607da

Browse files
committed
add tests for multiple scoped method additions
1 parent 044cbd2 commit 3e607da

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

agent/tests/test_user_instrument_wraprec_hashmap.c

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ tlib_parallel_info_t parallel_info
2020
#define FUNCTION_NAME "global_function"
2121

2222
static void test_wraprecs_hashmap() {
23-
nruserfn_t *wraprec, *found_wraprec;
24-
zend_string *func_name, *scope_name, *method_name;
23+
nruserfn_t *wraprec, *another_method_wraprec, *yet_another_method_wraprec, *found_wraprec;
24+
zend_string *func_name, *scope_name, *method_name, *scope, *method;
2525
bool is_new_wraprec = false;
2626
bool *is_new_wraprec_tests[] = {NULL, &is_new_wraprec};
2727

@@ -104,6 +104,43 @@ static void test_wraprecs_hashmap() {
104104
found_wraprec = nr_php_user_instrument_wraprec_hashmap_get(method_name, NULL);
105105
tlib_pass_if_null("getting scoped method without scope", found_wraprec);
106106

107+
another_method_wraprec = nr_php_user_instrument_wraprec_hashmap_add(NR_PSTR(SCOPE_NAME "::anotherMethod"),
108+
is_new_wraprec_ptr);
109+
tlib_pass_if_not_null("adding another scoped method", another_method_wraprec);
110+
if (NULL != is_new_wraprec_ptr) {
111+
tlib_pass_if_true("adding another scoped method", *is_new_wraprec_ptr,
112+
"expected true for is_new_wraprec");
113+
}
114+
scope = zend_string_init_fast(NR_PSTR(SCOPE_NAME));
115+
method = zend_string_init_fast(NR_PSTR("anotherMethod"));
116+
found_wraprec = nr_php_user_instrument_wraprec_hashmap_get(method, scope);
117+
tlib_pass_if_ptr_equal("getting another scoped method", another_method_wraprec, found_wraprec);
118+
119+
another_method_wraprec = nr_php_user_instrument_wraprec_hashmap_add(NR_PSTR(SCOPE_NAME "::anotherMethod"),
120+
is_new_wraprec_ptr);
121+
tlib_pass_if_not_null("adding another scoped method one more time", another_method_wraprec);
122+
if (NULL != is_new_wraprec_ptr) {
123+
tlib_pass_if_false("adding another scoped method one more time", *is_new_wraprec_ptr,
124+
"expected false for is_new_wraprec");
125+
}
126+
tlib_pass_if_ptr_equal("getting another scoped method one more time", another_method_wraprec, found_wraprec);
127+
zend_string_free(method);
128+
zend_string_free(scope);
129+
130+
yet_another_method_wraprec = nr_php_user_instrument_wraprec_hashmap_add(NR_PSTR(SCOPE_NAME "::anotherMethodStill"),
131+
is_new_wraprec_ptr);
132+
tlib_pass_if_not_null("adding yet another scoped method", yet_another_method_wraprec);
133+
if (NULL != is_new_wraprec_ptr) {
134+
tlib_pass_if_true("adding yet another scoped method", *is_new_wraprec_ptr,
135+
"expected true for is_new_wraprec");
136+
}
137+
scope = zend_string_init_fast(NR_PSTR(SCOPE_NAME));
138+
method = zend_string_init_fast(NR_PSTR("anotherMethodStill"));
139+
found_wraprec = nr_php_user_instrument_wraprec_hashmap_get(method, scope);
140+
tlib_pass_if_ptr_equal("getting another scoped method", yet_another_method_wraprec, found_wraprec);
141+
zend_string_free(method);
142+
zend_string_free(scope);
143+
107144
nr_php_user_instrument_wraprec_hashmap_destroy();
108145
}
109146

0 commit comments

Comments
 (0)