aboutsummaryrefslogtreecommitdiff
path: root/src/armnn/test/CsvReaderTest.cpp
diff options
context:
space:
mode:
authortelsoa01 <telmo.soares@arm.com>2018-08-31 09:22:23 +0100
committertelsoa01 <telmo.soares@arm.com>2018-08-31 09:22:23 +0100
commitc577f2c6a3b4ddb6ba87a882723c53a248afbeba (patch)
treebd7d4c148df27f8be6649d313efb24f536b7cf34 /src/armnn/test/CsvReaderTest.cpp
parent4c7098bfeab1ffe1cdc77f6c15548d3e73274746 (diff)
downloadarmnn-c577f2c6a3b4ddb6ba87a882723c53a248afbeba.tar.gz
Release 18.08
Diffstat (limited to 'src/armnn/test/CsvReaderTest.cpp')
-rw-r--r--src/armnn/test/CsvReaderTest.cpp124
1 files changed, 124 insertions, 0 deletions
diff --git a/src/armnn/test/CsvReaderTest.cpp b/src/armnn/test/CsvReaderTest.cpp
new file mode 100644
index 0000000000..8df61e1fdd
--- /dev/null
+++ b/src/armnn/test/CsvReaderTest.cpp
@@ -0,0 +1,124 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// See LICENSE file in the project root for full license information.
+//
+#include "CsvReader.hpp"
+
+#include <boost/algorithm/string.hpp>
+#include <boost/test/unit_test.hpp>
+
+#include <iostream>
+#include <string>
+#include <boost/filesystem.hpp>
+
+using namespace armnnUtils;
+
+struct TestHelper {
+
+ TestHelper()
+ {
+ BOOST_TEST_MESSAGE("setup fixture");
+ }
+
+ ~TestHelper()
+ {
+ BOOST_TEST_MESSAGE("teardown fixture");
+ TearDown();
+ }
+
+ std::string CreateTempCsvFile()
+ {
+ std::string fileDir = boost::filesystem::temp_directory_path().c_str();
+ boost::filesystem::path p{fileDir + "/sampleFile.csv"};
+ try
+ {
+ boost::filesystem::ofstream ofs{p};
+ ofs << "airplane, bicycle , bird , \"m,o,n,k,e,y\"\n";
+ ofs << "banana, shoe, \"ice\"";
+ ofs.close();
+ } catch (std::exception &e)
+ {
+ std::cerr << "Unable to write to file at location [" << p.c_str() << "] : " << e.what() << std::endl;
+ BOOST_TEST(false);
+ }
+ return fileDir + "/sampleFile.csv";
+ }
+
+ int CheckStringsMatch(CsvRow &row, unsigned int index, std::string expectedValue)
+ {
+ return row.values.at(index).compare(expectedValue);
+ }
+
+ void TearDown()
+ {
+ RemoveCsvFile();
+ }
+
+ void RemoveCsvFile()
+ {
+ std::string fileDir = boost::filesystem::temp_directory_path().c_str();
+ std::string filePath = fileDir + "/sampleFile.csv";
+ try
+ {
+ boost::filesystem::remove(filePath);
+ }
+ catch (std::exception &e)
+ {
+ std::cerr << "Unable to delete file [" << filePath << "] : " << e.what() << std::endl;
+ BOOST_TEST(false);
+ }
+ }
+};
+
+BOOST_AUTO_TEST_SUITE(CsvReaderTest)
+
+BOOST_FIXTURE_TEST_CASE(TestParseVector, TestHelper)
+{
+ CsvReader reader;
+ std::vector<std::string> csvStrings;
+ csvStrings.reserve(2);
+ csvStrings.push_back("airplane, automobile , bird , \"c,a,t\"");
+ csvStrings.push_back("banana, shoe, \"ice\"");
+
+ std::vector<CsvRow> row = reader.ParseVector(csvStrings);
+ CsvRow row1 = row[0];
+ CsvRow row2 = row[1];
+
+ BOOST_CHECK(row.size() == 2);
+
+ BOOST_CHECK(row1.values.size() == 4);
+ BOOST_CHECK(CheckStringsMatch(row1, 0, "airplane") == 0);
+ BOOST_CHECK(CheckStringsMatch(row1, 1, "automobile") == 0);
+ BOOST_CHECK(CheckStringsMatch(row1, 2, "bird") == 0);
+ BOOST_CHECK(CheckStringsMatch(row1, 3, "c,a,t") == 0);
+
+ BOOST_CHECK(row2.values.size() == 3);
+ BOOST_CHECK(CheckStringsMatch(row2, 0, "banana") == 0);
+ BOOST_CHECK(CheckStringsMatch(row2, 1, "shoe") == 0);
+ BOOST_CHECK(CheckStringsMatch(row2, 2, "ice") == 0);
+}
+
+BOOST_FIXTURE_TEST_CASE(TestLoadingFileFromDisk, TestHelper)
+{
+ CsvReader reader;
+ std::string theFilePath = TestHelper::CreateTempCsvFile();
+
+ std::vector<CsvRow> row = reader.ParseFile(theFilePath);
+ CsvRow row1 = row[0];
+ CsvRow row2 = row[1];
+
+ BOOST_CHECK(row.size() == 2);
+
+ BOOST_CHECK(row1.values.size() == 4);
+ BOOST_CHECK(CheckStringsMatch(row1, 0, "airplane") == 0);
+ BOOST_CHECK(CheckStringsMatch(row1, 1, "bicycle") == 0);
+ BOOST_CHECK(CheckStringsMatch(row1, 2, "bird") == 0);
+ BOOST_CHECK(CheckStringsMatch(row1, 3, "m,o,n,k,e,y") == 0);
+
+ BOOST_CHECK(row2.values.size() == 3);
+ BOOST_CHECK(CheckStringsMatch(row2, 0, "banana") == 0);
+ BOOST_CHECK(CheckStringsMatch(row2, 1, "shoe") == 0);
+ BOOST_CHECK(CheckStringsMatch(row2, 2, "ice") == 0);
+}
+
+BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file