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

Side by Side Diff: base/observer_list_unittest.cc

Issue 10827112: base: Fix minor warnings reported by cppcheck. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix nit Created 8 years, 4 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
« no previous file with comments | « base/memory/scoped_ptr_unittest.cc ('k') | base/process_util_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/observer_list.h" 5 #include "base/observer_list.h"
6 #include "base/observer_list_threadsafe.h" 6 #include "base/observer_list_threadsafe.h"
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 static const int kThreadRunTime = 2000; // ms to run the multi-threaded test. 94 static const int kThreadRunTime = 2000; // ms to run the multi-threaded test.
95 95
96 // A thread for use in the ThreadSafeObserver test 96 // A thread for use in the ThreadSafeObserver test
97 // which will add and remove itself from the notification 97 // which will add and remove itself from the notification
98 // list repeatedly. 98 // list repeatedly.
99 class AddRemoveThread : public PlatformThread::Delegate, 99 class AddRemoveThread : public PlatformThread::Delegate,
100 public Foo { 100 public Foo {
101 public: 101 public:
102 AddRemoveThread(ObserverListThreadSafe<Foo>* list, bool notify) 102 AddRemoveThread(ObserverListThreadSafe<Foo>* list, bool notify)
103 : list_(list), 103 : list_(list),
104 loop_(NULL),
104 in_list_(false), 105 in_list_(false),
105 start_(Time::Now()), 106 start_(Time::Now()),
106 count_observes_(0), 107 count_observes_(0),
107 count_addtask_(0), 108 count_addtask_(0),
108 do_notifies_(notify), 109 do_notifies_(notify),
109 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 110 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
110 } 111 }
111 112
112 virtual ~AddRemoveThread() { 113 virtual ~AddRemoveThread() {
113 } 114 }
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 } 523 }
523 524
524 class ListDestructor : public Foo { 525 class ListDestructor : public Foo {
525 public: 526 public:
526 explicit ListDestructor(ObserverList<Foo>* list) : list_(list) {} 527 explicit ListDestructor(ObserverList<Foo>* list) : list_(list) {}
527 virtual ~ListDestructor() {} 528 virtual ~ListDestructor() {}
528 529
529 virtual void Observe(int x) OVERRIDE { 530 virtual void Observe(int x) OVERRIDE {
530 delete list_; 531 delete list_;
531 } 532 }
532 int total; 533
533 private: 534 private:
534 ObserverList<Foo>* list_; 535 ObserverList<Foo>* list_;
535 }; 536 };
536 537
537 538
538 TEST(ObserverListTest, IteratorOutlivesList) { 539 TEST(ObserverListTest, IteratorOutlivesList) {
539 ObserverList<Foo>* observer_list = new ObserverList<Foo>; 540 ObserverList<Foo>* observer_list = new ObserverList<Foo>;
540 ListDestructor a(observer_list); 541 ListDestructor a(observer_list);
541 observer_list->AddObserver(&a); 542 observer_list->AddObserver(&a);
542 543
543 FOR_EACH_OBSERVER(Foo, *observer_list, Observe(0)); 544 FOR_EACH_OBSERVER(Foo, *observer_list, Observe(0));
544 // If this test fails, there'll be Valgrind errors when this function goes out 545 // If this test fails, there'll be Valgrind errors when this function goes out
545 // of scope. 546 // of scope.
546 } 547 }
547 548
548 } // namespace 549 } // namespace
OLDNEW
« no previous file with comments | « base/memory/scoped_ptr_unittest.cc ('k') | base/process_util_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698