blob: 5eecc8f5fb20c37592dd5c8dd77d583f65644dd3 [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 Lesinskice5e56e2016-10-21 17:56:45 -070024 AAPT_ASSERT_FALSE(xml::ExtractPackageFromNamespace("com.android"));
25 AAPT_ASSERT_FALSE(
26 xml::ExtractPackageFromNamespace("http://schemas.android.com/apk"));
27 AAPT_ASSERT_FALSE(
28 xml::ExtractPackageFromNamespace("http://schemas.android.com/apk/res"));
29 AAPT_ASSERT_FALSE(
30 xml::ExtractPackageFromNamespace("http://schemas.android.com/apk/res/"));
31 AAPT_ASSERT_FALSE(xml::ExtractPackageFromNamespace(
32 "http://schemas.android.com/apk/prv/res/"));
Adam Lesinski467f1712015-11-16 17:35:44 -080033
Adam Lesinskice5e56e2016-10-21 17:56:45 -070034 Maybe<xml::ExtractedPackage> p =
35 xml::ExtractPackageFromNamespace("http://schemas.android.com/apk/res/a");
36 AAPT_ASSERT_TRUE(p);
37 EXPECT_EQ(std::string("a"), p.value().package);
38 EXPECT_FALSE(p.value().private_namespace);
Adam Lesinski467f1712015-11-16 17:35:44 -080039
Adam Lesinskice5e56e2016-10-21 17:56:45 -070040 p = xml::ExtractPackageFromNamespace(
41 "http://schemas.android.com/apk/prv/res/android");
42 AAPT_ASSERT_TRUE(p);
43 EXPECT_EQ(std::string("android"), p.value().package);
44 EXPECT_TRUE(p.value().private_namespace);
Adam Lesinski467f1712015-11-16 17:35:44 -080045
Adam Lesinskice5e56e2016-10-21 17:56:45 -070046 p = xml::ExtractPackageFromNamespace(
47 "http://schemas.android.com/apk/prv/res/com.test");
48 AAPT_ASSERT_TRUE(p);
49 EXPECT_EQ(std::string("com.test"), p.value().package);
50 EXPECT_TRUE(p.value().private_namespace);
Adam Lesinski467f1712015-11-16 17:35:44 -080051
Adam Lesinskice5e56e2016-10-21 17:56:45 -070052 p = xml::ExtractPackageFromNamespace(
53 "http://schemas.android.com/apk/res-auto");
54 AAPT_ASSERT_TRUE(p);
55 EXPECT_EQ(std::string(), p.value().package);
56 EXPECT_TRUE(p.value().private_namespace);
Adam Lesinski467f1712015-11-16 17:35:44 -080057}
58
Adam Lesinskice5e56e2016-10-21 17:56:45 -070059} // namespace aapt