]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/fswatcher/fswatchertest.cpp
update version check for glib 2.32
[wxWidgets.git] / tests / fswatcher / fswatchertest.cpp
index 6cefa259697eea2db7ac1b67700a3451e3115b55..a3fc759dcca2f364fe9c7479728af19166b7098d 100644 (file)
@@ -335,19 +335,6 @@ public:
 
         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();
 
@@ -360,6 +347,35 @@ public:
 
         CPPUNIT_ASSERT_EQUAL(expected.GetPath(), e->GetPath());
         CPPUNIT_ASSERT_EQUAL(expected.GetNewPath(), e->GetNewPath());
+
+        // Under MSW extra modification events are sometimes reported after a
+        // rename and we just can't get rid of them, so ignore them in this
+        // test if they do happen.
+        if ( e->GetChangeType() == wxFSW_EVENT_RENAME &&
+                m_events.size() == 2 )
+        {
+            const wxFileSystemWatcherEvent* const e2 = m_events.back();
+            if ( e2->GetChangeType() == wxFSW_EVENT_MODIFY &&
+                    e2->GetPath() == e->GetNewPath() )
+            {
+                // This is a modify event for the new file, ignore it.
+                return;
+            }
+        }
+
+        WX_ASSERT_EQUAL_MESSAGE
+        (
+            (
+                "Extra events received, last one is of type %x, path=\"%s\" "
+                "(the original event was for \"%s\" (\"%s\")",
+                m_events.back()->GetChangeType(),
+                m_events.back()->GetPath().GetFullPath(),
+                e->GetPath().GetFullPath(),
+                e->GetNewPath().GetFullPath()
+            ),
+            1, m_events.size()
+        );
+
     }
 
     virtual void GenerateEvent() = 0;
@@ -412,9 +428,9 @@ private:
         CPPUNIT_TEST( TestEventModify );
 
         // MSW implementation doesn't detect file access events currently
-#ifndef __WXMSW__
+#ifndef __WINDOWS__
         CPPUNIT_TEST( TestEventAccess );
-#endif // __WXMSW__
+#endif // __WINDOWS__
 #endif // !wxHAS_KQUEUE
 
         CPPUNIT_TEST( TestNoEventsAfterRemove );
@@ -614,45 +630,59 @@ void FileSystemWatcherTestCase::TestEventAccess()
     tester.Run();
 }
 
-void FileSystemWatcherTestCase::TestNoEventsAfterRemove()
+namespace
 {
-    class EventTester : public EventHandler,
-                        public wxTimer
+
+// 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()
     {
-    public:
-        EventTester()
-        {
-            // 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);
-        }
+        // 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 GenerateEvent()
+    {
+        m_watcher->Remove(EventGenerator::GetWatchDir());
+        CPPUNIT_ASSERT(eg.CreateFile());
+    }
 
-        virtual void CheckResult()
-        {
-            CPPUNIT_ASSERT( m_events.empty() );
-        }
+    virtual void CheckResult()
+    {
+        CPPUNIT_ASSERT( m_events.empty() );
+    }
 
-        virtual wxFileSystemWatcherEvent ExpectedEvent()
-        {
-            CPPUNIT_FAIL( "Shouldn't be called" );
+    virtual wxFileSystemWatcherEvent ExpectedEvent()
+    {
+        CPPUNIT_FAIL( "Shouldn't be called" );
 
-            return wxFileSystemWatcherEvent(wxFSW_EVENT_ERROR);
-        }
+        return wxFileSystemWatcherEvent(wxFSW_EVENT_ERROR);
+    }
 
-        virtual void Notify()
-        {
-            SendIdle();
-        }
-    };
+    virtual void Notify()
+    {
+        SendIdle();
+    }
+};
 
-    EventTester tester;
+} // anonymous namespace
+
+void FileSystemWatcherTestCase::TestNoEventsAfterRemove()
+{
+    NoEventsAfterRemoveEventTester tester;
     tester.Run();
 }