]> git.saurik.com Git - wxWidgets.git/commitdiff
added a simple wxLog unit test
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 7 Jul 2009 12:19:34 +0000 (12:19 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 7 Jul 2009 12:19:34 +0000 (12:19 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61343 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

tests/Makefile.in
tests/log/logtest.cpp [new file with mode: 0644]
tests/makefile.bcc
tests/makefile.gcc
tests/makefile.vc
tests/makefile.wat
tests/test.bkl
tests/test_test.dsp
tests/test_vc7_test.vcproj
tests/test_vc8_test.vcproj
tests/test_vc9_test.vcproj

index 51ab17eb551523457ed56c71b980c11b2940de63..b4d15181cd4d43042a2c5d0e2e35f1e9a88c356b 100644 (file)
@@ -46,7 +46,7 @@ wx_top_builddir = @wx_top_builddir@
 
 DESTDIR = 
 WX_RELEASE = 2.9
-WX_VERSION = $(WX_RELEASE).0
+WX_VERSION = $(WX_RELEASE).1
 LIBDIRNAME = $(wx_top_builddir)/lib
 TEST_CXXFLAGS = $(__test_PCH_INC) -D__WX$(TOOLKIT)__ $(__WXUNIV_DEFINE_p) \
        $(__EXCEPTIONS_DEFINE_p) $(__RTTI_DEFINE_p) $(__THREAD_DEFINE_p) \
@@ -73,6 +73,7 @@ TEST_OBJECTS =  \
        test_hashes.o \
        test_intltest.o \
        test_lists.o \
+       test_logtest.o \
        test_longlongtest.o \
        test_convautotest.o \
        test_mbconvtest.o \
@@ -399,6 +400,9 @@ test_intltest.o: $(srcdir)/intl/intltest.cpp $(TEST_ODEP)
 test_lists.o: $(srcdir)/lists/lists.cpp $(TEST_ODEP)
        $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/lists/lists.cpp
 
+test_logtest.o: $(srcdir)/log/logtest.cpp $(TEST_ODEP)
+       $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/log/logtest.cpp
+
 test_longlongtest.o: $(srcdir)/longlong/longlongtest.cpp $(TEST_ODEP)
        $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/longlong/longlongtest.cpp
 
diff --git a/tests/log/logtest.cpp b/tests/log/logtest.cpp
new file mode 100644 (file)
index 0000000..c038628
--- /dev/null
@@ -0,0 +1,161 @@
+///////////////////////////////////////////////////////////////////////////////
+// Name:        tests/log/logtest.cpp
+// Purpose:     wxLog unit test
+// Author:      Vadim Zeitlin
+// Created:     2009-07-07
+// RCS-ID:      $Id$
+// Copyright:   (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
+///////////////////////////////////////////////////////////////////////////////
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
+#include "testprec.h"
+
+#ifdef __BORLANDC__
+    #pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+    #include "wx/log.h"
+#endif // WX_PRECOMP
+
+// ----------------------------------------------------------------------------
+// test logger
+// ----------------------------------------------------------------------------
+
+// simple log sink which just stores the messages logged for each level
+class TestLog : public wxLog
+{
+public:
+    TestLog() { }
+
+    wxString GetLog(wxLogLevel level) const
+    {
+        return m_logs[level];
+    }
+
+    void Clear()
+    {
+        for ( unsigned n = 0; n < WXSIZEOF(m_logs); n++ )
+            m_logs[n].clear();
+    }
+
+protected:
+    virtual void DoLog(wxLogLevel level, const wxString& str, time_t WXUNUSED(t))
+    {
+        m_logs[level] = str;
+    }
+
+    wxSUPPRESS_DOLOG_HIDE_WARNING()
+
+private:
+    wxString m_logs[wxLOG_Trace + 1];
+
+    wxDECLARE_NO_COPY_CLASS(TestLog);
+};
+
+// ----------------------------------------------------------------------------
+// test class
+// ----------------------------------------------------------------------------
+
+class LogTestCase : public CppUnit::TestCase
+{
+public:
+    LogTestCase() { }
+
+    virtual void setUp();
+    virtual void tearDown();
+
+private:
+    CPPUNIT_TEST_SUITE( LogTestCase );
+        CPPUNIT_TEST( Functions );
+        CPPUNIT_TEST( Null );
+#if wxDEBUG_LEVEL
+        CPPUNIT_TEST( Trace );
+#endif // wxDEBUG_LEVEL
+    CPPUNIT_TEST_SUITE_END();
+
+    void Functions();
+    void Null();
+#if wxDEBUG_LEVEL
+    void Trace();
+#endif // wxDEBUG_LEVEL
+
+    TestLog *m_log;
+    wxLog *m_logOld;
+    bool m_logWasEnabled;
+
+    wxDECLARE_NO_COPY_CLASS(LogTestCase);
+};
+
+// register in the unnamed registry so that these tests are run by default
+CPPUNIT_TEST_SUITE_REGISTRATION( LogTestCase );
+
+// also include in it's own registry so that these tests can be run alone
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( LogTestCase, "LogTestCase" );
+
+void LogTestCase::setUp()
+{
+    m_logOld = wxLog::SetActiveTarget(m_log = new TestLog);
+    m_logWasEnabled = wxLog::EnableLogging();
+}
+
+void LogTestCase::tearDown()
+{
+    delete wxLog::SetActiveTarget(m_logOld);
+    wxLog::EnableLogging(m_logWasEnabled);
+}
+
+void LogTestCase::Functions()
+{
+    wxLogMessage("Message");
+    CPPUNIT_ASSERT_EQUAL( "Message", m_log->GetLog(wxLOG_Message) );
+
+    wxLogError("Error %d", 17);
+    CPPUNIT_ASSERT_EQUAL( "Error 17", m_log->GetLog(wxLOG_Error) );
+
+    wxLogDebug("Debug");
+#if wxDEBUG_LEVEL
+    CPPUNIT_ASSERT_EQUAL( "Debug", m_log->GetLog(wxLOG_Debug) );
+#else
+    CPPUNIT_ASSERT_EQUAL( "", m_log->GetLog(wxLOG_Debug) );
+#endif
+}
+
+void LogTestCase::Null()
+{
+    {
+        wxLogNull noLog;
+        wxLogWarning("%s warning", "Not important");
+
+        CPPUNIT_ASSERT_EQUAL( "", m_log->GetLog(wxLOG_Warning) );
+    }
+
+    wxLogWarning("%s warning", "Important");
+    CPPUNIT_ASSERT_EQUAL( "Important warning", m_log->GetLog(wxLOG_Warning) );
+}
+
+#if wxDEBUG_LEVEL
+
+void LogTestCase::Trace()
+{
+    static const char *TEST_MASK = "test";
+
+    wxLogTrace(TEST_MASK, "Not shown");
+    CPPUNIT_ASSERT_EQUAL( "", m_log->GetLog(wxLOG_Trace) );
+
+    wxLog::AddTraceMask(TEST_MASK);
+    wxLogTrace(TEST_MASK, "Shown");
+    CPPUNIT_ASSERT_EQUAL( wxString::Format("(%s) Shown", TEST_MASK),
+                          m_log->GetLog(wxLOG_Trace) );
+
+    wxLog::RemoveTraceMask(TEST_MASK);
+    m_log->Clear();
+
+    wxLogTrace(TEST_MASK, "Not shown again");
+    CPPUNIT_ASSERT_EQUAL( "", m_log->GetLog(wxLOG_Trace) );
+}
+
+#endif // wxDEBUG_LEVEL
index 52b673772ca395b96ddb231a060b728890dabd70..bded0d0f184918904a25a9b4f1b575db084b2631 100644 (file)
@@ -57,6 +57,7 @@ TEST_OBJECTS =  \
        $(OBJS)\test_hashes.obj \
        $(OBJS)\test_intltest.obj \
        $(OBJS)\test_lists.obj \
+       $(OBJS)\test_logtest.obj \
        $(OBJS)\test_longlongtest.obj \
        $(OBJS)\test_convautotest.obj \
        $(OBJS)\test_mbconvtest.obj \
@@ -442,6 +443,9 @@ $(OBJS)\test_intltest.obj: .\intl\intltest.cpp
 $(OBJS)\test_lists.obj: .\lists\lists.cpp
        $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\lists\lists.cpp
 
+$(OBJS)\test_logtest.obj: .\log\logtest.cpp
+       $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\log\logtest.cpp
+
 $(OBJS)\test_longlongtest.obj: .\longlong\longlongtest.cpp
        $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\longlong\longlongtest.cpp
 
index bff61a8b8bc1e016b353358666c563212bfd5c1e..0abb68726159759b4afcc5408feb3e68d510e54b 100644 (file)
@@ -49,6 +49,7 @@ TEST_OBJECTS =  \
        $(OBJS)\test_hashes.o \
        $(OBJS)\test_intltest.o \
        $(OBJS)\test_lists.o \
+       $(OBJS)\test_logtest.o \
        $(OBJS)\test_longlongtest.o \
        $(OBJS)\test_convautotest.o \
        $(OBJS)\test_mbconvtest.o \
@@ -429,6 +430,9 @@ $(OBJS)\test_intltest.o: ./intl/intltest.cpp
 $(OBJS)\test_lists.o: ./lists/lists.cpp
        $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
 
+$(OBJS)\test_logtest.o: ./log/logtest.cpp
+       $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
+
 $(OBJS)\test_longlongtest.o: ./longlong/longlongtest.cpp
        $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
 
index d3353c0e7837eb881e6febde4c8d5888c4ec3bb1..dfa04f336716889f8a068211abde1cf7ee7cb11d 100644 (file)
@@ -50,6 +50,7 @@ TEST_OBJECTS =  \
        $(OBJS)\test_hashes.obj \
        $(OBJS)\test_intltest.obj \
        $(OBJS)\test_lists.obj \
+       $(OBJS)\test_logtest.obj \
        $(OBJS)\test_longlongtest.obj \
        $(OBJS)\test_convautotest.obj \
        $(OBJS)\test_mbconvtest.obj \
@@ -522,6 +523,9 @@ $(OBJS)\test_intltest.obj: .\intl\intltest.cpp
 $(OBJS)\test_lists.obj: .\lists\lists.cpp
        $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\lists\lists.cpp
 
+$(OBJS)\test_logtest.obj: .\log\logtest.cpp
+       $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\log\logtest.cpp
+
 $(OBJS)\test_longlongtest.obj: .\longlong\longlongtest.cpp
        $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\longlong\longlongtest.cpp
 
index 7b0d21e5e1e9baee4537791367c338bcd804cc47..d74e72d02824a404643ed8a7f4412fa66850a492 100644 (file)
@@ -288,6 +288,7 @@ TEST_OBJECTS =  &
        $(OBJS)\test_hashes.obj &
        $(OBJS)\test_intltest.obj &
        $(OBJS)\test_lists.obj &
+       $(OBJS)\test_logtest.obj &
        $(OBJS)\test_longlongtest.obj &
        $(OBJS)\test_convautotest.obj &
        $(OBJS)\test_mbconvtest.obj &
@@ -481,6 +482,9 @@ $(OBJS)\test_intltest.obj :  .AUTODEPEND .\intl\intltest.cpp
 $(OBJS)\test_lists.obj :  .AUTODEPEND .\lists\lists.cpp
        $(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
 
+$(OBJS)\test_logtest.obj :  .AUTODEPEND .\log\logtest.cpp
+       $(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
+
 $(OBJS)\test_longlongtest.obj :  .AUTODEPEND .\longlong\longlongtest.cpp
        $(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
 
index b679cfb4715394222475ee6749eca651b8a8f7d7..37a7cdb7f499350b611e0a0c9abe0f7bfed8ffce 100644 (file)
@@ -48,6 +48,7 @@
             hashes/hashes.cpp
             intl/intltest.cpp
             lists/lists.cpp
+            log/logtest.cpp
             longlong/longlongtest.cpp
             mbconv/convautotest.cpp
             mbconv/mbconvtest.cpp
index b2d5ec01a3e03259ecf12e46eddde8e36786edff..611166829c648b1bdf85928ba19dcfc45f18ca75 100644 (file)
@@ -357,6 +357,10 @@ SOURCE=.\lists\lists.cpp
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=.\log\logtest.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=.\longlong\longlongtest.cpp\r
 # End Source File\r
 # Begin Source File\r
index b728cb2f740bdfc777154e5bad31ab52d9211809..754193aa5ccfdfcdf63da5c91e5d111feb585c01 100644 (file)
                        <File\r
                                RelativePath=".\lists\lists.cpp">\r
                        </File>\r
+                       <File\r
+                               RelativePath=".\log\logtest.cpp">\r
+                       </File>\r
                        <File\r
                                RelativePath=".\longlong\longlongtest.cpp">\r
                        </File>\r
index 2e9d07f6e213729a0cdf6a49445dc2e27a9c1fbd..671f7358b09d59707cd2c33ddbf852bb56a0735b 100644 (file)
                                RelativePath=".\lists\lists.cpp"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath=".\log\logtest.cpp"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath=".\longlong\longlongtest.cpp"\r
                                >\r
index 765ae89a641ba41b561070c2cf1c355b64a79eb2..71d96a4b651db979cd88769dfbb8340f49cd54e5 100644 (file)
                                RelativePath=".\lists\lists.cpp"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath=".\log\logtest.cpp"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath=".\longlong\longlongtest.cpp"\r
                                >\r