]> git.saurik.com Git - wxWidgets.git/commitdiff
added a failtest target to Makefile to test for the (expected) compilation failures
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 16 Apr 2009 14:47:22 +0000 (14:47 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 16 Apr 2009 14:47:22 +0000 (14:47 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60200 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

tests/Makefile.in
tests/events/evthandler.cpp
tests/test.bkl

index 3ac2885e143b1dfd83ef0269c1411b40538db326..f5c1b47c29d9ab501e3f847f7005d00d48547ff1 100644 (file)
@@ -628,6 +628,23 @@ printfbench_printfbench.o: $(srcdir)/benchmarks/printfbench.cpp $(PRINTFBENCH_OD
 @COND_USE_STC_1@monolib_stc.o monodll_stc.o stcdll_stc.o stclib_stc.o: \
 @COND_USE_STC_1@    $(srcdir)/include/wx/stc/stc.h
 
+# notice the ugly hack with using CXXWARNINGS: we can't use CPPFLAGS as
+# currently the value in the makefile would be ignored if we did, but
+# warnings don't matter when we expect compilation to fail anyhow so we can
+# use this variable to enable the compilation of code which is supposed to
+# fail
+failtest:
+       @$(RM) test_evthandler.o
+       @for d in GLOBAL STATIC METHOD FUNCTOR DERIVED WRONG_CLASS; do \
+           if $(MAKE) CXXWARNINGS=-DTEST_INVALID_BIND_$$d test_evthandler.o 2>/dev/null; then \
+               echo "*** Compilation with TEST_INVALID_BIND_$$d unexpectedly succeeded.">&2; \
+               exit 1; \
+           fi; \
+       done; \
+       exit 0
+
+.PHONY: failtest
+
 # Include dependency info, if present:
 @IF_GNU_MAKE@-include ./.deps/*.d
 
index 031a0658da36764c259563b66ad467e98bd8f9af..309b34442fda853a8e97ee7547f2d4ff34e94ad8 100644 (file)
@@ -366,20 +366,35 @@ void EvtHandlerTestCase::InvalidBind()
     // automatically, you need to uncomment them manually and test that
     // compilation does indeed fail
 
-    //handler.Bind(MyEventType, GlobalOnAnotherEvent);
-    //IdleFunctor f; handler.Bind(MyEventType, f);
-    //handler.Bind(MyEventType, &MyHandler::StaticOnAnotherEvent);
-    //handler.Bind(MyEventType, &MyHandler::OnAnotherEvent, &handler);
-
-    // Test that this sample (discussed on the mailing list) doesn't compile:
-    // >struct C1 : wxEvtHandler { };
-    // >struct C2 : wxEvtHandler { void OnWhatever(wxEvent&) };
-    // >C1 c1;
-    // >c1.Connect(&C2::OnWhatever); // BOOM
-
-    //MySink mySink;
-    //MyHandler myHandler;
-    //myHandler.Bind( MyEventType, &MyHandler::OnMyEvent, &mySink ); 
+    // connecting a handler with incompatible signature shouldn't work
+#ifdef TEST_INVALID_BIND_GLOBAL
+    handler.Bind(MyEventType, GlobalOnAnotherEvent);
+#endif
+#ifdef TEST_INVALID_BIND_STATIC
+    handler.Bind(MyEventType, &MyHandler::StaticOnAnotherEvent);
+#endif
+#ifdef TEST_INVALID_BIND_METHOD
+    handler.Bind(MyEventType, &MyHandler::OnAnotherEvent, &handler);
+#endif
+#ifdef TEST_INVALID_BIND_FUNCTOR
+    IdleFunctor f;
+    handler.Bind(MyEventType, f);
+#endif
+
+    // calling a derived class method with a base class pointer must not work
+#ifdef TEST_INVALID_BIND_DERIVED
+    struct C1 : wxEvtHandler { };
+    struct C2 : wxEvtHandler { void OnWhatever(wxEvent&); };
+    C1 c1;
+    c1.Bind(&C2::OnWhatever);
+#endif
+
+    // using object pointer incompatible with the method must not work
+#ifdef TEST_INVALID_BIND_WRONG_CLASS
+    MySink mySink;
+    MyHandler myHandler;
+    myHandler.Bind(MyEventType, &MyHandler::OnMyEvent, &mySink);
+#endif
 }
 
 #endif // !wxEVENTS_COMPATIBILITY_2_8
index 31507cdf569d99177ec7c7a3e1aff1ce15eecb84..b78a570a0cf719e65513865e251aa13138a8608e 100644 (file)
         <wx-lib>base</wx-lib>
     </exe>
 
+    <fragment format="autoconf">
+# notice the ugly hack with using CXXWARNINGS: we can't use CPPFLAGS as
+# currently the value in the makefile would be ignored if we did, but
+# warnings don't matter when we expect compilation to fail anyhow so we can
+# use this variable to enable the compilation of code which is supposed to
+# fail
+failtest:
+       @$(RM) test_evthandler.o
+       @for d in GLOBAL STATIC METHOD FUNCTOR DERIVED WRONG_CLASS; do \
+           if $(MAKE) CXXWARNINGS=-DTEST_INVALID_BIND_$$d test_evthandler.o 2>/dev/null; then \
+               echo "*** Compilation with TEST_INVALID_BIND_$$d unexpectedly succeeded.">&amp;2; \
+               exit 1; \
+           fi; \
+       done; \
+       exit 0
+
+.PHONY: failtest
+    </fragment>
 
 </makefile>