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-2018, 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 std;
15 
17 {
18  EXPECT_EQ(
19  mrpt::system::fileNameChangeExtension("cool.bar", "txt"), "cool.txt");
20  EXPECT_EQ(
21  mrpt::system::fileNameChangeExtension("d:/dataset.rawlog", "log"),
22  "d:/dataset.log");
23  EXPECT_EQ(
24  mrpt::system::fileNameChangeExtension("d:/dataset.rawlog", ""),
25  "d:/dataset.");
26  EXPECT_EQ(
27  mrpt::system::fileNameChangeExtension("d:/dataset.", ""),
28  "d:/dataset.");
29  EXPECT_EQ(
30  mrpt::system::fileNameChangeExtension("d:/dataset", "rawlog"),
31  "d:/dataset.rawlog");
32  EXPECT_EQ(
33  mrpt::system::fileNameChangeExtension("c:\\foo.txt", "bar"),
34  "c:\\foo.bar");
35  EXPECT_EQ(
36  mrpt::system::fileNameChangeExtension("/home/pepe/foo.txt", "bar"),
37  "/home/pepe/foo.bar");
38 }
39 
41 {
42  EXPECT_EQ(mrpt::system::extractFileExtension("c:\\foo.txt"), "txt");
43  EXPECT_EQ(mrpt::system::extractFileExtension("/home/pepe/foo.txt"), "txt");
44  EXPECT_EQ(mrpt::system::extractFileExtension("/home/pepe/foo"), "");
45  EXPECT_EQ(mrpt::system::extractFileExtension("/home/pepe/foo."), "");
46 }
47 
49 {
50  EXPECT_EQ(
51  mrpt::system::extractFileDirectory("/home/pepe/foo.txt"),
52  "/home/pepe/");
53  EXPECT_EQ(
54  mrpt::system::extractFileDirectory("D:\\imgs\\foo.txt"), "D:\\imgs\\");
55 }
56 
57 TEST(FileSystem, extractFileName)
58 {
59  EXPECT_EQ(mrpt::system::extractFileName("/home/pepe/foo.txt"), "foo");
60  EXPECT_EQ(
61  mrpt::system::extractFileName("d:\\imgs\\dataset.log"), "dataset");
62 }
63 
65 {
66 #ifdef _WIN32
67  EXPECT_EQ(mrpt::system::filePathSeparatorsToNative("C:"), "C:");
68  EXPECT_EQ(mrpt::system::filePathSeparatorsToNative("C:\\"), "C:\\");
69  EXPECT_EQ(mrpt::system::filePathSeparatorsToNative("C:/"), "C:\\");
70  EXPECT_EQ(mrpt::system::filePathSeparatorsToNative("/loco"), "\\loco");
71  EXPECT_EQ(
73  "\\loco\\perico");
74  EXPECT_EQ(
76  "\\loco\\perico");
77  EXPECT_EQ(
79  "\\loco\\perico\\");
80 #else
81  EXPECT_EQ(mrpt::system::filePathSeparatorsToNative("C:"), "C:");
82  EXPECT_EQ(mrpt::system::filePathSeparatorsToNative("C:\\"), "C:/");
83  EXPECT_EQ(mrpt::system::filePathSeparatorsToNative("C:/"), "C:/");
84  EXPECT_EQ(mrpt::system::filePathSeparatorsToNative("/loco"), "/loco");
85  EXPECT_EQ(
87  "/loco/perico");
88  EXPECT_EQ(
90  "/loco/perico");
91  EXPECT_EQ(
93  "/loco/perico/");
94 #endif
95 }
filesystem.h
TEST
TEST(FileSystem, fileNameChangeExtension)
Definition: filesystem_unittest.cpp:16
mrpt::system::extractFileDirectory
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
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::system::fileNameChangeExtension
std::string fileNameChangeExtension(const std::string &filename, const std::string &newExtension)
Replace the filename extension by another one.
Definition: filesystem.cpp:370
mrpt::system::filePathSeparatorsToNative
std::string filePathSeparatorsToNative(const std::string &filePath)
Windows: replace all '/'->'\' , in Linux/MacOS: replace all '\'->'/'.
Definition: filesystem.cpp:609
mrpt::system::extractFileExtension
std::string extractFileExtension(const std::string &filePath, bool ignore_gz=false)
Extract the extension of a filename.
Definition: filesystem.cpp:97
mrpt::system::extractFileName
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



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST