• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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"
22 #include "SdkConstants.h"
23 
24 using android::String8;
25 
TestParse(const String8 & input,ConfigDescription * config=NULL)26 static ::testing::AssertionResult TestParse(const String8& input, ConfigDescription* config=NULL) {
27     if (AaptConfig::parse(String8(input), config)) {
28         return ::testing::AssertionSuccess() << input << " was successfully parsed";
29     }
30     return ::testing::AssertionFailure() << input << " could not be parsed";
31 }
32 
TestParse(const char * input,ConfigDescription * config=NULL)33 static ::testing::AssertionResult TestParse(const char* input, ConfigDescription* config=NULL) {
34     return TestParse(String8(input), config);
35 }
36 
TEST(AaptConfigTest,ParseFailWhenQualifiersAreOutOfOrder)37 TEST(AaptConfigTest, ParseFailWhenQualifiersAreOutOfOrder) {
38     EXPECT_FALSE(TestParse("en-sw600dp-ldrtl"));
39     EXPECT_FALSE(TestParse("land-en"));
40     EXPECT_FALSE(TestParse("hdpi-320dpi"));
41 }
42 
TEST(AaptConfigTest,ParseFailWhenQualifiersAreNotMatched)43 TEST(AaptConfigTest, ParseFailWhenQualifiersAreNotMatched) {
44     EXPECT_FALSE(TestParse("en-sw600dp-ILLEGAL"));
45 }
46 
TEST(AaptConfigTest,ParseFailWhenQualifiersHaveTrailingDash)47 TEST(AaptConfigTest, ParseFailWhenQualifiersHaveTrailingDash) {
48     EXPECT_FALSE(TestParse("en-sw600dp-land-"));
49 }
50 
TEST(AaptConfigTest,ParseBasicQualifiers)51 TEST(AaptConfigTest, ParseBasicQualifiers) {
52     ConfigDescription config;
53     EXPECT_TRUE(TestParse("", &config));
54     EXPECT_EQ(String8(""), config.toString());
55 
56     EXPECT_TRUE(TestParse("fr-land", &config));
57     EXPECT_EQ(String8("fr-land"), config.toString());
58 
59     EXPECT_TRUE(TestParse("mcc310-pl-sw720dp-normal-long-port-night-"
60                 "xhdpi-keyssoft-qwerty-navexposed-nonav", &config));
61     EXPECT_EQ(String8("mcc310-pl-sw720dp-normal-long-port-night-"
62                 "xhdpi-keyssoft-qwerty-navexposed-nonav-v13"), config.toString());
63 }
64 
TEST(AaptConfigTest,ParseLocales)65 TEST(AaptConfigTest, ParseLocales) {
66     ConfigDescription config;
67     EXPECT_TRUE(TestParse("en-rUS", &config));
68     EXPECT_EQ(String8("en-rUS"), config.toString());
69 }
70 
TEST(AaptConfigTest,ParseQualifierAddedInApi13)71 TEST(AaptConfigTest, ParseQualifierAddedInApi13) {
72     ConfigDescription config;
73     EXPECT_TRUE(TestParse("sw600dp", &config));
74     EXPECT_EQ(String8("sw600dp-v13"), config.toString());
75 
76     EXPECT_TRUE(TestParse("sw600dp-v8", &config));
77     EXPECT_EQ(String8("sw600dp-v13"), config.toString());
78 }
79 
TEST(AaptConfigTest,TestParsingOfCarAttribute)80 TEST(AaptConfigTest, TestParsingOfCarAttribute) {
81     ConfigDescription config;
82     EXPECT_TRUE(TestParse("car", &config));
83     EXPECT_EQ(android::ResTable_config::UI_MODE_TYPE_CAR, config.uiMode);
84 }
85 
TEST(AaptConfigTest,TestParsingRoundQualifier)86 TEST(AaptConfigTest, TestParsingRoundQualifier) {
87     ConfigDescription config;
88     EXPECT_TRUE(TestParse("round", &config));
89     EXPECT_EQ(android::ResTable_config::SCREENROUND_YES,
90               config.screenLayout2 & android::ResTable_config::MASK_SCREENROUND);
91     EXPECT_EQ(SDK_MNC, config.sdkVersion);
92     EXPECT_EQ(String8("round-v23"), config.toString());
93 
94     EXPECT_TRUE(TestParse("notround", &config));
95     EXPECT_EQ(android::ResTable_config::SCREENROUND_NO,
96               config.screenLayout2 & android::ResTable_config::MASK_SCREENROUND);
97     EXPECT_EQ(SDK_MNC, config.sdkVersion);
98     EXPECT_EQ(String8("notround-v23"), config.toString());
99 }
100 
TEST(AaptConfigTest,WideColorGamutQualifier)101 TEST(AaptConfigTest, WideColorGamutQualifier) {
102     ConfigDescription config;
103     EXPECT_TRUE(TestParse("widecg", &config));
104     EXPECT_EQ(android::ResTable_config::WIDE_COLOR_GAMUT_YES,
105               config.colorMode & android::ResTable_config::MASK_WIDE_COLOR_GAMUT);
106     EXPECT_EQ(SDK_O, config.sdkVersion);
107     EXPECT_EQ(String8("widecg-v26"), config.toString());
108 
109     EXPECT_TRUE(TestParse("nowidecg", &config));
110     EXPECT_EQ(android::ResTable_config::WIDE_COLOR_GAMUT_NO,
111               config.colorMode & android::ResTable_config::MASK_WIDE_COLOR_GAMUT);
112     EXPECT_EQ(SDK_O, config.sdkVersion);
113     EXPECT_EQ(String8("nowidecg-v26"), config.toString());
114 }
115 
TEST(AaptConfigTest,HdrQualifier)116 TEST(AaptConfigTest, HdrQualifier) {
117     ConfigDescription config;
118     EXPECT_TRUE(TestParse("highdr", &config));
119     EXPECT_EQ(android::ResTable_config::HDR_YES,
120               config.colorMode & android::ResTable_config::MASK_HDR);
121     EXPECT_EQ(SDK_O, config.sdkVersion);
122     EXPECT_EQ(String8("highdr-v26"), config.toString());
123 
124     EXPECT_TRUE(TestParse("lowdr", &config));
125     EXPECT_EQ(android::ResTable_config::HDR_NO,
126               config.colorMode & android::ResTable_config::MASK_HDR);
127     EXPECT_EQ(SDK_O, config.sdkVersion);
128     EXPECT_EQ(String8("lowdr-v26"), config.toString());
129 }
130