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.
5 #include "gpu/command_buffer/service/id_manager.h"
6 #include "testing/gtest/include/gtest/gtest.h"
11 class IdManagerTest
: public testing::Test
{
17 virtual void SetUp() {
20 virtual void TearDown() {
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
);
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.
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
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
);
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
));