1 /*
2  * Copyright (C) 2015 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 #include <utils/String8.h>
18 #include <gtest/gtest.h>
19 
20 #include "ConfigDescription.h"
21 #include "ResourceTable.h"
22 #include "TestHelper.h"
23 
24 using android::String16;
25 
TEST(ResourceTableTest,generateVersionedResources)26 TEST(ResourceTableTest, generateVersionedResources) {
27     sp<ResourceTable::ConfigList> configs(new ResourceTable::ConfigList(String16(), SourcePos()));
28 
29     ConfigDescription defaultConfig = {};
30 
31     ConfigDescription landConfig = {};
32     landConfig.orientation = ResTable_config::ORIENTATION_LAND;
33 
34     ConfigDescription sw600dpLandConfig = {};
35     sw600dpLandConfig.orientation = ResTable_config::ORIENTATION_LAND;
36     sw600dpLandConfig.smallestScreenWidthDp = 600;
37 
38     configs->addEntry(defaultConfig, new ResourceTable::Entry(String16(), SourcePos()));
39     configs->addEntry(landConfig, new ResourceTable::Entry(String16(), SourcePos()));
40     configs->addEntry(sw600dpLandConfig, new ResourceTable::Entry(String16(), SourcePos()));
41 
42     EXPECT_TRUE(ResourceTable::shouldGenerateVersionedResource(configs, defaultConfig, 17));
43     EXPECT_TRUE(ResourceTable::shouldGenerateVersionedResource(configs, landConfig, 17));
44 }
45 
TEST(ResourceTableTest,generateVersionedResourceWhenHigherVersionExists)46 TEST(ResourceTableTest, generateVersionedResourceWhenHigherVersionExists) {
47     sp<ResourceTable::ConfigList> configs(new ResourceTable::ConfigList(String16(), SourcePos()));
48 
49     ConfigDescription defaultConfig = {};
50 
51     ConfigDescription v21Config = {};
52     v21Config.sdkVersion = 21;
53 
54     ConfigDescription sw600dpV13Config = {};
55     sw600dpV13Config.smallestScreenWidthDp = 600;
56     sw600dpV13Config.sdkVersion = 13;
57 
58     configs->addEntry(defaultConfig, new ResourceTable::Entry(String16(), SourcePos()));
59     configs->addEntry(v21Config, new ResourceTable::Entry(String16(), SourcePos()));
60     configs->addEntry(sw600dpV13Config, new ResourceTable::Entry(String16(), SourcePos()));
61 
62     EXPECT_TRUE(ResourceTable::shouldGenerateVersionedResource(configs, defaultConfig, 17));
63     EXPECT_FALSE(ResourceTable::shouldGenerateVersionedResource(configs, defaultConfig, 22));
64 }
65