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

Function AddVerifyUint8Uint64

Test/AddVerify.cpp:4334–4390  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4332};
4333
4334void AddVerifyUint8Uint64()
4335{
4336 size_t i;
4337
4338 for( i = 0; i < COUNTOF(uint8_uint64); ++i )
4339 {
4340 std::uint8_t ret;
4341 if( SafeAdd(uint8_uint64[i].x, uint8_uint64[i].y, ret) != uint8_uint64[i].fExpected )
4342 {
4343 cerr << "Error in case uint8_uint64: ";
4344 cerr << HEX(2) << (0xFF & (unsigned int)uint8_uint64[i].x) << ", ";
4345 cerr << HEX(16) << uint8_uint64[i].y << ", ";
4346 cerr << "expected = " << uint8_uint64[i].fExpected << endl;
4347 }
4348
4349 // Now test throwing version
4350 bool fSuccess = true;
4351 try
4352 {
4353 SafeInt<std::uint8_t> si(uint8_uint64[i].x);
4354 si += uint8_uint64[i].y;
4355 }
4356 catch(...)
4357 {
4358 fSuccess = false;
4359 }
4360
4361 if( fSuccess != uint8_uint64[i].fExpected )
4362 {
4363 cerr << "Error in case uint8_uint64 throw (1): ";
4364 cerr << HEX(2) << (0xFF & (unsigned int)uint8_uint64[i].x) << ", ";
4365 cerr << HEX(16) << uint8_uint64[i].y << ", ";
4366 cerr << "expected = " << uint8_uint64[i].fExpected << endl;
4367 }
4368
4369 // Also need to test the version that assigns back out
4370 // to a plain int, as it has different logic
4371 fSuccess = true;
4372 try
4373 {
4374 std::uint8_t x(uint8_uint64[i].x);
4375 x += SafeInt<std::uint64_t>(uint8_uint64[i].y);
4376 }
4377 catch(...)
4378 {
4379 fSuccess = false;
4380 }
4381
4382 if( fSuccess != uint8_uint64[i].fExpected )
4383 {
4384 cerr << "Error in case uint8_uint64 throw (2): ";
4385 cerr << HEX(2) << (0xFF & (unsigned int)uint8_uint64[i].x) << ", ";
4386 cerr << HEX(16) << uint8_uint64[i].y << ", ";
4387 cerr << "expected = " << uint8_uint64[i].fExpected << endl;
4388 }
4389 }
4390}
4391

Callers 1

AddVerifyFunction · 0.70

Calls 1

SafeAddFunction · 0.50

Tested by

no test coverage detected