Path: blob/main/lib/libc/tests/db/dbm_nextkey_test.c
39553 views
/*-1* Copyright (c) 2025 Klara, Inc.2*3* SPDX-License-Identifier: BSD-2-Clause4*/56#include <fcntl.h>7#include <ndbm.h>8#include <stdio.h>910#include <atf-c.h>1112static const char *path = "tmp";13static const char *dbname = "tmp.db";1415ATF_TC(dbm_nextkey_test);16ATF_TC_HEAD(dbm_nextkey_test, tc)17{18atf_tc_set_md_var(tc, "descr",19"Check that dbm_nextkey always returns NULL after reaching the end of the database");20}2122ATF_TC_BODY(dbm_nextkey_test, tc)23{24DBM *db;25datum key, data;2627data.dptr = "bar";28data.dsize = strlen("bar");29key.dptr = "foo";30key.dsize = strlen("foo");3132db = dbm_open(path, O_RDWR | O_CREAT, 0755);33ATF_CHECK(db != NULL);34ATF_REQUIRE(atf_utils_file_exists(dbname));35ATF_REQUIRE(dbm_store(db, key, data, DBM_INSERT) != -1);3637key = dbm_firstkey(db);38ATF_REQUIRE(key.dptr != NULL);39key = dbm_nextkey(db);40ATF_REQUIRE(key.dptr == NULL);41key = dbm_nextkey(db);42ATF_REQUIRE(key.dptr == NULL);4344dbm_close(db);45}4647ATF_TP_ADD_TCS(tp)48{49ATF_TP_ADD_TC(tp, dbm_nextkey_test);5051return (atf_no_error());52}535455