jorlow@chromium.org | f67e15e | 2011-03-18 22:37:00 +0000 | [diff] [blame] | 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, |
dgrogan@chromium.org | ba6dac0 | 2011-04-20 22:48:11 +0000 | [diff] [blame] | 29 | InternalKey("foo", kBig + 500 + i, kTypeValue), |
jorlow@chromium.org | f67e15e | 2011-03-18 22:37:00 +0000 | [diff] [blame] | 30 | InternalKey("zoo", kBig + 600 + i, kTypeDeletion)); |
| 31 | edit.DeleteFile(4, kBig + 700 + i); |
jorlow@chromium.org | f67e15e | 2011-03-18 22:37:00 +0000 | [diff] [blame] | 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 | |
Hans Wennborg | 36a5f8e | 2011-10-31 17:22:06 +0000 | [diff] [blame] | 42 | } // namespace leveldb |
jorlow@chromium.org | f67e15e | 2011-03-18 22:37:00 +0000 | [diff] [blame] | 43 | |
| 44 | int main(int argc, char** argv) { |
| 45 | return leveldb::test::RunAllTests(); |
| 46 | } |