diff options
Diffstat (limited to 'base/object_watcher_unittest.cc')
-rw-r--r-- | base/object_watcher_unittest.cc | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/base/object_watcher_unittest.cc b/base/object_watcher_unittest.cc index 51ed968..6c3fcce 100644 --- a/base/object_watcher_unittest.cc +++ b/base/object_watcher_unittest.cc @@ -27,6 +27,8 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#include <process.h> + #include "base/message_loop.h" #include "base/object_watcher.h" #include "testing/gtest/include/gtest/gtest.h" @@ -113,3 +115,34 @@ TEST(ObjectWatcherTest, CancelAfterSet) { CloseHandle(event); } + +// Used so we can simulate a MessageLoop that dies before an ObjectWatcher. +// This ordinarily doesn't happen when people use the Thread class, but it can +// happen when people use the Singleton pattern or atexit. +static unsigned __stdcall ThreadFunc(void* param) { + HANDLE event = CreateEvent(NULL, TRUE, FALSE, NULL); // not signaled + { + base::ObjectWatcher watcher; + { + MessageLoop message_loop; + + QuitDelegate delegate; + watcher.StartWatching(event, &delegate); + } + } + CloseHandle(event); + return 0; +} + +TEST(ObjectWatcherTest, OutlivesMessageLoop) { + unsigned int thread_id; + HANDLE thread = reinterpret_cast<HANDLE>( + _beginthreadex(NULL, + 0, + ThreadFunc, + NULL, + 0, + &thread_id)); + WaitForSingleObject(thread, INFINITE); + CloseHandle(thread); +} |