aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAdnan Begovic <adnan@cyngn.com>2016-03-07 11:49:52 -0800
committerAdnan Begovic <adnan@cyngn.com>2016-03-08 09:24:34 -0800
commitb4eafda7de11276522946d13e5860652aacccd4c (patch)
tree5e3a59391df818e0e05e9edf188b58c74389c417 /tests
parent7ed4fcaf8e51bfa2d8c3d1a0ca16c9250eac271d (diff)
downloadvendor_cmsdk-b4eafda7de11276522946d13e5860652aacccd4c.zip
vendor_cmsdk-b4eafda7de11276522946d13e5860652aacccd4c.tar.gz
vendor_cmsdk-b4eafda7de11276522946d13e5860652aacccd4c.tar.bz2
cmsdk: Add PerformanceManager tests, Change target permission.
Since PerformanceManager is strictly a CyanogenMod construct, it doesn't make sense to enforce the interfaces with an android specific permission (even though the implementation is delegated to power manager). To keep consistency with the other api's, modify the enforcing permission to a cm specific declaration. Also add test cases for the PerformanceManager public interfaces. Change-Id: I430b69dbee73bf94bb60932d1942ab97e3ba193e
Diffstat (limited to 'tests')
-rw-r--r--tests/AndroidManifest.xml1
-rw-r--r--tests/src/org/cyanogenmod/tests/power/unit/PerfomanceManagerTest.java95
2 files changed, 96 insertions, 0 deletions
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
index 5016a35..28fc932 100644
--- a/tests/AndroidManifest.xml
+++ b/tests/AndroidManifest.xml
@@ -20,6 +20,7 @@
<uses-permission android:name="cyanogenmod.permission.HARDWARE_ABSTRACTION_ACCESS" />
<uses-permission android:name="cyanogenmod.permission.MODIFY_PROFILES" />
<uses-permission android:name="cyanogenmod.permission.MANAGE_PERSISTENT_STORAGE" />
+ <uses-permission android:name="cyanogenmod.permission.PERFORMANCE_ACCESS" />
<uses-permission android:name="android.permission.STATUS_BAR_SERVICE" />
<application android:name=".CyanogenModTestApplication"
diff --git a/tests/src/org/cyanogenmod/tests/power/unit/PerfomanceManagerTest.java b/tests/src/org/cyanogenmod/tests/power/unit/PerfomanceManagerTest.java
new file mode 100644
index 0000000..7b00a5c
--- /dev/null
+++ b/tests/src/org/cyanogenmod/tests/power/unit/PerfomanceManagerTest.java
@@ -0,0 +1,95 @@
+/**
+ * Copyright (c) 2016, The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.cyanogenmod.tests.power.unit;
+
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+import cyanogenmod.power.IPerformanceManager;
+import cyanogenmod.power.PerformanceManager;
+
+/**
+ * Code coverage for public facing {@link PerformanceManager} interfaces.
+ * The test below will save and restore the current performance profile to
+ * not impact successive tests.
+ */
+public class PerfomanceManagerTest extends AndroidTestCase {
+ private static final String TAG = PerfomanceManagerTest.class.getSimpleName();
+ private static final int IMPOSSIBLE_POWER_PROFILE = -1;
+ private PerformanceManager mCMPerformanceManager;
+ private int mSavedPerfProfile;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mCMPerformanceManager = PerformanceManager.getInstance(mContext);
+ // Save the perf profile for later restore.
+ mSavedPerfProfile = mCMPerformanceManager.getPowerProfile();
+ }
+
+ @SmallTest
+ public void testManagerExists() {
+ assertNotNull(mCMPerformanceManager);
+ }
+
+ @SmallTest
+ public void testManagerServiceIsAvailable() {
+ IPerformanceManager icmStatusBarManager = mCMPerformanceManager.getService();
+ assertNotNull(icmStatusBarManager);
+ }
+
+ @SmallTest
+ public void testGetNumberOfPerformanceProfiles() {
+ // Assert that we can even set perf profiles
+ assertTrue(mCMPerformanceManager.getNumberOfProfiles() > 0);
+ }
+
+ @SmallTest
+ public void testGetPowerProfile() {
+ assertNotSame(IMPOSSIBLE_POWER_PROFILE, mSavedPerfProfile);
+ }
+
+ @SmallTest
+ public void testSetAndGetPowerProfile() {
+ int[] expectedStates = new int[] { PerformanceManager.PROFILE_POWER_SAVE,
+ PerformanceManager.PROFILE_BALANCED,
+ PerformanceManager.PROFILE_HIGH_PERFORMANCE};
+
+ // Set the state
+ for (int profile : expectedStates) {
+ // If the target perf profile is the same as the current one,
+ // setPowerProfile will noop, ignore that scenario
+ if (mCMPerformanceManager.getPowerProfile() != profile) {
+ mCMPerformanceManager.setPowerProfile(profile);
+ // Verify that it was set correctly.
+ assertEquals(profile, mCMPerformanceManager.getPowerProfile());
+ }
+ }
+ }
+
+ @SmallTest
+ public void testGetPerfProfileHasAppProfiles() {
+ // No application has power save by default
+ assertEquals(false, mCMPerformanceManager.getProfileHasAppProfiles(
+ PerformanceManager.PROFILE_POWER_SAVE));
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ // Reset
+ mCMPerformanceManager.setPowerProfile(mSavedPerfProfile);
+ }
+}