Chromium Code Reviews| Index: base/scoped_vector_unittest.cc |
| diff --git a/base/scoped_vector_unittest.cc b/base/scoped_vector_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d5e6da1895670c8f2c4677898d2c5add77a03b30 |
| --- /dev/null |
| +++ b/base/scoped_vector_unittest.cc |
| @@ -0,0 +1,53 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/scoped_vector.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +using std::vector; |
|
James Hawkins
2011/03/16 22:39:35
Never use 'using std::'.
Sheridan Rawlins
2011/03/18 15:45:48
Done.
|
| + |
| +namespace { |
| + |
| +class ConDecLogger { |
|
James Hawkins
2011/03/16 22:39:35
This class name is unreadable. The class also need
Sheridan Rawlins
2011/03/20 08:13:11
Done.
|
| + public: |
| + ConDecLogger() : ptr_(NULL) { } |
| + explicit ConDecLogger(int* ptr) { set_ptr(ptr); } |
| + ~ConDecLogger() { --*ptr_; } |
| + |
| + void set_ptr(int* ptr) { ptr_ = ptr; ++*ptr_; } |
| + |
| + int SomeMeth(int x) { return x; } |
| + |
| + private: |
| + int* ptr_; |
| + DISALLOW_COPY_AND_ASSIGN(ConDecLogger); |
| +}; |
| + |
| +} // namespace |
| + |
| +TEST(ScopedVectorTest, ScopedVector) { |
|
James Hawkins
2011/03/16 22:39:35
s/ScopedVector/<something more descriptive>/
Sheridan Rawlins
2011/03/20 08:13:11
Done.
|
| + int constructed = 0; |
| + int constructed1 = 0; |
| + int constructed2 = 0; |
| + { |
| + ScopedVector<ConDecLogger> scoper; |
| + scoper.push_back(new ConDecLogger(&constructed)); |
| + EXPECT_EQ(1, constructed); |
| + } |
| + EXPECT_EQ(0, constructed); |
| + { |
| + ScopedVector<ConDecLogger> scoper; |
| + scoper.push_back(new ConDecLogger(&constructed1)); |
| + EXPECT_EQ(1, constructed1); |
| + vector<ConDecLogger*> vec; |
| + vec.push_back(new ConDecLogger(&constructed2)); |
| + EXPECT_EQ(1, constructed2); |
| + scoper.reset(vec); |
| + EXPECT_EQ(0, constructed1); |
| + EXPECT_EQ(1, constructed2); |
| + } |
| + EXPECT_EQ(0, constructed2); |
| +} |
| + |
| +// TODO write more tests. |
|
James Hawkins
2011/03/16 22:39:35
Remove the TODO. It's implicit.
Sheridan Rawlins
2011/03/20 08:13:11
Done.
|