1 //===- llvm/unittest/Support/Path.cpp - Path tests ------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/Support/PathV2.h"
12 #include "gtest/gtest.h"
16 #define TEST_OUT(func, result) outs() << " " #func ": " << result << '\n';
18 #define TEST_PATH_(header, func, funcname, output) \
20 if (error_code ec = sys::path::func) \
21 ASSERT_FALSE(ec.message().c_str()); \
22 TEST_OUT(funcname, output)
24 #define TEST_PATH(func, ipath, res) TEST_PATH_(, func(ipath, res), func, res);
26 #define TEST_PATH_SMALLVEC(func, ipath, inout) \
27 TEST_PATH_(inout = ipath, func(inout), func, inout)
29 #define TEST_PATH_SMALLVEC_P(func, ipath, inout, param) \
30 TEST_PATH_(inout = ipath, func(inout, param), func, inout)
35 SmallVector<StringRef, 40> paths;
38 paths.push_back("..");
39 paths.push_back("foo");
41 paths.push_back("/foo");
42 paths.push_back("foo/");
43 paths.push_back("/foo/");
44 paths.push_back("foo/bar");
45 paths.push_back("/foo/bar");
46 paths.push_back("//net");
47 paths.push_back("//net/foo");
48 paths.push_back("///foo///");
49 paths.push_back("///foo///bar");
50 paths.push_back("/.");
51 paths.push_back("./");
52 paths.push_back("/..");
53 paths.push_back("../");
54 paths.push_back("foo/.");
55 paths.push_back("foo/..");
56 paths.push_back("foo/./");
57 paths.push_back("foo/./bar");
58 paths.push_back("foo/..");
59 paths.push_back("foo/../");
60 paths.push_back("foo/../bar");
61 paths.push_back("c:");
62 paths.push_back("c:/");
63 paths.push_back("c:foo");
64 paths.push_back("c:/foo");
65 paths.push_back("c:foo/");
66 paths.push_back("c:/foo/");
67 paths.push_back("c:/foo/bar");
68 paths.push_back("prn:");
69 paths.push_back("c:\\");
70 paths.push_back("c:foo");
71 paths.push_back("c:\\foo");
72 paths.push_back("c:foo\\");
73 paths.push_back("c:\\foo\\");
74 paths.push_back("c:\\foo/");
75 paths.push_back("c:/foo\\bar");
77 for (SmallVector<StringRef, 40>::const_iterator i = paths.begin(),
81 outs() << *i << " =>\n Iteration: [";
82 for (sys::path::const_iterator ci = sys::path::begin(*i),
83 ce = sys::path::end(*i);
90 outs() << " Reverse Iteration: [";
91 for (sys::path::reverse_iterator ci = sys::path::rbegin(*i),
92 ce = sys::path::rend(*i);
100 TEST_PATH(root_path, *i, sfres);
101 TEST_PATH(root_name, *i, sfres);
102 TEST_PATH(root_directory, *i, sfres);
103 TEST_PATH(parent_path, *i, sfres);
104 TEST_PATH(filename, *i, sfres);
105 TEST_PATH(stem, *i, sfres);
106 TEST_PATH(extension, *i, sfres);
108 SmallString<16> temp_store;
109 TEST_PATH_SMALLVEC(make_absolute, *i, temp_store);
110 TEST_PATH_SMALLVEC(remove_filename, *i, temp_store);
112 TEST_PATH_SMALLVEC_P(replace_extension, *i, temp_store, "ext");
113 StringRef filename(temp_store.begin(), temp_store.size()), stem, ext;
114 TEST_PATH(stem, filename, stem);
115 TEST_PATH(extension, filename, ext);
116 EXPECT_EQ(*(--sys::path::end(filename)), (stem + ext).str());
118 TEST_PATH_(, native(*i, temp_store), native, temp_store);
124 } // anonymous namespace