]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/tools/ldb_cmd_test.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / rocksdb / tools / ldb_cmd_test.cc
CommitLineData
7c673cae 1// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
11fdf7f2
TL
2// This source code is licensed under both the GPLv2 (found in the
3// COPYING file in the root directory) and Apache 2.0 License
4// (found in the LICENSE.Apache file in the root directory).
7c673cae
FG
5//
6#ifndef ROCKSDB_LITE
7
8#include "rocksdb/utilities/ldb_cmd.h"
9#include "util/testharness.h"
10
11using std::string;
12using std::vector;
13using std::map;
14
15class LdbCmdTest : public testing::Test {};
16
17TEST_F(LdbCmdTest, HexToString) {
18 // map input to expected outputs.
19 // odd number of "hex" half bytes doesn't make sense
20 map<string, vector<int>> inputMap = {
21 {"0x07", {7}}, {"0x5050", {80, 80}}, {"0xFF", {-1}},
22 {"0x1234", {18, 52}}, {"0xaaAbAC", {-86, -85, -84}}, {"0x1203", {18, 3}},
23 };
24
25 for (const auto& inPair : inputMap) {
26 auto actual = rocksdb::LDBCommand::HexToString(inPair.first);
27 auto expected = inPair.second;
28 for (unsigned int i = 0; i < actual.length(); i++) {
29 EXPECT_EQ(expected[i], static_cast<int>((signed char) actual[i]));
30 }
31 auto reverse = rocksdb::LDBCommand::StringToHex(actual);
32 EXPECT_STRCASEEQ(inPair.first.c_str(), reverse.c_str());
33 }
34}
35
36TEST_F(LdbCmdTest, HexToStringBadInputs) {
37 const vector<string> badInputs = {
38 "0xZZ", "123", "0xx5", "0x111G", "0x123", "Ox12", "0xT", "0x1Q1",
39 };
40 for (const auto badInput : badInputs) {
41 try {
42 rocksdb::LDBCommand::HexToString(badInput);
43 std::cerr << "Should fail on bad hex value: " << badInput << "\n";
44 FAIL();
45 } catch (...) {
46 }
47 }
48}
49
50int main(int argc, char** argv) {
51 ::testing::InitGoogleTest(&argc, argv);
52 return RUN_ALL_TESTS();
53}
54#else
55#include <stdio.h>
56
11fdf7f2 57int main(int /*argc*/, char** /*argv*/) {
7c673cae
FG
58 fprintf(stderr, "SKIPPED as LDBCommand is not supported in ROCKSDB_LITE\n");
59 return 0;
60}
61
62#endif // ROCKSDB_LITE