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<