XmlUtil_test.cpp revision 467f171315f9c2037fcd3eb5edcfabc40671bf7b
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 "test/Common.h"
18#include "xml/XmlUtil.h"
19
20#include <gtest/gtest.h>
21
22namespace aapt {
23
24TEST(XmlUtilTest, ExtractPackageFromNamespace) {
25    AAPT_ASSERT_FALSE(xml::extractPackageFromNamespace(u"com.android"));
26    AAPT_ASSERT_FALSE(xml::extractPackageFromNamespace(u"http://schemas.android.com/apk"));
27    AAPT_ASSERT_FALSE(xml::extractPackageFromNamespace(u"http://schemas.android.com/apk/res"));
28    AAPT_ASSERT_FALSE(xml::extractPackageFromNamespace(u"http://schemas.android.com/apk/res/"));
29    AAPT_ASSERT_FALSE(xml::extractPackageFromNamespace(
30            u"http://schemas.android.com/apk/prv/res/"));
31
32    Maybe<xml::ExtractedPackage> p =
33            xml::extractPackageFromNamespace(u"http://schemas.android.com/apk/res/a");
34    AAPT_ASSERT_TRUE(p);
35    EXPECT_EQ(std::u16string(u"a"), p.value().package);
36    EXPECT_EQ(false, p.value().privateNamespace);
37
38    p = xml::extractPackageFromNamespace(u"http://schemas.android.com/apk/prv/res/android");
39    AAPT_ASSERT_TRUE(p);
40    EXPECT_EQ(std::u16string(u"android"), p.value().package);
41    EXPECT_EQ(true, p.value().privateNamespace);
42
43    p = xml::extractPackageFromNamespace(u"http://schemas.android.com/apk/prv/res/com.test");
44    AAPT_ASSERT_TRUE(p);
45    EXPECT_EQ(std::u16string(u"com.test"), p.value().package);
46    EXPECT_EQ(true, p.value().privateNamespace);
47
48    p = xml::extractPackageFromNamespace(u"http://schemas.android.com/apk/res-auto");
49    AAPT_ASSERT_TRUE(p);
50    EXPECT_EQ(std::u16string(), p.value().package);
51    EXPECT_EQ(true, p.value().privateNamespace);
52}
53
54} // namespace aapt
55