s3:winbindd:cache: fix offline logons with cached credentials (bug #9321)
[Samba/gebeck_regimport.git] / lib / ntdb / test / run-11-simple-fetch.c
blob9565ade930d7f906ff3fde32374980bd70fe739f
1 #include <ccan/failtest/failtest_override.h>
2 #include "ntdb-source.h"
3 #include "tap-interface.h"
4 #include <ccan/failtest/failtest.h>
5 #include "logging.h"
6 #include "failtest_helper.h"
8 int main(int argc, char *argv[])
10 unsigned int i;
11 struct ntdb_context *ntdb;
12 int flags[] = { NTDB_INTERNAL, NTDB_DEFAULT, NTDB_NOMMAP,
13 NTDB_INTERNAL|NTDB_CONVERT, NTDB_CONVERT,
14 NTDB_NOMMAP|NTDB_CONVERT };
15 NTDB_DATA key = ntdb_mkdata("key", 3);
16 NTDB_DATA data = ntdb_mkdata("data", 4);
18 failtest_init(argc, argv);
19 failtest_hook = block_repeat_failures;
20 failtest_exit_check = exit_check_log;
22 failtest_suppress = true;
23 plan_tests(sizeof(flags) / sizeof(flags[0]) * 8 + 1);
24 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
25 ntdb = ntdb_open("run-11-simple-fetch.ntdb",
26 flags[i]|MAYBE_NOSYNC,
27 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
28 ok1(ntdb);
29 if (ntdb) {
30 NTDB_DATA d = { NULL, 0 }; /* Bogus GCC warning */
32 /* fetch should fail. */
33 failtest_suppress = false;
34 if (!ok1(ntdb_fetch(ntdb, key, &d) == NTDB_ERR_NOEXIST))
35 goto fail;
36 failtest_suppress = true;
37 ok1(ntdb_check(ntdb, NULL, NULL) == 0);
38 /* Insert should succeed. */
39 ok1(ntdb_store(ntdb, key, data, NTDB_INSERT) == 0);
40 ok1(ntdb_check(ntdb, NULL, NULL) == 0);
41 /* Fetch should now work. */
42 failtest_suppress = false;
43 if (!ok1(ntdb_fetch(ntdb, key, &d) == NTDB_SUCCESS))
44 goto fail;
45 failtest_suppress = true;
46 ok1(ntdb_deq(d, data));
47 free(d.dptr);
48 ok1(ntdb_check(ntdb, NULL, NULL) == 0);
49 ntdb_close(ntdb);
52 ok1(tap_log_messages == 0);
53 failtest_exit(exit_status());
55 fail:
56 failtest_suppress = true;
57 ntdb_close(ntdb);
58 failtest_exit(exit_status());