/*
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <vector>
#include <glog/logging.h>
-#include <gtest/gtest.h>
#include <folly/Benchmark.h>
#include <folly/Random.h>
+#include <folly/portability/GTest.h>
DEFINE_int32(random_seed, folly::randomNumberSeed(), "random seed");
}
}
+TEST(Varint, Interface) {
+ // Make sure decodeVarint() accepts all of StringPiece, MutableStringPiece,
+ // ByteRange, and MutableByteRange.
+ char c = 0;
+
+ StringPiece sp(&c, 1);
+ EXPECT_EQ(decodeVarint(sp), 0);
+
+ MutableStringPiece msp(&c, 1);
+ EXPECT_EQ(decodeVarint(msp), 0);
+
+ ByteRange br(reinterpret_cast<unsigned char*>(&c), 1);
+ EXPECT_EQ(decodeVarint(br), 0);
+
+ MutableByteRange mbr(reinterpret_cast<unsigned char*>(&c), 1);
+ EXPECT_EQ(decodeVarint(mbr), 0);
+}
+
TEST(Varint, Simple) {
testVarint(0, {0});
testVarint(1, {1});
for (size_t i = 0; i < kNumValues; ++i) {
int n = numBytes(rng);
uint64_t val = 0;
- for (size_t j = 0; j < n; ++j) {
+ for (int j = 0; j < n; ++j) {
val = (val << 8) + byte(rng);
}
gValues[i] = val;
BENCHMARK(VarintEncoding, iters) {
uint8_t* start = &(*gEncoded.begin());
uint8_t* p = start;
- bool empty = (iters == 0);
while (iters--) {
p = start;
for (auto& v : gValues) {
int main(int argc, char *argv[]) {
testing::InitGoogleTest(&argc, argv);
- google::ParseCommandLineFlags(&argc, &argv, true);
+ gflags::ParseCommandLineFlags(&argc, &argv, true);
google::InitGoogleLogging(argv[0]);
int ret = RUN_ALL_TESTS();
if (ret == 0) {
}
return ret;
}
-