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 5 #include "db/version_edit.h" 6 #include "util/testharness.h" 7 8 namespace leveldb { 9 10 static void TestEncodeDecode(const VersionEdit& edit) { 11 std::string encoded, encoded2; 12 edit.EncodeTo(&encoded); 13 VersionEdit parsed; 14 Status s = parsed.DecodeFrom(encoded); 15 ASSERT_TRUE(s.ok()) << s.ToString(); 16 parsed.EncodeTo(&encoded2); 17 ASSERT_EQ(encoded, encoded2); 18 } 19 20 class VersionEditTest { }; 21 22 TEST(VersionEditTest, EncodeDecode) { 23 static const uint64_t kBig = 1ull << 50; 24 25 VersionEdit edit; 26 for (int i = 0; i < 4; i++) { 27 TestEncodeDecode(edit); 28 edit.AddFile(3, kBig + 300 + i, kBig + 400 + i, 29 InternalKey("foo", kBig + 500 + i, kTypeValue), 30 InternalKey("zoo", kBig + 600 + i, kTypeDeletion)); 31 edit.DeleteFile(4, kBig + 700 + i); 32 edit.SetCompactPointer(i, InternalKey("x", kBig + 900 + i, kTypeValue)); 33 } 34 35 edit.SetComparatorName("foo"); 36 edit.SetLogNumber(kBig + 100); 37 edit.SetNextFile(kBig + 200); 38 edit.SetLastSequence(kBig + 1000); 39 TestEncodeDecode(edit); 40 } 41 42 } // namespace leveldb 43 44 int main(int argc, char** argv) { 45 return leveldb::test::RunAllTests(); 46 } 47