Add editor to a few more missing places.
[dcpomatic.git] / test / windows_test.cc
1 /*
2     Copyright (C) 2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21
22 #include "lib/cross.h"
23 #include "lib/util.h"
24 #include <boost/filesystem.hpp>
25 #include <boost/test/unit_test.hpp>
26 #include <iostream>
27
28
29 BOOST_AUTO_TEST_CASE (fix_long_path_test)
30 {
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();
36         fixed_bar /= "bar";
37         BOOST_CHECK_EQUAL (fix_long_path("bar"), fixed_bar);
38
39         BOOST_CHECK_EQUAL (fix_long_path("\\\\?\\c:\\foo"), "\\\\?\\c:\\foo");
40 #else
41         BOOST_CHECK_EQUAL (fix_long_path("foo/bar/baz"), "foo/bar/baz");
42 #endif
43 }
44
45
46 #ifdef DCPOMATIC_WINDOWS
47 BOOST_AUTO_TEST_CASE (windows_long_filename_test)
48 {
49         using namespace boost::filesystem;
50
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";
52
53         BOOST_CHECK (too_long.string().length() > 260);
54         boost::system::error_code ec;
55         create_directories (too_long, ec);
56         BOOST_CHECK (ec);
57
58         path fixed_path = fix_long_path(too_long);
59         create_directories (fixed_path, ec);
60         BOOST_CHECK (!ec);
61
62         auto file = fopen_boost(too_long / "hello", "w");
63         BOOST_REQUIRE (file);
64         fprintf (file, "Hello_world");
65         fclose (file);
66
67         file = fopen_boost(too_long / "hello", "r");
68         BOOST_REQUIRE (file);
69         char buffer[64];
70         fscanf (file, "%63s", buffer);
71         BOOST_CHECK_EQUAL (strcmp(buffer, "Hello_world"), 0);
72 }
73 #endif
74