version_edit_test.cc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file. See the AUTHORS file for names of contributors.
  4. #include "db/version_edit.h"
  5. #include "gtest/gtest.h"
  6. namespace leveldb {
  7. static void TestEncodeDecode(const VersionEdit& edit) {
  8. std::string encoded, encoded2;
  9. edit.EncodeTo(&encoded);
  10. VersionEdit parsed;
  11. Status s = parsed.DecodeFrom(encoded);
  12. ASSERT_TRUE(s.ok()) << s.ToString();
  13. parsed.EncodeTo(&encoded2);
  14. ASSERT_EQ(encoded, encoded2);
  15. }
  16. TEST(VersionEditTest, EncodeDecode) {
  17. static const uint64_t kBig = 1ull << 50;
  18. VersionEdit edit;
  19. for (int i = 0; i < 4; i++) {
  20. TestEncodeDecode(edit);
  21. edit.AddFile(3, kBig + 300 + i, kBig + 400 + i,
  22. InternalKey("foo", kBig + 500 + i, kTypeValue),
  23. InternalKey("zoo", kBig + 600 + i, kTypeDeletion));
  24. edit.RemoveFile(4, kBig + 700 + i);
  25. edit.SetCompactPointer(i, InternalKey("x", kBig + 900 + i, kTypeValue));
  26. }
  27. edit.SetComparatorName("foo");
  28. edit.SetLogNumber(kBig + 100);
  29. edit.SetNextFile(kBig + 200);
  30. edit.SetLastSequence(kBig + 1000);
  31. TestEncodeDecode(edit);
  32. }
  33. } // namespace leveldb