#include <stddef.h>
#endif
-/* delete pointer if it is not NULL and NULL it afterwards */
-/* (checking that it's !NULL before passing it to delete is just a */
-/* a question of style, because delete will do it itself anyhow, but it might */
-/* be considered as an error by some overzealous debugging implementations of */
-/* the library, so we do it ourselves) */
-#define wxDELETE(p) if ( (p) != NULL ) { delete p; p = NULL; }
-
-/* delete an array and NULL it (see comments above) */
-#define wxDELETEA(p) if ( (p) ) { delete [] (p); p = NULL; }
+#ifdef __cplusplus
+ // delete pointer if it is not NULL and NULL it afterwards
+ template <typename T>
+ inline void wxDELETE(T*& ptr)
+ {
+ typedef char TypeIsCompleteCheck[sizeof(T)];
+
+ if ( ptr != NULL )
+ {
+ delete ptr;
+ ptr = NULL;
+ }
+ }
+
+ // delete an array and NULL it (see comments above)
+ template <typename T>
+ inline void wxDELETEA(T*& ptr)
+ {
+ typedef char TypeIsCompleteCheck[sizeof(T)];
+
+ if ( ptr != NULL )
+ {
+ delete [] ptr;
+ ptr = NULL;
+ }
+ }
+#endif /*__cplusplus*/
/* size of statically declared array */
#define WXSIZEOF(array) (sizeof(array)/sizeof(array[0]))
test_longlongtest.o \
test_convautotest.o \
test_mbconvtest.o \
+ test_misctests.o \
test_ipc.o \
test_regextest.o \
test_wxregextest.o \
test_mbconvtest.o: $(srcdir)/mbconv/mbconvtest.cpp $(TEST_ODEP)
$(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/mbconv/mbconvtest.cpp
+test_misctests.o: $(srcdir)/misc/misctests.cpp $(TEST_ODEP)
+ $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/misc/misctests.cpp
+
test_ipc.o: $(srcdir)/net/ipc.cpp $(TEST_ODEP)
$(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/net/ipc.cpp
$(OBJS)\test_longlongtest.obj \
$(OBJS)\test_convautotest.obj \
$(OBJS)\test_mbconvtest.obj \
+ $(OBJS)\test_misctests.obj \
$(OBJS)\test_ipc.obj \
$(OBJS)\test_regextest.obj \
$(OBJS)\test_wxregextest.obj \
$(OBJS)\test_mbconvtest.obj: .\mbconv\mbconvtest.cpp
$(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\mbconv\mbconvtest.cpp
+$(OBJS)\test_misctests.obj: .\misc\misctests.cpp
+ $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\misc\misctests.cpp
+
$(OBJS)\test_ipc.obj: .\net\ipc.cpp
$(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\net\ipc.cpp
$(OBJS)\test_longlongtest.o \
$(OBJS)\test_convautotest.o \
$(OBJS)\test_mbconvtest.o \
+ $(OBJS)\test_misctests.o \
$(OBJS)\test_ipc.o \
$(OBJS)\test_regextest.o \
$(OBJS)\test_wxregextest.o \
$(OBJS)\test_mbconvtest.o: ./mbconv/mbconvtest.cpp
$(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
+$(OBJS)\test_misctests.o: ./misc/misctests.cpp
+ $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
+
$(OBJS)\test_ipc.o: ./net/ipc.cpp
$(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
$(OBJS)\test_longlongtest.obj \
$(OBJS)\test_convautotest.obj \
$(OBJS)\test_mbconvtest.obj \
+ $(OBJS)\test_misctests.obj \
$(OBJS)\test_ipc.obj \
$(OBJS)\test_regextest.obj \
$(OBJS)\test_wxregextest.obj \
$(OBJS)\test_mbconvtest.obj: .\mbconv\mbconvtest.cpp
$(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\mbconv\mbconvtest.cpp
+$(OBJS)\test_misctests.obj: .\misc\misctests.cpp
+ $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\misc\misctests.cpp
+
$(OBJS)\test_ipc.obj: .\net\ipc.cpp
$(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\net\ipc.cpp
$(OBJS)\test_longlongtest.obj &
$(OBJS)\test_convautotest.obj &
$(OBJS)\test_mbconvtest.obj &
+ $(OBJS)\test_misctests.obj &
$(OBJS)\test_ipc.obj &
$(OBJS)\test_regextest.obj &
$(OBJS)\test_wxregextest.obj &
$(OBJS)\test_mbconvtest.obj : .AUTODEPEND .\mbconv\mbconvtest.cpp
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
+$(OBJS)\test_misctests.obj : .AUTODEPEND .\misc\misctests.cpp
+ $(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
+
$(OBJS)\test_ipc.obj : .AUTODEPEND .\net\ipc.cpp
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
--- /dev/null
+///////////////////////////////////////////////////////////////////////////////
+// Name: tests/misc/misctests.cpp
+// Purpose: test miscellaneous stuff
+// Author: Peter Most
+// Created: 2008-07-10
+// RCS-ID: $Id$
+// Copyright: (c) 2008 Peter Most
+///////////////////////////////////////////////////////////////////////////////
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
+#include "testprec.h"
+
+#ifdef __BORLANDC__
+ #pragma hdrstop
+#endif
+
+#include "wx/defs.h"
+
+// ----------------------------------------------------------------------------
+// test class
+// ----------------------------------------------------------------------------
+
+class MiscTestCase : public CppUnit::TestCase
+{
+public:
+ MiscTestCase() { }
+
+private:
+ CPPUNIT_TEST_SUITE( MiscTestCase );
+ CPPUNIT_TEST( Delete );
+ CPPUNIT_TEST_SUITE_END();
+
+ void Delete();
+
+ DECLARE_NO_COPY_CLASS(MiscTestCase)
+};
+
+// register in the unnamed registry so that these tests are run by default
+CPPUNIT_TEST_SUITE_REGISTRATION( MiscTestCase );
+
+// also include in it's own registry so that these tests can be run alone
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MiscTestCase, "MiscTestCase" );
+
+void MiscTestCase::Delete()
+{
+ // Allocate some arbitrary memory to get a valid pointer:
+ long *pointer = new long;
+ CPPUNIT_ASSERT( pointer != NULL );
+
+ // Check that wxDELETE sets the pointer to NULL:
+ wxDELETE( pointer );
+ CPPUNIT_ASSERT( pointer == NULL );
+
+ // Allocate some arbitrary array to get a valid pointer:
+ long *array = new long[ 3 ];
+ CPPUNIT_ASSERT( array != NULL );
+
+ // Check that wxDELETEA sets the pointer to NULL:
+ wxDELETE( array );
+ CPPUNIT_ASSERT( array == NULL );
+
+ // this results in compilation error, as it should
+#if 0
+ struct SomeUnknownStruct *p = NULL;
+ wxDELETE(p);
+#endif
+}
+
longlong/longlongtest.cpp
mbconv/convautotest.cpp
mbconv/mbconvtest.cpp
+ misc/misctests.cpp
net/ipc.cpp
regex/regextest.cpp
regex/wxregextest.cpp
# End Source File\r
# Begin Source File\r
\r
+SOURCE=.\misc\misctests.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=.\thread\queue.cpp\r
# End Source File\r
# Begin Source File\r
RelativePath=".\mbconv\mbconvtest.cpp"/>\r
<File\r
RelativePath=".\streams\memstream.cpp"/>\r
+ <File\r
+ RelativePath=".\misc\misctests.cpp"/>\r
<File\r
RelativePath=".\thread\queue.cpp"/>\r
<File\r
<File\r
RelativePath=".\streams\memstream.cpp"\r
/>\r
+ <File\r
+ RelativePath=".\misc\misctests.cpp"\r
+ />\r
<File\r
RelativePath=".\thread\queue.cpp"\r
/>\r