X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Ftest%2FVarintTest.cpp;h=8b8a1856cbf80c3181f0bb5540fbcf173dc86901;hb=e0b75e77cc224d3caffbb717342873c858e893fe;hp=91da0536626252b89f3bd968b7242693b086092d;hpb=546bd3f5f2ed1fdf3a0f5c2b6737a20c4bc2f561;p=folly.git diff --git a/folly/test/VarintTest.cpp b/folly/test/VarintTest.cpp index 91da0536..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) {