]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/fswatcher/fswatchertest.cpp
Resolve ambiguity between GetClientXXX() methods in wxOSX wxComboBox.
[wxWidgets.git] / tests / fswatcher / fswatchertest.cpp
index 32a9eb26fb3febe4ab460bc3ede1f869162ae265..fc158e7162049bb04c280d830fa5a4a22b977fd5 100644 (file)
     #pragma hdrstop
 #endif
 
+#ifndef WX_PRECOMP
+    #include "wx/timer.h"
+#endif
+
 #include "wx/evtloop.h"
 #include "wx/filename.h"
 #include "wx/filefn.h"
@@ -147,8 +151,10 @@ public:
         CPPUNIT_ASSERT(dir.DirExists());
 
         // just to be really sure we know what we remove
-        CPPUNIT_ASSERT(dir.GetDirs().Last() == "fswatcher_test");
-        CPPUNIT_ASSERT(dir.Rmdir(wxPATH_RMDIR_RECURSIVE));
+        CPPUNIT_ASSERT_EQUAL( "fswatcher_test", dir.GetDirs().Last() );
+
+        // FIXME-VC6: using non-static Rmdir() results in ICE
+        CPPUNIT_ASSERT( wxFileName::Rmdir(dir.GetFullPath(), wxPATH_RMDIR_RECURSIVE) );
     }
 
     static wxFileName RandomName(const wxFileName& base, int length = 10)
@@ -182,7 +188,7 @@ EventGenerator* EventGenerator::ms_instance = 0;
 class EventHandler : public wxEvtHandler
 {
 public:
-    const static int WAIT_DURATION = 3;
+    enum { WAIT_DURATION = 3 };
 
     EventHandler() :
         eg(EventGenerator::Get()), m_loop(0), m_count(0), m_watcher(0)
@@ -246,7 +252,7 @@ public:
             break;
         case 2:
             // actual test
-            CPPUNIT_ASSERT(CheckResult());
+            CheckResult();
             Exit();
             break;
 
@@ -293,7 +299,7 @@ public:
         // did we receive event already?
         if (!tested)
         {
-            // well, lets wait a bit more
+            // well, let's wait a bit more
             wxSleep(WAIT_DURATION);
         }
 
@@ -303,15 +309,13 @@ public:
     virtual bool AfterWait()
     {
         // fail if still no events
-         if (!tested)
-         {
-             wxString s;
-             s.Printf("No events from watcher during %d seconds!",
-                                                             WAIT_DURATION);
-             CPPUNIT_FAIL((const char*)s);
-         }
-
-         return true;
+        WX_ASSERT_MESSAGE
+        (
+             ("No events during %d seconds!", static_cast<int>(WAIT_DURATION)),
+             tested
+        );
+
+        return true;
     }
 
     virtual void OnFileSystemEvent(wxFileSystemWatcherEvent& evt)
@@ -325,11 +329,25 @@ public:
         tested = true;
     }
 
-    virtual bool CheckResult()
+    virtual void CheckResult()
     {
-        CPPUNIT_ASSERT_EQUAL( 1, m_events.size() );
+        CPPUNIT_ASSERT_MESSAGE( "No events received", !m_events.empty() );
+
         const wxFileSystemWatcherEvent * const e = m_events.front();
 
+        WX_ASSERT_EQUAL_MESSAGE
+        (
+            (
+                "Extra events received, first is of type %x, for path=\"%s\","
+                "last is of type %x, path=\"%s\"",
+                e->GetChangeType(),
+                e->GetPath().GetFullPath(),
+                m_events.back()->GetChangeType(),
+                m_events.back()->GetPath().GetFullPath()
+            ),
+            1, m_events.size()
+        );
+
         // this is our "reference event"
         const wxFileSystemWatcherEvent expected = ExpectedEvent();
 
@@ -342,9 +360,6 @@ public:
 
         CPPUNIT_ASSERT_EQUAL(expected.GetPath(), e->GetPath());
         CPPUNIT_ASSERT_EQUAL(expected.GetNewPath(), e->GetNewPath());
-        CPPUNIT_ASSERT_EQUAL(expected.GetChangeType(), e->GetChangeType());
-
-        return true;
     }
 
     virtual void GenerateEvent() = 0;
@@ -401,6 +416,8 @@ private:
         CPPUNIT_TEST( TestEventAccess );
 #endif // __WXMSW__
 #endif // !wxHAS_KQUEUE
+
+        CPPUNIT_TEST( TestNoEventsAfterRemove );
     CPPUNIT_TEST_SUITE_END();
 
     void TestEventCreate();
@@ -409,13 +426,22 @@ private:
     void TestEventModify();
     void TestEventAccess();
 
+    void TestNoEventsAfterRemove();
+
     DECLARE_NO_COPY_CLASS(FileSystemWatcherTestCase)
 };
 
+// the test currently hangs under OS X for some reason and this prevents tests
+// ran by buildbot from completing so disable it until someone has time to
+// debug it
+//
+// FIXME: debug and fix this!
+#ifndef __WXOSX__
 // register in the unnamed registry so that these tests are run by default
 CPPUNIT_TEST_SUITE_REGISTRATION( FileSystemWatcherTestCase );
+#endif
 
-// also include in it's own registry so that these tests can be run alone
+// also include in its own registry so that these tests can be run alone
 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( FileSystemWatcherTestCase,
                                         "FileSystemWatcherTestCase" );
 
@@ -587,3 +613,60 @@ void FileSystemWatcherTestCase::TestEventAccess()
     EventTester tester;
     tester.Run();
 }
+
+namespace
+{
+
+// We can't define this class locally inside TestNoEventsAfterRemove() for some
+// reason with g++ 4.0 under OS X 10.5, it results in the following mysterious
+// error:
+//
+// /var/tmp//ccTkNCkc.s:unknown:Non-global symbol:
+// __ZThn80_ZN25FileSystemWatcherTestCase23TestNoEventsAfterRemoveEvEN11EventTester6NotifyEv.eh
+// can't be a weak_definition
+//
+// So define this class outside the function instead.
+class NoEventsAfterRemoveEventTester : public EventHandler,
+                                       public wxTimer
+{
+public:
+    NoEventsAfterRemoveEventTester()
+    {
+        // We need to use an inactivity timer as we never get any file
+        // system events in this test, so we consider that the test is
+        // finished when this 1s timeout expires instead of, as usual,
+        // stopping after getting the file system events.
+        Start(1000, true);
+    }
+
+    virtual void GenerateEvent()
+    {
+        m_watcher->Remove(EventGenerator::GetWatchDir());
+        CPPUNIT_ASSERT(eg.CreateFile());
+    }
+
+    virtual void CheckResult()
+    {
+        CPPUNIT_ASSERT( m_events.empty() );
+    }
+
+    virtual wxFileSystemWatcherEvent ExpectedEvent()
+    {
+        CPPUNIT_FAIL( "Shouldn't be called" );
+
+        return wxFileSystemWatcherEvent(wxFSW_EVENT_ERROR);
+    }
+
+    virtual void Notify()
+    {
+        SendIdle();
+    }
+};
+
+} // anonymous namespace
+
+void FileSystemWatcherTestCase::TestNoEventsAfterRemove()
+{
+    NoEventsAfterRemoveEventTester tester;
+    tester.Run();
+}