LCOV - code coverage report
Current view: top level - lib/tdb/test - run-readonly-check.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 19 19 100.0 %
Date: 2024-04-21 15:09:00 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* We should be able to tdb_check a O_RDONLY tdb, and we were previously allowed
       2             :  * to tdb_check() inside a transaction (though that's paranoia!). */
       3             : #include "../common/tdb_private.h"
       4             : #include "../common/io.c"
       5             : #include "../common/tdb.c"
       6             : #include "../common/lock.c"
       7             : #include "../common/freelist.c"
       8             : #include "../common/traverse.c"
       9             : #include "../common/transaction.c"
      10             : #include "../common/error.c"
      11             : #include "../common/open.c"
      12             : #include "../common/check.c"
      13             : #include "../common/hash.c"
      14             : #include "../common/mutex.c"
      15             : #include "tap-interface.h"
      16             : #include <stdlib.h>
      17             : #include "logging.h"
      18             : 
      19           1 : int main(int argc, char *argv[])
      20             : {
      21             :         struct tdb_context *tdb;
      22             :         TDB_DATA key, data;
      23             : 
      24             :         plan_tests(11);
      25           1 :         tdb = tdb_open_ex("run-readonly-check.tdb", 1024,
      26             :                           TDB_DEFAULT,
      27             :                           O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
      28             : 
      29           1 :         ok1(tdb);
      30           1 :         key.dsize = strlen("hi");
      31           1 :         key.dptr = discard_const_p(uint8_t, "hi");
      32           1 :         data.dsize = strlen("world");
      33           1 :         data.dptr = discard_const_p(uint8_t, "world");
      34             : 
      35           1 :         ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
      36           1 :         ok1(tdb_check(tdb, NULL, NULL) == 0);
      37             : 
      38             :         /* We are also allowed to do a check inside a transaction. */
      39           1 :         ok1(tdb_transaction_start(tdb) == 0);
      40           1 :         ok1(tdb_check(tdb, NULL, NULL) == 0);
      41           1 :         ok1(tdb_close(tdb) == 0);
      42             : 
      43           1 :         tdb = tdb_open_ex("run-readonly-check.tdb", 1024,
      44             :                           TDB_DEFAULT, O_RDONLY, 0, &taplogctx, NULL);
      45             : 
      46           1 :         ok1(tdb);
      47           1 :         ok1(tdb_store(tdb, key, data, TDB_MODIFY) == -1);
      48           1 :         ok1(tdb_error(tdb) == TDB_ERR_RDONLY);
      49           1 :         ok1(tdb_check(tdb, NULL, NULL) == 0);
      50           1 :         ok1(tdb_close(tdb) == 0);
      51             : 
      52           1 :         return exit_status();
      53             : }

Generated by: LCOV version 1.14