10225501448 李度 10225101546 陈胤遒 10215501422 高宇菲
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.
 
 

51 regels
1.4 KiB

#include "gtest/gtest.h"
#include "leveldb/env.h"
#include "leveldb/db.h"
using namespace leveldb;
using Field = std::pair<std::string, std::string>; // field_name:field_value
using FieldArray = std::vector<std::pair<std::string, std::string>>;
Status OpenDB(std::string dbName, DB **db) {
Options options;
options.create_if_missing = true;
return DB::Open(options, dbName, db);
}
TEST(TestLab1, Basic) {
DestroyDB("testdb",Options());
DB *db;
if(OpenDB("testdb", &db).ok() == false) {
std::cerr << "open db failed" << std::endl;
abort();
}
std::string key = "k_1";
FieldArray fields = {
{"name", "Customer#000000001"},
{"address", "IVhzIApeRb"},
{"phone", "25-989-741-2988"}
};
// 序列化并插入
db->PutFields(WriteOptions(), key, fields);
// 读取并反序列化
FieldArray fields_ret;
db->GetFields(ReadOptions(), key, &fields_ret);
// ASSERT_EQ(fields, fields_ret); 顺序不一样
for (const Field& pairs : fields_ret) {
ASSERT_NE(std::find(fields.begin(), fields.end(), pairs), fields.end());
}
//todo
Field field = {"name", "Customer#000000001"};
std::vector<std::string> resKeys = db->FindKeysByField(field);
}
int main(int argc, char** argv) {
// All tests currently run with the same read-only file limits.
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}