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

Side by Side Diff: gpu/command_buffer/common/id_allocator_test.cc

Issue 169403005: command_buffer: Implement path rendering functions for CHROMIUM_path_rendering (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@nv-pr-02-texgen
Patch Set: rebase and cleanup ids Created 6 years, 2 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // This file has the unit tests for the IdAllocator class. 5 // This file has the unit tests for the IdAllocator class.
6 6
7 #include "gpu/command_buffer/common/id_allocator.h" 7 #include "gpu/command_buffer/common/id_allocator.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace gpu { 10 namespace gpu {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 allocator->FreeID(id1); 118 allocator->FreeID(id1);
119 allocator->FreeID(id1 + 1); 119 allocator->FreeID(id1 + 1);
120 120
121 ResourceId id2 = allocator->AllocateID(); 121 ResourceId id2 = allocator->AllocateID();
122 ResourceId id3 = allocator->AllocateID(); 122 ResourceId id3 = allocator->AllocateID();
123 EXPECT_NE(id2, id3); 123 EXPECT_NE(id2, id3);
124 EXPECT_NE(kInvalidResource, id2); 124 EXPECT_NE(kInvalidResource, id2);
125 EXPECT_NE(kInvalidResource, id3); 125 EXPECT_NE(kInvalidResource, id3);
126 } 126 }
127 127
128 TEST_F(IdAllocatorTest, AllocateIDRange) {
129 const ResourceId kMaxPossibleOffset = ~static_cast<ResourceId>(0);
130
131 IdAllocator* allocator = id_allocator();
132
133 ResourceId id1 = allocator->AllocateIDRange(1);
134 EXPECT_EQ(1u, id1);
135 ResourceId id2 = allocator->AllocateIDRange(2);
136 EXPECT_EQ(2u, id2);
137 ResourceId id3 = allocator->AllocateIDRange(3);
138 EXPECT_EQ(4u, id3);
139 ResourceId id4 = allocator->AllocateID();
140 EXPECT_EQ(7u, id4);
141 allocator->FreeID(3);
142 ResourceId id5 = allocator->AllocateIDRange(1);
143 EXPECT_EQ(3u, id5);
144 allocator->FreeID(5);
145 allocator->FreeID(2);
146 allocator->FreeID(4);
147 ResourceId id6 = allocator->AllocateIDRange(2);
148 EXPECT_EQ(4u, id6);
149 ResourceId id7 = allocator->AllocateIDAtOrAbove(kMaxPossibleOffset);
150 EXPECT_EQ(kMaxPossibleOffset, id7);
151 ResourceId id8 = allocator->AllocateIDAtOrAbove(kMaxPossibleOffset);
152 EXPECT_EQ(2u, id8);
153 ResourceId id9 = allocator->AllocateIDRange(50);
154 EXPECT_EQ(8u, id9);
155 ResourceId id10 = allocator->AllocateIDRange(50);
156 EXPECT_EQ(58u, id10);
157 // Remove all the low-numbered ids.
158 allocator->FreeID(1);
159 allocator->FreeID(15);
160 allocator->FreeIDRange(2, 107);
161 ResourceId id11 = allocator->AllocateIDRange(100);
162 EXPECT_EQ(1u, id11);
163 allocator->FreeID(kMaxPossibleOffset);
164 ResourceId id12 = allocator->AllocateIDRange(100);
165 EXPECT_EQ(101u, id12);
166
167 ResourceId id13 = allocator->AllocateIDAtOrAbove(kMaxPossibleOffset - 2u);
168 EXPECT_EQ(kMaxPossibleOffset, id13);
169 ResourceId id14 = allocator->AllocateIDRange(3);
170 EXPECT_EQ(201u, id14);
171 }
172
173 TEST_F(IdAllocatorTest, AllocateIDRangeNoWrapInRange) {
174 const ResourceId kMaxPossibleOffset = ~static_cast<ResourceId>(0);
175
176 IdAllocator* allocator = id_allocator();
177 ResourceId id1 = allocator->AllocateIDAtOrAbove(kMaxPossibleOffset - 2u);
178 EXPECT_EQ(kMaxPossibleOffset - 2u, id1);
179 ResourceId id3 = allocator->AllocateIDRange(3);
180 EXPECT_EQ(1u, id3);
181 ResourceId id2 = allocator->AllocateIDRange(2);
182 EXPECT_EQ(kMaxPossibleOffset - 1, id2);
183 }
184
128 } // namespace gpu 185 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698