blob: 458474eedcf0d2f8b49ce978c94229bf915f71f7 [file] [log] [blame]
Dmitriy Ivanova1feb112015-10-01 18:41:57 -07001/*
2 * Copyright (C) 2013 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 <stdlib.h>
18#include <string.h>
19#include <sys/mman.h>
20
21#include <gtest/gtest.h>
22
23#include "../linker_utils.h"
24
25TEST(linker_utils, normalize_path_smoke) {
26 std::string output;
27 ASSERT_TRUE(normalize_path("/../root///dir/.///dir2/somedir/../zipfile!/dir/dir9//..///afile", &output));
28 ASSERT_EQ("/root/dir/dir2/zipfile!/dir/afile", output);
29
30 ASSERT_TRUE(normalize_path("/../root///dir/.///dir2/somedir/.../zipfile!/.dir/dir9//..///afile", &output));
31 ASSERT_EQ("/root/dir/dir2/somedir/.../zipfile!/.dir/afile", output);
32
33 ASSERT_TRUE(normalize_path("/root/..", &output));
34 ASSERT_EQ("/", output);
35
36 ASSERT_TRUE(normalize_path("/root/notroot/..", &output));
37 ASSERT_EQ("/root/", output);
38
39 ASSERT_TRUE(normalize_path("/a/../../b", &output));
40 ASSERT_EQ("/b", output);
41
42 output = "unchanged";
43 ASSERT_FALSE(normalize_path("root///dir/.///dir2/somedir/../zipfile!/dir/dir9//..///afile", &output));
44 ASSERT_EQ("unchanged", output);
45}