C and C++ web framework.
http://rapida.vilor.one/docs
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.1 KiB
45 lines
1.1 KiB
2 years ago
|
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||
|
/* Copyright 2022 Ivan Polyakov */
|
||
|
|
||
|
#include "keyval.h"
|
||
|
#include "tests.hxx"
|
||
|
|
||
|
using namespace rpd;
|
||
|
|
||
|
TEST_CASE("Key-value storage")
|
||
|
{
|
||
|
rpd_keyval keyval;
|
||
|
rpd_keyval_init(&keyval, 10);
|
||
|
|
||
|
SECTION("Initializing")
|
||
|
{
|
||
|
rpd_keyval_init(&keyval, 10);
|
||
|
REQUIRE(keyval.size == 0);
|
||
|
REQUIRE(keyval.capacity == 10);
|
||
|
}
|
||
|
|
||
|
SECTION("Inserting")
|
||
|
{
|
||
|
REQUIRE(rpd_keyval_insert(&keyval, "key", "val") == 0);
|
||
|
REQUIRE(keyval.size == 1);
|
||
|
REQUIRE(std::string(keyval.items[0].key) == "key");
|
||
|
REQUIRE(std::string(keyval.items[0].val) == "val");
|
||
|
}
|
||
|
|
||
|
SECTION("Search")
|
||
|
{
|
||
|
int sz = keyval.size;
|
||
|
REQUIRE(rpd_keyval_insert(&keyval, "key1", "val") == 0);
|
||
|
REQUIRE(keyval.size == sz + 1);
|
||
|
rpd_keyval_item *item = rpd_keyval_find(&keyval, "key1");
|
||
|
REQUIRE(item != NULL);
|
||
|
REQUIRE(std::string(item->val) == "val");
|
||
|
}
|
||
|
|
||
|
SECTION("Cleanup")
|
||
|
{
|
||
|
rpd_keyval_cleanup(&keyval);
|
||
|
REQUIRE(keyval.size == 0);
|
||
|
}
|
||
|
}
|