mirror of
https://github.com/thunderbrewhq/squall.git
synced 2026-02-04 00:49:08 +00:00
chore(region): simplify region tests with fixture and matcher
This commit is contained in:
parent
e1587a932c
commit
c5ee72aabb
2 changed files with 72 additions and 76 deletions
50
test/RegionTest.hpp
Normal file
50
test/RegionTest.hpp
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#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) {
|
||||
os << "{ " << value.left << ", " << value.bottom << ", " << value.right << ", " << value.top << " }";
|
||||
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> MatchesRect(RECTF arg) {
|
||||
return { arg };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue