Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 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 | |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 19 | #include <string> |
| 20 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 21 | #include "test/Test.h" |
| 22 | |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 23 | namespace aapt { |
| 24 | |
| 25 | TEST(NameManglerTest, MangleName) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 26 | std::string package = "android.appcompat"; |
| 27 | std::string name = "Platform.AppCompat"; |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 28 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 29 | std::string mangled_name = NameMangler::MangleEntry(package, name); |
| 30 | EXPECT_EQ(mangled_name, "android.appcompat$Platform.AppCompat"); |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 31 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 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"); |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | TEST(NameManglerTest, IgnoreUnmangledName) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 40 | std::string package; |
| 41 | std::string name = "foo_bar"; |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 42 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 43 | EXPECT_FALSE(NameMangler::Unmangle(&name, &package)); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 44 | EXPECT_EQ(name, "foo_bar"); |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 47 | } // namespace aapt |