blob: 50913cd2cd7f3555c718cdd6245ee73014fde9cc [file] [log] [blame]
jorlow@chromium.orgf67e15e2011-03-18 22:37:00 +00001// 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
8namespace leveldb {
9
10static 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
20class VersionEditTest { };
21
22TEST(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, kTypeLargeValueRef),
30 InternalKey("zoo", kBig + 600 + i, kTypeDeletion));
31 edit.DeleteFile(4, kBig + 700 + i);
32 edit.AddLargeValueRef(LargeValueRef::Make("big", kNoCompression),
33 kBig + 800 + i, "foobar");
34 edit.AddLargeValueRef(LargeValueRef::Make("big2", kLightweightCompression),
35 kBig + 801 + i, "baz");
36 edit.SetCompactPointer(i, InternalKey("x", kBig + 900 + i, kTypeValue));
37 }
38
39 edit.SetComparatorName("foo");
40 edit.SetLogNumber(kBig + 100);
41 edit.SetNextFile(kBig + 200);
42 edit.SetLastSequence(kBig + 1000);
43 TestEncodeDecode(edit);
44}
45
46}
47
48int main(int argc, char** argv) {
49 return leveldb::test::RunAllTests();
50}