From c97d7cee71824aeba65127d2d7c8e0826b90ee65 Mon Sep 17 00:00:00 2001 From: GUJIEJASON <1776127334@qq.com> Date: Tue, 29 Oct 2024 08:05:35 +0800 Subject: [PATCH] init --- CMakeLists.txt | 5 +++++ test/db_test1.cc | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 test/db_test1.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 54b14a1..78abc6e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -518,6 +518,11 @@ if(LEVELDB_INSTALL) ) endif(LEVELDB_INSTALL) +add_executable(db_test1 + "${PROJECT_SOURCE_DIR}/test/db_test1.cc" +) +target_link_libraries(db_test1 leveldb) + add_executable(db_test2 "${PROJECT_SOURCE_DIR}/test/db_test2.cc" diff --git a/test/db_test1.cc b/test/db_test1.cc new file mode 100644 index 0000000..7e5eb3a --- /dev/null +++ b/test/db_test1.cc @@ -0,0 +1,26 @@ +#include "leveldb/db.h" +#include + +using namespace std; +using namespace leveldb; + +int main() { + DB* db = nullptr; + Options op; + op.create_if_missing = true; + Status status = DB::Open(op, "testdb", &db); + assert(status.ok()); + db->Put(WriteOptions(), "001", "leveldb"); + string s; + db->Get(ReadOptions(), "001", &s); + cout<Put(WriteOptions(), "002", "world"); + string s1; + db->Delete(WriteOptions(), "002"); + db->Get(ReadOptions(), "002", &s1); + cout<