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 3 // found in the LICENSE file. 4 5 #include "gpu/command_buffer/service/id_manager.h" 6 #include "testing/gtest/include/gtest/gtest.h" 7 8 namespace gpu { 9 namespace gles2 { 10 11 class IdManagerTest : public testing::Test { 12 public: 13 IdManagerTest() { 14 } 15 16 protected: 17 virtual void SetUp() { 18 } 19 20 virtual void TearDown() { 21 } 22 23 IdManager manager_; 24 }; 25 26 TEST_F(IdManagerTest, Basic) { 27 const GLuint kClientId1 = 1; 28 const GLuint kClientId2 = 2; 29 const GLuint kServiceId1 = 201; 30 const GLuint kServiceId2 = 202; 31 // Check we can add an id 32 EXPECT_TRUE(manager_.AddMapping(kClientId1, kServiceId1)); 33 // Check we can get that mapping 34 GLuint service_id = 0; 35 EXPECT_TRUE(manager_.GetServiceId(kClientId1, &service_id)); 36 EXPECT_EQ(kServiceId1, service_id); 37 GLuint client_id = 0; 38 EXPECT_TRUE(manager_.GetClientId(kServiceId1, &client_id)); 39 EXPECT_EQ(kClientId1, client_id); 40 // Check that it fails if we get a non-existent id. 41 service_id = 0; 42 client_id = 0; 43 EXPECT_FALSE(manager_.GetServiceId(kClientId2, &service_id)); 44 EXPECT_FALSE(manager_.GetClientId(kServiceId2, &client_id)); 45 EXPECT_EQ(0u, service_id); 46 EXPECT_EQ(0u, client_id); 47 // Check we can add a second id. 48 EXPECT_TRUE(manager_.AddMapping(kClientId2, kServiceId2)); 49 // Check we can get that mapping 50 service_id = 0; 51 EXPECT_TRUE(manager_.GetServiceId(kClientId1, &service_id)); 52 EXPECT_EQ(kServiceId1, service_id); 53 EXPECT_TRUE(manager_.GetServiceId(kClientId2, &service_id)); 54 EXPECT_EQ(kServiceId2, service_id); 55 client_id = 0; 56 EXPECT_TRUE(manager_.GetClientId(kServiceId1, &client_id)); 57 EXPECT_EQ(kClientId1, client_id); 58 EXPECT_TRUE(manager_.GetClientId(kServiceId2, &client_id)); 59 EXPECT_EQ(kClientId2, client_id); 60 // Check if we remove an id we can no longer get it. 61 EXPECT_TRUE(manager_.RemoveMapping(kClientId1, kServiceId1)); 62 EXPECT_FALSE(manager_.GetServiceId(kClientId1, &service_id)); 63 EXPECT_FALSE(manager_.GetClientId(kServiceId1, &client_id)); 64 // Check we get an error if we try to remove a non-existent id. 65 EXPECT_FALSE(manager_.RemoveMapping(kClientId1, kServiceId1)); 66 EXPECT_FALSE(manager_.RemoveMapping(kClientId2, kServiceId1)); 67 EXPECT_FALSE(manager_.RemoveMapping(kClientId1, kServiceId2)); 68 // Check we get an error if we try to map an existing id. 69 EXPECT_FALSE(manager_.AddMapping(kClientId2, kServiceId2)); 70 EXPECT_FALSE(manager_.AddMapping(kClientId2, kServiceId1)); 71 } 72 73 } // namespace gles2 74 } // namespace gpu 75 76 77