OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "ui/gfx/sequential_id_generator.h" | 5 #include "ui/gfx/sequential_id_generator.h" |
6 | 6 |
| 7 #include <stdint.h> |
| 8 |
7 #include "base/logging.h" | 9 #include "base/logging.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
9 | 11 |
10 namespace ui { | 12 namespace ui { |
11 | 13 |
12 typedef testing::Test SequentialIDGeneratorTest; | 14 typedef testing::Test SequentialIDGeneratorTest; |
13 | 15 |
14 TEST(SequentialIDGeneratorTest, AddRemove) { | 16 TEST(SequentialIDGeneratorTest, AddRemove) { |
15 const uint32 kMinID = 2; | 17 const uint32_t kMinID = 2; |
16 SequentialIDGenerator generator(kMinID); | 18 SequentialIDGenerator generator(kMinID); |
17 | 19 |
18 EXPECT_EQ(2U, generator.GetGeneratedID(45)); | 20 EXPECT_EQ(2U, generator.GetGeneratedID(45)); |
19 EXPECT_EQ(3U, generator.GetGeneratedID(23)); | 21 EXPECT_EQ(3U, generator.GetGeneratedID(23)); |
20 EXPECT_EQ(2U, generator.GetGeneratedID(45)); | 22 EXPECT_EQ(2U, generator.GetGeneratedID(45)); |
21 EXPECT_TRUE(generator.HasGeneratedIDFor(45)); | 23 EXPECT_TRUE(generator.HasGeneratedIDFor(45)); |
22 EXPECT_TRUE(generator.HasGeneratedIDFor(23)); | 24 EXPECT_TRUE(generator.HasGeneratedIDFor(23)); |
23 | 25 |
24 generator.ReleaseGeneratedID(2); | 26 generator.ReleaseGeneratedID(2); |
25 EXPECT_FALSE(generator.HasGeneratedIDFor(45)); | 27 EXPECT_FALSE(generator.HasGeneratedIDFor(45)); |
26 EXPECT_TRUE(generator.HasGeneratedIDFor(23)); | 28 EXPECT_TRUE(generator.HasGeneratedIDFor(23)); |
27 EXPECT_EQ(3U, generator.GetGeneratedID(23)); | 29 EXPECT_EQ(3U, generator.GetGeneratedID(23)); |
28 | 30 |
29 EXPECT_FALSE(generator.HasGeneratedIDFor(1)); | 31 EXPECT_FALSE(generator.HasGeneratedIDFor(1)); |
30 EXPECT_EQ(2U, generator.GetGeneratedID(1)); | 32 EXPECT_EQ(2U, generator.GetGeneratedID(1)); |
31 EXPECT_TRUE(generator.HasGeneratedIDFor(1)); | 33 EXPECT_TRUE(generator.HasGeneratedIDFor(1)); |
32 | 34 |
33 generator.ReleaseGeneratedID(3); | 35 generator.ReleaseGeneratedID(3); |
34 EXPECT_EQ(3U, generator.GetGeneratedID(45)); | 36 EXPECT_EQ(3U, generator.GetGeneratedID(45)); |
35 EXPECT_TRUE(generator.HasGeneratedIDFor(45)); | 37 EXPECT_TRUE(generator.HasGeneratedIDFor(45)); |
36 | 38 |
37 generator.ReleaseNumber(45); | 39 generator.ReleaseNumber(45); |
38 EXPECT_FALSE(generator.HasGeneratedIDFor(45)); | 40 EXPECT_FALSE(generator.HasGeneratedIDFor(45)); |
39 } | 41 } |
40 | 42 |
41 TEST(SequentialIDGeneratorTest, RemoveMultipleNumbers) { | 43 TEST(SequentialIDGeneratorTest, RemoveMultipleNumbers) { |
42 const uint32 kMinID = 4; | 44 const uint32_t kMinID = 4; |
43 SequentialIDGenerator generator(kMinID); | 45 SequentialIDGenerator generator(kMinID); |
44 | 46 |
45 EXPECT_EQ(4U, generator.GetGeneratedID(45)); | 47 EXPECT_EQ(4U, generator.GetGeneratedID(45)); |
46 EXPECT_EQ(5U, generator.GetGeneratedID(55)); | 48 EXPECT_EQ(5U, generator.GetGeneratedID(55)); |
47 EXPECT_EQ(6U, generator.GetGeneratedID(15)); | 49 EXPECT_EQ(6U, generator.GetGeneratedID(15)); |
48 | 50 |
49 generator.ReleaseNumber(45); | 51 generator.ReleaseNumber(45); |
50 EXPECT_FALSE(generator.HasGeneratedIDFor(45)); | 52 EXPECT_FALSE(generator.HasGeneratedIDFor(45)); |
51 generator.ReleaseNumber(15); | 53 generator.ReleaseNumber(15); |
52 EXPECT_FALSE(generator.HasGeneratedIDFor(15)); | 54 EXPECT_FALSE(generator.HasGeneratedIDFor(15)); |
53 | 55 |
54 EXPECT_EQ(5U, generator.GetGeneratedID(55)); | 56 EXPECT_EQ(5U, generator.GetGeneratedID(55)); |
55 EXPECT_EQ(4U, generator.GetGeneratedID(12)); | 57 EXPECT_EQ(4U, generator.GetGeneratedID(12)); |
56 | 58 |
57 generator.ReleaseNumber(12); | 59 generator.ReleaseNumber(12); |
58 generator.ReleaseNumber(55); | 60 generator.ReleaseNumber(55); |
59 EXPECT_EQ(4U, generator.GetGeneratedID(0)); | 61 EXPECT_EQ(4U, generator.GetGeneratedID(0)); |
60 } | 62 } |
61 | 63 |
62 } // namespace ui | 64 } // namespace ui |
OLD | NEW |