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 "NameMangler.h"
18 
19 #include <string>
20 
21 #include "test/Test.h"
22 
23 namespace aapt {
24 
TEST(NameManglerTest,MangleName)25 TEST(NameManglerTest, MangleName) {
26   std::string package = "android.appcompat";
27   std::string name = "Platform.AppCompat";
28 
29   std::string mangled_name = NameMangler::MangleEntry(package, name);
30   EXPECT_EQ(mangled_name, "android.appcompat$Platform.AppCompat");
31 
32   std::string unmangled_package;
33   std::string unmangled_name = mangled_name;
34   ASSERT_TRUE(NameMangler::Unmangle(&unmangled_name, &unmangled_package));
35   EXPECT_EQ(unmangled_name, "Platform.AppCompat");
36   EXPECT_EQ(unmangled_package, "android.appcompat");
37 }
38 
TEST(NameManglerTest,IgnoreUnmangledName)39 TEST(NameManglerTest, IgnoreUnmangledName) {
40   std::string package;
41   std::string name = "foo_bar";
42 
43   EXPECT_FALSE(NameMangler::Unmangle(&name, &package));
44   EXPECT_EQ(name, "foo_bar");
45 }
46 
47 }  // namespace aapt
48