123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- #ifndef BROKEN_INTERNAL_H
- #define BROKEN_INTERNAL_H
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <utility>
- struct BrokenAPI {
-
- typedef void (*Entry)(void);
- enum Flags : unsigned {
- kFlagFinished = 0x1
- };
-
- struct Unit {
- Entry entry;
- const char* name;
- int priority;
- unsigned flags;
- Unit* next;
- };
-
- struct AutoUnit : Unit {
- inline AutoUnit(Entry entry_, const char* name_, int priority_ = 0, int dummy_ = 0) noexcept {
-
- (void)dummy_;
- this->entry = entry_;
- this->name = name_;
- this->priority = priority_;
- this->flags = 0;
- this->next = nullptr;
- BrokenAPI::add(this);
- }
- };
- static bool hasArg(const char* name) noexcept;
-
- static void add(Unit* unit) noexcept;
-
- static void setOutputFile(FILE* file) noexcept;
-
-
-
- static int run(int argc, const char* argv[], Entry onBeforeRun = nullptr, Entry onAfterRun = nullptr);
-
- static void info(const char* fmt, ...) noexcept;
-
- static void fail(const char* file, int line, const char* expression, const char* fmt, ...) noexcept;
-
- template<typename T>
- static inline void expect(const char* file, int line, const char* expression, const T& result) noexcept {
- if (!result)
- fail(file, line, expression, nullptr);
- }
-
- template<typename T, typename... Args>
- static inline void expect(const char* file, int line, const char* expression, const T& result, const char* fmt, Args&&... args) noexcept {
- if (!result)
- fail(file, line, expression, fmt, std::forward<Args>(args)...);
- }
- };
- #define BROKEN_UNIT_INTERNAL(NAME, PRIORITY) \
- static void unit_##NAME##_entry(void); \
- static ::BrokenAPI::AutoUnit unit_##NAME##_autoinit(unit_##NAME##_entry, #NAME, PRIORITY); \
- static void unit_##NAME##_entry(void)
- #define BROKEN_STRINFIGY_EXPRESSION_INTERNAL(EXP, ...) #EXP
- #define UNIT(NAME, ...) BROKEN_UNIT_INTERNAL(NAME, __VA_ARGS__ + 0)
- #define INFO(...) ::BrokenAPI::info(__VA_ARGS__)
- #define EXPECT(...) ::BrokenAPI::expect(__FILE__, __LINE__, BROKEN_STRINFIGY_EXPRESSION_INTERNAL(__VA_ARGS__), __VA_ARGS__)
- #endif
|