Main MRPT website > C++ reference for MRPT 1.5.7
filesystem_unittest.cpp
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 
10 #include <mrpt/system/filesystem.h>
11 #include <gtest/gtest.h>
12 
13 using namespace mrpt;
14 using namespace mrpt::utils;
15 using namespace std;
16 
17 
19 {
20  EXPECT_EQ( mrpt::system::fileNameChangeExtension("cool.bar","txt"), "cool.txt" );
21  EXPECT_EQ( mrpt::system::fileNameChangeExtension("d:/dataset.rawlog","log"), "d:/dataset.log" );
22  EXPECT_EQ( mrpt::system::fileNameChangeExtension("d:/dataset.rawlog",""), "d:/dataset." );
23  EXPECT_EQ( mrpt::system::fileNameChangeExtension("d:/dataset.",""), "d:/dataset." );
24  EXPECT_EQ( mrpt::system::fileNameChangeExtension("d:/dataset","rawlog"), "d:/dataset.rawlog" );
25  EXPECT_EQ( mrpt::system::fileNameChangeExtension("c:\\foo.txt","bar"), "c:\\foo.bar" );
26  EXPECT_EQ( mrpt::system::fileNameChangeExtension("/home/pepe/foo.txt","bar"), "/home/pepe/foo.bar" );
27 }
28 
30 {
31  EXPECT_EQ( mrpt::system::extractFileExtension("c:\\foo.txt"),"txt");
32  EXPECT_EQ( mrpt::system::extractFileExtension("/home/pepe/foo.txt"),"txt");
33  EXPECT_EQ( mrpt::system::extractFileExtension("/home/pepe/foo"),"");
34  EXPECT_EQ( mrpt::system::extractFileExtension("/home/pepe/foo."),"");
35 }
36 
38 {
39  EXPECT_EQ( mrpt::system::extractFileDirectory("/home/pepe/foo.txt"),"/home/pepe/");
40  EXPECT_EQ( mrpt::system::extractFileDirectory("D:\\imgs\\foo.txt"),"D:\\imgs\\");
41 }
42 
43 
44 TEST(FileSystem, extractFileName)
45 {
46  EXPECT_EQ( mrpt::system::extractFileName("/home/pepe/foo.txt"),"foo");
47  EXPECT_EQ( mrpt::system::extractFileName("d:\\imgs\\dataset.log"),"dataset");
48 }
49 
51 {
52 #ifdef MRPT_OS_WINDOWS
53  EXPECT_EQ( mrpt::system::filePathSeparatorsToNative("C:"),"C:");
54  EXPECT_EQ( mrpt::system::filePathSeparatorsToNative("C:\\"),"C:\\");
55  EXPECT_EQ( mrpt::system::filePathSeparatorsToNative("C:/"),"C:\\");
56  EXPECT_EQ( mrpt::system::filePathSeparatorsToNative("/loco"),"\\loco");
57  EXPECT_EQ( mrpt::system::filePathSeparatorsToNative("/loco/perico"),"\\loco\\perico");
58  EXPECT_EQ( mrpt::system::filePathSeparatorsToNative("/loco\\perico"),"\\loco\\perico");
59  EXPECT_EQ( mrpt::system::filePathSeparatorsToNative("/loco\\perico/"),"\\loco\\perico\\");
60 #else
61  EXPECT_EQ( mrpt::system::filePathSeparatorsToNative("C:"),"C:");
62  EXPECT_EQ( mrpt::system::filePathSeparatorsToNative("C:\\"),"C:/");
63  EXPECT_EQ( mrpt::system::filePathSeparatorsToNative("C:/"),"C:/");
64  EXPECT_EQ( mrpt::system::filePathSeparatorsToNative("/loco"),"/loco");
65  EXPECT_EQ( mrpt::system::filePathSeparatorsToNative("/loco/perico"),"/loco/perico");
66  EXPECT_EQ( mrpt::system::filePathSeparatorsToNative("/loco\\perico"),"/loco/perico");
67  EXPECT_EQ( mrpt::system::filePathSeparatorsToNative("/loco\\perico/"),"/loco/perico/");
68 #endif
69 }
70 
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
Definition: zip.h:16
STL namespace.
std::string BASE_IMPEXP filePathSeparatorsToNative(const std::string &filePath)
Windows: replace all &#39;/&#39;->&#39;\&#39; , in Linux/MacOS: replace all &#39;\&#39;->&#39;/&#39;.
Definition: filesystem.cpp:543
std::string BASE_IMPEXP fileNameChangeExtension(const std::string &filename, const std::string &newExtension)
Replace the filename extension by another one.
Definition: filesystem.cpp:356
std::string BASE_IMPEXP extractFileExtension(const std::string &filePath, bool ignore_gz=false)
Extract the extension of a filename.
Definition: filesystem.cpp:96
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
std::string BASE_IMPEXP extractFileName(const std::string &filePath)
Extract just the name (without extension) of a filename from a complete path plus name plus extension...
Definition: filesystem.cpp:61
std::string BASE_IMPEXP extractFileDirectory(const std::string &filePath)
Extract the whole path (the directory) of a filename from a complete path plus name plus extension...
Definition: filesystem.cpp:77
TEST(FileSystem, fileNameChangeExtension)



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 8277875f6 Mon Jun 11 02:47:32 2018 +0200 at lun oct 28 01:50:49 CET 2019