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

Side by Side Diff: components/network_hints/renderer/dns_prefetch_queue_unittest.cc

Issue 1551433002: Switch to standard integer types in components/, part 3 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more Created 4 years, 12 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <stddef.h>
6 #include <stdint.h>
7
5 #include <sstream> 8 #include <sstream>
6 9
10 #include "base/macros.h"
7 #include "components/network_hints/renderer/dns_prefetch_queue.h" 11 #include "components/network_hints/renderer/dns_prefetch_queue.h"
8 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
9 13
10 // Single threaded tests of DnsQueue functionality. 14 // Single threaded tests of DnsQueue functionality.
11 15
12 namespace network_hints { 16 namespace network_hints {
13 17
14 class DnsQueueTest : public testing::Test { 18 class DnsQueueTest : public testing::Test {
15 }; 19 };
16 20
17 // Define a helper class that does Push'es and Pop's of numbers. 21 // Define a helper class that does Push'es and Pop's of numbers.
18 // This makes it easy to test a LOT of reads, and keep the expected Pop 22 // This makes it easy to test a LOT of reads, and keep the expected Pop
19 // value in sync with the Push value. 23 // value in sync with the Push value.
20 class DnsQueueSequentialTester { 24 class DnsQueueSequentialTester {
21 public: 25 public:
22 DnsQueueSequentialTester(DnsQueue& buffer, int32 read_counter = 0, 26 DnsQueueSequentialTester(DnsQueue& buffer,
23 int32 write_counter = 0); 27 int32_t read_counter = 0,
28 int32_t write_counter = 0);
24 29
25 // Return of false means buffer was full, or would not take entry. 30 // Return of false means buffer was full, or would not take entry.
26 bool Push(void); // Push the string value of next number. 31 bool Push(void); // Push the string value of next number.
27 32
28 // Return of false means buffer returned wrong value. 33 // Return of false means buffer returned wrong value.
29 bool Pop(void); // Validate string value of next read. 34 bool Pop(void); // Validate string value of next read.
30 35
31 private: 36 private:
32 DnsQueue* buffer_; 37 DnsQueue* buffer_;
33 int32 read_counter_; // expected value of next read string. 38 int32_t read_counter_; // expected value of next read string.
34 int32 write_counter_; // Numerical value to write next string. 39 int32_t write_counter_; // Numerical value to write next string.
35 DISALLOW_COPY_AND_ASSIGN(DnsQueueSequentialTester); 40 DISALLOW_COPY_AND_ASSIGN(DnsQueueSequentialTester);
36 }; 41 };
37 42
38 43 DnsQueueSequentialTester::DnsQueueSequentialTester(DnsQueue& buffer,
39 DnsQueueSequentialTester::DnsQueueSequentialTester( 44 int32_t read_counter,
40 DnsQueue& buffer, int32 read_counter, int32 write_counter) 45 int32_t write_counter)
41 : buffer_(&buffer), 46 : buffer_(&buffer),
42 read_counter_(read_counter), 47 read_counter_(read_counter),
43 write_counter_(write_counter) { 48 write_counter_(write_counter) {}
44 }
45 49
46 bool DnsQueueSequentialTester::Push(void) { 50 bool DnsQueueSequentialTester::Push(void) {
47 std::ostringstream value; 51 std::ostringstream value;
48 value << write_counter_; 52 value << write_counter_;
49 53
50 // Exercise both write methods intermittently. 54 // Exercise both write methods intermittently.
51 DnsQueue::PushResult result = (write_counter_ % 2) ? 55 DnsQueue::PushResult result = (write_counter_ % 2) ?
52 buffer_->Push(value.str().c_str(), value.str().size()) : 56 buffer_->Push(value.str().c_str(), value.str().size()) :
53 buffer_->Push(value.str()); 57 buffer_->Push(value.str());
54 if (DnsQueue::SUCCESSFUL_PUSH == result) 58 if (DnsQueue::SUCCESSFUL_PUSH == result)
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 } 257 }
254 258
255 // Read back the accumulated 3 extra blocks. 259 // Read back the accumulated 3 extra blocks.
256 EXPECT_TRUE(tester.Pop()); 260 EXPECT_TRUE(tester.Pop());
257 EXPECT_TRUE(tester.Pop()); 261 EXPECT_TRUE(tester.Pop());
258 EXPECT_TRUE(tester.Pop()); 262 EXPECT_TRUE(tester.Pop());
259 EXPECT_FALSE(tester.Pop()); 263 EXPECT_FALSE(tester.Pop());
260 } 264 }
261 265
262 }; // namespace network_hints 266 }; // namespace network_hints
OLDNEW
« no previous file with comments | « components/network_hints/renderer/dns_prefetch_queue.h ('k') | components/network_hints/renderer/renderer_dns_prefetch.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698