Debian Codegraph @

core/tests/GameManagerTests/src/android/app/GameManagerTests.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package android.app;
18
19 import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
20
21 import static junit.framework.Assert.assertEquals;
22
23 import android.content.Context;
24 import android.platform.test.annotations.Presubmit;
25
26 import androidx.test.filters.SmallTest;
27 import androidx.test.runner.AndroidJUnit4;
28
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32
33 /**
34 * Unit tests for {@link android.app.GameManager}.
35 */
36 @RunWith(AndroidJUnit4.class)
37 @SmallTest
38 @Presubmit
39 public final class GameManagerTests {
40 protected Context mContext;
41 private GameManager mGameManager;
42 private String mPackageName;
43
44 @Before
45 public void setUp() {
46 mContext = getInstrumentation().getContext();
47 mGameManager = mContext.getSystemService(GameManager.class);
48 mPackageName = mContext.getPackageName();
49
50 // Reset the Game Mode for the test app, since it persists across invocations.
51 mGameManager.setGameMode(mPackageName, GameManager.GAME_MODE_UNSUPPORTED);
52 }
53
54 @Test
55 public void testPublicApiGameModeGetterSetter() {
56 assertEquals(GameManager.GAME_MODE_UNSUPPORTED,
57 mGameManager.getGameMode());
58
59 mGameManager.setGameMode(mPackageName, GameManager.GAME_MODE_STANDARD);
60 assertEquals(GameManager.GAME_MODE_STANDARD,
61 mGameManager.getGameMode());
62
63 mGameManager.setGameMode(mPackageName, GameManager.GAME_MODE_PERFORMANCE);
64 assertEquals(GameManager.GAME_MODE_PERFORMANCE,
65 mGameManager.getGameMode());
66 }
67
68 @Test
69 public void testPrivilegedGameModeGetterSetter() {
70 assertEquals(GameManager.GAME_MODE_UNSUPPORTED,
71 mGameManager.getGameMode(mPackageName));
72
73 mGameManager.setGameMode(mPackageName, GameManager.GAME_MODE_STANDARD);
74 assertEquals(GameManager.GAME_MODE_STANDARD,
75 mGameManager.getGameMode(mPackageName));
76
77 mGameManager.setGameMode(mPackageName, GameManager.GAME_MODE_PERFORMANCE);
78 assertEquals(GameManager.GAME_MODE_PERFORMANCE,
79 mGameManager.getGameMode(mPackageName));
80 }
81 }