diff options
author | Alexander Harkness <me@bearbin.net> | 2015-06-12 12:00:47 +0200 |
---|---|---|
committer | Alexander Harkness <me@bearbin.net> | 2015-06-12 12:00:47 +0200 |
commit | 001305247fa28e78d0f3d9d565ff7aff25864edc (patch) | |
tree | 9f1e41fa0e6afee7ce9f90f3778f02e7a770ebf7 /src/SelfTests.h | |
parent | Update gratipay (diff) | |
parent | SelfTests are registered and executed after logging framework init. (diff) | |
download | cuberite-001305247fa28e78d0f3d9d565ff7aff25864edc.tar cuberite-001305247fa28e78d0f3d9d565ff7aff25864edc.tar.gz cuberite-001305247fa28e78d0f3d9d565ff7aff25864edc.tar.bz2 cuberite-001305247fa28e78d0f3d9d565ff7aff25864edc.tar.lz cuberite-001305247fa28e78d0f3d9d565ff7aff25864edc.tar.xz cuberite-001305247fa28e78d0f3d9d565ff7aff25864edc.tar.zst cuberite-001305247fa28e78d0f3d9d565ff7aff25864edc.zip |
Diffstat (limited to 'src/SelfTests.h')
-rw-r--r-- | src/SelfTests.h | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/SelfTests.h b/src/SelfTests.h new file mode 100644 index 000000000..03a3b5faa --- /dev/null +++ b/src/SelfTests.h @@ -0,0 +1,51 @@ + +// SelfTests.h + +// Declares the cSelfTests class representing the singleton used for registering self-tests +// This class is only declared if SELF_TEST macro is defined. + + + + + +#pragma once + + + + + +#ifdef SELF_TEST + /** Singleton containing registered self-tests. + Used to schedule self-tests to run after the logging framework is initialized (#2228). */ + class cSelfTests + { + public: + /** Returns the singleton instance of this class. */ + static cSelfTests & Get(void); + + // typedef void (* SelfTestFunction)(void); + typedef std::function<void(void)> SelfTestFunction; + + /** Registers a self-test to be executed once the logging framework is initialized. */ + static void Register(SelfTestFunction a_FnToExecute, const AString & a_TestName); + + /** Executes all the registered self-tests. */ + static void ExecuteAll(void); + + protected: + typedef std::vector<std::pair<SelfTestFunction, AString>> SelfTestFunctions; + + /** Functions (registered self-tests) to call once the logging framework is initialized. */ + SelfTestFunctions m_SelfTests; + + /** If true, tests may be registered. Set to false once the tests are executed, to detect tests that are registered too late. */ + bool m_AllowRegistering; + + + cSelfTests(void); + }; +#endif // SELF_TEST + + + + |