+
+ // Now test the refcount mechanism by watching items more than once
+ wxFileName child(dir);
+ child.AppendDir("child");
+ m_watcher->AddTree(child);
+ // Check some watches were added; we don't care about the number
+ CPPUNIT_ASSERT(initial < m_watcher->GetWatchedPathsCount());
+ // Now watch the whole tree and check that the count is the same
+ // as it was the first time, despite also adding 'child' separately
+ // Except that in wxMSW this isn't true: each watch will be a
+ // single, recursive dir; so fudge the count
+ size_t fudge = 0;
+#ifdef __WINDOWS__
+ fudge = 1;
+#endif // __WINDOWS__
+ m_watcher->AddTree(dir);
+ CPPUNIT_ASSERT_EQUAL(plustree + fudge, m_watcher->GetWatchedPathsCount());
+ m_watcher->RemoveTree(child);
+ CPPUNIT_ASSERT(initial < m_watcher->GetWatchedPathsCount());
+ m_watcher->RemoveTree(dir);
+ CPPUNIT_ASSERT_EQUAL(initial, m_watcher->GetWatchedPathsCount());
+#if defined(__UNIX__)
+ // Finally, test a tree containing internal symlinks
+ RmDir(dir);
+ GrowTree(dir, true /* test symlinks */);
+
+ // Without the DontFollowLink() call AddTree() would now assert
+ // (and without the assert, it would infinitely loop)
+ wxFileName fn = dir;
+ fn.DontFollowLink();
+ CPPUNIT_ASSERT(m_watcher->AddTree(fn));
+ CPPUNIT_ASSERT(m_watcher->RemoveTree(fn));
+
+ // Regrow the tree without symlinks, ready for the next test
+ RmDir(dir);
+ GrowTree(dir, false);
+#endif // __UNIX__
+ }
+
+ void WatchTreeWithFilespec(const wxFileName& dir)
+ {
+ CPPUNIT_ASSERT(m_watcher);
+ CPPUNIT_ASSERT(dir.DirExists()); // Was built in WatchTree()
+
+ // Store the initial count; there may already be some watches
+ const int initial = m_watcher->GetWatchedPathsCount();
+
+ // When we use a filter, both wxMSW and wxGTK implementations set
+ // an additional watch for each subdir (+1 for the root dir itself
+ // and another +1 for "child").
+ const size_t treeitems = subdirs + 2;
+ m_watcher->AddTree(dir, wxFSW_EVENT_ALL, "*.txt");
+
+ const int plustree = m_watcher->GetWatchedPathsCount();
+ CPPUNIT_ASSERT_EQUAL(initial + treeitems, plustree);
+
+ // RemoveTree should try to remove only those files that were added
+ m_watcher->RemoveTree(dir);
+ CPPUNIT_ASSERT_EQUAL(initial, m_watcher->GetWatchedPathsCount());