MRPT  2.0.1
filesystem_unittest.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include <gtest/gtest.h>
11 #include <mrpt/system/filesystem.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
71  EXPECT_EQ(
73  "\\loco\\perico");
74  EXPECT_EQ(
76  "\\loco\\perico");
77  EXPECT_EQ(
79  "\\loco\\perico\\");
80 #else
85  EXPECT_EQ(
87  "/loco/perico");
88  EXPECT_EQ(
90  "/loco/perico");
91  EXPECT_EQ(
93  "/loco/perico/");
94 #endif
95 }
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:612
std::string fileNameChangeExtension(const std::string &filename, const std::string &newExtension)
Replace the filename extension by another one.
Definition: filesystem.cpp:373
std::string extractFileExtension(const std::string &filePath, bool ignore_gz=false)
Extract the extension of a filename.
Definition: filesystem.cpp:98
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
EXPECT_EQ(out.image_pair_was_used.size(), NUM_IMGS)
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:62
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:78
TEST(FileSystem, fileNameChangeExtension)



Page generated by Doxygen 1.8.14 for MRPT 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020