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 "xml/XmlUtil.h"
18 
19 #include "test/Test.h"
20 
21 namespace aapt {
22 
TEST(XmlUtilTest,ExtractPackageFromNamespace)23 TEST(XmlUtilTest, ExtractPackageFromNamespace) {
24   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/"));
29 
30   Maybe<xml::ExtractedPackage> p =
31       xml::ExtractPackageFromNamespace("http://schemas.android.com/apk/res/a");
32   ASSERT_TRUE(p);
33   EXPECT_EQ(std::string("a"), p.value().package);
34   EXPECT_FALSE(p.value().private_namespace);
35 
36   p = xml::ExtractPackageFromNamespace("http://schemas.android.com/apk/prv/res/android");
37   ASSERT_TRUE(p);
38   EXPECT_EQ(std::string("android"), p.value().package);
39   EXPECT_TRUE(p.value().private_namespace);
40 
41   p = xml::ExtractPackageFromNamespace("http://schemas.android.com/apk/prv/res/com.test");
42   ASSERT_TRUE(p);
43   EXPECT_EQ(std::string("com.test"), p.value().package);
44   EXPECT_TRUE(p.value().private_namespace);
45 
46   p = xml::ExtractPackageFromNamespace("http://schemas.android.com/apk/res-auto");
47   ASSERT_TRUE(p);
48   EXPECT_EQ(std::string(), p.value().package);
49   EXPECT_TRUE(p.value().private_namespace);
50 }
51 
52 }  // namespace aapt
53