lib/replace: memset_explicit() only takes three arguments
[Samba.git] / ctdb / tests / src / reqid_test.c
blob2a0828c38e381e8a2f27a9600d92a59c54787ffe
1 /*
2 reqid tests
4 Copyright (C) Amitay Isaacs 2015
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include "replace.h"
22 #include <talloc.h>
23 #include <assert.h>
25 #include "common/reqid.c"
28 int main(void)
30 struct reqid_context *reqid_ctx;
31 TALLOC_CTX *mem_ctx = talloc_new(NULL);
32 int i, ret;
33 uint32_t reqid;
34 int *data, *tmp;
36 ret = reqid_init(mem_ctx, INT_MAX-200, &reqid_ctx);
37 assert(ret == 0);
39 data = talloc_zero(mem_ctx, int);
40 assert(data != 0);
42 for (i=0; i<1024*1024; i++) {
43 reqid = reqid_new(reqid_ctx, data);
44 assert(reqid != REQID_INVALID);
47 for (i=0; i<1024; i++) {
48 tmp = reqid_find(reqid_ctx, i, int);
49 assert(tmp == data);
52 for (i=0; i<1024; i++) {
53 ret = reqid_remove(reqid_ctx, i);
54 assert(ret == 0);
57 for (i=0; i<1024; i++) {
58 tmp = reqid_find(reqid_ctx, i, int);
59 assert(tmp == NULL);
62 for (i=0; i<1024; i++) {
63 ret = reqid_remove(reqid_ctx, i);
64 assert(ret == ENOENT);
67 talloc_free(reqid_ctx);
68 assert(talloc_get_size(mem_ctx) == 0);
70 ret = reqid_init(mem_ctx, INT_MAX-1, &reqid_ctx);
71 assert(ret == 0);
73 reqid = reqid_new(reqid_ctx, data);
74 assert(reqid == INT_MAX);
76 reqid = reqid_new(reqid_ctx, data);
77 assert(reqid == 0);
79 reqid_remove(reqid_ctx, 0);
81 reqid = reqid_new(reqid_ctx, data);
82 assert(reqid == 1);
84 talloc_free(reqid_ctx);
86 talloc_free(mem_ctx);
88 return 0;