blob: f624df28e7bc47bdbb0ecd0b14debbb06205b977 [file] [log] [blame]
Adam Lesinski769de982015-04-10 19:43:55 -07001/*
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 Lesinskid0f116b2016-07-08 15:00:32 -070018#include "test/Test.h"
Adam Lesinski769de982015-04-10 19:43:55 -070019
Adam Lesinski769de982015-04-10 19:43:55 -070020#include <string>
21
22namespace aapt {
23
24TEST(NameManglerTest, MangleName) {
Adam Lesinskid0f116b2016-07-08 15:00:32 -070025 std::string package = "android.appcompat";
26 std::string name = "Platform.AppCompat";
Adam Lesinski769de982015-04-10 19:43:55 -070027
Adam Lesinskid0f116b2016-07-08 15:00:32 -070028 std::string mangledName = NameMangler::mangleEntry(package, name);
29 EXPECT_EQ(mangledName, "android.appcompat$Platform.AppCompat");
Adam Lesinski769de982015-04-10 19:43:55 -070030
Adam Lesinskid0f116b2016-07-08 15:00:32 -070031 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 Lesinski769de982015-04-10 19:43:55 -070036}
37
38TEST(NameManglerTest, IgnoreUnmangledName) {
Adam Lesinskid0f116b2016-07-08 15:00:32 -070039 std::string package;
40 std::string name = "foo_bar";
Adam Lesinski769de982015-04-10 19:43:55 -070041
42 EXPECT_FALSE(NameMangler::unmangle(&name, &package));
Adam Lesinskid0f116b2016-07-08 15:00:32 -070043 EXPECT_EQ(name, "foo_bar");
Adam Lesinski769de982015-04-10 19:43:55 -070044}
45
46} // namespace aapt