Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2011 The LevelDB Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file. See the AUTHORS file for names of contributors.5#ifndef STORAGE_LEVELDB_UTIL_TESTHARNESS_H_6#define STORAGE_LEVELDB_UTIL_TESTHARNESS_H_8#include <stdio.h>9#include <stdlib.h>11#include <sstream>13#include "leveldb/status.h"15namespace leveldb {16namespace test {18// Run some of the tests registered by the TEST() macro. If the19// environment variable "LEVELDB_TESTS" is not set, runs all tests.20// Otherwise, runs only the tests whose name contains the value of21// "LEVELDB_TESTS" as a substring. E.g., suppose the tests are:22// TEST(Foo, Hello) { ... }23// TEST(Foo, World) { ... }24// LEVELDB_TESTS=Hello will run the first test25// LEVELDB_TESTS=o will run both tests26// LEVELDB_TESTS=Junk will run no tests27//28// Returns 0 if all tests pass.29// Dies or returns a non-zero value if some test fails.30int RunAllTests();32// Return the directory to use for temporary storage.33std::string TmpDir();35// Return a randomization seed for this run. Typically returns the36// same number on repeated invocations of this binary, but automated37// runs may be able to vary the seed.38int RandomSeed();40// An instance of Tester is allocated to hold temporary state during41// the execution of an assertion.42class Tester {43private:44bool ok_;45const char* fname_;46int line_;47std::stringstream ss_;49public:50Tester(const char* f, int l) : ok_(true), fname_(f), line_(l) {}52~Tester() {53if (!ok_) {54fprintf(stderr, "%s:%d:%s\n", fname_, line_, ss_.str().c_str());55exit(1);56}57}59Tester& Is(bool b, const char* msg) {60if (!b) {61ss_ << " Assertion failure " << msg;62ok_ = false;63}64return *this;65}67Tester& IsOk(const Status& s) {68if (!s.ok()) {69ss_ << " " << s.ToString();70ok_ = false;71}72return *this;73}75#define BINARY_OP(name, op) \76template <class X, class Y> \77Tester& name(const X& x, const Y& y) { \78if (!(x op y)) { \79ss_ << " failed: " << x << (" " #op " ") << y; \80ok_ = false; \81} \82return *this; \83}85BINARY_OP(IsEq, ==)86BINARY_OP(IsNe, !=)87BINARY_OP(IsGe, >=)88BINARY_OP(IsGt, >)89BINARY_OP(IsLe, <=)90BINARY_OP(IsLt, <)91#undef BINARY_OP93// Attach the specified value to the error message if an error has occurred94template <class V>95Tester& operator<<(const V& value) {96if (!ok_) {97ss_ << " " << value;98}99return *this;100}101};103#define ASSERT_TRUE(c) ::leveldb::test::Tester(__FILE__, __LINE__).Is((c), #c)104#define ASSERT_OK(s) ::leveldb::test::Tester(__FILE__, __LINE__).IsOk((s))105#define ASSERT_EQ(a, b) \106::leveldb::test::Tester(__FILE__, __LINE__).IsEq((a), (b))107#define ASSERT_NE(a, b) \108::leveldb::test::Tester(__FILE__, __LINE__).IsNe((a), (b))109#define ASSERT_GE(a, b) \110::leveldb::test::Tester(__FILE__, __LINE__).IsGe((a), (b))111#define ASSERT_GT(a, b) \112::leveldb::test::Tester(__FILE__, __LINE__).IsGt((a), (b))113#define ASSERT_LE(a, b) \114::leveldb::test::Tester(__FILE__, __LINE__).IsLe((a), (b))115#define ASSERT_LT(a, b) \116::leveldb::test::Tester(__FILE__, __LINE__).IsLt((a), (b))118#define TCONCAT(a, b) TCONCAT1(a, b)119#define TCONCAT1(a, b) a##b121#define TEST(base, name) \122class TCONCAT(_Test_, name) : public base { \123public: \124void _Run(); \125static void _RunIt() { \126TCONCAT(_Test_, name) t; \127t._Run(); \128} \129}; \130bool TCONCAT(_Test_ignored_, name) = ::leveldb::test::RegisterTest( \131#base, #name, &TCONCAT(_Test_, name)::_RunIt); \132void TCONCAT(_Test_, name)::_Run()134// Register the specified test. Typically not used directly, but135// invoked via the macro expansion of TEST.136bool RegisterTest(const char* base, const char* name, void (*func)());138} // namespace test139} // namespace leveldb141#endif // STORAGE_LEVELDB_UTIL_TESTHARNESS_H_
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.