2 Copyright (C) 2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 #include "lib/cross.h"
24 #include <boost/filesystem.hpp>
25 #include <boost/test/unit_test.hpp>
29 BOOST_AUTO_TEST_CASE (fix_long_path_test)
31 #ifdef DCPOMATIC_WINDOWS
32 BOOST_CHECK_EQUAL (fix_long_path("c:\\foo"), "\\\\?\\c:\\foo");
33 BOOST_CHECK_EQUAL (fix_long_path("c:\\foo\\bar"), "\\\\?\\c:\\foo\\bar");
34 boost::filesystem::path fixed_bar = "\\\\?\\";
35 fixed_bar += boost::filesystem::current_path();
37 BOOST_CHECK_EQUAL (fix_long_path("bar"), fixed_bar);
39 BOOST_CHECK_EQUAL (fix_long_path("\\\\?\\c:\\foo"), "\\\\?\\c:\\foo");
41 BOOST_CHECK_EQUAL (fix_long_path("foo/bar/baz"), "foo/bar/baz");
46 #ifdef DCPOMATIC_WINDOWS
47 BOOST_AUTO_TEST_CASE (windows_long_filename_test)
49 using namespace boost::filesystem;
51 path too_long = current_path() / "build\\test\\a\\really\\very\\long\\filesystem\\path\\indeed\\that\\will\\be\\so\\long\\that\\windows\\cannot\\normally\\cope\\with\\it\\unless\\we\\add\\this\\crazy\\prefix\\and\\then\\magically\\it\\can\\do\\it\\fine\\I\\dont\\really\\know\\why\\its\\like\\that\\but\\hey\\it\\is\\so\\here\\we\\are\\what\\can\\we\\do\\other\\than\\bodge\\it";
53 BOOST_CHECK (too_long.string().length() > 260);
54 boost::system::error_code ec;
55 create_directories (too_long, ec);
58 path fixed_path = fix_long_path(too_long);
59 create_directories (fixed_path, ec);
62 auto file = fopen_boost(too_long / "hello", "w");
64 fprintf (file, "Hello_world");
67 file = fopen_boost(too_long / "hello", "r");
70 fscanf (file, "%63s", buffer);
71 BOOST_CHECK_EQUAL (strcmp(buffer, "Hello_world"), 0);