summaryrefslogtreecommitdiffstats
path: root/src/tests/core/file_sys/path_parser.cpp
blob: 2b543e438af5a930a4e985741146ad0637e35a02 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright 2016 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#include <catch.hpp>
#include "common/file_util.h"
#include "core/file_sys/path_parser.h"

namespace FileSys {

TEST_CASE("PathParser", "[core][file_sys]") {
    REQUIRE(!PathParser(Path(std::vector<u8>{})).IsValid());
    REQUIRE(!PathParser(Path("a")).IsValid());
    REQUIRE(!PathParser(Path("/|")).IsValid());
    REQUIRE(PathParser(Path("/a")).IsValid());
    REQUIRE(!PathParser(Path("/a/b/../../c/../../d")).IsValid());
    REQUIRE(PathParser(Path("/a/b/../c/../../d")).IsValid());
    REQUIRE(PathParser(Path("/")).IsRootDirectory());
    REQUIRE(!PathParser(Path("/a")).IsRootDirectory());
    REQUIRE(PathParser(Path("/a/..")).IsRootDirectory());
}

TEST_CASE("PathParser - Host file system", "[core][file_sys]") {
    std::string test_dir = "./test";
    FileUtil::CreateDir(test_dir);
    FileUtil::CreateDir(test_dir + "/z");
    FileUtil::CreateEmptyFile(test_dir + "/a");

    REQUIRE(PathParser(Path("/a")).GetHostStatus(test_dir) == PathParser::FileFound);
    REQUIRE(PathParser(Path("/b")).GetHostStatus(test_dir) == PathParser::NotFound);
    REQUIRE(PathParser(Path("/z")).GetHostStatus(test_dir) == PathParser::DirectoryFound);
    REQUIRE(PathParser(Path("/a/c")).GetHostStatus(test_dir) == PathParser::FileInPath);
    REQUIRE(PathParser(Path("/b/c")).GetHostStatus(test_dir) == PathParser::PathNotFound);

    FileUtil::DeleteDirRecursively(test_dir);
}

} // namespace FileSys