[Cronet] Delay StartNetLog and StopNetLog until native request context is initialized
[chromium-blink-merge.git] / ui / gfx / sequential_id_generator_unittest.cc
blob7a07f90ff05ca7bd39d66d4976c7f39884d90281
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
3 // found in the LICENSE file.
5 #include "ui/gfx/sequential_id_generator.h"
7 #include "base/logging.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace ui {
12 typedef testing::Test SequentialIDGeneratorTest;
14 TEST(SequentialIDGeneratorTest, AddRemove) {
15 const uint32 kMinID = 2;
16 SequentialIDGenerator generator(kMinID);
18 EXPECT_EQ(2U, generator.GetGeneratedID(45));
19 EXPECT_EQ(3U, generator.GetGeneratedID(23));
20 EXPECT_EQ(2U, generator.GetGeneratedID(45));
21 EXPECT_TRUE(generator.HasGeneratedIDFor(45));
22 EXPECT_TRUE(generator.HasGeneratedIDFor(23));
24 generator.ReleaseGeneratedID(2);
25 EXPECT_FALSE(generator.HasGeneratedIDFor(45));
26 EXPECT_TRUE(generator.HasGeneratedIDFor(23));
27 EXPECT_EQ(3U, generator.GetGeneratedID(23));
29 EXPECT_FALSE(generator.HasGeneratedIDFor(1));
30 EXPECT_EQ(2U, generator.GetGeneratedID(1));
31 EXPECT_TRUE(generator.HasGeneratedIDFor(1));
33 generator.ReleaseGeneratedID(3);
34 EXPECT_EQ(3U, generator.GetGeneratedID(45));
35 EXPECT_TRUE(generator.HasGeneratedIDFor(45));
37 generator.ReleaseNumber(45);
38 EXPECT_FALSE(generator.HasGeneratedIDFor(45));
41 TEST(SequentialIDGeneratorTest, RemoveMultipleNumbers) {
42 const uint32 kMinID = 4;
43 SequentialIDGenerator generator(kMinID);
45 EXPECT_EQ(4U, generator.GetGeneratedID(45));
46 EXPECT_EQ(5U, generator.GetGeneratedID(55));
47 EXPECT_EQ(6U, generator.GetGeneratedID(15));
49 generator.ReleaseNumber(45);
50 EXPECT_FALSE(generator.HasGeneratedIDFor(45));
51 generator.ReleaseNumber(15);
52 EXPECT_FALSE(generator.HasGeneratedIDFor(15));
54 EXPECT_EQ(5U, generator.GetGeneratedID(55));
55 EXPECT_EQ(4U, generator.GetGeneratedID(12));
57 generator.ReleaseNumber(12);
58 generator.ReleaseNumber(55);
59 EXPECT_EQ(4U, generator.GetGeneratedID(0));
62 } // namespace ui