blob: 319e7707d8745dabd1eb9e4bf8dbbe98bb264006 [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
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);
Adam Lesinski803c7c82016-04-06 16:09:43 -070036 EXPECT_FALSE(p.value().privateNamespace);
Adam Lesinski467f1712015-11-16 17:35:44 -080037
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);
Adam Lesinski803c7c82016-04-06 16:09:43 -070041 EXPECT_TRUE(p.value().privateNamespace);
Adam Lesinski467f1712015-11-16 17:35:44 -080042
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);
Adam Lesinski803c7c82016-04-06 16:09:43 -070046 EXPECT_TRUE(p.value().privateNamespace);
Adam Lesinski467f1712015-11-16 17:35:44 -080047
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);
Adam Lesinski803c7c82016-04-06 16:09:43 -070051 EXPECT_TRUE(p.value().privateNamespace);
Adam Lesinski467f1712015-11-16 17:35:44 -080052}
53
54} // namespace aapt