Commit 35dabb16 authored by tfarina@chromium.org's avatar tfarina@chromium.org

base: Use TEST() macro when possible.

There is no need to inherit from testing::Test and then have to use TEST_F(),
if you aren't overridding SetUp() or TearDow(). So if you don't need to customize
it, you can use TEST() macro directly and it does that for us automagically.

Fix all the cases found with the following command line:

$ git grep -n1 "public testing::Test" base/ | grep "};"

TEST=base_unittests
R=willchan@chromium.org

Review URL: https://codereview.chromium.org/11308261

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@170747 0039d316-1c4b-4281-b951-d872f2087c98
parent 8be50f06
...@@ -14,9 +14,6 @@ ...@@ -14,9 +14,6 @@
namespace { namespace {
class FileVersionInfoTest : public testing::Test {
};
#if defined(OS_WIN) #if defined(OS_WIN)
FilePath GetTestDataPath() { FilePath GetTestDataPath() {
FilePath path; FilePath path;
......
...@@ -8,9 +8,6 @@ ...@@ -8,9 +8,6 @@
namespace { namespace {
class IDMapTest : public testing::Test {
};
class TestObject { class TestObject {
}; };
...@@ -18,11 +15,12 @@ class DestructorCounter { ...@@ -18,11 +15,12 @@ class DestructorCounter {
public: public:
explicit DestructorCounter(int* counter) : counter_(counter) {} explicit DestructorCounter(int* counter) : counter_(counter) {}
~DestructorCounter() { ++(*counter_); } ~DestructorCounter() { ++(*counter_); }
private: private:
int* counter_; int* counter_;
}; };
TEST_F(IDMapTest, Basic) { TEST(IDMapTest, Basic) {
IDMap<TestObject> map; IDMap<TestObject> map;
EXPECT_TRUE(map.IsEmpty()); EXPECT_TRUE(map.IsEmpty());
EXPECT_EQ(0U, map.size()); EXPECT_EQ(0U, map.size());
...@@ -58,7 +56,7 @@ TEST_F(IDMapTest, Basic) { ...@@ -58,7 +56,7 @@ TEST_F(IDMapTest, Basic) {
EXPECT_EQ(0, map.iteration_depth()); EXPECT_EQ(0, map.iteration_depth());
} }
TEST_F(IDMapTest, IteratorRemainsValidWhenRemovingCurrentElement) { TEST(IDMapTest, IteratorRemainsValidWhenRemovingCurrentElement) {
IDMap<TestObject> map; IDMap<TestObject> map;
TestObject obj1; TestObject obj1;
...@@ -91,7 +89,7 @@ TEST_F(IDMapTest, IteratorRemainsValidWhenRemovingCurrentElement) { ...@@ -91,7 +89,7 @@ TEST_F(IDMapTest, IteratorRemainsValidWhenRemovingCurrentElement) {
EXPECT_EQ(0, map.iteration_depth()); EXPECT_EQ(0, map.iteration_depth());
} }
TEST_F(IDMapTest, IteratorRemainsValidWhenRemovingOtherElements) { TEST(IDMapTest, IteratorRemainsValidWhenRemovingOtherElements) {
IDMap<TestObject> map; IDMap<TestObject> map;
const int kCount = 5; const int kCount = 5;
...@@ -133,7 +131,7 @@ TEST_F(IDMapTest, IteratorRemainsValidWhenRemovingOtherElements) { ...@@ -133,7 +131,7 @@ TEST_F(IDMapTest, IteratorRemainsValidWhenRemovingOtherElements) {
EXPECT_EQ(0, map.iteration_depth()); EXPECT_EQ(0, map.iteration_depth());
} }
TEST_F(IDMapTest, CopyIterator) { TEST(IDMapTest, CopyIterator) {
IDMap<TestObject> map; IDMap<TestObject> map;
TestObject obj1; TestObject obj1;
...@@ -161,7 +159,7 @@ TEST_F(IDMapTest, CopyIterator) { ...@@ -161,7 +159,7 @@ TEST_F(IDMapTest, CopyIterator) {
EXPECT_EQ(0, map.iteration_depth()); EXPECT_EQ(0, map.iteration_depth());
} }
TEST_F(IDMapTest, AssignIterator) { TEST(IDMapTest, AssignIterator) {
IDMap<TestObject> map; IDMap<TestObject> map;
TestObject obj1; TestObject obj1;
...@@ -191,7 +189,7 @@ TEST_F(IDMapTest, AssignIterator) { ...@@ -191,7 +189,7 @@ TEST_F(IDMapTest, AssignIterator) {
EXPECT_EQ(0, map.iteration_depth()); EXPECT_EQ(0, map.iteration_depth());
} }
TEST_F(IDMapTest, IteratorRemainsValidWhenClearing) { TEST(IDMapTest, IteratorRemainsValidWhenClearing) {
IDMap<TestObject> map; IDMap<TestObject> map;
const int kCount = 5; const int kCount = 5;
...@@ -227,7 +225,7 @@ TEST_F(IDMapTest, IteratorRemainsValidWhenClearing) { ...@@ -227,7 +225,7 @@ TEST_F(IDMapTest, IteratorRemainsValidWhenClearing) {
EXPECT_EQ(0U, map.size()); EXPECT_EQ(0U, map.size());
} }
TEST_F(IDMapTest, OwningPointersDeletesThemOnRemove) { TEST(IDMapTest, OwningPointersDeletesThemOnRemove) {
const int kCount = 3; const int kCount = 3;
int external_del_count = 0; int external_del_count = 0;
...@@ -265,7 +263,7 @@ TEST_F(IDMapTest, OwningPointersDeletesThemOnRemove) { ...@@ -265,7 +263,7 @@ TEST_F(IDMapTest, OwningPointersDeletesThemOnRemove) {
EXPECT_EQ(owned_del_count, kCount); EXPECT_EQ(owned_del_count, kCount);
} }
TEST_F(IDMapTest, OwningPointersDeletesThemOnClear) { TEST(IDMapTest, OwningPointersDeletesThemOnClear) {
const int kCount = 3; const int kCount = 3;
int external_del_count = 0; int external_del_count = 0;
...@@ -302,7 +300,7 @@ TEST_F(IDMapTest, OwningPointersDeletesThemOnClear) { ...@@ -302,7 +300,7 @@ TEST_F(IDMapTest, OwningPointersDeletesThemOnClear) {
EXPECT_EQ(owned_del_count, kCount); EXPECT_EQ(owned_del_count, kCount);
} }
TEST_F(IDMapTest, OwningPointersDeletesThemOnDestruct) { TEST(IDMapTest, OwningPointersDeletesThemOnDestruct) {
const int kCount = 3; const int kCount = 3;
int external_del_count = 0; int external_del_count = 0;
......
...@@ -33,8 +33,6 @@ using base::TimeTicks; ...@@ -33,8 +33,6 @@ using base::TimeTicks;
namespace { namespace {
class MessageLoopTest : public testing::Test {};
class Foo : public base::RefCounted<Foo> { class Foo : public base::RefCounted<Foo> {
public: public:
Foo() : test_count_(0) { Foo() : test_count_(0) {
......
...@@ -3,13 +3,11 @@ ...@@ -3,13 +3,11 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "base/prefs/pref_value_map.h" #include "base/prefs/pref_value_map.h"
#include "base/values.h" #include "base/values.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
class PrefValueMapTest : public testing::Test { TEST(PrefValueMapTest, SetValue) {
};
TEST_F(PrefValueMapTest, SetValue) {
PrefValueMap map; PrefValueMap map;
const Value* result = NULL; const Value* result = NULL;
EXPECT_FALSE(map.GetValue("key", &result)); EXPECT_FALSE(map.GetValue("key", &result));
...@@ -23,7 +21,7 @@ TEST_F(PrefValueMapTest, SetValue) { ...@@ -23,7 +21,7 @@ TEST_F(PrefValueMapTest, SetValue) {
EXPECT_TRUE(StringValue("hi mom!").Equals(result)); EXPECT_TRUE(StringValue("hi mom!").Equals(result));
} }
TEST_F(PrefValueMapTest, GetAndSetIntegerValue) { TEST(PrefValueMapTest, GetAndSetIntegerValue) {
PrefValueMap map; PrefValueMap map;
ASSERT_TRUE(map.SetValue("key", Value::CreateIntegerValue(5))); ASSERT_TRUE(map.SetValue("key", Value::CreateIntegerValue(5)));
...@@ -36,7 +34,7 @@ TEST_F(PrefValueMapTest, GetAndSetIntegerValue) { ...@@ -36,7 +34,7 @@ TEST_F(PrefValueMapTest, GetAndSetIntegerValue) {
EXPECT_EQ(-14, int_value); EXPECT_EQ(-14, int_value);
} }
TEST_F(PrefValueMapTest, RemoveValue) { TEST(PrefValueMapTest, RemoveValue) {
PrefValueMap map; PrefValueMap map;
EXPECT_FALSE(map.RemoveValue("key")); EXPECT_FALSE(map.RemoveValue("key"));
...@@ -49,7 +47,7 @@ TEST_F(PrefValueMapTest, RemoveValue) { ...@@ -49,7 +47,7 @@ TEST_F(PrefValueMapTest, RemoveValue) {
EXPECT_FALSE(map.RemoveValue("key")); EXPECT_FALSE(map.RemoveValue("key"));
} }
TEST_F(PrefValueMapTest, Clear) { TEST(PrefValueMapTest, Clear) {
PrefValueMap map; PrefValueMap map;
EXPECT_TRUE(map.SetValue("key", Value::CreateStringValue("test"))); EXPECT_TRUE(map.SetValue("key", Value::CreateStringValue("test")));
EXPECT_TRUE(map.GetValue("key", NULL)); EXPECT_TRUE(map.GetValue("key", NULL));
...@@ -59,7 +57,7 @@ TEST_F(PrefValueMapTest, Clear) { ...@@ -59,7 +57,7 @@ TEST_F(PrefValueMapTest, Clear) {
EXPECT_FALSE(map.GetValue("key", NULL)); EXPECT_FALSE(map.GetValue("key", NULL));
} }
TEST_F(PrefValueMapTest, GetDifferingKeys) { TEST(PrefValueMapTest, GetDifferingKeys) {
PrefValueMap reference; PrefValueMap reference;
EXPECT_TRUE(reference.SetValue("b", Value::CreateStringValue("test"))); EXPECT_TRUE(reference.SetValue("b", Value::CreateStringValue("test")));
EXPECT_TRUE(reference.SetValue("c", Value::CreateStringValue("test"))); EXPECT_TRUE(reference.SetValue("c", Value::CreateStringValue("test")));
...@@ -88,7 +86,7 @@ TEST_F(PrefValueMapTest, GetDifferingKeys) { ...@@ -88,7 +86,7 @@ TEST_F(PrefValueMapTest, GetDifferingKeys) {
EXPECT_EQ(expected_differing_paths, differing_paths); EXPECT_EQ(expected_differing_paths, differing_paths);
} }
TEST_F(PrefValueMapTest, SwapTwoMaps) { TEST(PrefValueMapTest, SwapTwoMaps) {
PrefValueMap first_map; PrefValueMap first_map;
EXPECT_TRUE(first_map.SetValue("a", Value::CreateStringValue("test"))); EXPECT_TRUE(first_map.SetValue("a", Value::CreateStringValue("test")));
EXPECT_TRUE(first_map.SetValue("b", Value::CreateStringValue("test"))); EXPECT_TRUE(first_map.SetValue("b", Value::CreateStringValue("test")));
......
...@@ -3,13 +3,12 @@ ...@@ -3,13 +3,12 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "base/string_tokenizer.h" #include "base/string_tokenizer.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
using std::string; using std::string;
namespace { namespace {
class StringTokenizerTest : public testing::Test {};
}
TEST(StringTokenizerTest, Simple) { TEST(StringTokenizerTest, Simple) {
string input = "this is a test"; string input = "this is a test";
...@@ -227,3 +226,5 @@ TEST(StringTokenizerTest, ParseQuotedString_EscapedQuotes2) { ...@@ -227,3 +226,5 @@ TEST(StringTokenizerTest, ParseQuotedString_EscapedQuotes2) {
EXPECT_FALSE(t.GetNext()); EXPECT_FALSE(t.GetNext());
} }
} // namespace
...@@ -2,19 +2,18 @@ ...@@ -2,19 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "base/memory/scoped_ptr.h"
#include "base/version.h" #include "base/version.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
class VersionTest : public testing::Test { namespace {
};
TEST_F(VersionTest, DefaultConstructor) { TEST(VersionTest, DefaultConstructor) {
Version v; Version v;
EXPECT_FALSE(v.IsValid()); EXPECT_FALSE(v.IsValid());
} }
TEST_F(VersionTest, ValueSemantics) { TEST(VersionTest, ValueSemantics) {
Version v1("1.2.3.4"); Version v1("1.2.3.4");
EXPECT_TRUE(v1.IsValid()); EXPECT_TRUE(v1.IsValid());
Version v3; Version v3;
...@@ -28,7 +27,7 @@ TEST_F(VersionTest, ValueSemantics) { ...@@ -28,7 +27,7 @@ TEST_F(VersionTest, ValueSemantics) {
EXPECT_TRUE(v3.Equals(v1)); EXPECT_TRUE(v3.Equals(v1));
} }
TEST_F(VersionTest, GetVersionFromString) { TEST(VersionTest, GetVersionFromString) {
static const struct version_string { static const struct version_string {
const char* input; const char* input;
size_t parts; size_t parts;
...@@ -62,7 +61,7 @@ TEST_F(VersionTest, GetVersionFromString) { ...@@ -62,7 +61,7 @@ TEST_F(VersionTest, GetVersionFromString) {
} }
} }
TEST_F(VersionTest, Compare) { TEST(VersionTest, Compare) {
static const struct version_compare { static const struct version_compare {
const char* lhs; const char* lhs;
const char* rhs; const char* rhs;
...@@ -89,7 +88,7 @@ TEST_F(VersionTest, Compare) { ...@@ -89,7 +88,7 @@ TEST_F(VersionTest, Compare) {
} }
} }
TEST_F(VersionTest, CompareToWildcardString) { TEST(VersionTest, CompareToWildcardString) {
static const struct version_compare { static const struct version_compare {
const char* lhs; const char* lhs;
const char* rhs; const char* rhs;
...@@ -116,7 +115,7 @@ TEST_F(VersionTest, CompareToWildcardString) { ...@@ -116,7 +115,7 @@ TEST_F(VersionTest, CompareToWildcardString) {
} }
} }
TEST_F(VersionTest, IsValidWildcardString) { TEST(VersionTest, IsValidWildcardString) {
static const struct version_compare { static const struct version_compare {
const char* version; const char* version;
bool expected; bool expected;
...@@ -138,3 +137,5 @@ TEST_F(VersionTest, IsValidWildcardString) { ...@@ -138,3 +137,5 @@ TEST_F(VersionTest, IsValidWildcardString) {
cases[i].expected) << cases[i].version << "?" << cases[i].expected; cases[i].expected) << cases[i].version << "?" << cases[i].expected;
} }
} }
} // namespace
...@@ -14,10 +14,7 @@ namespace logging { ...@@ -14,10 +14,7 @@ namespace logging {
namespace { namespace {
class VlogTest : public testing::Test { TEST(VlogTest, NoVmodule) {
};
TEST_F(VlogTest, NoVmodule) {
int min_log_level = 0; int min_log_level = 0;
EXPECT_EQ(0, VlogInfo("", "", &min_log_level).GetVlogLevel("test1")); EXPECT_EQ(0, VlogInfo("", "", &min_log_level).GetVlogLevel("test1"));
EXPECT_EQ(0, VlogInfo("0", "", &min_log_level).GetVlogLevel("test2")); EXPECT_EQ(0, VlogInfo("0", "", &min_log_level).GetVlogLevel("test2"));
...@@ -27,7 +24,7 @@ TEST_F(VlogTest, NoVmodule) { ...@@ -27,7 +24,7 @@ TEST_F(VlogTest, NoVmodule) {
EXPECT_EQ(5, VlogInfo("5", "", &min_log_level).GetVlogLevel("test6")); EXPECT_EQ(5, VlogInfo("5", "", &min_log_level).GetVlogLevel("test6"));
} }
TEST_F(VlogTest, MatchVlogPattern) { TEST(VlogTest, MatchVlogPattern) {
// Degenerate cases. // Degenerate cases.
EXPECT_TRUE(MatchVlogPattern("", "")); EXPECT_TRUE(MatchVlogPattern("", ""));
EXPECT_TRUE(MatchVlogPattern("", "****")); EXPECT_TRUE(MatchVlogPattern("", "****"));
...@@ -75,7 +72,7 @@ TEST_F(VlogTest, MatchVlogPattern) { ...@@ -75,7 +72,7 @@ TEST_F(VlogTest, MatchVlogPattern) {
EXPECT_TRUE(MatchVlogPattern("\\b/lah", "/b\\lah")); EXPECT_TRUE(MatchVlogPattern("\\b/lah", "/b\\lah"));
} }
TEST_F(VlogTest, VmoduleBasic) { TEST(VlogTest, VmoduleBasic) {
const char kVSwitch[] = "-1"; const char kVSwitch[] = "-1";
const char kVModuleSwitch[] = const char kVModuleSwitch[] =
"foo=,bar=0,baz=blah,,qux=0blah1,quux=1,corge.ext=5"; "foo=,bar=0,baz=blah,,qux=0blah1,quux=1,corge.ext=5";
...@@ -91,7 +88,7 @@ TEST_F(VlogTest, VmoduleBasic) { ...@@ -91,7 +88,7 @@ TEST_F(VlogTest, VmoduleBasic) {
EXPECT_EQ(5, vlog_info.GetVlogLevel("c:\\path/to/corge.ext.h")); EXPECT_EQ(5, vlog_info.GetVlogLevel("c:\\path/to/corge.ext.h"));
} }
TEST_F(VlogTest, VmoduleDirs) { TEST(VlogTest, VmoduleDirs) {
const char kVModuleSwitch[] = const char kVModuleSwitch[] =
"foo/bar.cc=1,baz\\*\\qux.cc=2,*quux/*=3,*/*-inl.h=4"; "foo/bar.cc=1,baz\\*\\qux.cc=2,*quux/*=3,*/*-inl.h=4";
int min_log_level = 0; int min_log_level = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment