2011-03-18 22:37:00 +00:00
|
|
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
|
|
|
|
#include "db/version_edit.h"
|
|
|
|
#include "util/testharness.h"
|
|
|
|
|
|
|
|
namespace leveldb {
|
|
|
|
|
|
|
|
static void TestEncodeDecode(const VersionEdit& edit) {
|
|
|
|
std::string encoded, encoded2;
|
|
|
|
edit.EncodeTo(&encoded);
|
2012-06-23 02:30:03 +00:00
|
|
|
VersionEdit parsed(7);
|
2011-03-18 22:37:00 +00:00
|
|
|
Status s = parsed.DecodeFrom(encoded);
|
|
|
|
ASSERT_TRUE(s.ok()) << s.ToString();
|
|
|
|
parsed.EncodeTo(&encoded2);
|
|
|
|
ASSERT_EQ(encoded, encoded2);
|
|
|
|
}
|
|
|
|
|
|
|
|
class VersionEditTest { };
|
|
|
|
|
|
|
|
TEST(VersionEditTest, EncodeDecode) {
|
|
|
|
static const uint64_t kBig = 1ull << 50;
|
|
|
|
|
2012-06-23 02:30:03 +00:00
|
|
|
VersionEdit edit(7);
|
2011-03-18 22:37:00 +00:00
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
TestEncodeDecode(edit);
|
|
|
|
edit.AddFile(3, kBig + 300 + i, kBig + 400 + i,
|
2011-04-20 22:48:11 +00:00
|
|
|
InternalKey("foo", kBig + 500 + i, kTypeValue),
|
2013-06-14 05:09:08 +00:00
|
|
|
InternalKey("zoo", kBig + 600 + i, kTypeDeletion),
|
|
|
|
kBig + 500 + i,
|
|
|
|
kBig + 600 + i);
|
2011-03-18 22:37:00 +00:00
|
|
|
edit.DeleteFile(4, kBig + 700 + i);
|
|
|
|
edit.SetCompactPointer(i, InternalKey("x", kBig + 900 + i, kTypeValue));
|
|
|
|
}
|
|
|
|
|
|
|
|
edit.SetComparatorName("foo");
|
|
|
|
edit.SetLogNumber(kBig + 100);
|
|
|
|
edit.SetNextFile(kBig + 200);
|
|
|
|
edit.SetLastSequence(kBig + 1000);
|
|
|
|
TestEncodeDecode(edit);
|
|
|
|
}
|
|
|
|
|
2011-10-31 17:22:06 +00:00
|
|
|
} // namespace leveldb
|
2011-03-18 22:37:00 +00:00
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
return leveldb::test::RunAllTests();
|
|
|
|
}
|