3 #include "tap-interface.h"
9 #define NUM_RECORDS 1000
11 static bool store_records(struct ntdb_context
*ntdb
)
14 NTDB_DATA key
= { (unsigned char *)&i
, sizeof(i
) };
15 NTDB_DATA data
= { (unsigned char *)&i
, sizeof(i
) };
17 for (i
= 0; i
< NUM_RECORDS
; i
++)
18 if (ntdb_store(ntdb
, key
, data
, NTDB_REPLACE
) != 0)
23 static enum NTDB_ERROR
check(NTDB_DATA key
,
29 if (key
.dsize
!= sizeof(val
)) {
30 diag("Wrong key size: %zu\n", key
.dsize
);
31 return NTDB_ERR_CORRUPT
;
34 if (key
.dsize
!= data
.dsize
35 || memcmp(key
.dptr
, data
.dptr
, sizeof(val
)) != 0) {
36 diag("Key and data differ\n");
37 return NTDB_ERR_CORRUPT
;
40 memcpy(&val
, key
.dptr
, sizeof(val
));
41 if (val
>= NUM_RECORDS
|| val
< 0) {
42 diag("check value %i\n", val
);
43 return NTDB_ERR_CORRUPT
;
47 diag("Value %i already seen\n", val
);
48 return NTDB_ERR_CORRUPT
;
55 int main(int argc
, char *argv
[])
58 struct ntdb_context
*ntdb
;
59 int flags
[] = { NTDB_INTERNAL
, NTDB_DEFAULT
, NTDB_NOMMAP
,
60 NTDB_INTERNAL
|NTDB_CONVERT
, NTDB_CONVERT
,
61 NTDB_NOMMAP
|NTDB_CONVERT
};
64 plan_tests(sizeof(flags
) / sizeof(flags
[0]) * 4 + 1);
65 for (i
= 0; i
< sizeof(flags
) / sizeof(flags
[0]); i
++) {
66 bool array
[NUM_RECORDS
];
68 ntdb
= ntdb_open("run-check-callback.ntdb",
69 flags
[i
]|MAYBE_NOSYNC
,
70 O_RDWR
|O_CREAT
|O_TRUNC
, 0600, &tap_log_attr
);
75 ok1(store_records(ntdb
));
76 for (j
= 0; j
< NUM_RECORDS
; j
++)
78 ok1(ntdb_check(ntdb
, check
, array
) == NTDB_SUCCESS
);
79 for (j
= 0; j
< NUM_RECORDS
; j
++)
82 ok1(j
== NUM_RECORDS
);
86 ok1(tap_log_messages
== 0);