MRPT  2.0.4
CTextFileLinesParser_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/core/common.h>
13 #include <sstream>
14 
15 TEST(CTextFileLinesParser, parse)
16 {
17  std::stringstream ss;
18  ss << "1st line\n"
19  "2nd line\n"
20  "# comment\n"
21  "3rd line";
22  ss.seekg(0); // rewind
23 
25  parser.enableCommentFilters(true, true, true);
26 
27  std::string line;
28  bool ret = parser.getNextLine(line);
29  EXPECT_TRUE(ret);
30  EXPECT_EQ(parser.getCurrentLineNumber(), 1U);
31  EXPECT_EQ(line, "1st line");
32 
33  ret = parser.getNextLine(line);
34  EXPECT_TRUE(ret);
35  EXPECT_EQ(parser.getCurrentLineNumber(), 2U);
36  EXPECT_EQ(line, "2nd line");
37 
38  ret = parser.getNextLine(line);
39  EXPECT_TRUE(ret);
40  EXPECT_EQ(parser.getCurrentLineNumber(), 4U);
41 
42  EXPECT_EQ(line, "3rd line");
43 
44  // EOF:
45  EXPECT_FALSE(parser.getNextLine(line));
46 }
EXPECT_TRUE(mrpt::system::fileExists(ini_fil))
A class for parsing text files, returning each non-empty and non-comment line, along its line number...
size_t getCurrentLineNumber() const
Return the line number of the last line returned with getNextLine.
bool getNextLine(std::string &out_str)
Reads from the file and return the next (non-comment) line, as a std::string.
void enableCommentFilters(bool filter_MATLAB_comments, bool filter_C_comments, bool filter_SH_comments)
Enable/disable filtering of lines starting with "%", "//" or "#", respectively.
EXPECT_EQ(out.image_pair_was_used.size(), NUM_IMGS)
TEST(CTextFileLinesParser, parse)



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020