Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 1 | /* |
| 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 "ConfigDescription.h" |
Adam Lesinski | 6425497 | 2015-11-03 16:16:17 -0800 | [diff] [blame] | 18 | #include "SdkConstants.h" |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame^] | 19 | #include "test/Test.h" |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 20 | #include "util/StringPiece.h" |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 21 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 22 | #include <string> |
| 23 | |
| 24 | namespace aapt { |
| 25 | |
| 26 | static ::testing::AssertionResult TestParse(const StringPiece& input, |
| 27 | ConfigDescription* config = nullptr) { |
| 28 | if (ConfigDescription::parse(input, config)) { |
| 29 | return ::testing::AssertionSuccess() << input << " was successfully parsed"; |
| 30 | } |
| 31 | return ::testing::AssertionFailure() << input << " could not be parsed"; |
| 32 | } |
| 33 | |
| 34 | TEST(ConfigDescriptionTest, ParseFailWhenQualifiersAreOutOfOrder) { |
| 35 | EXPECT_FALSE(TestParse("en-sw600dp-ldrtl")); |
| 36 | EXPECT_FALSE(TestParse("land-en")); |
| 37 | EXPECT_FALSE(TestParse("hdpi-320dpi")); |
| 38 | } |
| 39 | |
| 40 | TEST(ConfigDescriptionTest, ParseFailWhenQualifiersAreNotMatched) { |
| 41 | EXPECT_FALSE(TestParse("en-sw600dp-ILLEGAL")); |
| 42 | } |
| 43 | |
| 44 | TEST(ConfigDescriptionTest, ParseFailWhenQualifiersHaveTrailingDash) { |
| 45 | EXPECT_FALSE(TestParse("en-sw600dp-land-")); |
| 46 | } |
| 47 | |
| 48 | TEST(ConfigDescriptionTest, ParseBasicQualifiers) { |
| 49 | ConfigDescription config; |
| 50 | EXPECT_TRUE(TestParse("", &config)); |
| 51 | EXPECT_EQ(std::string(""), config.toString().string()); |
| 52 | |
| 53 | EXPECT_TRUE(TestParse("fr-land", &config)); |
| 54 | EXPECT_EQ(std::string("fr-land"), config.toString().string()); |
| 55 | |
| 56 | EXPECT_TRUE(TestParse("mcc310-pl-sw720dp-normal-long-port-night-" |
| 57 | "xhdpi-keyssoft-qwerty-navexposed-nonav", &config)); |
| 58 | EXPECT_EQ(std::string("mcc310-pl-sw720dp-normal-long-port-night-" |
| 59 | "xhdpi-keyssoft-qwerty-navexposed-nonav-v13"), config.toString().string()); |
| 60 | } |
| 61 | |
| 62 | TEST(ConfigDescriptionTest, ParseLocales) { |
| 63 | ConfigDescription config; |
| 64 | EXPECT_TRUE(TestParse("en-rUS", &config)); |
| 65 | EXPECT_EQ(std::string("en-rUS"), config.toString().string()); |
| 66 | } |
| 67 | |
| 68 | TEST(ConfigDescriptionTest, ParseQualifierAddedInApi13) { |
| 69 | ConfigDescription config; |
| 70 | EXPECT_TRUE(TestParse("sw600dp", &config)); |
| 71 | EXPECT_EQ(std::string("sw600dp-v13"), config.toString().string()); |
| 72 | |
| 73 | EXPECT_TRUE(TestParse("sw600dp-v8", &config)); |
| 74 | EXPECT_EQ(std::string("sw600dp-v13"), config.toString().string()); |
| 75 | } |
| 76 | |
| 77 | TEST(ConfigDescriptionTest, ParseCarAttribute) { |
| 78 | ConfigDescription config; |
| 79 | EXPECT_TRUE(TestParse("car", &config)); |
| 80 | EXPECT_EQ(android::ResTable_config::UI_MODE_TYPE_CAR, config.uiMode); |
| 81 | } |
| 82 | |
Adam Lesinski | 6425497 | 2015-11-03 16:16:17 -0800 | [diff] [blame] | 83 | TEST(ConfigDescriptionTest, TestParsingRoundQualifier) { |
| 84 | ConfigDescription config; |
| 85 | EXPECT_TRUE(TestParse("round", &config)); |
| 86 | EXPECT_EQ(android::ResTable_config::SCREENROUND_YES, |
| 87 | config.screenLayout2 & android::ResTable_config::MASK_SCREENROUND); |
| 88 | EXPECT_EQ(SDK_MARSHMALLOW, config.sdkVersion); |
| 89 | EXPECT_EQ(std::string("round-v23"), config.toString().string()); |
| 90 | |
| 91 | EXPECT_TRUE(TestParse("notround", &config)); |
| 92 | EXPECT_EQ(android::ResTable_config::SCREENROUND_NO, |
| 93 | config.screenLayout2 & android::ResTable_config::MASK_SCREENROUND); |
| 94 | EXPECT_EQ(SDK_MARSHMALLOW, config.sdkVersion); |
| 95 | EXPECT_EQ(std::string("notround-v23"), config.toString().string()); |
| 96 | } |
| 97 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 98 | } // namespace aapt |