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

Function DivVerifyInt64Int32

Archive/releases/2/DivVerify.cpp:1748–1796  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1746};
1747
1748void DivVerifyInt64Int32()
1749{
1750 size_t i;
1751
1752 for( i = 0; i < sizeof(int64_int32)/sizeof(int64_int32[0]); ++i )
1753 {
1754 __int64 ret;
1755 if( SafeDivide(int64_int32[i].x, int64_int32[i].y, ret) != int64_int32[i].fExpected )
1756 {
1757 //assert(false);
1758 printf("Error in case int64_int32: %I64X, %I64X, expected = %s\n", int64_int32[i].x, int64_int32[i].y, int64_int32[i].fExpected ? "true" : "false");
1759 }
1760
1761 // Now test throwing version
1762 bool fSuccess = true;
1763 try
1764 {
1765 SafeInt<__int64> si(int64_int32[i].x);
1766 si /= int64_int32[i].y;
1767 }
1768 catch(...)
1769 {
1770 fSuccess = false;
1771 }
1772
1773 if( fSuccess != int64_int32[i].fExpected )
1774 {
1775 printf("Error in case int64_int32 throw: %I64X, %I64X, expected = %s\n", int64_int32[i].x, int64_int32[i].y, int64_int32[i].fExpected ? "true" : "false");
1776 }
1777
1778 // Also need to test the version that assigns back out
1779 // to a plain int, as it has different logic
1780 fSuccess = true;
1781 try
1782 {
1783 __int64 x(int64_int32[i].x);
1784 x /= SafeInt<__int32>(int64_int32[i].y);
1785 }
1786 catch(...)
1787 {
1788 fSuccess = false;
1789 }
1790
1791 if( fSuccess != int64_int32[i].fExpected )
1792 {
1793 printf("Error in case int64_int32 throw: %I64X, %I64X, expected = %s\n", int64_int32[i].x, int64_int32[i].y, int64_int32[i].fExpected ? "true" : "false");
1794 }
1795 }
1796}
1797
1798DivTest< __int64, __int32 > int64_int32_2[] =
1799{

Callers 1

DivVerifyFunction · 0.70

Calls 1

SafeDivideFunction · 0.50

Tested by

no test coverage detected