blob: b9fb5b2868a781abec1bc23435daa15cb5f00df2 [file] [log] [blame]
Donald Chaib8f078c2017-10-18 23:51:18 -07001/*
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 Mitchell5fa2bb12018-07-12 11:24:51 -070021#include "test/Builders.h"
Donald Chaib8f078c2017-10-18 23:51:18 -070022#include "test/Test.h"
23
24namespace aapt {
25
26TEST(UtilTest, SplitNamesAreSanitized) {
27 AppInfo app_info{"com.pkg"};
Donald Chai414e48a2017-11-09 21:06:52 -080028 SplitConstraints split_constraints{
29 {test::ParseConfigOrDie("en-rUS-land"), test::ParseConfigOrDie("b+sr+Latn")}};
Donald Chaib8f078c2017-10-18 23:51:18 -070030
31 const auto doc = GenerateSplitManifest(app_info, split_constraints);
32 const auto &root = doc->root;
33 EXPECT_EQ(root->name, "manifest");
Donald Chai414e48a2017-11-09 21:06:52 -080034 // split names cannot contain hyphens or plus signs.
35 EXPECT_EQ(root->FindAttribute("", "split")->value, "config.b_sr_Latn_en_rUS_land");
Donald Chaib8f078c2017-10-18 23:51:18 -070036 // but we should use resource qualifiers verbatim in 'targetConfig'.
Donald Chai414e48a2017-11-09 21:06:52 -080037 EXPECT_EQ(root->FindAttribute("", "targetConfig")->value, "b+sr+Latn,en-rUS-land");
Donald Chaib8f078c2017-10-18 23:51:18 -070038}
39
Ryan Mitchell5fa2bb12018-07-12 11:24:51 -070040TEST (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
60TEST (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 Chaib8f078c2017-10-18 23:51:18 -070087} // namespace aapt