forked from newrelic/newrelic-php-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_reply.c
165 lines (142 loc) · 6.35 KB
/
test_reply.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
#include "nr_axiom.h"
#include "nr_rules.h"
#include "util_metrics.h"
#include "util_object.h"
#include "util_reply.h"
#include "tlib_main.h"
nr_rules_result_t nr_rules_apply(const nrrules_t* rules NRUNUSED,
const char* name NRUNUSED,
char** new_name NRUNUSED) {
return NR_RULES_RESULT_UNCHANGED;
}
static void test_reply_get_int(const nrobj_t* reply,
const nrobj_t* arr,
const nrobj_t* empty) {
int rv;
rv = nr_reply_get_int(0, 0, 11);
tlib_pass_if_true("null params", 11 == rv, "rv=%d", rv);
rv = nr_reply_get_int(0, "intkey", 11);
tlib_pass_if_true("null reply", 11 == rv, "rv=%d", rv);
rv = nr_reply_get_int(reply, 0, 11);
tlib_pass_if_true("null name", 11 == rv, "rv=%d", rv);
rv = nr_reply_get_int(reply, "", 11);
tlib_pass_if_true("empty name", 11 == rv, "rv=%d", rv);
rv = nr_reply_get_int(arr, "intkey", 11);
tlib_pass_if_true("reply is wrong type", 11 == rv, "rv=%d", rv);
rv = nr_reply_get_int(empty, "intkey", 11);
tlib_pass_if_true("reply is empty", 11 == rv, "rv=%d", rv);
rv = nr_reply_get_int(reply, "hashkey", 11);
tlib_pass_if_true("name is wrong type", 11 == rv, "rv=%d", rv);
rv = nr_reply_get_int(reply, "intkey", 11);
tlib_pass_if_true("success int", 22 == rv, "rv=%d", rv);
}
static void test_reply_get_bool(const nrobj_t* reply,
const nrobj_t* arr,
const nrobj_t* empty) {
int rv;
rv = nr_reply_get_bool(0, 0, 11);
tlib_pass_if_true("null params", 11 == rv, "rv=%d", rv);
rv = nr_reply_get_bool(0, "intkey", 11);
tlib_pass_if_true("null reply", 11 == rv, "rv=%d", rv);
rv = nr_reply_get_bool(reply, 0, 11);
tlib_pass_if_true("null name", 11 == rv, "rv=%d", rv);
rv = nr_reply_get_bool(reply, "", 11);
tlib_pass_if_true("empty name", 11 == rv, "rv=%d", rv);
rv = nr_reply_get_bool(arr, "intkey", 11);
tlib_pass_if_true("reply is wrong type", 11 == rv, "rv=%d", rv);
rv = nr_reply_get_bool(empty, "intkey", 11);
tlib_pass_if_true("reply is empty", 11 == rv, "rv=%d", rv);
rv = nr_reply_get_bool(reply, "hashkey", 11);
tlib_pass_if_true("name is wrong type", 11 == rv, "rv=%d", rv);
rv = nr_reply_get_bool(reply, "stringkey", 11);
tlib_pass_if_true("unknown string", 11 == rv, "rv=%d", rv);
rv = nr_reply_get_bool(reply, "intkey", 11);
tlib_pass_if_true("success int", 22 == rv, "rv=%d", rv);
rv = nr_reply_get_bool(reply, "1key", 11);
tlib_pass_if_true("success 1key", 1 == rv, "rv=%d", rv);
rv = nr_reply_get_bool(reply, "ykey", 11);
tlib_pass_if_true("success ykey", 1 == rv, "rv=%d", rv);
rv = nr_reply_get_bool(reply, "Ykey", 11);
tlib_pass_if_true("success Ykey", 1 == rv, "rv=%d", rv);
rv = nr_reply_get_bool(reply, "tkey", 11);
tlib_pass_if_true("success tkey", 1 == rv, "rv=%d", rv);
rv = nr_reply_get_bool(reply, "Tkey", 11);
tlib_pass_if_true("success Tkey", 1 == rv, "rv=%d", rv);
rv = nr_reply_get_bool(reply, "onkey", 11);
tlib_pass_if_true("success onkey", 1 == rv, "rv=%d", rv);
rv = nr_reply_get_bool(reply, "0key", 11);
tlib_pass_if_true("success 0key", 0 == rv, "rv=%d", rv);
rv = nr_reply_get_bool(reply, "nkey", 11);
tlib_pass_if_true("success nkey", 0 == rv, "rv=%d", rv);
rv = nr_reply_get_bool(reply, "Nkey", 11);
tlib_pass_if_true("success Nkey", 0 == rv, "rv=%d", rv);
rv = nr_reply_get_bool(reply, "fkey", 11);
tlib_pass_if_true("success fkey", 0 == rv, "rv=%d", rv);
rv = nr_reply_get_bool(reply, "Fkey", 11);
tlib_pass_if_true("success Fkey", 0 == rv, "rv=%d", rv);
rv = nr_reply_get_bool(reply, "offkey", 11);
tlib_pass_if_true("success offkey", 0 == rv, "rv=%d", rv);
}
static void test_reply_get_double(const nrobj_t* reply,
const nrobj_t* arr,
const nrobj_t* empty) {
double rv;
rv = nr_reply_get_double(0, 0, 1.1);
tlib_pass_if_true("null params", 1.1 == rv, "rv=%f", rv);
rv = nr_reply_get_double(0, "intkey", 1.1);
tlib_pass_if_true("null reply", 1.1 == rv, "rv=%f", rv);
rv = nr_reply_get_double(reply, 0, 1.1);
tlib_pass_if_true("null name", 1.1 == rv, "rv=%f", rv);
rv = nr_reply_get_double(reply, "", 1.1);
tlib_pass_if_true("empty name", 1.1 == rv, "rv=%f", rv);
rv = nr_reply_get_double(arr, "intkey", 1.1);
tlib_pass_if_true("reply is wrong type", 1.1 == rv, "rv=%f", rv);
rv = nr_reply_get_double(empty, "intkey", 1.1);
tlib_pass_if_true("reply is empty", 1.1 == rv, "rv=%f", rv);
rv = nr_reply_get_double(reply, "hashkey", 1.1);
tlib_pass_if_true("name is wrong type", 1.1 == rv, "rv=%f", rv);
rv = nr_reply_get_double(reply, "stringkey", 1.1);
tlib_pass_if_true("name is wrong type", 1.1 == rv, "rv=%f", rv);
rv = nr_reply_get_double(reply, "intkey", 1.1);
tlib_pass_if_true("success int", 22 == rv, "rv=%f", rv);
rv = nr_reply_get_double(reply, "longkey", 1.1);
tlib_pass_if_true("success long", 44 == rv, "rv=%f", rv);
rv = nr_reply_get_double(reply, "doublekey", 1.1);
tlib_pass_if_true("success double", 12.5 == rv, "rv=%f", rv);
}
tlib_parallel_info_t parallel_info = {.suggested_nthreads = 2, .state_size = 0};
void test_main(void* p NRUNUSED) {
nrobj_t* reply;
nrobj_t* arr;
nrobj_t* empty;
reply = nro_new_hash();
arr = nro_new_array();
empty = nro_new_hash();
nro_set_hash(reply, "hashkey", empty);
nro_set_hash_int(reply, "intkey", 22);
nro_set_hash_long(reply, "longkey", 44);
nro_set_hash_double(reply, "doublekey", 12.5);
nro_set_hash_string(reply, "stringkey", "stringvalue");
nro_set_hash_string(reply, "1key", "1value");
nro_set_hash_string(reply, "ykey", "yvalue");
nro_set_hash_string(reply, "Ykey", "Yvalue");
nro_set_hash_string(reply, "tkey", "tvalue");
nro_set_hash_string(reply, "Tkey", "Tvalue");
nro_set_hash_string(reply, "onkey", "on");
nro_set_hash_string(reply, "0key", "0value");
nro_set_hash_string(reply, "nkey", "nvalue");
nro_set_hash_string(reply, "Nkey", "Nvalue");
nro_set_hash_string(reply, "fkey", "fvalue");
nro_set_hash_string(reply, "Fkey", "Fvalue");
nro_set_hash_string(reply, "offkey", "off");
test_reply_get_int(reply, arr, empty);
test_reply_get_bool(reply, arr, empty);
test_reply_get_double(reply, arr, empty);
nro_delete(empty);
nro_delete(reply);
nro_delete(arr);
}