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
21namespace aapt {
22
23TEST(XmlUtilTest, ExtractPackageFromNamespace) {
24  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/"));
33
34  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);
39
40  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);
45
46  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);
51
52  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);
57}
58
59}  // namespace aapt
60