| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008 |
- /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
- file Copyright.txt or https://cmake.org/licensing for details. */
- #include <algorithm>
- #include <iostream>
- #include <sstream>
- #include <string>
- #include <vector>
- #include <cm/filesystem>
- namespace {
- namespace fs = cm::filesystem;
- void checkResult(bool success)
- {
- if (!success) {
- std::cout << " => failed";
- }
- std::cout << std::endl;
- }
- bool testConstructors()
- {
- std::cout << "testConstructors()";
- bool result = true;
- {
- fs::path p;
- if (p != fs::path()) {
- result = false;
- }
- }
- {
- fs::path p1("/a/b/c");
- fs::path p2("/a/b/c");
- if (p1 != p2) {
- result = false;
- }
- if (p1.string() != p2.string()) {
- result = false;
- }
- if (p1.string() != "/a/b/c") {
- result = false;
- }
- }
- {
- std::string s("/a/b/c");
- fs::path p1(s);
- fs::path p2(s.begin(), s.end());
- if (p1 != p2) {
- result = false;
- }
- if (p1.string() != s || p2.string() != s) {
- result = false;
- }
- #if CM_FILESYSTEM_SOURCE_TRAITS_ITERATOR
- std::string s2(s);
- s2 += '\0';
- fs::path p3(s2.begin());
- if (p1 != p3 || p3.string() != s) {
- result = false;
- }
- #endif
- }
- {
- std::wstring s(L"/a/b/c");
- fs::path p1(s);
- fs::path p2(s.begin(), s.end());
- if (p1 != p2) {
- result = false;
- }
- if (p1.wstring() != s || p2.wstring() != s) {
- result = false;
- }
- #if CM_FILESYSTEM_SOURCE_TRAITS_ITERATOR
- std::wstring s2(s);
- s2 += L'\0';
- fs::path p3(s2.begin());
- if (p1 != p3 || p3.wstring() != s) {
- result = false;
- }
- #endif
- }
- {
- std::string s("/a/b/c");
- fs::path::string_type ws;
- for (auto c : s) {
- ws += fs::path::value_type(c);
- }
- fs::path p1(ws);
- fs::path p2(ws.begin(), ws.end());
- if (p1 != p2) {
- result = false;
- }
- if (p1.native() != ws || p2.native() != ws) {
- result = false;
- }
- #if CM_FILESYSTEM_SOURCE_TRAITS_ITERATOR
- fs::path::string_type ws2(ws);
- ws2 += fs::path::value_type('\0');
- fs::path p3(ws2.begin());
- if (p1 != p3 || p3.native() != ws) {
- result = false;
- }
- #endif
- }
- checkResult(result);
- return result;
- }
- bool testConcatenation()
- {
- std::cout << "testConcatenation()";
- bool result = true;
- {
- fs::path p("/a/b");
- p /= "c";
- if (!(p.string() == "/a/b/c" || p.string() == "/a/b\\c")) {
- result = false;
- }
- p += "d";
- if (!(p.string() == "/a/b/cd" || p.string() == "/a/b\\cd")) {
- result = false;
- }
- fs::path p2("x/y");
- p /= p2;
- if (!(p.string() == "/a/b/cd/x/y" || p.string() == "/a/b\\cd\\x/y")) {
- result = false;
- }
- p = p / p2;
- if (!(p.string() == "/a/b/cd/x/y/x/y" ||
- p.string() == "/a/b\\cd\\x/y\\x/y")) {
- result = false;
- }
- }
- {
- fs::path p("a");
- p /= "";
- if (!(p.string() == "a/" || p.string() == "a\\")) {
- result = false;
- }
- p /= "/b";
- if (p.string() != "/b") {
- result = false;
- }
- }
- #if defined(_WIN32)
- {
- fs::path p("a");
- p /= "c:/b";
- if (p.string() != "c:/b") {
- result = false;
- }
- p = fs::path("a") / "c:";
- if (p.string() != "c:") {
- result = false;
- }
- p = fs::path("c:") / "";
- if (p.string() != "c:") {
- result = false;
- }
- p = fs::path("c:a") / "/b";
- if (p.string() != "c:/b") {
- result = false;
- }
- p = fs::path("c:a") / "c:b";
- if (p.string() != "c:a\\b") {
- result = false;
- }
- p = fs::path("//host") / "b";
- if (p.string() != "//host\\b") {
- result = false;
- }
- p = fs::path("//host/") / "b";
- if (p.string() != "//host/b") {
- result = false;
- }
- }
- #endif
- checkResult(result);
- return result;
- }
- bool testModifiers()
- {
- std::cout << "testModifiers()";
- bool result = true;
- {
- std::string s("a///b/");
- fs::path p(s);
- std::replace(
- s.begin(), s.end(), '/',
- static_cast<std::string::value_type>(fs::path::preferred_separator));
- p.make_preferred();
- if (p.string() != s) {
- result = false;
- }
- }
- {
- fs::path p("a/b/c.e.f");
- p.remove_filename();
- if (p.string() != "a/b/") {
- result = false;
- }
- p.remove_filename();
- if (p.string() != "a/b/") {
- result = false;
- }
- }
- {
- fs::path p("a/b/c.e.f");
- p.replace_filename("x.y");
- if (p.string() != "a/b/x.y") {
- result = false;
- }
- }
- {
- fs::path p("a/b/c.e.f");
- p.replace_extension(".x");
- if (p.string() != "a/b/c.e.x") {
- result = false;
- }
- p.replace_extension(".y");
- if (p.string() != "a/b/c.e.y") {
- result = false;
- }
- p.replace_extension();
- if (p.string() != "a/b/c.e") {
- result = false;
- }
- p = "/a/b";
- p.replace_extension(".x");
- if (p.string() != "/a/b.x") {
- result = false;
- }
- p = "/a/b/";
- p.replace_extension(".x");
- if (p.string() != "/a/b/.x") {
- result = false;
- }
- }
- checkResult(result);
- return result;
- }
- bool testObservers()
- {
- std::cout << "testObservers()";
- bool result = true;
- {
- std::string s("a/b/c");
- fs::path p(s);
- fs::path::string_type st;
- for (auto c : s) {
- st += static_cast<fs::path::value_type>(c);
- }
- if (p.native() != st || static_cast<fs::path::string_type>(p) != st ||
- p.c_str() != st) {
- result = false;
- }
- }
- {
- std::string s("a//b//c");
- std::wstring ws(L"a//b//c");
- fs::path p(s);
- if (p.string() != s || p.wstring() != ws) {
- result = false;
- }
- }
- {
- std::string s("a/b/c");
- std::wstring ws;
- for (auto c : s) {
- ws += static_cast<std::wstring::value_type>(c);
- }
- std::string ns(s);
- std::replace(
- ns.begin(), ns.end(), '/',
- static_cast<std::string::value_type>(fs::path::preferred_separator));
- fs::path p(ns);
- if (p.generic_string() != s || p.generic_wstring() != ws) {
- result = false;
- }
- }
- checkResult(result);
- return result;
- }
- bool testCompare()
- {
- std::cout << "testCompare()";
- bool result = true;
- {
- std::string s("a/b/c");
- fs::path p1(s);
- fs::path p2(s);
- if (p1.compare(p2) != 0) {
- result = false;
- }
- p2 = "a/b";
- if (p1.compare(p2) <= 0) {
- result = false;
- }
- p2 = "a/d";
- if (p1.compare(p2) >= 0) {
- result = false;
- }
- p2 = "a/b/d";
- if (p1.compare(p2) >= 0) {
- result = false;
- }
- p2 = "a/b/a";
- if (p1.compare(p2) <= 0) {
- result = false;
- }
- p2 = "a/b/c/d";
- if (p1.compare(p2) >= 0) {
- result = false;
- }
- p1 = "a";
- p2 = "b";
- if (p1.compare(p2) == 0) {
- result = false;
- }
- }
- {
- // LWG 3096 (https://cplusplus.github.io/LWG/issue3096)
- // fs::path p1("/a/");
- // fs::path p2("/a/.");
- // if (p1.compare(p2) != 0) {
- // result = false;
- // }
- }
- checkResult(result);
- return result;
- }
- bool testGeneration()
- {
- std::cout << "testGeneration()";
- bool result = true;
- {
- fs::path p("a/./b/..");
- if (p.lexically_normal().generic_string() != "a/") {
- result = false;
- }
- p = "a/.///b/../";
- if (p.lexically_normal().generic_string() != "a/") {
- result = false;
- }
- }
- #if defined(_WIN32)
- {
- fs::path p("//host/./b/..");
- if (p.lexically_normal().string() != "\\\\host\\") {
- result = false;
- }
- p = "//host/.///b/../";
- if (p.lexically_normal().string() != "\\\\host\\") {
- result = false;
- }
- p = "c://a/.///b/../";
- if (p.lexically_normal().string() != "c:\\a\\") {
- result = false;
- }
- }
- #endif
- {
- if (fs::path("/a//d").lexically_relative("/a/b/c") != "../../d") {
- result = false;
- }
- if (fs::path("/a//b///c").lexically_relative("/a/d") != "../b/c") {
- result = false;
- }
- if (fs::path("a/b/c").lexically_relative("a") != "b/c") {
- result = false;
- }
- if (fs::path("a/b/c").lexically_relative("a/b/c/x/y") != "../..") {
- result = false;
- }
- if (fs::path("a/b/c").lexically_relative("a/b/c") != ".") {
- result = false;
- }
- if (fs::path("a/b").lexically_relative("c/d") != "../../a/b") {
- result = false;
- }
- }
- {
- #if defined(_WIN32)
- if (fs::path("/a/d").lexically_relative("e/d/c") != "/a/d") {
- result = false;
- }
- if (!fs::path("c:/a/d").lexically_relative("e/d/c").empty()) {
- result = false;
- }
- #else
- if (!fs::path("/a/d").lexically_relative("e/d/c").empty()) {
- result = false;
- }
- #endif
- }
- {
- #if defined(_WIN32)
- if (fs::path("c:/a/d").lexically_proximate("e/d/c") != "c:/a/d") {
- result = false;
- }
- #else
- if (fs::path("/a/d").lexically_proximate("e/d/c") != "/a/d") {
- result = false;
- }
- #endif
- if (fs::path("/a/d").lexically_proximate("/a/b/c") != "../../d") {
- result = false;
- }
- }
- // LWG 3070
- {
- #if defined(_WIN32)
- if (!fs::path("/a:/b:").lexically_relative("/a:/c:").empty()) {
- result = false;
- }
- if (fs::path("c:/a/b").lexically_relative("c:/a/d") != "../b") {
- result = false;
- }
- if (!fs::path("c:/a/b:").lexically_relative("c:/a/d").empty()) {
- result = false;
- }
- if (!fs::path("c:/a/b").lexically_relative("c:/a/d:").empty()) {
- result = false;
- }
- #else
- if (fs::path("/a:/b:").lexically_relative("/a:/c:") != "../b:") {
- result = false;
- }
- #endif
- }
- // LWG 3096
- {
- if (fs::path("/a").lexically_relative("/a/.") != ".") {
- result = false;
- }
- if (fs::path("/a").lexically_relative("/a/") != ".") {
- result = false;
- }
- if (fs::path("a/b/c").lexically_relative("a/b/c") != ".") {
- result = false;
- }
- if (fs::path("a/b/c").lexically_relative("a/b/c/") != ".") {
- result = false;
- }
- if (fs::path("a/b/c").lexically_relative("a/b/c/.") != ".") {
- result = false;
- }
- if (fs::path("a/b/c/").lexically_relative("a/b/c") != ".") {
- result = false;
- }
- if (fs::path("a/b/c/.").lexically_relative("a/b/c") != ".") {
- result = false;
- }
- if (fs::path("a/b/c/.").lexically_relative("a/b/c/") != ".") {
- result = false;
- }
- }
- checkResult(result);
- return result;
- }
- bool testDecomposition()
- {
- std::cout << "testDecomposition()";
- bool result = true;
- {
- if (!fs::path("/a/b").root_name().empty()) {
- result = false;
- }
- #if defined(_WIN32)
- if (fs::path("c:/a/b").root_name() != "c:") {
- result = false;
- }
- if (fs::path("c:a/b").root_name() != "c:") {
- result = false;
- }
- if (fs::path("c:").root_name() != "c:") {
- result = false;
- }
- if (fs::path("//host/b").root_name() != "//host") {
- result = false;
- }
- if (fs::path("//host").root_name() != "//host") {
- result = false;
- }
- #endif
- }
- {
- if (!fs::path("a/b").root_directory().empty()) {
- result = false;
- }
- if (fs::path("/a/b").root_directory() != "/") {
- result = false;
- }
- #if defined(_WIN32)
- if (!fs::path("c:a/b").root_directory().empty()) {
- result = false;
- }
- if (fs::path("/a/b").root_directory() != "/") {
- result = false;
- }
- if (fs::path("c:/a/b").root_directory() != "/") {
- result = false;
- }
- if (fs::path("//host/b").root_directory() != "/") {
- result = false;
- }
- #endif
- }
- {
- if (!fs::path("a/b").root_path().empty()) {
- result = false;
- }
- if (fs::path("/a/b").root_path() != "/") {
- result = false;
- }
- #if defined(_WIN32)
- if (fs::path("c:a/b").root_path() != "c:") {
- result = false;
- }
- if (fs::path("/a/b").root_path() != "/") {
- result = false;
- }
- if (fs::path("c:/a/b").root_path() != "c:/") {
- result = false;
- }
- if (fs::path("//host/b").root_path() != "//host/") {
- result = false;
- }
- #endif
- }
- {
- if (!fs::path("/").relative_path().empty()) {
- result = false;
- }
- if (fs::path("a/b").relative_path() != "a/b") {
- result = false;
- }
- if (fs::path("/a/b").relative_path() != "a/b") {
- result = false;
- }
- #if defined(_WIN32)
- if (fs::path("c:a/b").relative_path() != "a/b") {
- result = false;
- }
- if (fs::path("/a/b").relative_path() != "a/b") {
- result = false;
- }
- if (fs::path("c:/a/b").relative_path() != "a/b") {
- result = false;
- }
- if (fs::path("//host/b").relative_path() != "b") {
- result = false;
- }
- #endif
- }
- {
- if (fs::path("/a/b").parent_path() != "/a") {
- result = false;
- }
- if (fs::path("/a/b/").parent_path() != "/a/b") {
- result = false;
- }
- if (fs::path("/a/b/.").parent_path() != "/a/b") {
- result = false;
- }
- if (fs::path("/").parent_path() != "/") {
- result = false;
- }
- #if defined(_WIN32)
- if (fs::path("c:/a/b").parent_path() != "c:/a") {
- result = false;
- }
- if (fs::path("c:a").parent_path() != "c:") {
- result = false;
- }
- if (fs::path("c:/").parent_path() != "c:/") {
- result = false;
- }
- if (fs::path("c:").parent_path() != "c:") {
- result = false;
- }
- if (fs::path("//host/").parent_path() != "//host/") {
- result = false;
- }
- if (fs::path("//host").parent_path() != "//host") {
- result = false;
- }
- #endif
- }
- {
- if (fs::path("/a/b.txt").filename() != "b.txt") {
- result = false;
- }
- if (fs::path("/a/.b").filename() != ".b") {
- result = false;
- }
- if (fs::path("/foo/bar/").filename() != "") {
- result = false;
- }
- if (fs::path("/foo/.").filename() != ".") {
- result = false;
- }
- if (fs::path("/foo/..").filename() != "..") {
- result = false;
- }
- if (fs::path(".").filename() != ".") {
- result = false;
- }
- if (fs::path("..").filename() != "..") {
- result = false;
- }
- if (!fs::path("/").filename().empty()) {
- result = false;
- }
- #if defined(_WIN32)
- if (fs::path("c:a").filename() != "a") {
- result = false;
- }
- if (fs::path("c:/a").filename() != "a") {
- result = false;
- }
- if (!fs::path("c:").filename().empty()) {
- result = false;
- }
- if (!fs::path("c:/").filename().empty()) {
- result = false;
- }
- if (!fs::path("//host").filename().empty()) {
- result = false;
- }
- #endif
- }
- {
- if (fs::path("/a/b.txt").stem() != "b") {
- result = false;
- }
- if (fs::path("/a/b.c.txt").stem() != "b.c") {
- result = false;
- }
- if (fs::path("/a/.b").stem() != ".b") {
- result = false;
- }
- if (fs::path("/a/b").stem() != "b") {
- result = false;
- }
- if (fs::path("/a/b/.").stem() != ".") {
- result = false;
- }
- if (fs::path("/a/b/..").stem() != "..") {
- result = false;
- }
- if (!fs::path("/a/b/").stem().empty()) {
- result = false;
- }
- #if defined(_WIN32)
- if (!fs::path("c:/a/b/").stem().empty()) {
- result = false;
- }
- if (!fs::path("c:/").stem().empty()) {
- result = false;
- }
- if (!fs::path("c:").stem().empty()) {
- result = false;
- }
- if (!fs::path("//host/").stem().empty()) {
- result = false;
- }
- if (!fs::path("//host").stem().empty()) {
- result = false;
- }
- #endif
- }
- {
- if (fs::path("/a/b.txt").extension() != ".txt") {
- result = false;
- }
- if (fs::path("/a/b.").extension() != ".") {
- result = false;
- }
- if (!fs::path("/a/b").extension().empty()) {
- result = false;
- }
- if (fs::path("/a/b.txt/b.cc").extension() != ".cc") {
- result = false;
- }
- if (fs::path("/a/b.txt/b.").extension() != ".") {
- result = false;
- }
- if (!fs::path("/a/b.txt/b").extension().empty()) {
- result = false;
- }
- if (!fs::path("/a/.").extension().empty()) {
- result = false;
- }
- if (!fs::path("/a/..").extension().empty()) {
- result = false;
- }
- if (!fs::path("/a/.hidden").extension().empty()) {
- result = false;
- }
- if (fs::path("/a/..b").extension() != ".b") {
- result = false;
- }
- }
- checkResult(result);
- return result;
- }
- bool testQueries()
- {
- std::cout << "testQueries()";
- bool result = true;
- {
- if (fs::path("/a/b").has_root_name()) {
- result = false;
- }
- fs::path p("/a/b");
- if (!p.has_root_directory() || !p.has_root_path()) {
- result = false;
- }
- if (!fs::path("/a/b").has_root_path() || fs::path("a/b").has_root_path()) {
- result = false;
- }
- if (!fs::path("/a/b").has_relative_path() ||
- fs::path("/").has_relative_path()) {
- result = false;
- }
- if (!fs::path("/a/b").has_parent_path() ||
- !fs::path("/").has_parent_path() || fs::path("a").has_parent_path()) {
- result = false;
- }
- if (!fs::path("/a/b").has_filename() || !fs::path("a.b").has_filename() ||
- fs::path("/a/").has_filename() || fs::path("/").has_filename()) {
- result = false;
- }
- if (!fs::path("/a/b").has_stem() || !fs::path("a.b").has_stem() ||
- !fs::path("/.a").has_stem() || fs::path("/a/").has_stem() ||
- fs::path("/").has_stem()) {
- result = false;
- }
- if (!fs::path("/a/b.c").has_extension() ||
- !fs::path("a.b").has_extension() || fs::path("/.a").has_extension() ||
- fs::path("/a/").has_extension() || fs::path("/").has_extension()) {
- result = false;
- }
- #if defined(_WIN32)
- p = "c:/a/b";
- if (!fs::path("c:/a/b").has_root_name() || !p.has_root_directory() ||
- !p.has_root_path()) {
- result = false;
- }
- p = "c:a/b";
- if (!p.has_root_name() || p.has_root_directory() || !p.has_root_path()) {
- result = false;
- }
- p = "//host/b";
- if (!p.has_root_name() || !p.has_root_directory() || !p.has_root_path()) {
- result = false;
- }
- p = "//host";
- if (!p.has_root_name() || p.has_root_directory() || !p.has_root_path()) {
- result = false;
- }
- if (!fs::path("c:/a/b").has_relative_path() ||
- !fs::path("c:a/b").has_relative_path() ||
- !fs::path("//host/b").has_relative_path()) {
- result = false;
- }
- if (!fs::path("c:/a/b").has_parent_path() ||
- !fs::path("c:/").has_parent_path() ||
- !fs::path("c:").has_parent_path() ||
- !fs::path("//host/").has_parent_path() ||
- !fs::path("//host").has_parent_path()) {
- result = false;
- }
- #endif
- }
- {
- #if defined(_WIN32)
- fs::path p("c:/a");
- #else
- fs::path p("/a");
- #endif
- if (!p.is_absolute() || p.is_relative()) {
- result = false;
- }
- p = "a/b";
- if (p.is_absolute() || !p.is_relative()) {
- result = false;
- }
- #if defined(_WIN32)
- p = "c:/a/b";
- if (!p.is_absolute() || p.is_relative()) {
- result = false;
- }
- p = "//host/b";
- if (!p.is_absolute() || p.is_relative()) {
- result = false;
- }
- p = "/a";
- if (p.is_absolute() || !p.is_relative()) {
- result = false;
- }
- p = "c:a";
- if (p.is_absolute() || !p.is_relative()) {
- result = false;
- }
- #endif
- }
- checkResult(result);
- return result;
- }
- bool testIterators()
- {
- std::cout << "testIterators()";
- bool result = true;
- {
- fs::path p("/a/b/");
- #if defined(_WIN32)
- std::vector<fs::path::string_type> ref{ L"/", L"a", L"b", L"" };
- #else
- std::vector<fs::path::string_type> ref{ "/", "a", "b", "" };
- #endif
- std::vector<fs::path::string_type> res;
- for (auto i = p.begin(), e = p.end(); i != e; ++i) {
- res.push_back(*i);
- }
- if (res != ref) {
- result = false;
- }
- res.clear();
- for (const auto& e : p) {
- res.push_back(e);
- }
- if (res != ref) {
- result = false;
- }
- }
- {
- fs::path p("/a/b/");
- #if defined(_WIN32)
- std::vector<fs::path::string_type> ref{ L"", L"b", L"a", L"/" };
- #else
- std::vector<fs::path::string_type> ref{ "", "b", "a", "/" };
- #endif
- std::vector<fs::path::string_type> res;
- auto i = p.end(), b = p.begin();
- do {
- res.push_back(*--i);
- } while (i != b);
- if (res != ref) {
- result = false;
- }
- }
- checkResult(result);
- return result;
- }
- bool testNonMemberFunctions()
- {
- std::cout << "testNonMemberFunctions()";
- bool result = true;
- {
- fs::path p1("/a/b/");
- fs::path p2("/c/d");
- fs::swap(p1, p2);
- if (p1.string() != "/c/d" || p2.string() != "/a/b/")
- result = false;
- }
- {
- auto h1 = fs::hash_value(fs::path("/a//b//"));
- auto h2 = fs::hash_value(fs::path("/a/b/"));
- if (h1 != h2)
- result = false;
- }
- {
- fs::path p1("/a/b/");
- fs::path p2("/c/d");
- if (p1 == p2)
- result = false;
- p1 = "/a//b//";
- p2 = "/a/b/";
- if (p1 != p2)
- result = false;
- }
- {
- fs::path p = "/a";
- p = p / "b" / "c";
- if (p.generic_string() != "/a/b/c") {
- result = false;
- }
- fs::path::string_type ref;
- ref += fs::path::value_type('/');
- ref += fs::path::value_type('a');
- ref += fs::path::preferred_separator;
- ref += fs::path::value_type('b');
- ref += fs::path::preferred_separator;
- ref += fs::path::value_type('c');
- if (p.native() != ref) {
- result = false;
- }
- }
- {
- fs::path p("/a b\\c/");
- std::ostringstream oss;
- oss << p;
- if (oss.str() != "\"/a b\\\\c/\"") {
- result = false;
- }
- std::istringstream iss(oss.str());
- fs::path p2;
- iss >> p2;
- if (p2 != p) {
- result = false;
- }
- }
- checkResult(result);
- return result;
- }
- }
- int testCMFilesystemPath(int /*unused*/, char* /*unused*/[])
- {
- int result = 0;
- if (!testConstructors()) {
- result = 1;
- }
- if (!testConcatenation()) {
- result = 1;
- }
- if (!testModifiers()) {
- result = 1;
- }
- if (!testObservers()) {
- result = 1;
- }
- if (!testCompare()) {
- result = 1;
- }
- if (!testGeneration()) {
- result = 1;
- }
- if (!testDecomposition()) {
- result = 1;
- }
- if (!testQueries()) {
- result = 1;
- }
- if (!testIterators()) {
- result = 1;
- }
- if (!testNonMemberFunctions()) {
- result = 1;
- }
- return result;
- }
|