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