blob: 7b6ce9e96689dfac5f91bfb75ae361247ac4d7dc [file] [log] [blame]
Adam Lesinski467f1712015-11-16 17:35:44 -08001/*
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
Adam Lesinski467f1712015-11-16 17:35:44 -080017#include "xml/XmlUtil.h"
18
Adam Lesinskice5e56e2016-10-21 17:56:45 -070019#include "test/Test.h"
20
Adam Lesinski467f1712015-11-16 17:35:44 -080021namespace aapt {
22
23TEST(XmlUtilTest, ExtractPackageFromNamespace) {
Adam Lesinskia45893a2017-05-30 15:19:02 -070024 ASSERT_FALSE(xml::ExtractPackageFromNamespace("com.android"));
25 ASSERT_FALSE(xml::ExtractPackageFromNamespace("http://schemas.android.com/apk"));
26 ASSERT_FALSE(xml::ExtractPackageFromNamespace("http://schemas.android.com/apk/res"));
27 ASSERT_FALSE(xml::ExtractPackageFromNamespace("http://schemas.android.com/apk/res/"));
28 ASSERT_FALSE(xml::ExtractPackageFromNamespace("http://schemas.android.com/apk/prv/res/"));
Adam Lesinski467f1712015-11-16 17:35:44 -080029
Ryan Mitchell4382e442021-07-14 12:53:01 -070030 std::optional<xml::ExtractedPackage> p =
Adam Lesinskice5e56e2016-10-21 17:56:45 -070031 xml::ExtractPackageFromNamespace("http://schemas.android.com/apk/res/a");
Adam Lesinskia45893a2017-05-30 15:19:02 -070032 ASSERT_TRUE(p);
Adam Lesinskice5e56e2016-10-21 17:56:45 -070033 EXPECT_EQ(std::string("a"), p.value().package);
34 EXPECT_FALSE(p.value().private_namespace);
Adam Lesinski467f1712015-11-16 17:35:44 -080035
Adam Lesinskia45893a2017-05-30 15:19:02 -070036 p = xml::ExtractPackageFromNamespace("http://schemas.android.com/apk/prv/res/android");
37 ASSERT_TRUE(p);
Adam Lesinskice5e56e2016-10-21 17:56:45 -070038 EXPECT_EQ(std::string("android"), p.value().package);
39 EXPECT_TRUE(p.value().private_namespace);
Adam Lesinski467f1712015-11-16 17:35:44 -080040
Adam Lesinskia45893a2017-05-30 15:19:02 -070041 p = xml::ExtractPackageFromNamespace("http://schemas.android.com/apk/prv/res/com.test");
42 ASSERT_TRUE(p);
Adam Lesinskice5e56e2016-10-21 17:56:45 -070043 EXPECT_EQ(std::string("com.test"), p.value().package);
44 EXPECT_TRUE(p.value().private_namespace);
Adam Lesinski467f1712015-11-16 17:35:44 -080045
Adam Lesinskia45893a2017-05-30 15:19:02 -070046 p = xml::ExtractPackageFromNamespace("http://schemas.android.com/apk/res-auto");
47 ASSERT_TRUE(p);
Adam Lesinskice5e56e2016-10-21 17:56:45 -070048 EXPECT_EQ(std::string(), p.value().package);
49 EXPECT_TRUE(p.value().private_namespace);
Adam Lesinski467f1712015-11-16 17:35:44 -080050}
51
Adam Lesinskice5e56e2016-10-21 17:56:45 -070052} // namespace aapt