MCPcopy Create free account
hub / github.com/dcleblanc/SafeInt / AddVerifyInt64Uint16

Function AddVerifyInt64Uint16

Test/AddVerify.cpp:2844–2900  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2842};
2843
2844void AddVerifyInt64Uint16()
2845{
2846 size_t i;
2847
2848 for( i = 0; i < COUNTOF(int64_uint16); ++i )
2849 {
2850 std::int64_t ret;
2851 if( SafeAdd(int64_uint16[i].x, int64_uint16[i].y, ret) != int64_uint16[i].fExpected )
2852 {
2853 cerr << "Error in case int64_uint16: ";
2854 cerr << HEX(16) << int64_uint16[i].x << ", ";
2855 cerr << HEX(4) << int64_uint16[i].y << ", ";
2856 cerr << "expected = " << int64_uint16[i].fExpected << endl;
2857 }
2858
2859 // Now test throwing version
2860 bool fSuccess = true;
2861 try
2862 {
2863 SafeInt<std::int64_t> si(int64_uint16[i].x);
2864 si += int64_uint16[i].y;
2865 }
2866 catch(...)
2867 {
2868 fSuccess = false;
2869 }
2870
2871 if( fSuccess != int64_uint16[i].fExpected )
2872 {
2873 cerr << "Error in case int64_uint16 throw (1): ";
2874 cerr << HEX(16) << int64_uint16[i].x << ", ";
2875 cerr << HEX(4) << int64_uint16[i].y << ", ";
2876 cerr << "expected = " << int64_uint16[i].fExpected << endl;
2877 }
2878
2879 // Also need to test the version that assigns back out
2880 // to a plain int, as it has different logic
2881 fSuccess = true;
2882 try
2883 {
2884 std::int64_t x(int64_uint16[i].x);
2885 x += SafeInt<std::uint16_t>(int64_uint16[i].y);
2886 }
2887 catch(...)
2888 {
2889 fSuccess = false;
2890 }
2891
2892 if( fSuccess != int64_uint16[i].fExpected )
2893 {
2894 cerr << "Error in case int64_uint16 throw (2): ";
2895 cerr << HEX(16) << int64_uint16[i].x << ", ";
2896 cerr << HEX(4) << int64_uint16[i].y << ", ";
2897 cerr << "expected = " << int64_uint16[i].fExpected << endl;
2898 }
2899 }
2900}
2901

Callers 1

AddVerifyFunction · 0.70

Calls 1

SafeAddFunction · 0.50

Tested by

no test coverage detected