Skip to content

Commit 2ae43e7

Browse files
committed
TestUtils: added even more tests to strToInt()
1 parent b691479 commit 2ae43e7

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

test/testutils.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,22 +244,36 @@ class TestUtils : public TestFixture {
244244
ASSERT_THROW_EQUALS(::strToInt<int>("1.0"), std::runtime_error, "converting '1.0' to integer failed - not an integer (pos)");
245245
ASSERT_THROW_EQUALS(::strToInt<int>("+1.0"), std::runtime_error, "converting '+1.0' to integer failed - not an integer (pos)");
246246
ASSERT_THROW_EQUALS(::strToInt<int>("-1.0"), std::runtime_error, "converting '-1.0' to integer failed - not an integer (pos)");
247+
ASSERT_THROW_EQUALS(::strToInt<int>("1U"), std::runtime_error, "converting '1U' to integer failed - not an integer (pos)");
248+
ASSERT_THROW_EQUALS(::strToInt<int>("1L"), std::runtime_error, "converting '1L' to integer failed - not an integer (pos)");
249+
ASSERT_THROW_EQUALS(::strToInt<int>("1Z"), std::runtime_error, "converting '1Z' to integer failed - not an integer (pos)");
250+
// ASSERT_THROW_EQUALS(::strToInt<int>("01"), std::runtime_error, "converting '01' to integer failed - not an integer"); // TODO: should fail
251+
ASSERT_THROW_EQUALS(::strToInt<int>("0x1"), std::runtime_error, "converting '0x1' to integer failed - not an integer (pos)");
252+
ASSERT_THROW_EQUALS(::strToInt<int>("0b1"), std::runtime_error, "converting '0b1' to integer failed - not an integer (pos)");
247253
ASSERT_THROW_EQUALS(::strToInt<int>("one"), std::runtime_error, "converting 'one' to integer failed - not an integer (invalid_argument)");
248254
ASSERT_THROW_EQUALS(::strToInt<int>(" 1"), std::runtime_error, "converting ' 1' to integer failed - not an integer");
249255
ASSERT_THROW_EQUALS(::strToInt<int>("\t1"), std::runtime_error, "converting '\t1' to integer failed - not an integer");
250256
ASSERT_THROW_EQUALS(::strToInt<int>("1 "), std::runtime_error, "converting '1 ' to integer failed - not an integer (pos)");
251257
ASSERT_THROW_EQUALS(::strToInt<int>("1\t"), std::runtime_error, "converting '1\t' to integer failed - not an integer (pos)");
252258
ASSERT_THROW_EQUALS(::strToInt<int>("+ 1"), std::runtime_error, "converting '+ 1' to integer failed - not an integer (invalid_argument)");
259+
ASSERT_THROW_EQUALS(::strToInt<int>("O1"), std::runtime_error, "converting 'O1' to integer failed - not an integer (invalid_argument)");
253260
ASSERT_THROW_EQUALS(::strToInt<unsigned int>("1ms"), std::runtime_error, "converting '1ms' to integer failed - not an integer (pos)");
254261
ASSERT_THROW_EQUALS(::strToInt<unsigned int>("1.0"), std::runtime_error, "converting '1.0' to integer failed - not an integer (pos)");
255262
ASSERT_THROW_EQUALS(::strToInt<unsigned int>("+1.0"), std::runtime_error, "converting '+1.0' to integer failed - not an integer (pos)");
256263
ASSERT_THROW_EQUALS(::strToInt<unsigned int>("-1.0"), std::runtime_error, "converting '-1.0' to integer failed - not an integer (pos)");
264+
ASSERT_THROW_EQUALS(::strToInt<unsigned int>("1U"), std::runtime_error, "converting '1U' to integer failed - not an integer (pos)");
265+
ASSERT_THROW_EQUALS(::strToInt<unsigned int>("1L"), std::runtime_error, "converting '1L' to integer failed - not an integer (pos)");
266+
ASSERT_THROW_EQUALS(::strToInt<unsigned int>("1Z"), std::runtime_error, "converting '1Z' to integer failed - not an integer (pos)");
267+
// ASSERT_THROW_EQUALS(::strToInt<unsigned int>("01"), std::runtime_error, "converting '01' to integer failed - not an integer"); // TODO: should fail
268+
ASSERT_THROW_EQUALS(::strToInt<unsigned int>("0x1"), std::runtime_error, "converting '0x1' to integer failed - not an integer (pos)");
269+
ASSERT_THROW_EQUALS(::strToInt<unsigned int>("0b1"), std::runtime_error, "converting '0b1' to integer failed - not an integer (pos)");
257270
ASSERT_THROW_EQUALS(::strToInt<unsigned int>("one"), std::runtime_error, "converting 'one' to integer failed - not an integer (invalid_argument)");
258271
ASSERT_THROW_EQUALS(::strToInt<unsigned int>(" 1"), std::runtime_error, "converting ' 1' to integer failed - not an integer");
259272
ASSERT_THROW_EQUALS(::strToInt<unsigned int>("\t1"), std::runtime_error, "converting '\t1' to integer failed - not an integer");
260273
ASSERT_THROW_EQUALS(::strToInt<unsigned int>("1 "), std::runtime_error, "converting '1 ' to integer failed - not an integer (pos)");
261274
ASSERT_THROW_EQUALS(::strToInt<unsigned int>("1\t"), std::runtime_error, "converting '1\t' to integer failed - not an integer (pos)");
262275
ASSERT_THROW_EQUALS(::strToInt<unsigned int>("- 1"), std::runtime_error, "converting '- 1' to integer failed - not an integer (invalid_argument)");
276+
ASSERT_THROW_EQUALS(::strToInt<unsigned int>("O1"), std::runtime_error, "converting 'O1' to integer failed - not an integer (invalid_argument)");
263277
ASSERT_THROW_EQUALS(::strToInt<int>(std::to_string(static_cast<int64_t>(std::numeric_limits<int>::max()) + 1)), std::runtime_error, "converting '2147483648' to integer failed - out of range (limits)");
264278
ASSERT_THROW_EQUALS(::strToInt<int>(std::to_string(static_cast<int64_t>(std::numeric_limits<int>::min()) - 1)), std::runtime_error, "converting '-2147483649' to integer failed - out of range (limits)");
265279
ASSERT_THROW_EQUALS(::strToInt<int8_t>(std::to_string(static_cast<int64_t>(std::numeric_limits<int8_t>::max()) + 1)), std::runtime_error, "converting '128' to integer failed - out of range (limits)");

0 commit comments

Comments
 (0)