C++11 tidying.
[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 #else
39         BOOST_CHECK_EQUAL (fix_long_path("foo/bar/baz"), "foo/bar/baz");
40 #endif
41 }
42
43
44 #ifdef DCPOMATIC_WINDOWS
45 BOOST_AUTO_TEST_CASE (windows_long_filename_test)
46 {
47         using namespace boost::filesystem;
48
49         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";
50
51         BOOST_CHECK (too_long.string().length() > 260);
52         boost::system::error_code ec;
53         create_directories (too_long, ec);
54         BOOST_CHECK (ec);
55
56         path fixed_path = fix_long_path(too_long);
57         create_directories (fixed_path, ec);
58         BOOST_CHECK (!ec);
59
60         auto file = fopen_boost(too_long / "hello", "w");
61         BOOST_REQUIRE (file);
62         fprintf (file, "Hello_world");
63         fclose (file);
64
65         file = fopen_boost(too_long / "hello", "r");
66         BOOST_REQUIRE (file);
67         char buffer[64];
68         fscanf (file, "%63s", buffer);
69         BOOST_CHECK_EQUAL (strcmp(buffer, "Hello_world"), 0);
70 }
71 #endif
72