From d2a89b44d218b0bbb99b71873489b993e0787c5c Mon Sep 17 00:00:00 2001 From: Joey Kleingers Date: Thu, 5 Oct 2023 13:32:07 -0400 Subject: [PATCH] Add preflight check that checks for 0 total tuples. Signed-off-by: Joey Kleingers --- .../Filters/ImportCSVDataFilter.cpp | 20 ++++++++++++------- .../ComplexCore/test/ImportCSVDataTest.cpp | 1 + 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Plugins/ComplexCore/src/ComplexCore/Filters/ImportCSVDataFilter.cpp b/src/Plugins/ComplexCore/src/ComplexCore/Filters/ImportCSVDataFilter.cpp index 376aa09257..3d489817cc 100644 --- a/src/Plugins/ComplexCore/src/ComplexCore/Filters/ImportCSVDataFilter.cpp +++ b/src/Plugins/ComplexCore/src/ComplexCore/Filters/ImportCSVDataFilter.cpp @@ -277,7 +277,7 @@ bool skipNumberOfLines(std::fstream& inStream, usize numberOfLines) std::string tupleDimsToString(const std::vector& tupleDims) { std::string tupleDimsStr; - for(size_t i = 0; i < tupleDims.size(); ++i) + for(usize i = 0; i < tupleDims.size(); ++i) { tupleDimsStr += std::to_string(tupleDims[i]); if(i != tupleDims.size() - 1) @@ -464,7 +464,7 @@ IFilter::PreflightResult ImportCSVDataFilter::preflightImpl(const DataStructure& headers = csvImporterData.customHeaders; } - size_t totalLines = s_HeaderCache[s_InstanceId].TotalLines; + usize totalLines = s_HeaderCache[s_InstanceId].TotalLines; // Check that we have a valid start import row if(csvImporterData.startImportRow == 0) @@ -553,13 +553,19 @@ IFilter::PreflightResult ImportCSVDataFilter::preflightImpl(const DataStructure& } // Check that we have a valid tuple count - size_t totalImportedLines = totalLines - csvImporterData.startImportRow + 1; - size_t tupleTotal = std::accumulate(csvImporterData.tupleDims.begin(), csvImporterData.tupleDims.end(), static_cast(1), std::multiplies()); - if(tupleTotal > totalImportedLines) + usize totalImportedLines = totalLines - csvImporterData.startImportRow + 1; + usize tupleTotal = std::accumulate(csvImporterData.tupleDims.begin(), csvImporterData.tupleDims.end(), static_cast(1), std::multiplies()); + if(tupleTotal == 0) { std::string tupleDimsStr = tupleDimsToString(csvImporterData.tupleDims); - std::string errMsg = fmt::format("Error: The current tuple dimensions ({}) has {} tuples, but this is larger than the total number of available lines to import ({}).", tupleDimsStr, tupleTotal, - totalImportedLines); + std::string errMsg = fmt::format("Error: The current tuple dimensions ({}) has 0 total tuples. At least 1 tuple is required.", tupleDimsStr, tupleTotal, totalImportedLines); + return {MakeErrorResult(to_underlying(IssueCodes::INCORRECT_TUPLES), errMsg), {}}; + } + else if(tupleTotal > totalImportedLines) + { + std::string tupleDimsStr = tupleDimsToString(csvImporterData.tupleDims); + std::string errMsg = fmt::format("Error: The current tuple dimensions ({}) has {} total tuples, but this is larger than the total number of available lines to import ({}).", tupleDimsStr, + tupleTotal, totalImportedLines); return {MakeErrorResult(to_underlying(IssueCodes::INCORRECT_TUPLES), errMsg), {}}; } diff --git a/src/Plugins/ComplexCore/test/ImportCSVDataTest.cpp b/src/Plugins/ComplexCore/test/ImportCSVDataTest.cpp index a430e4cb5c..0d07bbbdd5 100644 --- a/src/Plugins/ComplexCore/test/ImportCSVDataTest.cpp +++ b/src/Plugins/ComplexCore/test/ImportCSVDataTest.cpp @@ -457,6 +457,7 @@ TEST_CASE("ComplexCore::ImportCSVDataFilter (Case 5): Invalid filter execution - fs::remove(tmp_file); // Incorrect Tuple Dimensions + TestCase_TestImporterData_Error(k_TestInput.string(), 2, CSVImporterData::HeaderMode::CUSTOM, 1, {"Custom Array"}, {DataType::int8}, {false}, {0}, v, k_IncorrectTuples); TestCase_TestImporterData_Error(k_TestInput.string(), 2, CSVImporterData::HeaderMode::CUSTOM, 1, {"Custom Array"}, {DataType::int8}, {false}, {30}, v, k_IncorrectTuples); TestCase_TestImporterData_Error(k_TestInput.string(), 2, CSVImporterData::HeaderMode::CUSTOM, 1, {"Custom Array"}, {DataType::int8}, {false}, {30, 2}, v, k_IncorrectTuples); TestCase_TestImporterData_Error(k_TestInput.string(), 2, CSVImporterData::HeaderMode::CUSTOM, 1, {"Custom Array"}, {DataType::int8}, {false}, {30, 5, 7}, v, k_IncorrectTuples);