blob: 4f22fa581a88414403ef972b13b51bbce552e477 [file] [log] [blame]
Adam Lesinskifab50872014-04-16 14:40:42 -07001/*
2 * Copyright (C) 2014 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 "AaptConfig.h"
21#include "ConfigDescription.h"
Adam Lesinski2738c962015-05-14 14:25:36 -070022#include "SdkConstants.h"
Adam Lesinskifab50872014-04-16 14:40:42 -070023#include "TestHelper.h"
24
25using android::String8;
26
27static ::testing::AssertionResult TestParse(const String8& input, ConfigDescription* config=NULL) {
28 if (AaptConfig::parse(String8(input), config)) {
29 return ::testing::AssertionSuccess() << input << " was successfully parsed";
30 }
31 return ::testing::AssertionFailure() << input << " could not be parsed";
32}
33
34static ::testing::AssertionResult TestParse(const char* input, ConfigDescription* config=NULL) {
35 return TestParse(String8(input), config);
36}
37
38TEST(AaptConfigTest, ParseFailWhenQualifiersAreOutOfOrder) {
39 EXPECT_FALSE(TestParse("en-sw600dp-ldrtl"));
40 EXPECT_FALSE(TestParse("land-en"));
41 EXPECT_FALSE(TestParse("hdpi-320dpi"));
42}
43
44TEST(AaptConfigTest, ParseFailWhenQualifiersAreNotMatched) {
45 EXPECT_FALSE(TestParse("en-sw600dp-ILLEGAL"));
46}
47
48TEST(AaptConfigTest, ParseFailWhenQualifiersHaveTrailingDash) {
49 EXPECT_FALSE(TestParse("en-sw600dp-land-"));
50}
51
52TEST(AaptConfigTest, ParseBasicQualifiers) {
53 ConfigDescription config;
54 EXPECT_TRUE(TestParse("", &config));
55 EXPECT_EQ(String8(""), config.toString());
56
57 EXPECT_TRUE(TestParse("fr-land", &config));
58 EXPECT_EQ(String8("fr-land"), config.toString());
59
60 EXPECT_TRUE(TestParse("mcc310-pl-sw720dp-normal-long-port-night-"
61 "xhdpi-keyssoft-qwerty-navexposed-nonav", &config));
62 EXPECT_EQ(String8("mcc310-pl-sw720dp-normal-long-port-night-"
63 "xhdpi-keyssoft-qwerty-navexposed-nonav-v13"), config.toString());
64}
65
66TEST(AaptConfigTest, ParseLocales) {
67 ConfigDescription config;
68 EXPECT_TRUE(TestParse("en-rUS", &config));
Adam Lesinski8a9355a2015-03-10 16:55:43 -070069 EXPECT_EQ(String8("en-rUS"), config.toString());
Adam Lesinskifab50872014-04-16 14:40:42 -070070}
71
72TEST(AaptConfigTest, ParseQualifierAddedInApi13) {
73 ConfigDescription config;
74 EXPECT_TRUE(TestParse("sw600dp", &config));
75 EXPECT_EQ(String8("sw600dp-v13"), config.toString());
76
77 EXPECT_TRUE(TestParse("sw600dp-v8", &config));
78 EXPECT_EQ(String8("sw600dp-v13"), config.toString());
79}
Narayan Kamath7f1a8952015-02-10 16:11:55 +000080
81TEST(AaptConfigTest, TestParsingOfCarAttribute) {
82 ConfigDescription config;
83 EXPECT_TRUE(TestParse("car", &config));
84 EXPECT_EQ(android::ResTable_config::UI_MODE_TYPE_CAR, config.uiMode);
85}
Adam Lesinski2738c962015-05-14 14:25:36 -070086
87TEST(AaptConfigTest, TestParsingRoundQualifier) {
88 ConfigDescription config;
89 EXPECT_TRUE(TestParse("round", &config));
90 EXPECT_EQ(android::ResTable_config::SCREENROUND_YES,
91 config.screenLayout2 & android::ResTable_config::MASK_SCREENROUND);
92 EXPECT_EQ(SDK_MNC, config.sdkVersion);
93 EXPECT_EQ(String8("round-v23"), config.toString());
94
95 EXPECT_TRUE(TestParse("notround", &config));
96 EXPECT_EQ(android::ResTable_config::SCREENROUND_NO,
97 config.screenLayout2 & android::ResTable_config::MASK_SCREENROUND);
98 EXPECT_EQ(SDK_MNC, config.sdkVersion);
99 EXPECT_EQ(String8("notround-v23"), config.toString());
100}
Romain Guyc9ba5592017-01-18 16:34:42 -0800101
102TEST(AaptConfigTest, WideColorGamutQualifier) {
103 ConfigDescription config;
104 EXPECT_TRUE(TestParse("widecg", &config));
105 EXPECT_EQ(android::ResTable_config::WIDE_COLOR_GAMUT_YES,
Romain Guy48327452017-01-23 17:03:35 -0800106 config.colorMode & android::ResTable_config::MASK_WIDE_COLOR_GAMUT);
Romain Guyc9ba5592017-01-18 16:34:42 -0800107 EXPECT_EQ(SDK_O, config.sdkVersion);
108 EXPECT_EQ(String8("widecg-v26"), config.toString());
109
110 EXPECT_TRUE(TestParse("nowidecg", &config));
111 EXPECT_EQ(android::ResTable_config::WIDE_COLOR_GAMUT_NO,
Romain Guy48327452017-01-23 17:03:35 -0800112 config.colorMode & android::ResTable_config::MASK_WIDE_COLOR_GAMUT);
Romain Guyc9ba5592017-01-18 16:34:42 -0800113 EXPECT_EQ(SDK_O, config.sdkVersion);
114 EXPECT_EQ(String8("nowidecg-v26"), config.toString());
115}
116
117TEST(AaptConfigTest, HdrQualifier) {
118 ConfigDescription config;
119 EXPECT_TRUE(TestParse("highdr", &config));
120 EXPECT_EQ(android::ResTable_config::HDR_YES,
Romain Guy48327452017-01-23 17:03:35 -0800121 config.colorMode & android::ResTable_config::MASK_HDR);
Romain Guyc9ba5592017-01-18 16:34:42 -0800122 EXPECT_EQ(SDK_O, config.sdkVersion);
123 EXPECT_EQ(String8("highdr-v26"), config.toString());
124
125 EXPECT_TRUE(TestParse("lowdr", &config));
126 EXPECT_EQ(android::ResTable_config::HDR_NO,
Romain Guy48327452017-01-23 17:03:35 -0800127 config.colorMode & android::ResTable_config::MASK_HDR);
Romain Guyc9ba5592017-01-18 16:34:42 -0800128 EXPECT_EQ(SDK_O, config.sdkVersion);
129 EXPECT_EQ(String8("lowdr-v26"), config.toString());
130}