Skip to content

Commit

Permalink
fixing fast float stod conversion according to ST_Number schema speci…
Browse files Browse the repository at this point in the history
…fication (#339)

* fixing stod conversion according to schema

* spaces to tabs

* adding test case

* adding test case for leading plus sign double conversion

* refactoring
  • Loading branch information
gangatp authored Jan 31, 2024
1 parent e5014c5 commit 8ceec9c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ file(GLOB
list(FILTER LIBS_INCLUDE EXCLUDE REGEX "zlib|libzip|libressl")
target_include_directories(${PROJECT_NAME} PRIVATE ${LIBS_INCLUDE})

# allow FASTFLOAT_ALLOWS_LEADING_PLUS
add_definitions(-DFASTFLOAT_ALLOWS_LEADING_PLUS=1)

target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR_AUTOGENERATED}/Source)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Include/API)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Include)
Expand Down
8 changes: 7 additions & 1 deletion Source/Common/NMR_StringUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,13 @@ namespace NMR {
{
throw CNMRException(NMR_ERROR_EMPTYSTRINGTODOUBLECONVERSION);
}

else if (answer.ptr) // Invalidate comma as decimal separator
{
if (answer.ptr[0] == ',')
{
throw CNMRException(NMR_ERROR_INVALIDSTRINGTODOUBLECONVERSION);
}
}
if ((dResult == HUGE_VAL) || (dResult == -HUGE_VAL))
throw CNMRException(NMR_ERROR_STRINGTODOUBLECONVERSIONOUTOFRANGE);

Expand Down
17 changes: 17 additions & 0 deletions Tests/CPP_Bindings/Source/Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,21 @@ namespace Lib3MF
auto reader = model->QueryReader("3mf");
ASSERT_SPECIFIC_THROW(reader->ReadFromFile(sTestFilesPath + "/Reader/" + "GEN-M-ADA-ITEM-TRANSFORM-0.3mf"), ELib3MFException);
}


TEST_F(Reader, ReadVerticesCommaSeparatedValue) {
// This file N_XXX_0422_01.3mf contains vertices with comma-separated values.
// The 3MFReader should throw an error at NMR_StringUtils::fnStringToDouble when reading this file because
// comma-separated values are not allowed in 3MF files.
auto reader = model->QueryReader("3mf");
ASSERT_SPECIFIC_THROW(reader->ReadFromFile(sTestFilesPath + "/Reader/" + "N_XXX_0422_01.3mf"), ELib3MFException);
}

TEST_F(Reader, ReadVerticesWithLeadingPLUSSign) {
// This file P_XXM_0519_01.3mf contains vertices with leading + sign e.g +1E+2.
// The 3MFReader allows leading = sign at NMR_StringUtils::fnStringToDouble when reading this file.
auto reader = model->QueryReader("3mf");
reader->ReadFromFile(sTestFilesPath + "/Reader/" + "P_XXM_0519_01.3mf");
CheckReaderWarnings(Reader::reader3MF, 0);
}
}
Binary file added Tests/TestFiles/Reader/N_XXX_0422_01.3mf
Binary file not shown.
Binary file added Tests/TestFiles/Reader/P_XXM_0519_01.3mf
Binary file not shown.

0 comments on commit 8ceec9c

Please sign in to comment.