forked from newrelic/newrelic-php-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_set.c
85 lines (64 loc) · 1.91 KB
/
test_set.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
/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
#include "nr_axiom.h"
#include "util_set.h"
#include "tlib_main.h"
#include <stdio.h>
tlib_parallel_info_t parallel_info = {.suggested_nthreads = 2, .state_size = 0};
static void test_bad_parameters(void) {
nr_set_t* set = NULL;
nr_set_destroy(NULL);
nr_set_destroy(&set);
tlib_pass_if_bool_equal("NULL contains", false, nr_set_contains(NULL, NULL));
nr_set_insert(NULL, NULL);
tlib_pass_if_size_t_equal("NULL size", 0, nr_set_size(NULL));
}
static void test_create_destroy(void) {
nr_set_t* set;
/*
* Test : Destroying an empty set.
*/
set = nr_set_create();
tlib_pass_if_not_null("create", set);
nr_set_destroy(&set);
/*
* Test : Destroying a non-empty set.
*/
set = nr_set_create();
tlib_pass_if_not_null("create", set);
nr_set_insert(set, (const void*)1);
nr_set_destroy(&set);
}
#define SET_SIZE 100000
static void test_set(void) {
uintptr_t i;
nr_set_t* set = nr_set_create();
/* Insert initial values. */
for (i = 0; i < SET_SIZE; i++) {
nr_set_insert(set, (const void*)i);
}
/* Insert the same values again. */
for (i = 0; i < SET_SIZE; i++) {
nr_set_insert(set, (const void*)i);
}
/* Verify that the duplicate values weren't added. */
tlib_pass_if_size_t_equal("set size", SET_SIZE, nr_set_size(set));
/* Test that the expected values all exist. */
for (i = 0; i < SET_SIZE; i++) {
tlib_pass_if_bool_equal("exists", true,
nr_set_contains(set, (const void*)i));
}
/* Test that unexpected values don't exist. */
for (i = SET_SIZE; i < SET_SIZE * 2; i++) {
tlib_pass_if_bool_equal("doesn't exist", false,
nr_set_contains(set, (const void*)i));
}
nr_set_destroy(&set);
}
void test_main(void* p NRUNUSED) {
test_bad_parameters();
test_create_destroy();
test_set();
}