1179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org// Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org// Use of this source code is governed by a BSD-style license that can be 3179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org// found in the LICENSE file. See the AUTHORS file for names of contributors. 4179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 5179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org#include "db/version_edit.h" 6179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org#include "util/testharness.h" 7179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 8179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.orgnamespace leveldb { 9179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 10179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.orgstatic void TestEncodeDecode(const VersionEdit& edit) { 11179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org std::string encoded, encoded2; 12179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org edit.EncodeTo(&encoded); 13179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org VersionEdit parsed; 14179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org Status s = parsed.DecodeFrom(encoded); 15179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org ASSERT_TRUE(s.ok()) << s.ToString(); 16179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org parsed.EncodeTo(&encoded2); 17179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org ASSERT_EQ(encoded, encoded2); 18179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org} 19179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 20179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.orgclass VersionEditTest { }; 21179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 22179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.orgTEST(VersionEditTest, EncodeDecode) { 23179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org static const uint64_t kBig = 1ull << 50; 24179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 25179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org VersionEdit edit; 26179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org for (int i = 0; i < 4; i++) { 27179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org TestEncodeDecode(edit); 28179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org edit.AddFile(3, kBig + 300 + i, kBig + 400 + i, 291511be6edb54b6ade2bfad94256f76bc191e92ecdgrogan@chromium.org InternalKey("foo", kBig + 500 + i, kTypeValue), 30179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org InternalKey("zoo", kBig + 600 + i, kTypeDeletion)); 31179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org edit.DeleteFile(4, kBig + 700 + i); 32179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org edit.SetCompactPointer(i, InternalKey("x", kBig + 900 + i, kTypeValue)); 33179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org } 34179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 35179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org edit.SetComparatorName("foo"); 36179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org edit.SetLogNumber(kBig + 100); 37179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org edit.SetNextFile(kBig + 200); 38179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org edit.SetLastSequence(kBig + 1000); 39179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org TestEncodeDecode(edit); 40179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org} 41179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 4245b9940be332834440bd5299419f396e38085ebehans@chromium.org} // namespace leveldb 43179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org 44179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.orgint main(int argc, char** argv) { 45179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org return leveldb::test::RunAllTests(); 46179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org} 47