squall/test/RegionTest.hpp
2025-10-02 22:23:04 -05:00

64 lines
1.6 KiB
C++

#include "storm/Region.hpp"
#include "test/Test.hpp"
#include <sstream>
// Fixture for repetitive handling of Rgn objects.
struct RgnDataTest {
HSRGN rgn = nullptr;
RgnDataTest() {
SRgnCreate(&rgn, 0);
}
~RgnDataTest() {
SRgnDelete(rgn);
rgn = nullptr;
}
HSRGN* operator &() { return &rgn; }
operator HSRGN() const { return rgn; }
HSRGN operator->() const { return rgn; }
};
// Helpers for comparing RECTF structs
std::ostream& operator <<(std::ostream& os, RECTF const& value) {
#if defined(WHOA_RECT_USES_SCREEN_COORDINATES)
os << "{ " << value.left << ", " << value.top << ", " << value.right << ", " << value.bottom << " }";
#else
os << "{ " << value.left << ", " << value.bottom << ", " << value.right << ", " << value.top << " }";
#endif
return os;
}
// Helpers for comparing RECTF structs
std::ostream& operator <<(std::ostream& os, RECT const& value) {
os << "{ " << value.left << ", " << value.top << ", " << value.right << ", " << value.bottom << " }";
return os;
}
template <class T>
class RECTMatcher : public Catch::MatcherBase<T> {
private:
T cmp;
public:
RECTMatcher(T arg) : cmp(arg) {}
bool match(T const& in) const override {
return cmp.left == in.left && cmp.bottom == in.bottom && cmp.right == in.right && cmp.top == in.top;
}
std::string describe() const override {
std::ostringstream ss;
ss << "equals " << cmp;
return ss.str();
}
};
RECTMatcher<RECTF> MatchesRectf(RECTF arg) {
return { arg };
}
RECTMatcher<RECT> MatchesRecti(RECT arg) {
return { arg };
}