-
Notifications
You must be signed in to change notification settings - Fork 5
/
test_memory_cache.c
56 lines (37 loc) · 1.26 KB
/
test_memory_cache.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
#include "test.h"
#include <core/system/memory_cache.h>
#include <core/structures/vector.h>
#include <stdint.h>
#include <inttypes.h>
int main(int argc, char **argv)
{
BEGIN_TESTS();
struct core_memory_cache cache;
size_t size = 5;
size_t chunk_size = 8388608;
void *pointer;
void *old_pointer;
struct core_vector vector;
int i;
core_memory_cache_init(&cache, -1, size, chunk_size);
TEST_INT_EQUALS(core_memory_cache_balance(&cache), 0);
pointer = core_memory_cache_allocate(&cache, size);
TEST_POINTER_NOT_EQUALS(pointer, NULL);
old_pointer = pointer;
TEST_INT_EQUALS(core_memory_cache_balance(&cache), 1);
core_memory_cache_free(&cache, pointer);
pointer = core_memory_cache_allocate(&cache, size);
TEST_POINTER_EQUALS(pointer, old_pointer);
core_memory_cache_free(&cache, pointer);
TEST_INT_EQUALS(core_memory_cache_balance(&cache), 0);
core_vector_init(&vector, sizeof(void *));
for (i = 0; i < 2000000; ++i) {
pointer = core_memory_cache_allocate(&cache, size);
TEST_POINTER_NOT_EQUALS(pointer, NULL);
core_vector_push_back(&vector, &pointer);
}
core_memory_cache_destroy(&cache);
core_vector_destroy(&vector);
END_TESTS();
return 0;
}