@@ -303,17 +303,40 @@ TEST_F(convert_test, fromString_LongInt_Fail)
303303 ASSERT_THAT (result.has_value (), Eq (false ));
304304}
305305
306- // / EDGE CASES START
306+ // / SINGED INTEGRAL EDGE CASES START
307307// / inc: increment, dec: decrement
308308
309+ TEST_F (convert_test, fromString_EdgeCase_SignedChar)
310+ {
311+ ::testing::Test::RecordProperty (" TEST_ID" , " 3a70481e-ae86-4b96-92c4-44169700e93a" );
312+
313+ std::string source = " -128" ;
314+ auto signed_char_min = iox::convert::from_string<signed char >(source.c_str ());
315+ ASSERT_THAT (signed_char_min.has_value (), Eq (true ));
316+ EXPECT_THAT (signed_char_min.value (), Eq (static_cast <signed char >(-128 )));
317+
318+ source = " -129" ;
319+ auto signed_char_min_dec_1 = iox::convert::from_string<signed char >(source.c_str ());
320+ ASSERT_THAT (signed_char_min_dec_1.has_value (), Eq (false ));
321+
322+ source = " 127" ;
323+ auto signed_char_max = iox::convert::from_string<signed char >(source.c_str ());
324+ ASSERT_THAT (signed_char_max.has_value (), Eq (true ));
325+ EXPECT_THAT (signed_char_max.value (), Eq (static_cast <signed char >(127 )));
326+
327+ source = " 128" ;
328+ auto signed_char_max_inc_1 = iox::convert::from_string<signed char >(source.c_str ());
329+ ASSERT_THAT (signed_char_max_inc_1.has_value (), Eq (false ));
330+ }
331+
309332TEST_F (convert_test, fromString_EdgeCase_SignedShort)
310333{
311334 ::testing::Test::RecordProperty (" TEST_ID" , " 98e33efd-ba39-4b88-8307-358be30e4e73" );
312335
313336 std::string source = " -32768" ;
314337 auto short_min = iox::convert::from_string<short >(source.c_str ());
315338 ASSERT_THAT (short_min.has_value (), Eq (true ));
316- EXPECT_THAT (short_min.value (), Eq (-32768 ));
339+ EXPECT_THAT (short_min.value (), Eq (static_cast < short >( -32768 ) ));
317340
318341 source = " -32769" ;
319342 auto short_min_dec_1 = iox::convert::from_string<short >(source.c_str ());
@@ -322,7 +345,7 @@ TEST_F(convert_test, fromString_EdgeCase_SignedShort)
322345 source = " 32767" ;
323346 auto short_max = iox::convert::from_string<short >(source.c_str ());
324347 ASSERT_THAT (short_max.has_value (), Eq (true ));
325- EXPECT_THAT (short_max.value (), Eq (32767 ));
348+ EXPECT_THAT (short_max.value (), Eq (static_cast < short >( 32767 ) ));
326349
327350 source = " 32768" ;
328351 auto short_max_inc_1 = iox::convert::from_string<short >(source.c_str ());
@@ -352,6 +375,83 @@ TEST_F(convert_test, fromString_EdgeCase_SignedInt)
352375 ASSERT_THAT (int_max_inc_1.has_value (), Eq (false ));
353376}
354377
378+ // platform dependent (32/64 bit system only)
379+ TEST_F (convert_test, fromString_EdgeCase_SignedLong)
380+ {
381+ ::testing::Test::RecordProperty (" TEST_ID" , " 5dc4c773-6a51-42b6-ad94-7ec885263856" );
382+
383+ constexpr bool IS_32_BIT{sizeof (long ) != sizeof (long long )};
384+
385+ std::string source = std::to_string (std::numeric_limits<long >::min ());
386+ auto long_min = iox::convert::from_string<long >(source.c_str ());
387+ ASSERT_THAT (long_min.has_value (), Eq (true ));
388+ EXPECT_THAT (long_min.value (), Eq (std::numeric_limits<long >::min ()));
389+
390+ source = IS_32_BIT ? " -2147483649" : " -9223372036854775809" ;
391+ auto long_min_dec_1 = iox::convert::from_string<long >(source.c_str ());
392+ ASSERT_THAT (long_min_dec_1.has_value (), Eq (false ));
393+
394+ source = std::to_string (std::numeric_limits<long >::max ());
395+ auto long_max = iox::convert::from_string<long >(source.c_str ());
396+ ASSERT_THAT (long_max.has_value (), Eq (true ));
397+ EXPECT_THAT (long_max.value (), Eq (std::numeric_limits<long >::max ()));
398+
399+ source = IS_32_BIT ? " 2147483648" : " 9223372036854775808" ;
400+ auto long_max_inc_1 = iox::convert::from_string<long >(source.c_str ());
401+ ASSERT_THAT (long_max_inc_1.has_value (), Eq (false ));
402+ }
403+
404+ TEST_F (convert_test, fromString_EdgeCase_SignedLongLong)
405+ {
406+ ::testing::Test::RecordProperty (" TEST_ID" , " 7c015ac0-06a7-407d-aa93-d39c50734951" );
407+
408+ std::string source = " -9223372036854775808" ;
409+ auto long_long_min = iox::convert::from_string<long long >(source.c_str ());
410+ ASSERT_THAT (long_long_min.has_value (), Eq (true ));
411+ // we don't use -9223372036854775808LL here for the compiler will parse it in way we don't want
412+ EXPECT_THAT (long_long_min.value (), Eq (std::numeric_limits<long long >::min ()));
413+
414+ source = " -9223372036854775809" ;
415+ auto long_long_min_dec_1 = iox::convert::from_string<long long >(source.c_str ());
416+ ASSERT_THAT (long_long_min_dec_1.has_value (), Eq (false ));
417+
418+ source = " 9223372036854775807" ;
419+ auto long_long_max = iox::convert::from_string<long long >(source.c_str ());
420+ ASSERT_THAT (long_long_max.has_value (), Eq (true ));
421+ EXPECT_THAT (long_long_max.value (), Eq (9223372036854775807LL ));
422+
423+ source = " 9223372036854775808" ;
424+ auto long_long_max_inc_1 = iox::convert::from_string<long long >(source.c_str ());
425+ ASSERT_THAT (long_long_max_inc_1.has_value (), Eq (false ));
426+ }
427+
428+ // / SINGED INTEGRAL EDGE CASES END
429+
430+ // / UNSINGED INTEGRAL EDGE CASES START
431+
432+ TEST_F (convert_test, fromString_EdgeCase_UnSignedChar)
433+ {
434+ ::testing::Test::RecordProperty (" TEST_ID" , " c11d74a1-be55-41fc-952f-519546eb04fe" );
435+
436+ std::string source = " 0" ;
437+ auto unchar_min = iox::convert::from_string<unsigned char >(source.c_str ());
438+ ASSERT_THAT (unchar_min.has_value (), Eq (true ));
439+ EXPECT_THAT (unchar_min.value (), Eq (0 ));
440+
441+ source = " -1" ;
442+ auto unchar_min_dec_1 = iox::convert::from_string<unsigned char >(source.c_str ());
443+ ASSERT_THAT (unchar_min_dec_1.has_value (), Eq (false ));
444+
445+ source = " 255" ;
446+ auto unchar_max = iox::convert::from_string<unsigned char >(source.c_str ());
447+ ASSERT_THAT (unchar_max.has_value (), Eq (true ));
448+ EXPECT_THAT (unchar_max.value (), Eq (static_cast <unsigned char >(255 )));
449+
450+ source = " 256" ;
451+ auto unchar_max_inc_1 = iox::convert::from_string<unsigned char >(source.c_str ());
452+ ASSERT_THAT (unchar_max_inc_1.has_value (), Eq (false ));
453+ }
454+
355455TEST_F (convert_test, fromString_EdgeCase_UnSignedShort)
356456{
357457 ::testing::Test::RecordProperty (" TEST_ID" , " f9196939-ae5d-4c27-85bf-b3b084343261" );
@@ -368,7 +468,7 @@ TEST_F(convert_test, fromString_EdgeCase_UnSignedShort)
368468 source = " 65535" ;
369469 auto unshort_max = iox::convert::from_string<unsigned short >(source.c_str ());
370470 ASSERT_THAT (unshort_max.has_value (), Eq (true ));
371- EXPECT_THAT (unshort_max.value (), Eq (65535 ));
471+ EXPECT_THAT (unshort_max.value (), Eq (static_cast < unsigned short >( 65535 ) ));
372472
373473 source = " 65536" ;
374474 auto unshort_max_inc_1 = iox::convert::from_string<unsigned short >(source.c_str ());
@@ -391,14 +491,63 @@ TEST_F(convert_test, fromString_EdgeCase_UnSignedInt)
391491 source = " 4294967295" ;
392492 auto unint_max = iox::convert::from_string<unsigned int >(source.c_str ());
393493 ASSERT_THAT (unint_max.has_value (), Eq (true ));
394- EXPECT_THAT (unint_max.value (), Eq (4294967295 ));
494+ EXPECT_THAT (unint_max.value (), Eq (4294967295U ));
395495
396496 source = " 4294967296" ;
397497 auto unint_max_inc_1 = iox::convert::from_string<unsigned int >(source.c_str ());
398498 ASSERT_THAT (unint_max_inc_1.has_value (), Eq (false ));
399499}
400500
401- // / EDGE CASES END
501+ // platform dependent (32/64 bit system only)
502+ TEST_F (convert_test, fromString_EdgeCase_UnSignedLong)
503+ {
504+ ::testing::Test::RecordProperty (" TEST_ID" , " 6e74e284-7f13-4d77-8d3f-009df216828f" );
505+
506+ constexpr bool IS_32_BIT{sizeof (long ) != sizeof (long long )};
507+
508+ std::string source = " 0" ;
509+ auto unlong_min = iox::convert::from_string<unsigned long >(source.c_str ());
510+ ASSERT_THAT (unlong_min.has_value (), Eq (true ));
511+ EXPECT_THAT (unlong_min.value (), Eq (0 ));
512+
513+ source = " -1" ;
514+ auto unlong_min_dec_1 = iox::convert::from_string<unsigned long >(source.c_str ());
515+ ASSERT_THAT (unlong_min_dec_1.has_value (), Eq (false ));
516+
517+ source = std::to_string (std::numeric_limits<unsigned long >::max ());
518+ auto unlong_max = iox::convert::from_string<unsigned long >(source.c_str ());
519+ ASSERT_THAT (unlong_max.has_value (), Eq (true ));
520+ EXPECT_THAT (unlong_max.value (), Eq (std::numeric_limits<unsigned long >::max ()));
521+
522+ source = IS_32_BIT ? " 4294967296" : " 18446744073709551616" ;
523+ auto unlong_max_inc_1 = iox::convert::from_string<unsigned long >(source.c_str ());
524+ ASSERT_THAT (unlong_max_inc_1.has_value (), Eq (false ));
525+ }
526+
527+ TEST_F (convert_test, fromString_EdgeCase_UnSignedLongLong)
528+ {
529+ ::testing::Test::RecordProperty (" TEST_ID" , " 96456d6f-2493-4db2-b5fa-f96f92ec64dd" );
530+
531+ std::string source = " 0" ;
532+ auto unlong_long_min = iox::convert::from_string<unsigned long long >(source.c_str ());
533+ ASSERT_THAT (unlong_long_min.has_value (), Eq (true ));
534+ EXPECT_THAT (unlong_long_min.value (), Eq (0 ));
535+
536+ source = " -1" ;
537+ auto unlong_long_min_dec_1 = iox::convert::from_string<unsigned long long >(source.c_str ());
538+ ASSERT_THAT (unlong_long_min_dec_1.has_value (), Eq (false ));
539+
540+ source = " 18446744073709551615" ;
541+ auto unlong_long_max = iox::convert::from_string<unsigned long long >(source.c_str ());
542+ ASSERT_THAT (unlong_long_max.has_value (), Eq (true ));
543+ EXPECT_THAT (unlong_long_max.value (), Eq (18446744073709551615ULL ));
544+
545+ source = " 18446744073709551616" ;
546+ auto unlong_long_max_inc_1 = iox::convert::from_string<unsigned long long >(source.c_str ());
547+ ASSERT_THAT (unlong_long_max_inc_1.has_value (), Eq (false ));
548+ }
549+
550+ // / UNSINGED INTEGRAL EDGE CASES END
402551
403552TEST_F (convert_test, fromString_cxxString)
404553{
0 commit comments