folly copyright 2015 -> copyright 2016
[folly.git] / folly / test / VarintTest.cpp
index 3914684830006f291593984d331a942f187373ff..e5dd0e6a8873ad8d384e38630532ef8fe60c7a07 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2013 Facebook, Inc.
+ * Copyright 2016 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "folly/Varint.h"
+#include <folly/Varint.h>
 
 #include <array>
 #include <initializer_list>
@@ -24,8 +24,8 @@
 #include <glog/logging.h>
 #include <gtest/gtest.h>
 
-#include "folly/Benchmark.h"
-#include "folly/Random.h"
+#include <folly/Benchmark.h>
+#include <folly/Random.h>
 
 DEFINE_int32(random_seed, folly::randomNumberSeed(), "random seed");
 
@@ -65,6 +65,24 @@ void testVarint(uint64_t val, std::initializer_list<uint8_t> 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<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});
@@ -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;
 }
-