Donald Chai | b8f078c | 2017-10-18 23:51:18 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 "Util.h" |
| 18 | |
| 19 | #include "AppInfo.h" |
| 20 | #include "split/TableSplitter.h" |
Ryan Mitchell | 5fa2bb1 | 2018-07-12 11:24:51 -0700 | [diff] [blame^] | 21 | #include "test/Builders.h" |
Donald Chai | b8f078c | 2017-10-18 23:51:18 -0700 | [diff] [blame] | 22 | #include "test/Test.h" |
| 23 | |
| 24 | namespace aapt { |
| 25 | |
| 26 | TEST(UtilTest, SplitNamesAreSanitized) { |
| 27 | AppInfo app_info{"com.pkg"}; |
Donald Chai | 414e48a | 2017-11-09 21:06:52 -0800 | [diff] [blame] | 28 | SplitConstraints split_constraints{ |
| 29 | {test::ParseConfigOrDie("en-rUS-land"), test::ParseConfigOrDie("b+sr+Latn")}}; |
Donald Chai | b8f078c | 2017-10-18 23:51:18 -0700 | [diff] [blame] | 30 | |
| 31 | const auto doc = GenerateSplitManifest(app_info, split_constraints); |
| 32 | const auto &root = doc->root; |
| 33 | EXPECT_EQ(root->name, "manifest"); |
Donald Chai | 414e48a | 2017-11-09 21:06:52 -0800 | [diff] [blame] | 34 | // split names cannot contain hyphens or plus signs. |
| 35 | EXPECT_EQ(root->FindAttribute("", "split")->value, "config.b_sr_Latn_en_rUS_land"); |
Donald Chai | b8f078c | 2017-10-18 23:51:18 -0700 | [diff] [blame] | 36 | // but we should use resource qualifiers verbatim in 'targetConfig'. |
Donald Chai | 414e48a | 2017-11-09 21:06:52 -0800 | [diff] [blame] | 37 | EXPECT_EQ(root->FindAttribute("", "targetConfig")->value, "b+sr+Latn,en-rUS-land"); |
Donald Chai | b8f078c | 2017-10-18 23:51:18 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Ryan Mitchell | 5fa2bb1 | 2018-07-12 11:24:51 -0700 | [diff] [blame^] | 40 | TEST (UtilTest, LongVersionCodeDefined) { |
| 41 | auto doc = test::BuildXmlDom(R"( |
| 42 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" |
| 43 | package="com.android.aapt.test" android:versionCode="0x1" android:versionCodeMajor="0x1"> |
| 44 | </manifest>)"); |
| 45 | SetLongVersionCode(doc->root.get(), 42); |
| 46 | |
| 47 | auto version_code = doc->root->FindAttribute(xml::kSchemaAndroid, "versionCode"); |
| 48 | ASSERT_NE(version_code, nullptr); |
| 49 | EXPECT_EQ(version_code->value, "0x0000002a"); |
| 50 | |
| 51 | ASSERT_NE(version_code->compiled_value, nullptr); |
| 52 | auto compiled_version_code = ValueCast<BinaryPrimitive>(version_code->compiled_value.get()); |
| 53 | ASSERT_NE(compiled_version_code, nullptr); |
| 54 | EXPECT_EQ(compiled_version_code->value.data, 42U); |
| 55 | |
| 56 | auto version_code_major = doc->root->FindAttribute(xml::kSchemaAndroid, "versionCodeMajor"); |
| 57 | EXPECT_EQ(version_code_major, nullptr); |
| 58 | } |
| 59 | |
| 60 | TEST (UtilTest, LongVersionCodeUndefined) { |
| 61 | auto doc = test::BuildXmlDom(R"( |
| 62 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" |
| 63 | package="com.android.aapt.test"> |
| 64 | </manifest>)"); |
| 65 | SetLongVersionCode(doc->root.get(), 420000000000); |
| 66 | |
| 67 | auto version_code = doc->root->FindAttribute(xml::kSchemaAndroid, "versionCode"); |
| 68 | ASSERT_NE(version_code, nullptr); |
| 69 | EXPECT_EQ(version_code->value, "0xc9f36800"); |
| 70 | |
| 71 | ASSERT_NE(version_code->compiled_value, nullptr); |
| 72 | auto compiled_version_code = ValueCast<BinaryPrimitive>(version_code->compiled_value.get()); |
| 73 | ASSERT_NE(compiled_version_code, nullptr); |
| 74 | EXPECT_EQ(compiled_version_code->value.data, 0xc9f36800); |
| 75 | |
| 76 | auto version_code_major = doc->root->FindAttribute(xml::kSchemaAndroid, "versionCodeMajor"); |
| 77 | ASSERT_NE(version_code_major, nullptr); |
| 78 | EXPECT_EQ(version_code_major->value, "0x00000061"); |
| 79 | |
| 80 | ASSERT_NE(version_code_major->compiled_value, nullptr); |
| 81 | auto compiled_version_code_major = ValueCast<BinaryPrimitive>( |
| 82 | version_code_major->compiled_value.get()); |
| 83 | ASSERT_NE(compiled_version_code_major, nullptr); |
| 84 | EXPECT_EQ(compiled_version_code_major->value.data, 0x61); |
| 85 | } |
| 86 | |
Donald Chai | b8f078c | 2017-10-18 23:51:18 -0700 | [diff] [blame] | 87 | } // namespace aapt |