Main MRPT website > C++ reference for MRPT 1.9.9
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 
18 {
19  EXPECT_EQ(
20  mrpt::system::fileNameChangeExtension("cool.bar", "txt"), "cool.txt");
21  EXPECT_EQ(
22  mrpt::system::fileNameChangeExtension("d:/dataset.rawlog", "log"),
23  "d:/dataset.log");
24  EXPECT_EQ(
25  mrpt::system::fileNameChangeExtension("d:/dataset.rawlog", ""),
26  "d:/dataset.");
27  EXPECT_EQ(
28  mrpt::system::fileNameChangeExtension("d:/dataset.", ""),
29  "d:/dataset.");
30  EXPECT_EQ(
31  mrpt::system::fileNameChangeExtension("d:/dataset", "rawlog"),
32  "d:/dataset.rawlog");
33  EXPECT_EQ(
34  mrpt::system::fileNameChangeExtension("c:\\foo.txt", "bar"),
35  "c:\\foo.bar");
36  EXPECT_EQ(
37  mrpt::system::fileNameChangeExtension("/home/pepe/foo.txt", "bar"),
38  "/home/pepe/foo.bar");
39 }
40 
42 {
43  EXPECT_EQ(mrpt::system::extractFileExtension("c:\\foo.txt"), "txt");
44  EXPECT_EQ(mrpt::system::extractFileExtension("/home/pepe/foo.txt"), "txt");
45  EXPECT_EQ(mrpt::system::extractFileExtension("/home/pepe/foo"), "");
46  EXPECT_EQ(mrpt::system::extractFileExtension("/home/pepe/foo."), "");
47 }
48 
50 {
51  EXPECT_EQ(
52  mrpt::system::extractFileDirectory("/home/pepe/foo.txt"),
53  "/home/pepe/");
54  EXPECT_EQ(
55  mrpt::system::extractFileDirectory("D:\\imgs\\foo.txt"), "D:\\imgs\\");
56 }
57 
58 TEST(FileSystem, extractFileName)
59 {
60  EXPECT_EQ(mrpt::system::extractFileName("/home/pepe/foo.txt"), "foo");
61  EXPECT_EQ(
62  mrpt::system::extractFileName("d:\\imgs\\dataset.log"), "dataset");
63 }
64 
66 {
67 #ifdef MRPT_OS_WINDOWS
68  EXPECT_EQ(mrpt::system::filePathSeparatorsToNative("C:"), "C:");
69  EXPECT_EQ(mrpt::system::filePathSeparatorsToNative("C:\\"), "C:\\");
70  EXPECT_EQ(mrpt::system::filePathSeparatorsToNative("C:/"), "C:\\");
71  EXPECT_EQ(mrpt::system::filePathSeparatorsToNative("/loco"), "\\loco");
72  EXPECT_EQ(
74  "\\loco\\perico");
75  EXPECT_EQ(
77  "\\loco\\perico");
78  EXPECT_EQ(
80  "\\loco\\perico\\");
81 #else
82  EXPECT_EQ(mrpt::system::filePathSeparatorsToNative("C:"), "C:");
83  EXPECT_EQ(mrpt::system::filePathSeparatorsToNative("C:\\"), "C:/");
84  EXPECT_EQ(mrpt::system::filePathSeparatorsToNative("C:/"), "C:/");
85  EXPECT_EQ(mrpt::system::filePathSeparatorsToNative("/loco"), "/loco");
86  EXPECT_EQ(
88  "/loco/perico");
89  EXPECT_EQ(
91  "/loco/perico");
92  EXPECT_EQ(
94  "/loco/perico/");
95 #endif
96 }
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
STL namespace.
std::string filePathSeparatorsToNative(const std::string &filePath)
Windows: replace all &#39;/&#39;->&#39;\&#39; , in Linux/MacOS: replace all &#39;\&#39;->&#39;/&#39;.
Definition: filesystem.cpp:608
std::string fileNameChangeExtension(const std::string &filename, const std::string &newExtension)
Replace the filename extension by another one.
Definition: filesystem.cpp:369
std::string extractFileExtension(const std::string &filePath, bool ignore_gz=false)
Extract the extension of a filename.
Definition: filesystem.cpp:97
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
std::string 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 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.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019