X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Ftest%2FVarintTest.cpp;h=8b8a1856cbf80c3181f0bb5540fbcf173dc86901;hb=e0b75e77cc224d3caffbb717342873c858e893fe;hp=812b888baea3a4d08250f4bed7507c88f1eb6965;hpb=ce64f0f685111ac24c7a321ea56d0c3524621df1;p=folly.git diff --git a/folly/test/VarintTest.cpp b/folly/test/VarintTest.cpp index 812b888b..8b8a1856 100644 --- a/folly/test/VarintTest.cpp +++ b/folly/test/VarintTest.cpp @@ -1,5 +1,5 @@ /* - * 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. @@ -22,10 +22,10 @@ #include #include -#include #include #include +#include DEFINE_int32(random_seed, folly::randomNumberSeed(), "random seed"); @@ -65,6 +65,24 @@ void testVarint(uint64_t val, std::initializer_list bytes) { } } +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(&c), 1); + EXPECT_EQ(decodeVarint(br), 0); + + MutableByteRange mbr(reinterpret_cast(&c), 1); + EXPECT_EQ(decodeVarint(mbr), 0); +} + TEST(Varint, Simple) { testVarint(0, {0}); testVarint(1, {1}); @@ -115,7 +133,7 @@ void generateRandomValues() { 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; @@ -145,7 +163,6 @@ void generateRandomValues() { BENCHMARK(VarintEncoding, iters) { uint8_t* start = &(*gEncoded.begin()); uint8_t* p = start; - bool empty = (iters == 0); while (iters--) { p = start; for (auto& v : gValues) { @@ -172,7 +189,7 @@ BENCHMARK(VarintDecoding, iters) { 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) { @@ -181,4 +198,3 @@ int main(int argc, char *argv[]) { } return ret; } -