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" |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame^] | 18 | #include "test/Test.h" |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 19 | |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 20 | #include <string> |
| 21 | |
| 22 | namespace aapt { |
| 23 | |
| 24 | TEST(NameManglerTest, MangleName) { |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame^] | 25 | std::string package = "android.appcompat"; |
| 26 | std::string name = "Platform.AppCompat"; |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 27 | |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame^] | 28 | std::string mangledName = NameMangler::mangleEntry(package, name); |
| 29 | EXPECT_EQ(mangledName, "android.appcompat$Platform.AppCompat"); |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 30 | |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame^] | 31 | std::string unmangledPackage; |
| 32 | std::string unmangledName = mangledName; |
| 33 | ASSERT_TRUE(NameMangler::unmangle(&unmangledName, &unmangledPackage)); |
| 34 | EXPECT_EQ(unmangledName, "Platform.AppCompat"); |
| 35 | EXPECT_EQ(unmangledPackage, "android.appcompat"); |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | TEST(NameManglerTest, IgnoreUnmangledName) { |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame^] | 39 | std::string package; |
| 40 | std::string name = "foo_bar"; |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 41 | |
| 42 | EXPECT_FALSE(NameMangler::unmangle(&name, &package)); |
Adam Lesinski | d0f116b | 2016-07-08 15:00:32 -0700 | [diff] [blame^] | 43 | EXPECT_EQ(name, "foo_bar"); |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | } // namespace aapt |