XmlUtil_test.cpp revision ce5e56e243d262a9b65459c3bd0bb9eaadd40628
1467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski/* 2467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski * Copyright (C) 2015 The Android Open Source Project 3467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski * 4467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski * Licensed under the Apache License, Version 2.0 (the "License"); 5467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski * you may not use this file except in compliance with the License. 6467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski * You may obtain a copy of the License at 7467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski * 8467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski * http://www.apache.org/licenses/LICENSE-2.0 9467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski * 10467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski * Unless required by applicable law or agreed to in writing, software 11467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski * distributed under the License is distributed on an "AS IS" BASIS, 12467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski * See the License for the specific language governing permissions and 14467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski * limitations under the License. 15467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski */ 16467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski 17467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski#include "xml/XmlUtil.h" 18467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski 19ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski#include "test/Test.h" 20ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski 21467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinskinamespace aapt { 22467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski 23467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam LesinskiTEST(XmlUtilTest, ExtractPackageFromNamespace) { 24ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski AAPT_ASSERT_FALSE(xml::ExtractPackageFromNamespace("com.android")); 25ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski AAPT_ASSERT_FALSE( 26ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski xml::ExtractPackageFromNamespace("http://schemas.android.com/apk")); 27ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski AAPT_ASSERT_FALSE( 28ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski xml::ExtractPackageFromNamespace("http://schemas.android.com/apk/res")); 29ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski AAPT_ASSERT_FALSE( 30ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski xml::ExtractPackageFromNamespace("http://schemas.android.com/apk/res/")); 31ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski AAPT_ASSERT_FALSE(xml::ExtractPackageFromNamespace( 32ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski "http://schemas.android.com/apk/prv/res/")); 33ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski 34ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski Maybe<xml::ExtractedPackage> p = 35ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski xml::ExtractPackageFromNamespace("http://schemas.android.com/apk/res/a"); 36ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski AAPT_ASSERT_TRUE(p); 37ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski EXPECT_EQ(std::string("a"), p.value().package); 38ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski EXPECT_FALSE(p.value().private_namespace); 39ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski 40ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski p = xml::ExtractPackageFromNamespace( 41ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski "http://schemas.android.com/apk/prv/res/android"); 42ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski AAPT_ASSERT_TRUE(p); 43ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski EXPECT_EQ(std::string("android"), p.value().package); 44ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski EXPECT_TRUE(p.value().private_namespace); 45ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski 46ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski p = xml::ExtractPackageFromNamespace( 47ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski "http://schemas.android.com/apk/prv/res/com.test"); 48ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski AAPT_ASSERT_TRUE(p); 49ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski EXPECT_EQ(std::string("com.test"), p.value().package); 50ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski EXPECT_TRUE(p.value().private_namespace); 51ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski 52ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski p = xml::ExtractPackageFromNamespace( 53ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski "http://schemas.android.com/apk/res-auto"); 54ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski AAPT_ASSERT_TRUE(p); 55ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski EXPECT_EQ(std::string(), p.value().package); 56ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski EXPECT_TRUE(p.value().private_namespace); 57467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski} 58467f171315f9c2037fcd3eb5edcfabc40671bf7bAdam Lesinski 59ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski} // namespace aapt 60