Adam Lesinski | fab5087 | 2014-04-16 14:40:42 -0700 | [diff] [blame] | 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" |
Adam Lesinski | 2738c96 | 2015-05-14 14:25:36 -0700 | [diff] [blame] | 22 | #include "SdkConstants.h" |
Adam Lesinski | fab5087 | 2014-04-16 14:40:42 -0700 | [diff] [blame] | 23 | #include "TestHelper.h" |
| 24 | |
| 25 | using android::String8; |
| 26 | |
| 27 | static ::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 | |
| 34 | static ::testing::AssertionResult TestParse(const char* input, ConfigDescription* config=NULL) { |
| 35 | return TestParse(String8(input), config); |
| 36 | } |
| 37 | |
| 38 | TEST(AaptConfigTest, ParseFailWhenQualifiersAreOutOfOrder) { |
| 39 | EXPECT_FALSE(TestParse("en-sw600dp-ldrtl")); |
| 40 | EXPECT_FALSE(TestParse("land-en")); |
| 41 | EXPECT_FALSE(TestParse("hdpi-320dpi")); |
| 42 | } |
| 43 | |
| 44 | TEST(AaptConfigTest, ParseFailWhenQualifiersAreNotMatched) { |
| 45 | EXPECT_FALSE(TestParse("en-sw600dp-ILLEGAL")); |
| 46 | } |
| 47 | |
| 48 | TEST(AaptConfigTest, ParseFailWhenQualifiersHaveTrailingDash) { |
| 49 | EXPECT_FALSE(TestParse("en-sw600dp-land-")); |
| 50 | } |
| 51 | |
| 52 | TEST(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 | |
| 66 | TEST(AaptConfigTest, ParseLocales) { |
| 67 | ConfigDescription config; |
| 68 | EXPECT_TRUE(TestParse("en-rUS", &config)); |
Adam Lesinski | 8a9355a | 2015-03-10 16:55:43 -0700 | [diff] [blame] | 69 | EXPECT_EQ(String8("en-rUS"), config.toString()); |
Adam Lesinski | fab5087 | 2014-04-16 14:40:42 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | TEST(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 Kamath | 7f1a895 | 2015-02-10 16:11:55 +0000 | [diff] [blame] | 80 | |
| 81 | TEST(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 Lesinski | 2738c96 | 2015-05-14 14:25:36 -0700 | [diff] [blame] | 86 | |
| 87 | TEST(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 Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 101 | |
| 102 | TEST(AaptConfigTest, WideColorGamutQualifier) { |
| 103 | ConfigDescription config; |
| 104 | EXPECT_TRUE(TestParse("widecg", &config)); |
| 105 | EXPECT_EQ(android::ResTable_config::WIDE_COLOR_GAMUT_YES, |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 106 | config.colorMode & android::ResTable_config::MASK_WIDE_COLOR_GAMUT); |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 107 | 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 Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 112 | config.colorMode & android::ResTable_config::MASK_WIDE_COLOR_GAMUT); |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 113 | EXPECT_EQ(SDK_O, config.sdkVersion); |
| 114 | EXPECT_EQ(String8("nowidecg-v26"), config.toString()); |
| 115 | } |
| 116 | |
| 117 | TEST(AaptConfigTest, HdrQualifier) { |
| 118 | ConfigDescription config; |
| 119 | EXPECT_TRUE(TestParse("highdr", &config)); |
| 120 | EXPECT_EQ(android::ResTable_config::HDR_YES, |
Romain Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 121 | config.colorMode & android::ResTable_config::MASK_HDR); |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 122 | 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 Guy | 4832745 | 2017-01-23 17:03:35 -0800 | [diff] [blame] | 127 | config.colorMode & android::ResTable_config::MASK_HDR); |
Romain Guy | c9ba559 | 2017-01-18 16:34:42 -0800 | [diff] [blame] | 128 | EXPECT_EQ(SDK_O, config.sdkVersion); |
| 129 | EXPECT_EQ(String8("lowdr-v26"), config.toString()); |
| 130 | } |