Line data Source code
1 :
2 : /* Copyright (c) 2014-2016, Daniel.Nachbaur@epfl.ch
3 : *
4 : * This library is free software; you can redistribute it and/or modify it under
5 : * the terms of the GNU Lesser General Public License version 2.1 as published
6 : * by the Free Software Foundation.
7 : *
8 : * This library is distributed in the hope that it will be useful, but WITHOUT
9 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 : * details.
12 : *
13 : * You should have received a copy of the GNU Lesser General Public License
14 : * along with this library; if not, write to the Free Software Foundation, Inc.,
15 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 : */
17 :
18 : #include "test.h"
19 :
20 : #include <lunchbox/file.h>
21 : #include <boost/algorithm/string/predicate.hpp>
22 : #include <boost/filesystem/path.hpp>
23 :
24 1 : int main( int, char** argv )
25 : {
26 1 : const boost::filesystem::path path( argv[0] );
27 2 : const std::string argvPath( path.parent_path().generic_string( ));
28 2 : const boost::filesystem::path execPath( lunchbox::getExecutablePath( ));
29 1 : TEST( boost::algorithm::ends_with( execPath.generic_string(), argvPath ));
30 :
31 2 : boost::filesystem::path referenceRootPath( execPath );
32 1 : referenceRootPath = referenceRootPath.parent_path();
33 : #ifdef _MSC_VER
34 : const lunchbox::Strings buildTypes { "debug", "relwithdebinfo", "release",
35 : "minsizerel" };
36 : std::string buildType( path.stem().string( ));
37 : std::transform( buildType.begin(), buildType.end(), buildType.begin(),
38 : ::tolower );
39 : if( std::find( buildTypes.begin(), buildTypes.end(),
40 : buildType ) != buildTypes.end( ))
41 : {
42 : referenceRootPath = referenceRootPath.parent_path();
43 : }
44 : #endif
45 1 : TEST( lunchbox::getRootPath() == referenceRootPath.string( ));
46 :
47 2 : const std::string filename = path.filename().generic_string();
48 1 : TEST( filename == lunchbox::getFilename( argv[0] ));
49 :
50 2 : const lunchbox::Strings files = lunchbox::searchDirectory( argvPath, ".*" );
51 1 : TEST( files.size() > 1 );
52 1 : TEST( std::find( files.begin(), files.end(), filename ) != files.end( ));
53 :
54 2 : return EXIT_SUCCESS;
55 3 : }
|