mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
7ec20bd5d5
- Abseil (HEAD) - Benchmark (HEAD) - Google Flags (HEAD) - Google Logging (HEAD) - Google Test/Mock (HEAD) - Protocol Buffers (3.11.4) PiperOrigin-RevId: 309012925 Change-Id: I826846afb3f2c4e92180915796890fce6b5a1d6c
99 lines
4.0 KiB
C++
99 lines
4.0 KiB
C++
// Copyright 2019 Google LLC
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
#include "sandboxed_api/sandbox2/util/path.h"
|
|
|
|
#include "gmock/gmock.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
namespace sandbox2 {
|
|
namespace {
|
|
|
|
using ::testing::Pair;
|
|
using ::testing::StrEq;
|
|
|
|
TEST(PathTest, ArgumentTypes) {
|
|
// JoinPath must be able to accept arguments that are compatible with
|
|
// absl::string_view. So test a few of them here.
|
|
const char char_array[] = "a";
|
|
const char* char_ptr = "b";
|
|
std::string string_type = "c";
|
|
absl::string_view sp_type = "d";
|
|
|
|
EXPECT_THAT(file::JoinPath(char_array, char_ptr, string_type, sp_type),
|
|
StrEq("a/b/c/d"));
|
|
}
|
|
|
|
TEST(PathTest, JoinPath) {
|
|
EXPECT_THAT(file::JoinPath("/foo", "bar"), StrEq("/foo/bar"));
|
|
EXPECT_THAT(file::JoinPath("foo", "bar"), StrEq("foo/bar"));
|
|
EXPECT_THAT(file::JoinPath("foo", "/bar"), StrEq("foo/bar"));
|
|
EXPECT_THAT(file::JoinPath("/foo", "/bar"), StrEq("/foo/bar"));
|
|
|
|
EXPECT_THAT(file::JoinPath("", "/bar"), StrEq("/bar"));
|
|
EXPECT_THAT(file::JoinPath("", "bar"), StrEq("bar"));
|
|
EXPECT_THAT(file::JoinPath("/foo", ""), StrEq("/foo"));
|
|
|
|
EXPECT_THAT(file::JoinPath("/foo/bar/baz/", "/blah/blink/biz"),
|
|
StrEq("/foo/bar/baz/blah/blink/biz"));
|
|
|
|
EXPECT_THAT(file::JoinPath("/foo", "bar", "baz"), StrEq("/foo/bar/baz"));
|
|
EXPECT_THAT(file::JoinPath("foo", "bar", "baz"), StrEq("foo/bar/baz"));
|
|
EXPECT_THAT(file::JoinPath("/foo", "bar", "baz", "blah"),
|
|
StrEq("/foo/bar/baz/blah"));
|
|
EXPECT_THAT(file::JoinPath("/foo", "bar", "/baz", "blah"),
|
|
StrEq("/foo/bar/baz/blah"));
|
|
EXPECT_THAT(file::JoinPath("/foo", "/bar/", "/baz", "blah"),
|
|
StrEq("/foo/bar/baz/blah"));
|
|
EXPECT_THAT(file::JoinPath("/foo", "/bar/", "baz", "blah"),
|
|
StrEq("/foo/bar/baz/blah"));
|
|
|
|
EXPECT_THAT(file::JoinPath("/", "a"), StrEq("/a"));
|
|
EXPECT_THAT(file::JoinPath(), StrEq(""));
|
|
}
|
|
|
|
TEST(PathTest, SplitPath) {
|
|
// We cannot write the type directly within the EXPECT, because the ',' breaks
|
|
// the macro.
|
|
EXPECT_THAT(file::SplitPath("/hello/"), Pair(StrEq("/hello"), StrEq("")));
|
|
EXPECT_THAT(file::SplitPath("/hello"), Pair(StrEq("/"), StrEq("hello")));
|
|
EXPECT_THAT(file::SplitPath("hello/world"),
|
|
Pair(StrEq("hello"), StrEq("world")));
|
|
EXPECT_THAT(file::SplitPath("hello/"), Pair(StrEq("hello"), StrEq("")));
|
|
EXPECT_THAT(file::SplitPath("world"), Pair(StrEq(""), StrEq("world")));
|
|
EXPECT_THAT(file::SplitPath("/"), Pair(StrEq("/"), StrEq("")));
|
|
EXPECT_THAT(file::SplitPath(""), Pair(StrEq(""), StrEq("")));
|
|
}
|
|
|
|
TEST(PathTest, CleanPath) {
|
|
EXPECT_THAT(file::CleanPath(""), StrEq("."));
|
|
EXPECT_THAT(file::CleanPath("x"), StrEq("x"));
|
|
EXPECT_THAT(file::CleanPath("/a/b/c/d"), StrEq("/a/b/c/d"));
|
|
EXPECT_THAT(file::CleanPath("/a/b/c/d/"), StrEq("/a/b/c/d"));
|
|
EXPECT_THAT(file::CleanPath("/a//b"), StrEq("/a/b"));
|
|
EXPECT_THAT(file::CleanPath("//a//b/"), StrEq("/a/b"));
|
|
EXPECT_THAT(file::CleanPath("/.."), StrEq("/"));
|
|
EXPECT_THAT(file::CleanPath("/././././"), StrEq("/"));
|
|
EXPECT_THAT(file::CleanPath("/a/b/.."), StrEq("/a"));
|
|
EXPECT_THAT(file::CleanPath("/a/b/../../.."), StrEq("/"));
|
|
EXPECT_THAT(file::CleanPath("//a//b/..////../..//"), StrEq("/"));
|
|
EXPECT_THAT(file::CleanPath("//a//../x//"), StrEq("/x"));
|
|
EXPECT_THAT(file::CleanPath("../../a/b/../c"), StrEq("../../a/c"));
|
|
EXPECT_THAT(file::CleanPath("../../a/b/../c/../.."), StrEq("../.."));
|
|
EXPECT_THAT(file::CleanPath("foo/../../../bar"), StrEq("../../bar"));
|
|
}
|
|
|
|
} // namespace
|
|
} // namespace sandbox2
|