blob: b7c6bd25a565fafd13fe4e16e17885b57390246a [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
24using android::String8;
25
26static ::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
33static ::testing::AssertionResult TestParse(const char* input, ConfigDescription* config=NULL) {
34 return TestParse(String8(input), config);
35}
36
37TEST(AaptConfigTest, ParseFailWhenQualifiersAreOutOfOrder) {
38 EXPECT_FALSE(TestParse("en-sw600dp-ldrtl"));
39 EXPECT_FALSE(TestParse("land-en"));
40 EXPECT_FALSE(TestParse("hdpi-320dpi"));
41}
42
43TEST(AaptConfigTest, ParseFailWhenQualifiersAreNotMatched) {
44 EXPECT_FALSE(TestParse("en-sw600dp-ILLEGAL"));
45}
46
47TEST(AaptConfigTest, ParseFailWhenQualifiersHaveTrailingDash) {
48 EXPECT_FALSE(TestParse("en-sw600dp-land-"));
49}
50
51TEST(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
65TEST(AaptConfigTest, ParseLocales) {
66 ConfigDescription config;
67 EXPECT_TRUE(TestParse("en-rUS", &config));
Adam Lesinski8a9355a2015-03-10 16:55:43 -070068 EXPECT_EQ(String8("en-rUS"), config.toString());
Adam Lesinskifab50872014-04-16 14:40:42 -070069}
70
71TEST(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}
Narayan Kamath7f1a8952015-02-10 16:11:55 +000079
80TEST(AaptConfigTest, TestParsingOfCarAttribute) {
81 ConfigDescription config;
82 EXPECT_TRUE(TestParse("car", &config));
83 EXPECT_EQ(android::ResTable_config::UI_MODE_TYPE_CAR, config.uiMode);
84}
Adam Lesinski2738c962015-05-14 14:25:36 -070085
86TEST(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}
Romain Guyc9ba5592017-01-18 16:34:42 -0800100
101TEST(AaptConfigTest, WideColorGamutQualifier) {
102 ConfigDescription config;
103 EXPECT_TRUE(TestParse("widecg", &config));
104 EXPECT_EQ(android::ResTable_config::WIDE_COLOR_GAMUT_YES,
Romain Guy4832745b2017-01-23 17:03:35 -0800105 config.colorMode & android::ResTable_config::MASK_WIDE_COLOR_GAMUT);
Romain Guyc9ba5592017-01-18 16:34:42 -0800106 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,
Romain Guy4832745b2017-01-23 17:03:35 -0800111 config.colorMode & android::ResTable_config::MASK_WIDE_COLOR_GAMUT);
Romain Guyc9ba5592017-01-18 16:34:42 -0800112 EXPECT_EQ(SDK_O, config.sdkVersion);
113 EXPECT_EQ(String8("nowidecg-v26"), config.toString());
114}
115
116TEST(AaptConfigTest, HdrQualifier) {
117 ConfigDescription config;
118 EXPECT_TRUE(TestParse("highdr", &config));
119 EXPECT_EQ(android::ResTable_config::HDR_YES,
Romain Guy4832745b2017-01-23 17:03:35 -0800120 config.colorMode & android::ResTable_config::MASK_HDR);
Romain Guyc9ba5592017-01-18 16:34:42 -0800121 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,
Romain Guy4832745b2017-01-23 17:03:35 -0800126 config.colorMode & android::ResTable_config::MASK_HDR);
Romain Guyc9ba5592017-01-18 16:34:42 -0800127 EXPECT_EQ(SDK_O, config.sdkVersion);
128 EXPECT_EQ(String8("lowdr-v26"), config.toString());
Steven Moreland4351d262020-02-26 09:02:08 -0800129}