KCC: docstring for kcc.graph.InternalEdge
[Samba.git] / source3 / torture / test_dbwrap_ctdb.c
blobd7380b1dad2e7a206c90c06c2fa613314f460347
1 /*
2 * Unix SMB/CIFS implementation.
3 * Test dbwrap_ctdb API
4 * Copyright (C) Volker Lendecke 2012
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 "includes.h"
21 #include "torture/proto.h"
22 #include "system/filesys.h"
23 #include "lib/dbwrap/dbwrap.h"
24 #include "lib/dbwrap/dbwrap_ctdb.h"
26 bool run_local_dbwrap_ctdb(int dummy)
28 struct db_context *db;
29 int res;
30 bool ret = false;
31 NTSTATUS status;
32 uint32_t val;
34 db = db_open_ctdb(talloc_tos(), "torture.tdb", 0, TDB_DEFAULT,
35 O_RDWR, 0755, DBWRAP_LOCK_ORDER_1, DBWRAP_FLAG_NONE);
36 if (db == NULL) {
37 perror("db_open_ctdb failed");
38 goto fail;
41 res = dbwrap_transaction_start(db);
42 if (res != 0) {
43 fprintf(stderr, "dbwrap_transaction_start failed");
44 goto fail;
46 res = dbwrap_transaction_cancel(db);
47 if (res != 0) {
48 fprintf(stderr, "dbwrap_transaction_cancel failed");
49 goto fail;
52 res = dbwrap_transaction_start(db);
53 if (res != 0) {
54 fprintf(stderr, "dbwrap_transaction_start failed");
55 goto fail;
58 status = dbwrap_store_uint32_bystring(db, "foo", 1);
59 if (!NT_STATUS_IS_OK(status)) {
60 fprintf(stderr, "store_uint32 failed: %s\n",
61 nt_errstr(status));
62 goto fail;
64 status = dbwrap_fetch_uint32_bystring(db, "foo", &val);
65 if (!NT_STATUS_IS_OK(status)) {
66 fprintf(stderr, "fetch_uint32 failed: %s\n",
67 nt_errstr(status));
68 goto fail;
70 if (val != 1) {
71 fprintf(stderr, "fetch_uint32 gave %u, expected 1",
72 (unsigned)val);
73 goto fail;
76 status = dbwrap_store_uint32_bystring(db, "bar", 5);
77 if (!NT_STATUS_IS_OK(status)) {
78 fprintf(stderr, "store_uint32 failed: %s\n",
79 nt_errstr(status));
80 goto fail;
82 status = dbwrap_fetch_uint32_bystring(db, "bar", &val);
83 if (!NT_STATUS_IS_OK(status)) {
84 fprintf(stderr, "fetch_uint32 failed: %s\n",
85 nt_errstr(status));
86 goto fail;
88 if (val != 5) {
89 fprintf(stderr, "fetch_uint32 gave %u, expected 5",
90 (unsigned)val);
91 goto fail;
94 status = dbwrap_store_uint32_bystring(db, "foo", 2);
95 if (!NT_STATUS_IS_OK(status)) {
96 fprintf(stderr, "store_uint32 failed: %s\n",
97 nt_errstr(status));
98 goto fail;
100 status = dbwrap_fetch_uint32_bystring(db, "foo", &val);
101 if (!NT_STATUS_IS_OK(status)) {
102 fprintf(stderr, "fetch_uint32 failed: %s\n",
103 nt_errstr(status));
104 goto fail;
106 if (val != 2) {
107 fprintf(stderr, "fetch_uint32 gave %u, expected 2",
108 (unsigned)val);
109 goto fail;
112 res = dbwrap_transaction_commit(db);
113 if (res != 0) {
114 fprintf(stderr, "dbwrap_transaction_commit failed");
115 goto fail;
119 * check that the values have reached the disk
121 status = dbwrap_fetch_uint32_bystring(db, "foo", &val);
122 if (!NT_STATUS_IS_OK(status)) {
123 fprintf(stderr, "fetch_uint32 failed: %s\n",
124 nt_errstr(status));
125 goto fail;
127 if (val != 2) {
128 fprintf(stderr, "fetch_uint32 gave %u, expected 1",
129 (unsigned)val);
130 goto fail;
133 status = dbwrap_fetch_uint32_bystring(db, "bar", &val);
134 if (!NT_STATUS_IS_OK(status)) {
135 fprintf(stderr, "fetch_uint32 failed: %s\n",
136 nt_errstr(status));
137 goto fail;
139 if (val != 5) {
140 fprintf(stderr, "fetch_uint32 gave %u, expected 1",
141 (unsigned)val);
142 goto fail;
145 ret = true;
146 fail:
147 TALLOC_FREE(db);
148 return ret;