• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 com.android.launcher3.responsive
18 
19 import android.content.Context
20 import androidx.test.ext.junit.runners.AndroidJUnit4
21 import androidx.test.filters.SmallTest
22 import androidx.test.platform.app.InstrumentationRegistry
23 import com.android.launcher3.AbstractDeviceProfileTest
24 import com.android.launcher3.tests.R as TestR
25 import com.android.launcher3.util.TestResourceHelper
26 import com.google.common.truth.Truth.assertThat
27 import org.junit.Before
28 import org.junit.Test
29 import org.junit.runner.RunWith
30 
31 @SmallTest
32 @RunWith(AndroidJUnit4::class)
33 class AllAppsSpecsTest : AbstractDeviceProfileTest() {
34     override val runningContext: Context = InstrumentationRegistry.getInstrumentation().context
35 
36     @Before
setupnull37     fun setup() {
38         initializeVarsForPhone(deviceSpecs["phone"]!!)
39     }
40 
41     @Test
parseValidFilenull42     fun parseValidFile() {
43         val allAppsSpecs =
44             AllAppsSpecs.create(TestResourceHelper(context!!, TestR.xml.valid_all_apps_file))
45         assertThat(allAppsSpecs.heightSpecs.size).isEqualTo(1)
46         assertThat(allAppsSpecs.heightSpecs[0].toString())
47             .isEqualTo(
48                 "AllAppsSpec(" +
49                     "maxAvailableSize=26247, " +
50                     "specType=HEIGHT, " +
51                     "startPadding=SizeSpec(fixedSize=0.0, " +
52                     "ofAvailableSpace=0.0, " +
53                     "ofRemainderSpace=0.0, " +
54                     "matchWorkspace=false, " +
55                     "maxSize=2147483647), " +
56                     "endPadding=SizeSpec(fixedSize=0.0, " +
57                     "ofAvailableSpace=0.0, " +
58                     "ofRemainderSpace=0.0, " +
59                     "matchWorkspace=false, " +
60                     "maxSize=2147483647), " +
61                     "gutter=SizeSpec(fixedSize=0.0, " +
62                     "ofAvailableSpace=0.0, " +
63                     "ofRemainderSpace=0.0, " +
64                     "matchWorkspace=true, " +
65                     "maxSize=2147483647), " +
66                     "cellSize=SizeSpec(fixedSize=0.0, " +
67                     "ofAvailableSpace=0.0, " +
68                     "ofRemainderSpace=0.0, " +
69                     "matchWorkspace=true, " +
70                     "maxSize=2147483647)" +
71                     ")"
72             )
73 
74         assertThat(allAppsSpecs.widthSpecs.size).isEqualTo(1)
75         assertThat(allAppsSpecs.widthSpecs[0].toString())
76             .isEqualTo(
77                 "AllAppsSpec(" +
78                     "maxAvailableSize=26247, " +
79                     "specType=WIDTH, " +
80                     "startPadding=SizeSpec(fixedSize=0.0, " +
81                     "ofAvailableSpace=0.0, " +
82                     "ofRemainderSpace=0.0, " +
83                     "matchWorkspace=true, " +
84                     "maxSize=2147483647), " +
85                     "endPadding=SizeSpec(fixedSize=0.0, " +
86                     "ofAvailableSpace=0.0, " +
87                     "ofRemainderSpace=0.0, " +
88                     "matchWorkspace=true, " +
89                     "maxSize=2147483647), " +
90                     "gutter=SizeSpec(fixedSize=0.0, " +
91                     "ofAvailableSpace=0.0, " +
92                     "ofRemainderSpace=0.0, " +
93                     "matchWorkspace=true, " +
94                     "maxSize=2147483647), " +
95                     "cellSize=SizeSpec(fixedSize=0.0, " +
96                     "ofAvailableSpace=0.0, " +
97                     "ofRemainderSpace=0.0, " +
98                     "matchWorkspace=true, " +
99                     "maxSize=2147483647)" +
100                     ")"
101             )
102     }
103 
104     @Test(expected = IllegalStateException::class)
parseInvalidFile_missingTag_throwsErrornull105     fun parseInvalidFile_missingTag_throwsError() {
106         AllAppsSpecs.create(TestResourceHelper(context!!, TestR.xml.invalid_all_apps_file_case_1))
107     }
108 
109     @Test(expected = IllegalStateException::class)
parseInvalidFile_moreThanOneValuePerTag_throwsErrornull110     fun parseInvalidFile_moreThanOneValuePerTag_throwsError() {
111         AllAppsSpecs.create(TestResourceHelper(context!!, TestR.xml.invalid_all_apps_file_case_2))
112     }
113 
114     @Test(expected = IllegalStateException::class)
parseInvalidFile_valueBiggerThan1_throwsErrornull115     fun parseInvalidFile_valueBiggerThan1_throwsError() {
116         AllAppsSpecs.create(TestResourceHelper(context!!, TestR.xml.invalid_all_apps_file_case_3))
117     }
118 }
119