Skip to content

Commit

Permalink
Move NSAutoreleasePool management into the PlatformTest constructor and
Browse files Browse the repository at this point in the history
destructor.  The pool operations are moving from SetUp and TearDown, which are
scoped slightly too narrowly for our needs.  Using the constructor and
destructor ensures that the pools properly bracket tests.
Review URL: http://codereview.chromium.org/174171

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23897 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
mark@chromium.org committed Aug 20, 2009
1 parent 756797e commit c77043f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
5 changes: 5 additions & 0 deletions testing/gtest.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
'sources': [
'platform_test_mac.mm'
],
'link_settings': {
'libraries': [
'$(SDKROOT)/System/Library/Frameworks/Foundation.framework',
],
},
}],
['OS == "mac" or OS == "linux"', {
'defines': [
Expand Down
12 changes: 6 additions & 6 deletions testing/platform_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ class NSAutoreleasePool;
#endif

// The purpose of this class us to provide a hook for platform-specific
// SetUp and TearDown across unit tests. For example, on the Mac, it
// creates and releases an outer AutoreleasePool for each test. For now, it's
// only implemented on the Mac. To enable this for another platform, just
// adjust the #ifdefs and add a platform_test_<platform>.cc implementation file.
// operations across unit tests. For example, on the Mac, it creates and
// releases an outer NSAutoreleasePool for each test case. For now, it's only
// implemented on the Mac. To enable this for another platform, just adjust
// the #ifdefs and add a platform_test_<platform>.cc implementation file.
class PlatformTest : public testing::Test {
protected:
virtual void SetUp();
virtual void TearDown();
PlatformTest();
virtual ~PlatformTest();

private:
NSAutoreleasePool* pool_;
Expand Down
8 changes: 4 additions & 4 deletions testing/platform_test_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

#import <Foundation/Foundation.h>

void PlatformTest::SetUp() {
pool_ = [[NSAutoreleasePool alloc] init];
PlatformTest::PlatformTest()
: pool_([[NSAutoreleasePool alloc] init]) {
}

void PlatformTest::TearDown() {
[pool_ drain];
PlatformTest::~PlatformTest() {
[pool_ release];
}

0 comments on commit c77043f

Please sign in to comment.