proxygen
FsUtilTest.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2012-present Facebook, Inc.
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 
18 
19 #include <glog/logging.h>
20 
22 
23 using namespace folly;
24 using namespace folly::fs;
25 
26 TEST(Simple, Path) {
27  path root("/");
28  path abs1("/hello/world");
29  path rel1("meow");
30  EXPECT_TRUE(starts_with(abs1, root));
31  EXPECT_FALSE(starts_with(rel1, root));
32  EXPECT_EQ(path("hello/world"), remove_prefix(abs1, root));
33  EXPECT_THROW({ remove_prefix(rel1, root); }, filesystem_error);
34 
35  path abs2("/hello");
36  path abs3("/hello/");
37  path abs4("/hello/world");
38  path abs5("/hello/world/");
39  path abs6("/hello/wo");
40  EXPECT_TRUE(starts_with(abs1, abs2));
41  EXPECT_TRUE(starts_with(abs1, abs3));
42  EXPECT_TRUE(starts_with(abs1, abs4));
43  EXPECT_FALSE(starts_with(abs1, abs5));
44  EXPECT_FALSE(starts_with(abs1, abs6));
45  EXPECT_EQ(path("world"), remove_prefix(abs1, abs2));
46  EXPECT_EQ(path("world"), remove_prefix(abs1, abs3));
47  EXPECT_EQ(path(), remove_prefix(abs1, abs4));
48  EXPECT_THROW({ remove_prefix(abs1, abs5); }, filesystem_error);
49  EXPECT_THROW({ remove_prefix(abs1, abs6); }, filesystem_error);
50 }
51 
52 TEST(Simple, CanonicalizeParent) {
53  path a("/usr/bin/tail");
54  path b("/usr/lib/../bin/tail");
55  path c("/usr/bin/DOES_NOT_EXIST_ASDF");
56  path d("/usr/lib/../bin/DOES_NOT_EXIST_ASDF");
57 
58  EXPECT_EQ(a, canonical(a));
60  EXPECT_EQ(a, canonical(b));
62  EXPECT_THROW({ canonical(c); }, filesystem_error);
63  EXPECT_THROW({ canonical(d); }, filesystem_error);
66 }
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
char b
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
path remove_prefix(const path &pth, const path &prefix)
Definition: FsUtil.cpp:50
char a
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
char c
TEST(SequencedExecutor, CPUThreadPoolExecutor)
path canonical_parent(const path &pth, const path &base)
Definition: FsUtil.cpp:68
bool starts_with(const path &pth, const path &prefix)
Definition: FsUtil.cpp:45