blob: cbeb8bcda9e0a0aa650631347c4b6c7d85aee916 [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 Lesinskid0f116b2016-07-08 15:00:32 -070017#include "test/Test.h"
Adam Lesinski467f1712015-11-16 17:35:44 -080018#include "xml/XmlUtil.h"
19
Adam Lesinski467f1712015-11-16 17:35:44 -080020namespace aapt {
21
22TEST(XmlUtilTest, ExtractPackageFromNamespace) {
Adam Lesinskid0f116b2016-07-08 15:00:32 -070023 AAPT_ASSERT_FALSE(xml::extractPackageFromNamespace("com.android"));
24 AAPT_ASSERT_FALSE(xml::extractPackageFromNamespace("http://schemas.android.com/apk"));
25 AAPT_ASSERT_FALSE(xml::extractPackageFromNamespace("http://schemas.android.com/apk/res"));
26 AAPT_ASSERT_FALSE(xml::extractPackageFromNamespace("http://schemas.android.com/apk/res/"));
27 AAPT_ASSERT_FALSE(xml::extractPackageFromNamespace("http://schemas.android.com/apk/prv/res/"));
Adam Lesinski467f1712015-11-16 17:35:44 -080028
29 Maybe<xml::ExtractedPackage> p =
Adam Lesinskid0f116b2016-07-08 15:00:32 -070030 xml::extractPackageFromNamespace("http://schemas.android.com/apk/res/a");
Adam Lesinski467f1712015-11-16 17:35:44 -080031 AAPT_ASSERT_TRUE(p);
Adam Lesinskid0f116b2016-07-08 15:00:32 -070032 EXPECT_EQ(std::string("a"), p.value().package);
Adam Lesinski803c7c82016-04-06 16:09:43 -070033 EXPECT_FALSE(p.value().privateNamespace);
Adam Lesinski467f1712015-11-16 17:35:44 -080034
Adam Lesinskid0f116b2016-07-08 15:00:32 -070035 p = xml::extractPackageFromNamespace("http://schemas.android.com/apk/prv/res/android");
Adam Lesinski467f1712015-11-16 17:35:44 -080036 AAPT_ASSERT_TRUE(p);
Adam Lesinskid0f116b2016-07-08 15:00:32 -070037 EXPECT_EQ(std::string("android"), p.value().package);
Adam Lesinski803c7c82016-04-06 16:09:43 -070038 EXPECT_TRUE(p.value().privateNamespace);
Adam Lesinski467f1712015-11-16 17:35:44 -080039
Adam Lesinskid0f116b2016-07-08 15:00:32 -070040 p = xml::extractPackageFromNamespace("http://schemas.android.com/apk/prv/res/com.test");
Adam Lesinski467f1712015-11-16 17:35:44 -080041 AAPT_ASSERT_TRUE(p);
Adam Lesinskid0f116b2016-07-08 15:00:32 -070042 EXPECT_EQ(std::string("com.test"), p.value().package);
Adam Lesinski803c7c82016-04-06 16:09:43 -070043 EXPECT_TRUE(p.value().privateNamespace);
Adam Lesinski467f1712015-11-16 17:35:44 -080044
Adam Lesinskid0f116b2016-07-08 15:00:32 -070045 p = xml::extractPackageFromNamespace("http://schemas.android.com/apk/res-auto");
Adam Lesinski467f1712015-11-16 17:35:44 -080046 AAPT_ASSERT_TRUE(p);
Adam Lesinskid0f116b2016-07-08 15:00:32 -070047 EXPECT_EQ(std::string(), p.value().package);
Adam Lesinski803c7c82016-04-06 16:09:43 -070048 EXPECT_TRUE(p.value().privateNamespace);
Adam Lesinski467f1712015-11-16 17:35:44 -080049}
50
51} // namespace aapt