Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions conan.lock
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
"ninja/1.13.2"
],
"python_requires": [
"cor_recipe_utils/0.18.2",
"cor_recipe_utils/0.8.7"
"cor_recipe_utils/0.19.1"
],
"overrides": {
"libunwind/[>=1.8 <2]": [
Expand Down
1 change: 1 addition & 0 deletions test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class turtle_kvTestConan(ConanFile):

def requirements(self):
self.requires(self.tested_reference_str)
self.requires("batteries/[>=0.71.1 <1]", visible=True, force=True)

def build(self):
cmake = CMake(self)
Expand Down
55 changes: 49 additions & 6 deletions test_package/src/example.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,54 @@
#include "turtle_kv/turtle_kv.hpp"
#include <turtle_kv/kv_store.hpp>

#include <batteries/assert.hpp>

#include <iostream>

int main()
{
if (turtle_kv::entry_point()) {
std::cout << "Test package is working!" << std::endl;
}
return 0;
}
namespace fs = std::filesystem;

using turtle_kv::KVStore;
using turtle_kv::RemoveExisting;
using turtle_kv::Status;
using turtle_kv::StatusOr;
using turtle_kv::TreeOptions;
using turtle_kv::ValueView;

// First create a database instance.
//
Status create_status =
KVStore::create(fs::path{"path/to/my/data"},
KVStore::Config::with_default_values(),
RemoveExisting{true});

BATT_CHECK_OK(create_status);

// Now open and use the new instance.
//
StatusOr<std::unique_ptr<KVStore>> opened_kv_store =
KVStore::open(fs::path{"path/to/my/data"},
TreeOptions::with_default_values());

BATT_CHECK_OK(opened_kv_store);

// Use the key-value store.
//
KVStore& kv = **opened_kv_store;

BATT_CHECK_OK(kv.put("hello", ValueView::from_str("world")));

StatusOr<ValueView> value = kv.get("hello");
BATT_CHECK_OK(value);
BATT_CHECK_EQ(value->as_str(), "world");

// Query a key that doesn't exist.
//
value = kv.get("no such key");
BATT_CHECK(!value.ok());
BATT_CHECK_EQ(value.status(), batt::StatusCode::kNotFound);

std::cout << "Test package is working!" << std::endl;

return 0;
}