From f1e1257f21610dcf20ed7cc379fa3e97817bdf11 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Wed, 7 Aug 2019 05:18:04 -0400 Subject: [PATCH] refactor tests --- include/common.h | 43 ++++++++++++++++++++++++++----------------- test/main.cpp | 2 +- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/include/common.h b/include/common.h index a9b5daf..fddfd9f 100644 --- a/include/common.h +++ b/include/common.h @@ -31,6 +31,32 @@ constexpr bool x64 = false; template using Array = T[]; +template using Functor = std::integral_constant, F>; + +template +struct Identity { V operator()(V v) const { return v; } }; + +struct PermissivePointer +{ + template + operator T*() { return (T*)p; } + void* p; +}; + +template > +class AutoHandle +{ +public: + AutoHandle(HANDLE h) : h(h) {} + operator HANDLE() { return h.get(); } + PHANDLE operator&() { static_assert(sizeof(*this) == sizeof(HANDLE)); assert(!h); return (PHANDLE)this; } + operator bool() { return h.get() != NULL && h.get() != INVALID_HANDLE_VALUE; } + +private: + struct HandleCleaner { void operator()(void* h) { if (h != INVALID_HANDLE_VALUE) HandleCloser()(PermissivePointer{ h }); } }; + std::unique_ptr h; +}; + template class Synchronized { @@ -53,23 +79,6 @@ private: M m; }; -template -using Functor = std::integral_constant, F>; - -template > -class AutoHandle -{ -public: - AutoHandle(HANDLE h) : h(h) {} - operator HANDLE() { return h.get(); } - PHANDLE operator&() { static_assert(sizeof(*this) == sizeof(HANDLE)); return (PHANDLE)this; } - operator bool() { return h.get() != NULL && h.get() != INVALID_HANDLE_VALUE; } - -private: - struct HandleCleaner { void operator()(void* h) { if (h != INVALID_HANDLE_VALUE) HandleCloser()(h); } }; - std::unique_ptr h; -}; - static struct { BYTE DUMMY[100]; diff --git a/test/main.cpp b/test/main.cpp index 14b5810..3535971 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -13,7 +13,7 @@ int& mode = vars.at(0); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int _) { QApplication a(_ = 0, DUMMY); - static std::vector, Functor>> extensions; + static std::vector>> extensions; for (auto file : std::filesystem::directory_iterator(std::filesystem::current_path())) if (file.path().extension() == L".dll" && (std::stringstream() << std::ifstream(file.path(), std::ios::binary).rdbuf()).str().find("OnNewSentence") != std::string::npos)