7 #include <boost/algorithm/string.hpp> 8 #include <boost/test/unit_test.hpp> 12 #include <boost/filesystem.hpp> 13 #include <boost/optional.hpp> 22 BOOST_TEST_MESSAGE(
"setup fixture");
27 BOOST_TEST_MESSAGE(
"teardown fixture");
31 std::string CreateTempCsvFile()
33 boost::filesystem::path fileDir = boost::filesystem::temp_directory_path();
34 boost::filesystem::path p{fileDir / boost::filesystem::unique_path(
"%%%%-%%%%-%%%%.csv")};
37 boost::filesystem::ofstream ofs{p};
38 ofs <<
"airplane, bicycle , bird , \"m,o,n,k,e,y\"\n";
39 ofs <<
"banana, shoe, \"ice\"";
41 }
catch (std::exception &e)
43 std::cerr <<
"Unable to write to file at location [" << p.c_str() <<
"] : " << e.what() << std::endl;
51 int CheckStringsMatch(
CsvRow &row,
unsigned int index, std::string expectedValue)
53 return row.
values.at(index).compare(expectedValue);
67 boost::filesystem::remove(*m_CsvFile);
69 catch (std::exception &e)
71 std::cerr <<
"Unable to delete file [" << *m_CsvFile <<
"] : " << e.what() << std::endl;
77 boost::optional<boost::filesystem::path> m_CsvFile;
86 std::vector<std::string> csvStrings;
87 csvStrings.reserve(2);
88 csvStrings.push_back(
"airplane, automobile , bird , \"c,a,t\"");
89 csvStrings.push_back(
"banana, shoe, \"ice\"");
91 std::vector<CsvRow> row = reader.
ParseVector(csvStrings);
98 BOOST_CHECK(CheckStringsMatch(row1, 0,
"airplane") == 0);
99 BOOST_CHECK(CheckStringsMatch(row1, 1,
"automobile") == 0);
100 BOOST_CHECK(CheckStringsMatch(row1, 2,
"bird") == 0);
101 BOOST_CHECK(CheckStringsMatch(row1, 3,
"c,a,t") == 0);
104 BOOST_CHECK(CheckStringsMatch(row2, 0,
"banana") == 0);
105 BOOST_CHECK(CheckStringsMatch(row2, 1,
"shoe") == 0);
106 BOOST_CHECK(CheckStringsMatch(row2, 2,
"ice") == 0);
112 std::string theFilePath = TestHelper::CreateTempCsvFile();
114 std::vector<CsvRow> row = reader.
ParseFile(theFilePath);
121 BOOST_CHECK(CheckStringsMatch(row1, 0,
"airplane") == 0);
122 BOOST_CHECK(CheckStringsMatch(row1, 1,
"bicycle") == 0);
123 BOOST_CHECK(CheckStringsMatch(row1, 2,
"bird") == 0);
124 BOOST_CHECK(CheckStringsMatch(row1, 3,
"m,o,n,k,e,y") == 0);
127 BOOST_CHECK(CheckStringsMatch(row2, 0,
"banana") == 0);
128 BOOST_CHECK(CheckStringsMatch(row2, 1,
"shoe") == 0);
129 BOOST_CHECK(CheckStringsMatch(row2, 2,
"ice") == 0);
std::vector< std::string > values
BOOST_FIXTURE_TEST_CASE(TestParseVector, TestHelper)
static std::vector< CsvRow > ParseVector(const std::vector< std::string > &csvVector)
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
static std::vector< CsvRow > ParseFile(const std::string &csvFile)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)