blob: 0d550df16767e2dad7bafae46d4b7daafa373813 [file] [log] [blame]
Adam Lesinskibeb9e332015-08-14 13:16:18 -07001/*
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"
Adam Lesinskibeb9e332015-08-14 13:16:18 -070022
23using android::String16;
24
25TEST(ResourceTableTest, generateVersionedResources) {
26 sp<ResourceTable::ConfigList> configs(new ResourceTable::ConfigList(String16(), SourcePos()));
27
28 ConfigDescription defaultConfig = {};
29
30 ConfigDescription landConfig = {};
31 landConfig.orientation = ResTable_config::ORIENTATION_LAND;
32
33 ConfigDescription sw600dpLandConfig = {};
34 sw600dpLandConfig.orientation = ResTable_config::ORIENTATION_LAND;
35 sw600dpLandConfig.smallestScreenWidthDp = 600;
36
37 configs->addEntry(defaultConfig, new ResourceTable::Entry(String16(), SourcePos()));
38 configs->addEntry(landConfig, new ResourceTable::Entry(String16(), SourcePos()));
39 configs->addEntry(sw600dpLandConfig, new ResourceTable::Entry(String16(), SourcePos()));
40
41 EXPECT_TRUE(ResourceTable::shouldGenerateVersionedResource(configs, defaultConfig, 17));
42 EXPECT_TRUE(ResourceTable::shouldGenerateVersionedResource(configs, landConfig, 17));
43}
44
45TEST(ResourceTableTest, generateVersionedResourceWhenHigherVersionExists) {
46 sp<ResourceTable::ConfigList> configs(new ResourceTable::ConfigList(String16(), SourcePos()));
47
48 ConfigDescription defaultConfig = {};
49
50 ConfigDescription v21Config = {};
51 v21Config.sdkVersion = 21;
52
53 ConfigDescription sw600dpV13Config = {};
54 sw600dpV13Config.smallestScreenWidthDp = 600;
55 sw600dpV13Config.sdkVersion = 13;
56
57 configs->addEntry(defaultConfig, new ResourceTable::Entry(String16(), SourcePos()));
58 configs->addEntry(v21Config, new ResourceTable::Entry(String16(), SourcePos()));
59 configs->addEntry(sw600dpV13Config, new ResourceTable::Entry(String16(), SourcePos()));
60
61 EXPECT_TRUE(ResourceTable::shouldGenerateVersionedResource(configs, defaultConfig, 17));
62 EXPECT_FALSE(ResourceTable::shouldGenerateVersionedResource(configs, defaultConfig, 22));
63}