blob: bc89b5c3fb43d960bf083879913718bfd919c0e4 [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"
18
Adam Lesinski769de982015-04-10 19:43:55 -070019#include <string>
20
Adam Lesinskice5e56e2016-10-21 17:56:45 -070021#include "test/Test.h"
22
Adam Lesinski769de982015-04-10 19:43:55 -070023namespace aapt {
24
25TEST(NameManglerTest, MangleName) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070026 std::string package = "android.appcompat";
27 std::string name = "Platform.AppCompat";
Adam Lesinski769de982015-04-10 19:43:55 -070028
Adam Lesinskice5e56e2016-10-21 17:56:45 -070029 std::string mangled_name = NameMangler::MangleEntry(package, name);
30 EXPECT_EQ(mangled_name, "android.appcompat$Platform.AppCompat");
Adam Lesinski769de982015-04-10 19:43:55 -070031
Adam Lesinskice5e56e2016-10-21 17:56:45 -070032 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 Lesinski769de982015-04-10 19:43:55 -070037}
38
39TEST(NameManglerTest, IgnoreUnmangledName) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070040 std::string package;
41 std::string name = "foo_bar";
Adam Lesinski769de982015-04-10 19:43:55 -070042
Adam Lesinskice5e56e2016-10-21 17:56:45 -070043 EXPECT_FALSE(NameMangler::Unmangle(&name, &package));
Adam Lesinskicacb28f2016-10-19 12:18:14 -070044 EXPECT_EQ(name, "foo_bar");
Adam Lesinski769de982015-04-10 19:43:55 -070045}
46
Adam Lesinskicacb28f2016-10-19 12:18:14 -070047} // namespace aapt