20 #include <initializer_list> 24 #include <glog/logging.h> 36 size_t n = bytes.size();
56 memcpy(buf, &*bytes.begin(), n);
58 uint8_t fills[] = {0, 0x7f, 0x80, 0xff};
81 ByteRange br(reinterpret_cast<unsigned char*>(&c), 1);
97 testVarint(static_cast<uint32_t>(-1), {0xff, 0xff, 0xff, 0xff, 0x0f});
99 static_cast<uint64_t>(-1),
100 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01});
104 size_t n = bytes.size();
111 testVarintFail({0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff});
130 constexpr
size_t kNumValues = 1000;
131 std::vector<uint64_t> gValues;
132 std::vector<uint64_t> gDecodedValues;
133 std::vector<uint8_t> gEncoded;
135 void generateRandomValues() {
136 LOG(
INFO) <<
"Random seed is " << FLAGS_random_seed;
137 std::mt19937
rng(FLAGS_random_seed);
140 std::uniform_int_distribution<int> numBytes(1, 8);
141 std::uniform_int_distribution<int> byte(0, 255);
143 gValues.resize(kNumValues);
144 gDecodedValues.resize(kNumValues);
146 for (
size_t i = 0;
i < kNumValues; ++
i) {
147 int n = numBytes(rng);
149 for (
int j = 0; j < n; ++j) {
150 val = (val << 8) + byte(rng);
181 for (
auto&
v : gValues) {
186 gEncoded.erase(gEncoded.begin() + (p -
start), gEncoded.end());
193 while (!range.
empty()) {
205 gflags::ParseCommandLineFlags(&argc, &argv,
true);
206 google::InitGoogleLogging(argv[0]);
209 folly::test::generateRandomValues();
uint64_t encodeZigZag(int64_t val)
void testVarint(uint64_t val, std::initializer_list< uint8_t > bytes)
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
void Fail(const char *msg)
#define EXPECT_EQ(val1, val2)
constexpr size_t kMaxVarintLength64
constexpr size_type size() const
uint64_t decodeVarint(Range< T * > &data)
—— Concurrent Priority Queue Implementation ——
int main(int argc, char *argv[])
constexpr bool empty() const
int64_t decodeZigZag(uint64_t val)
constexpr auto data(C &c) -> decltype(c.data())
int encodeVarintSize(uint64_t val)
constexpr Range< Iter > range(Iter first, Iter last)
TEST(ProgramOptionsTest, Errors)
#define EXPECT_TRUE(condition)
BENCHMARK(fbFollyGlobalBenchmarkBaseline)
void testVarintFail(std::initializer_list< uint8_t > bytes)
bool runBenchmarksOnFlag()
Range< const unsigned char * > ByteRange
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
#define EXPECT_FALSE(condition)
size_t encodeVarint(uint64_t val, uint8_t *buf)
Expected< uint64_t, DecodeVarintError > tryDecodeVarint(Range< T * > &data)
uint32_t randomNumberSeed()
DEFINE_int32(random_seed, folly::randomNumberSeed(),"random seed")