LCOV - code coverage report
Current view: top level - source3/torture - test_tdb_validate.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 23 30 76.7 %
Date: 2024-04-21 15:09:00 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Unix SMB/CIFS implementation.
       3             :  *
       4             :  * This program is free software; you can redistribute it and/or modify
       5             :  * it under the terms of the GNU General Public License as published by
       6             :  * the Free Software Foundation; either version 3 of the License, or
       7             :  * (at your option) any later version.
       8             :  *
       9             :  * This program is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :  * GNU General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU General Public License
      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
      16             :  */
      17             : 
      18             : #include "source3/include/includes.h"
      19             : #include <tdb.h>
      20             : #include "source3/torture/proto.h"
      21             : #include "source3/lib/tdb_validate.h"
      22             : 
      23           1 : static int validate_fn(struct tdb_context *tdb, TDB_DATA key, TDB_DATA value,
      24             :                        void *private_data)
      25             : {
      26           1 :         struct tdb_validation_status *state = private_data;
      27           1 :         state->success = false;
      28           1 :         printf("validate_fn called\n");
      29           1 :         return -1;
      30             : }
      31             : 
      32           1 : bool run_tdb_validate(int dummy)
      33             : {
      34           1 :         const char tdb_name[] = "tdb_validate.tdb";
      35           1 :         bool result = false;
      36           1 :         struct tdb_context *tdb = NULL;
      37           1 :         char buf[] = "data";
      38           1 :         TDB_DATA data = { .dptr = (uint8_t *)buf, .dsize = sizeof(buf), };
      39           1 :         int ret;
      40             : 
      41           1 :         unlink(tdb_name);
      42             : 
      43           1 :         tdb = tdb_open(tdb_name, 0, 0, O_CREAT|O_EXCL|O_RDWR, 0600);
      44           1 :         if (tdb == NULL) {
      45           0 :                 perror("Could not open tdb");
      46           0 :                 goto done;
      47             :         }
      48             : 
      49           1 :         ret = tdb_store(tdb, data, data, 0);
      50           1 :         if (ret == -1) {
      51           0 :                 perror("tdb_store failed");
      52           0 :                 goto done;
      53             :         }
      54             : 
      55           1 :         ret = tdb_validate(tdb, validate_fn);
      56           1 :         if (ret == 0) {
      57           0 :                 fprintf(stderr,
      58             :                         "tdb_validate succeeded where it should have "
      59             :                         "failed\n");
      60           0 :                 goto done;
      61             :         }
      62             : 
      63           0 :         result = true;
      64           1 : done:
      65           1 :         tdb_close(tdb);
      66           1 :         unlink(tdb_name);
      67           1 :         return result;
      68             : }

Generated by: LCOV version 1.14