MRPT  2.0.4
vector_loadsave_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/format.h>
13 #include <test_mrpt_common.h>
14 
15 #include <regex>
16 
17 TEST(file_get_contents, readTestFile)
18 {
19  const std::string fil = mrpt::format(
20  "%s/tests/sample_text_file.txt", mrpt::UNITTEST_BASEDIR.c_str());
21 
22  std::string contents = mrpt::io::file_get_contents(fil);
23  contents = std::regex_replace(contents, std::regex("\r\n"), "\n");
24 
25  const std::string expectedContents = "0\n1\n2\n3\nhello\nworld!\n";
26 
27  EXPECT_EQ(contents, expectedContents);
28 }
29 
30 TEST(file_get_contents, throwOnError)
31 {
32  const std::string fil = mrpt::format(
33  "%s/tests/sample_text_file_bis.txt", mrpt::UNITTEST_BASEDIR.c_str());
34 
35  EXPECT_ANY_THROW(mrpt::io::file_get_contents(fil));
36 }
std::string std::string format(std::string_view fmt, ARGS &&... args)
Definition: format.h:26
EXPECT_EQ(out.image_pair_was_used.size(), NUM_IMGS)
std::string file_get_contents(const std::string &fileName)
Loads an entire text file and return its contents as a single std::string.
TEST(file_get_contents, readTestFile)



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