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

Side by Side Diff: base/scoped_vector_unittest.cc

Issue 6646051: Fix DCHECK, memory leak, and refactor PasswordStore to use CancelableRequest (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: git try works all platforms now. Created 9 years, 9 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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/scoped_vector.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7
8 using std::vector;
James Hawkins 2011/03/16 22:39:35 Never use 'using std::'.
Sheridan Rawlins 2011/03/18 15:45:48 Done.
9
10 namespace {
11
12 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.
13 public:
14 ConDecLogger() : ptr_(NULL) { }
15 explicit ConDecLogger(int* ptr) { set_ptr(ptr); }
16 ~ConDecLogger() { --*ptr_; }
17
18 void set_ptr(int* ptr) { ptr_ = ptr; ++*ptr_; }
19
20 int SomeMeth(int x) { return x; }
21
22 private:
23 int* ptr_;
24 DISALLOW_COPY_AND_ASSIGN(ConDecLogger);
25 };
26
27 } // namespace
28
29 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.
30 int constructed = 0;
31 int constructed1 = 0;
32 int constructed2 = 0;
33 {
34 ScopedVector<ConDecLogger> scoper;
35 scoper.push_back(new ConDecLogger(&constructed));
36 EXPECT_EQ(1, constructed);
37 }
38 EXPECT_EQ(0, constructed);
39 {
40 ScopedVector<ConDecLogger> scoper;
41 scoper.push_back(new ConDecLogger(&constructed1));
42 EXPECT_EQ(1, constructed1);
43 vector<ConDecLogger*> vec;
44 vec.push_back(new ConDecLogger(&constructed2));
45 EXPECT_EQ(1, constructed2);
46 scoper.reset(vec);
47 EXPECT_EQ(0, constructed1);
48 EXPECT_EQ(1, constructed2);
49 }
50 EXPECT_EQ(0, constructed2);
51 }
52
53 // 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.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698