Also differentiate pass/faile output and add a `make test` target.
+test: test-zc test-tr
+ ./test-zc
+ ./test-tr
+
test-zc: $(FILES) zcpointer.h
$(CXX) $(CXXFLAGS) $(FILES) -o $@
test-zc: $(FILES) zcpointer.h
$(CXX) $(CXXFLAGS) $(FILES) -o $@
#define EXPECT(expr) do { if (!(expr)) { throw std::logic_error(#expr); } } while(0)
#define EXPECT(expr) do { if (!(expr)) { throw std::logic_error(#expr); } } while(0)
+#if defined(ZCPOINTER_TRACK_REFS) && ZCPOINTER_TRACK_REFS
+
#define EXPECT_UAF(expr) do { \
try { \
(expr); \
#define EXPECT_UAF(expr) do { \
try { \
(expr); \
} catch (zc::UseAfterFreeError) {} \
} while(0)
} catch (zc::UseAfterFreeError) {} \
} while(0)
+#else
+
+#define EXPECT_UAF(expr) do { \
+ std::cout << ">>> ZCPOINTER_TRACK_REFS not enabled, cannot catch UAF" << std::endl; \
+ (expr); \
+ } while(0)
+
+#endif
+
void TestReset() {
zc::owned<C> c(new C());
zc::ref<C> owned = c.get();
void TestReset() {
zc::owned<C> c(new C());
zc::ref<C> owned = c.get();
std::cout << "=== BEGIN " << test.name << " ===" << std::endl;
try {
test.test();
std::cout << "=== BEGIN " << test.name << " ===" << std::endl;
try {
test.test();
- std::cout << "=== PASS " << test.name << " ===" << std::endl;
+ std::cout << "+++ PASS " << test.name << " +++" << std::endl;
} catch (const std::logic_error& e) {
passed = false;
} catch (const std::logic_error& e) {
passed = false;
- std::cout << "=== FAIL " << test.name
+ std::cout << "!!! FAIL " << test.name
<< ": Assertion failure: " << e.what() << " ===" << std::endl;
}
}
<< ": Assertion failure: " << e.what() << " ===" << std::endl;
}
}