Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(448)

Side by Side Diff: base/test/test_listener_ios.mm

Issue 10690161: Make it possible to run gtests on iOS. (Closed) Base URL: http://git.chromium.org/chromium/src.git@presubmit_change
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/test/test_listener_ios.h"
6
7 #import <Foundation/Foundation.h>
8 #include "base/mac/scoped_nsautorelease_pool.h"
9 #include <gtest/gtest.h>
stuartmorgan 2012/07/12 09:36:31 This should be: #import <Foundation/Foundation.h>
leng 2012/07/12 10:44:42 Done.
10
11 // The iOS watchdog timer will kill an app that doesn't spin the main event
12 // loop often enough. This uses a Gtest TestEventListener to spin the current
13 // loop after each test finishes. However, if any individual test takes too
14 // long, it is still possible that the app will get killed.
15
16 namespace {
17
18 class IOSRunLoopListener : public testing::EmptyTestEventListener {
19 public:
20 virtual void OnTestEnd(const testing::TestInfo& test_info);
21 };
22
23 void IOSRunLoopListener::OnTestEnd(const testing::TestInfo& test_info) {
24 base::mac::ScopedNSAutoreleasePool scoped_pool;
25
26 // At the end of the test, spin the default loop for a moment.
27 NSRunLoop* current_loop = [NSRunLoop currentRunLoop];
28 NSDate* stop_date = [NSDate dateWithTimeIntervalSinceNow:0.001];
29 [current_loop runUntilDate:stop_date];
30 }
31
32 } // namespace
33
34
35 namespace base {
36 namespace test_listener_ios {
37
38 void RegisterTestEndListener() {
39 testing::TestEventListeners& listeners =
40 testing::UnitTest::GetInstance()->listeners();
41 listeners.Append(new IOSRunLoopListener);
42 }
43
44 } // namespace test_listener_ios
45 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698