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

Side by Side Diff: base/stats_table_unittest.cc

Issue 552004: Style cleanup in preparation for auto-linting base/. (Closed)
Patch Set: Created 10 years, 11 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
« no previous file with comments | « base/stack_container_unittest.cc ('k') | base/string_piece.h » ('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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/multiprocess_test.h" 5 #include "base/multiprocess_test.h"
6 #include "base/platform_thread.h" 6 #include "base/platform_thread.h"
7 #include "base/simple_thread.h" 7 #include "base/simple_thread.h"
8 #include "base/shared_memory.h" 8 #include "base/shared_memory.h"
9 #include "base/stats_table.h" 9 #include "base/stats_table.h"
10 #include "base/stats_counters.h" 10 #include "base/stats_counters.h"
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 name = "c:" + kCounterDecrement; 235 name = "c:" + kCounterDecrement;
236 EXPECT_EQ(-kMaxProcs * kThreadLoops, 236 EXPECT_EQ(-kMaxProcs * kThreadLoops,
237 table.GetCounterValue(name)); 237 table.GetCounterValue(name));
238 EXPECT_EQ(0, table.CountThreadsRegistered()); 238 EXPECT_EQ(0, table.CountThreadsRegistered());
239 239
240 DeleteShmem(kMPTableName); 240 DeleteShmem(kMPTableName);
241 } 241 }
242 242
243 class MockStatsCounter : public StatsCounter { 243 class MockStatsCounter : public StatsCounter {
244 public: 244 public:
245 MockStatsCounter(const std::string& name) 245 explicit MockStatsCounter(const std::string& name)
246 : StatsCounter(name) {} 246 : StatsCounter(name) {}
247 int* Pointer() { return GetPtr(); } 247 int* Pointer() { return GetPtr(); }
248 }; 248 };
249 249
250 // Test some basic StatsCounter operations 250 // Test some basic StatsCounter operations
251 TEST_F(StatsTableTest, StatsCounter) { 251 TEST_F(StatsTableTest, StatsCounter) {
252 // Create a stats table. 252 // Create a stats table.
253 const std::string kTableName = "StatTable"; 253 const std::string kTableName = "StatTable";
254 const int kMaxThreads = 20; 254 const int kMaxThreads = 20;
255 const int kMaxCounter = 5; 255 const int kMaxCounter = 5;
256 DeleteShmem(kTableName); 256 DeleteShmem(kTableName);
257 StatsTable table(kTableName, kMaxThreads, kMaxCounter); 257 StatsTable table(kTableName, kMaxThreads, kMaxCounter);
258 StatsTable::set_current(&table); 258 StatsTable::set_current(&table);
259 259
260 MockStatsCounter foo("foo"); 260 MockStatsCounter foo("foo");
261 261
262 // Test initial state. 262 // Test initial state.
263 EXPECT_TRUE(foo.Enabled()); 263 EXPECT_TRUE(foo.Enabled());
264 ASSERT_NE(foo.Pointer(), static_cast<int*>(0)); 264 ASSERT_NE(foo.Pointer(), static_cast<int*>(0));
265 EXPECT_EQ(0, *(foo.Pointer())); 265 EXPECT_EQ(0, *(foo.Pointer()));
266 EXPECT_EQ(0, table.GetCounterValue("c:foo")); 266 EXPECT_EQ(0, table.GetCounterValue("c:foo"));
267 267
268 // Test Increment. 268 // Test Increment.
269 while(*(foo.Pointer()) < 123) foo.Increment(); 269 while (*(foo.Pointer()) < 123) foo.Increment();
270 EXPECT_EQ(123, table.GetCounterValue("c:foo")); 270 EXPECT_EQ(123, table.GetCounterValue("c:foo"));
271 foo.Add(0); 271 foo.Add(0);
272 EXPECT_EQ(123, table.GetCounterValue("c:foo")); 272 EXPECT_EQ(123, table.GetCounterValue("c:foo"));
273 foo.Add(-1); 273 foo.Add(-1);
274 EXPECT_EQ(122, table.GetCounterValue("c:foo")); 274 EXPECT_EQ(122, table.GetCounterValue("c:foo"));
275 275
276 // Test Set. 276 // Test Set.
277 foo.Set(0); 277 foo.Set(0);
278 EXPECT_EQ(0, table.GetCounterValue("c:foo")); 278 EXPECT_EQ(0, table.GetCounterValue("c:foo"));
279 foo.Set(100); 279 foo.Set(100);
280 EXPECT_EQ(100, table.GetCounterValue("c:foo")); 280 EXPECT_EQ(100, table.GetCounterValue("c:foo"));
281 foo.Set(-1); 281 foo.Set(-1);
282 EXPECT_EQ(-1, table.GetCounterValue("c:foo")); 282 EXPECT_EQ(-1, table.GetCounterValue("c:foo"));
283 foo.Set(0); 283 foo.Set(0);
284 EXPECT_EQ(0, table.GetCounterValue("c:foo")); 284 EXPECT_EQ(0, table.GetCounterValue("c:foo"));
285 285
286 // Test Decrement. 286 // Test Decrement.
287 foo.Subtract(1); 287 foo.Subtract(1);
288 EXPECT_EQ(-1, table.GetCounterValue("c:foo")); 288 EXPECT_EQ(-1, table.GetCounterValue("c:foo"));
289 foo.Subtract(0); 289 foo.Subtract(0);
290 EXPECT_EQ(-1, table.GetCounterValue("c:foo")); 290 EXPECT_EQ(-1, table.GetCounterValue("c:foo"));
291 foo.Subtract(-1); 291 foo.Subtract(-1);
292 EXPECT_EQ(0, table.GetCounterValue("c:foo")); 292 EXPECT_EQ(0, table.GetCounterValue("c:foo"));
293 293
294 DeleteShmem(kTableName); 294 DeleteShmem(kTableName);
295 } 295 }
296 296
297 class MockStatsCounterTimer : public StatsCounterTimer { 297 class MockStatsCounterTimer : public StatsCounterTimer {
298 public: 298 public:
299 MockStatsCounterTimer(const std::string& name) 299 explicit MockStatsCounterTimer(const std::string& name)
300 : StatsCounterTimer(name) {} 300 : StatsCounterTimer(name) {}
301 301
302 TimeTicks start_time() { return start_time_; } 302 TimeTicks start_time() { return start_time_; }
303 TimeTicks stop_time() { return stop_time_; } 303 TimeTicks stop_time() { return stop_time_; }
304 }; 304 };
305 305
306 // Test some basic StatsCounterTimer operations 306 // Test some basic StatsCounterTimer operations
307 TEST_F(StatsTableTest, StatsCounterTimer) { 307 TEST_F(StatsTableTest, StatsCounterTimer) {
308 // Create a stats table. 308 // Create a stats table.
309 const std::string kTableName = "StatTable"; 309 const std::string kTableName = "StatTable";
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 PlatformThread::Sleep(500); 398 PlatformThread::Sleep(500);
399 } 399 }
400 EXPECT_LE(1000, table.GetCounterValue("t:foo")); 400 EXPECT_LE(1000, table.GetCounterValue("t:foo"));
401 EXPECT_LE(1000, table.GetCounterValue("t:bar")); 401 EXPECT_LE(1000, table.GetCounterValue("t:bar"));
402 EXPECT_EQ(2, table.GetCounterValue("c:bar")); 402 EXPECT_EQ(2, table.GetCounterValue("c:bar"));
403 403
404 DeleteShmem(kTableName); 404 DeleteShmem(kTableName);
405 } 405 }
406 406
407 } // namespace base 407 } // namespace base
OLDNEW
« no previous file with comments | « base/stack_container_unittest.cc ('k') | base/string_piece.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698