-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpool.c
52 lines (37 loc) · 1.11 KB
/
pool.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
#include "munit/munit.h"
#include "../pool.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define sz 16
static MunitResult test_basic(const MunitParameter params[], void* data) {
session_pool p;
session *ss[sz];
munit_assert(0 == session_pool_init(&p, 16));
for (int i = 0; i < sz; i++) {
munit_assert(NULL != (ss[i] = session_pool_alloc(&p)));
}
munit_assert(NULL == session_pool_alloc(&p));
for (int i = 0; i < sz; i+=2) {
session_pool_free(&p, ss[i]);
}
for (int i = 0; i < sz; i+=2) {
munit_assert(NULL != session_pool_alloc(&p));
}
munit_assert(NULL == session_pool_alloc(&p));
session_pool_destroy(&p);
return MUNIT_OK;
}
static void* setup(const MunitParameter params[], void* user_data) {
return NULL;
}
static void tear_down(void* fixture) {
}
static MunitTest test_suite_tests[] = {
{ "/basic", test_basic, setup, tear_down, 0, NULL },
{ NULL, NULL, NULL, NULL, 0, NULL }
};
static const MunitSuite test_suite = { "pool", test_suite_tests, NULL, 1, 0 };
int main(int argc, char* argv[MUNIT_ARRAY_PARAM(argc + 1)]) {
return munit_suite_main(&test_suite, NULL, argc, argv);
}