作者: 韩晨旭 10225101440 李畅 10225102463
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.

49 lines
1.2 KiB

  1. #include <iostream>
  2. #include <gtest/gtest.h>
  3. #include "leveldb/db.h"
  4. #include "leveldb/env.h"
  5. #include "table/vtable_builder.h"
  6. #include "table/vtable_reader.h"
  7. #include "table/vtable_format.h"
  8. using namespace std;
  9. using namespace leveldb;
  10. TEST(TestVTable, BuilderReader) {
  11. VTableHandle handle1;
  12. VTableHandle handle2;
  13. VTableRecord record1;
  14. VTableRecord record2;
  15. record1.key = "001";
  16. record1.value = "value1";
  17. record2.key = "002";
  18. record2.value = "value2";
  19. Options opt;
  20. WritableFile *file;
  21. opt.env->NewWritableFile("1.vtb", &file);
  22. VTableBuilder builder(opt, file);
  23. builder.Add(record1, &handle1);
  24. builder.Add(record2, &handle2);
  25. builder.Finish();
  26. VTableReader reader;
  27. reader.Open(opt, "1.vtb");
  28. VTableRecord res_record;
  29. reader.Get(handle2, &res_record);
  30. ASSERT_TRUE(res_record.key.ToString() == record2.key.ToString());
  31. ASSERT_TRUE(res_record.value.ToString() == record2.value.ToString());
  32. reader.Get(handle1, &res_record);
  33. ASSERT_TRUE(res_record.key.ToString() == record1.key.ToString());
  34. ASSERT_TRUE(res_record.value.ToString() == record1.value.ToString());
  35. }
  36. int main(int argc, char **argv) {
  37. testing::InitGoogleTest(&argc, argv);
  38. return RUN_ALL_TESTS();
  39. }