test: utils: Validate hex sign extension
Converting strings to hex stores data in a uint64_t. This can incorrectly sign extend if the type being converted is signed. Provide tests to be sure that the signed conversion is correct. This is known to fail, so report as expected failure. Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
committed by
Laurent Pinchart
parent
b1f09c013a
commit
06044ca70d
@@ -218,6 +218,23 @@ protected:
|
||||
os << utils::hex(static_cast<uint64_t>(0x42), 1) << " ";
|
||||
ref += "0x42 ";
|
||||
|
||||
os << utils::hex(static_cast<int8_t>(-1)) << " ";
|
||||
ref += "0xff ";
|
||||
os << utils::hex(static_cast<uint8_t>(-1)) << " ";
|
||||
ref += "0xff ";
|
||||
os << utils::hex(static_cast<int16_t>(-1)) << " ";
|
||||
ref += "0xffff ";
|
||||
os << utils::hex(static_cast<uint16_t>(-1)) << " ";
|
||||
ref += "0xffff ";
|
||||
os << utils::hex(static_cast<int32_t>(-1)) << " ";
|
||||
ref += "0xffffffff ";
|
||||
os << utils::hex(static_cast<uint32_t>(-1)) << " ";
|
||||
ref += "0xffffffff ";
|
||||
os << utils::hex(static_cast<int64_t>(-1)) << " ";
|
||||
ref += "0xffffffffffffffff ";
|
||||
os << utils::hex(static_cast<uint64_t>(-1)) << " ";
|
||||
ref += "0xffffffffffffffff ";
|
||||
|
||||
std::string s = os.str();
|
||||
if (s != ref) {
|
||||
cerr << "utils::hex() test failed, expected '" << ref
|
||||
|
||||
Reference in New Issue
Block a user