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

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

Issue 375733004: Fixes for re-enabling more MSVC level 4 warnings: gpu/ edition (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 // Frees the other ID, check that it's not in use any more. 43 // Frees the other ID, check that it's not in use any more.
44 allocator->FreeID(id2); 44 allocator->FreeID(id2);
45 EXPECT_FALSE(allocator->InUse(id2)); 45 EXPECT_FALSE(allocator->InUse(id2));
46 } 46 }
47 47
48 // Checks that the resource IDs are re-used after being freed. 48 // Checks that the resource IDs are re-used after being freed.
49 TEST_F(IdAllocatorTest, TestAdvanced) { 49 TEST_F(IdAllocatorTest, TestAdvanced) {
50 IdAllocator *allocator = id_allocator(); 50 IdAllocator *allocator = id_allocator();
51 51
52 // Allocate the highest possible ID, to make life awkward. 52 // Allocate the highest possible ID, to make life awkward.
53 allocator->AllocateIDAtOrAbove(-1); 53 allocator->AllocateIDAtOrAbove(~static_cast<ResourceId>(0));
54 54
55 // Allocate a significant number of resources. 55 // Allocate a significant number of resources.
56 const unsigned int kNumResources = 100; 56 const unsigned int kNumResources = 100;
57 ResourceId ids[kNumResources]; 57 ResourceId ids[kNumResources];
58 for (unsigned int i = 0; i < kNumResources; ++i) { 58 for (unsigned int i = 0; i < kNumResources; ++i) {
59 ids[i] = allocator->AllocateID(); 59 ids[i] = allocator->AllocateID();
60 EXPECT_TRUE(allocator->InUse(ids[i])); 60 EXPECT_TRUE(allocator->InUse(ids[i]));
61 } 61 }
62 62
63 // Check that a new allocation re-uses the resource we just freed. 63 // Check that a new allocation re-uses the resource we just freed.
(...skipping 27 matching lines...) Expand all
91 const ResourceId kOffset = 123456; 91 const ResourceId kOffset = 123456;
92 IdAllocator* allocator = id_allocator(); 92 IdAllocator* allocator = id_allocator();
93 ResourceId id1 = allocator->AllocateIDAtOrAbove(kOffset); 93 ResourceId id1 = allocator->AllocateIDAtOrAbove(kOffset);
94 EXPECT_EQ(kOffset, id1); 94 EXPECT_EQ(kOffset, id1);
95 ResourceId id2 = allocator->AllocateIDAtOrAbove(kOffset); 95 ResourceId id2 = allocator->AllocateIDAtOrAbove(kOffset);
96 EXPECT_GT(id2, kOffset); 96 EXPECT_GT(id2, kOffset);
97 ResourceId id3 = allocator->AllocateIDAtOrAbove(kOffset); 97 ResourceId id3 = allocator->AllocateIDAtOrAbove(kOffset);
98 EXPECT_GT(id3, kOffset); 98 EXPECT_GT(id3, kOffset);
99 } 99 }
100 100
101 // Checks that AllocateIdAtOrAbove wraps around at the maximum 32-bit value. 101 // Checks that AllocateIdAtOrAbove wraps around at the maximum value.
102 TEST_F(IdAllocatorTest, AllocateIdAtOrAboveWrapsAround) { 102 TEST_F(IdAllocatorTest, AllocateIdAtOrAboveWrapsAround) {
103 const ResourceId kMaxPossibleOffset = -1; 103 const ResourceId kMaxPossibleOffset = ~static_cast<ResourceId>(0);
no sievers 2014/07/08 00:51:13 same
104 IdAllocator* allocator = id_allocator(); 104 IdAllocator* allocator = id_allocator();
105 ResourceId id1 = allocator->AllocateIDAtOrAbove(kMaxPossibleOffset); 105 ResourceId id1 = allocator->AllocateIDAtOrAbove(kMaxPossibleOffset);
106 EXPECT_EQ(kMaxPossibleOffset, id1); 106 EXPECT_EQ(kMaxPossibleOffset, id1);
107 ResourceId id2 = allocator->AllocateIDAtOrAbove(kMaxPossibleOffset); 107 ResourceId id2 = allocator->AllocateIDAtOrAbove(kMaxPossibleOffset);
108 EXPECT_EQ(1u, id2); 108 EXPECT_EQ(1u, id2);
109 ResourceId id3 = allocator->AllocateIDAtOrAbove(kMaxPossibleOffset); 109 ResourceId id3 = allocator->AllocateIDAtOrAbove(kMaxPossibleOffset);
110 EXPECT_EQ(2u, id3); 110 EXPECT_EQ(2u, id3);
111 } 111 }
112 112
113 TEST_F(IdAllocatorTest, RedundantFreeIsIgnored) { 113 TEST_F(IdAllocatorTest, RedundantFreeIsIgnored) {
114 IdAllocator* allocator = id_allocator(); 114 IdAllocator* allocator = id_allocator();
115 ResourceId id1 = allocator->AllocateID(); 115 ResourceId id1 = allocator->AllocateID();
116 allocator->FreeID(0); 116 allocator->FreeID(0);
117 allocator->FreeID(id1); 117 allocator->FreeID(id1);
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 } // namespace gpu 128 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698