ODK unit tests for release request

PiperOrigin-RevId: 584427947
Change-Id: I7a131739c5ea0d27c2f9e9c5ecb7b138176ce049
This commit is contained in:
Vicky Min
2023-11-21 14:21:06 -08:00
committed by Robert Shih
parent 91e573f574
commit 726f2d51e9
7 changed files with 160 additions and 15 deletions

View File

@@ -358,6 +358,8 @@ size_t ODK_FieldLength(ODK_FieldType type) {
return sizeof(uint32_t);
case ODK_UINT64:
return sizeof(uint64_t);
case ODK_INT64:
return sizeof(uint64_t);
case ODK_BOOL: // Booleans are stored in the message as 32 bit ints.
return sizeof(uint32_t);
case ODK_SUBSTRING:
@@ -414,6 +416,12 @@ OEMCryptoResult ODK_WriteSingleField(uint8_t* buf, const ODK_Field* field) {
memcpy(buf, &u64, sizeof(u64));
break;
}
case ODK_INT64: {
const int64_t i64 =
oemcrypto_htobe64(*static_cast<int64_t*>(field->value));
memcpy(buf, &i64, sizeof(i64));
break;
}
case ODK_BOOL: {
const bool value = *static_cast<bool*>(field->value);
const uint32_t u32 = oemcrypto_htobe32(value ? 1 : 0);
@@ -493,6 +501,12 @@ OEMCryptoResult ODK_ReadSingleField(const uint8_t* buf,
*u64p = oemcrypto_be64toh(*u64p);
break;
}
case ODK_INT64: {
memcpy(field->value, buf, sizeof(int64_t));
int64_t* i64p = static_cast<int64_t*>(field->value);
*i64p = oemcrypto_be64toh(*i64p);
break;
}
case ODK_BOOL: {
uint32_t value;
memcpy(&value, buf, sizeof(uint32_t));
@@ -612,6 +626,14 @@ OEMCryptoResult ODK_DumpSingleField(const uint8_t* buf,
<< "\n";
break;
}
case ODK_INT64: {
int64_t val;
memcpy(&val, buf, sizeof(int64_t));
val = oemcrypto_be64toh(val);
std::cerr << field->name << ": " << val << " = 0x" << std::hex << val
<< "\n";
break;
}
case ODK_SUBSTRING: {
uint32_t off = 0;
uint32_t len = 0;