-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
testutils.h
74 lines (61 loc) · 2.34 KB
/
testutils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright 2017 The Cockroach Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied. See the License for the specific language governing
// permissions and limitations under the License.
#pragma once
#include <gtest/gtest.h>
#include <rocksdb/env.h>
#include <rocksdb/status.h>
#include <string>
#include "include/libroach.h"
// Returns initialized DBOptions with reasonable values for unittests.
DBOptions defaultDBOptions() {
return DBOptions{
nullptr, // cache
2, // num_cpu
1024, // max_open_files
false, // use_file_registry
false, // must_exist
false, // read_only
DBSlice(), // rocksdb_options
DBSlice(), // extra_options
};
}
namespace testutils {
rocksdb::Status compareErrorMessage(rocksdb::Status status, const char* err_msg);
rocksdb::Status compareErrorMessage(rocksdb::Status status, std::string err_msg);
// FakeTimeEnv is a simple wrapper around a rocksdb::Env that returns a fixed time
// set through SetCurrentTime.
class FakeTimeEnv : public rocksdb::EnvWrapper {
public:
explicit FakeTimeEnv(rocksdb::Env* base_env) : rocksdb::EnvWrapper(base_env), fake_time_(0){};
virtual rocksdb::Status GetCurrentTime(int64_t* unix_time) override {
*unix_time = fake_time_;
return rocksdb::Status::OK();
}
void SetCurrentTime(int64_t t) { fake_time_ = t; };
private:
int64_t fake_time_;
};
} // namespace testutils
// clang-format isn't so great for macros.
// clang-format off
#define EXPECT_OK(status) { auto s(status); EXPECT_TRUE(s.ok()) << "got: " << s.getState(); }
#define ASSERT_OK(status) { auto s(status); ASSERT_TRUE(s.ok()) << "got: " << s.getState(); }
// If err_msg is empty, status must be ok. Otherwise, the status message must match
// 'err_msg' (regexp full match).
#define EXPECT_ERR(status, err_msg)\
{\
auto s(testutils::compareErrorMessage(status, err_msg)); \
EXPECT_TRUE(s.ok()) << s.getState();\
}
// clang-format on