aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/org/cyanogenmod/tests/profiles/unit/ProfileTest.java
blob: 38ba56e558748e549b63692b88bee2bc0f748ac9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/**
 * Copyright (c) 2015, 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.profiles.unit;

import android.media.AudioManager;
import android.os.Parcel;
import android.test.AndroidTestCase;

import android.test.suitebuilder.annotation.MediumTest;
import android.test.suitebuilder.annotation.SmallTest;

import cyanogenmod.app.CMContextConstants;
import cyanogenmod.app.Profile;
import cyanogenmod.profiles.AirplaneModeSettings;
import cyanogenmod.profiles.BrightnessSettings;
import cyanogenmod.profiles.ConnectionSettings;
import cyanogenmod.profiles.LockSettings;
import cyanogenmod.profiles.RingModeSettings;
import cyanogenmod.profiles.StreamSettings;

/**
 * Created by adnan on 7/14/15.
 */
public class ProfileTest extends AndroidTestCase {

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        // Only run this if we support profiles service
        org.junit.Assume.assumeTrue(mContext.getPackageManager().hasSystemFeature(
                CMContextConstants.Features.PROFILES));
    }

    @MediumTest
    public void testProfileConnectionSettingsUnravelFromParcel() {
        Profile profile = new Profile("Connection Profile");
        ConnectionSettings expectedConnectionSettings =
                new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_GPS,
                        ConnectionSettings.BooleanState.STATE_DISALED, true);
        profile.setConnectionSettings(expectedConnectionSettings);

        // Write to parcel
        Parcel parcel = Parcel.obtain();
        profile.writeToParcel(parcel, 0);

        // Rewind
        parcel.setDataPosition(0);

        // Verify data when unraveling
        Profile fromParcel = Profile.CREATOR.createFromParcel(parcel);

        assertNotNull(fromParcel);
        ConnectionSettings actualConnectionSettings = fromParcel.getSettingsForConnection(
                expectedConnectionSettings.getConnectionId());

        assertEquals(expectedConnectionSettings.getConnectionId(),
                actualConnectionSettings.getConnectionId());
        assertEquals(expectedConnectionSettings.getValue(),
                actualConnectionSettings.getValue());
        assertEquals(expectedConnectionSettings.isDirty(),
                actualConnectionSettings.isDirty());
        assertEquals(expectedConnectionSettings.isOverride(),
                actualConnectionSettings.isOverride());
    }

    @MediumTest
    public void testProfileAirplaneModeSettingsUnravelFromParcel() {
        Profile profile = new Profile("AirplaneMode Profile");
        AirplaneModeSettings expectedAirplaneModeSettings =
                new AirplaneModeSettings(AirplaneModeSettings.BooleanState.STATE_ENABLED, true);
        profile.setAirplaneMode(expectedAirplaneModeSettings);

        // Write to parcel
        Parcel parcel = Parcel.obtain();
        profile.writeToParcel(parcel, 0);

        // Rewind
        parcel.setDataPosition(0);

        // Verify data when unraveling
        Profile fromParcel = Profile.CREATOR.createFromParcel(parcel);

        assertNotNull(fromParcel);
        AirplaneModeSettings actualAirplaneModeSettings = fromParcel.getAirplaneMode();

        assertEquals(expectedAirplaneModeSettings.getValue(),
                actualAirplaneModeSettings.getValue());
        assertEquals(expectedAirplaneModeSettings.isDirty(),
                actualAirplaneModeSettings.isDirty());
        assertEquals(expectedAirplaneModeSettings.isOverride(),
                expectedAirplaneModeSettings.isOverride());
    }

    @MediumTest
    public void testProfileBrightnessSettingsUnravelFromParcel() {
        Profile profile = new Profile("Brightness Profile");
        BrightnessSettings expectedBrightnessSettings = new BrightnessSettings(0, true);
        profile.setBrightness(expectedBrightnessSettings);

        // Write to parcel
        Parcel parcel = Parcel.obtain();
        profile.writeToParcel(parcel, 0);

        // Rewind
        parcel.setDataPosition(0);

        // Verify data when unraveling
        Profile fromParcel = Profile.CREATOR.createFromParcel(parcel);

        assertNotNull(fromParcel);
        BrightnessSettings actualBrightnessSettings = fromParcel.getBrightness();

        assertEquals(expectedBrightnessSettings.getValue(), actualBrightnessSettings.getValue());
        assertEquals(expectedBrightnessSettings.isOverride(),
                actualBrightnessSettings.isOverride());
        assertEquals(expectedBrightnessSettings.isDirty(), actualBrightnessSettings.isDirty());
    }

    @MediumTest
    public void testProfileRingmodeSettingsUnravelFromParcel() {
        Profile profile = new Profile("Ringmode Profile");
        RingModeSettings expectedRingModeSettings =
                new RingModeSettings(RingModeSettings.RING_MODE_MUTE, true);
        profile.setRingMode(expectedRingModeSettings);

        // Write to parcel
        Parcel parcel = Parcel.obtain();
        profile.writeToParcel(parcel, 0);

        // Rewind
        parcel.setDataPosition(0);

        // Verify data when unraveling
        Profile fromParcel = Profile.CREATOR.createFromParcel(parcel);

        RingModeSettings actualRingModeSettings = fromParcel.getRingMode();

        assertNotNull(fromParcel);
        assertEquals(expectedRingModeSettings.getValue(), actualRingModeSettings.getValue());
        assertEquals(expectedRingModeSettings.isDirty(), actualRingModeSettings.isDirty());
        assertEquals(expectedRingModeSettings.isOverride(), actualRingModeSettings.isOverride());
    }

    @MediumTest
    public void testProfileStreamSettingsUnravelFromParcel() {
        Profile profile = new Profile("Stream Profile");
        StreamSettings expectedStreamSettings =
                new StreamSettings(AudioManager.STREAM_RING, 0, true);
        profile.setStreamSettings(expectedStreamSettings);

        // Write to parcel
        Parcel parcel = Parcel.obtain();
        profile.writeToParcel(parcel, 0);

        // Rewind
        parcel.setDataPosition(0);

        // Verify data when unraveling
        Profile fromParcel = Profile.CREATOR.createFromParcel(parcel);

        StreamSettings actualStreamSettings = fromParcel.getSettingsForStream(
                expectedStreamSettings.getStreamId());

        assertNotNull(fromParcel);
        assertEquals(expectedStreamSettings.getValue(), actualStreamSettings.getValue());
        assertEquals(expectedStreamSettings.isOverride(), actualStreamSettings.isOverride());
        assertEquals(expectedStreamSettings.isDirty(), actualStreamSettings.isDirty());
    }

    @MediumTest
    public void testProfileLockSettingsUnravelFromParcel() {
        Profile profile = new Profile("Lock Profile");
        LockSettings expectedLockSettings = new LockSettings(Profile.LockMode.INSECURE);
        profile.setScreenLockMode(expectedLockSettings);

        // Write to parcel
        Parcel parcel = Parcel.obtain();
        profile.writeToParcel(parcel, 0);

        // Rewind
        parcel.setDataPosition(0);

        // Verify data when unraveling
        Profile fromParcel = Profile.CREATOR.createFromParcel(parcel);

        LockSettings actualLockSettings = fromParcel.getScreenLockMode();

        assertNotNull(fromParcel);
        assertEquals(expectedLockSettings.getValue(), actualLockSettings.getValue());
        assertEquals(expectedLockSettings.isDirty(), actualLockSettings.isDirty());
    }

    @MediumTest
    public void testProfileUnravelFromParcel() {
        Profile profile = new Profile("Single Profile");
        profile.setProfileType(Profile.Type.TOGGLE);
        profile.setDozeMode(Profile.DozeMode.ENABLE);
        profile.setStatusBarIndicator(true);

        // Write to parcel
        Parcel parcel = Parcel.obtain();
        profile.writeToParcel(parcel, 0);

        // Rewind
        parcel.setDataPosition(0);

        // Verify data when unraveling
        Profile fromParcel = Profile.CREATOR.createFromParcel(parcel);

        assertNotNull(fromParcel);
        assertEquals(profile.getName(), fromParcel.getName());
        assertEquals(profile.getProfileType(), fromParcel.getProfileType());
        assertEquals(profile.getDozeMode(), fromParcel.getDozeMode());
        assertEquals(profile.getStatusBarIndicator(), fromParcel.getStatusBarIndicator());
    }
}