phrocker commented on a change in pull request #472: MINIFICPP-710 - Fix errors in Property StringToInt conversion URL: https://github.com/apache/nifi-minifi-cpp/pull/472#discussion_r246969665
########## File path: libminifi/test/unit/PropertyTests.cpp ########## @@ -107,3 +107,28 @@ TEST_CASE("Test Trimmer Left", "[testTrims]") { REQUIRE(test.c_str()[1] == ' '); } +TEST_CASE("Test int conversion", "[testStringToInt]") { + using org::apache::nifi::minifi::core::Property; + + uint64_t uint64_var = 0; + REQUIRE(Property::StringToInt("-2", uint64_var) == false); // Negative shouldn't be converted to uint + + uint32_t uint32_var = 0; + REQUIRE(Property::StringToInt("3 GB", uint32_var) == true); // Test skipping of spaces, too + uint32_t expected_value = 3u * 1024 * 1024 * 1024; + REQUIRE(uint32_var == expected_value); + + int32_t int32_var = 0; + REQUIRE(Property::StringToInt("3GB", int32_var) == false); // Doesn't fit + + REQUIRE(Property::StringToInt("-1 G", int32_var) == true); + REQUIRE(int32_var == -1 * 1000 * 1000 * 1000); + + REQUIRE(Property::StringToInt("-1G", uint32_var) == false); // Negative to uint Review comment: This shouldn't be allowed. Whether this barrier exists here or elsewhere is what I think we should discuss. It's about the end to end correctness, so not sure if the appropriate action is to fix the signedness issues or correct the overall issue that 707 was hoping to look into. I fear that resolving any issues like signed values without looking into solving the whole picture takes us to an unknown state. Thoughts? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services