| 13 | } |
| 14 | |
| 15 | FBE::decimal_t VerifyDecimal(uint32_t low, uint32_t mid, uint32_t high, bool negative, uint8_t scale) |
| 16 | { |
| 17 | uint32_t flags = negative ? ((scale << 16) | 0x80000000) : (scale << 16); |
| 18 | |
| 19 | uint8_t data[16]; |
| 20 | *((uint32_t*)(data + 0)) = low; |
| 21 | *((uint32_t*)(data + 4)) = mid; |
| 22 | *((uint32_t*)(data + 8)) = high; |
| 23 | *((uint32_t*)(data + 12)) = flags; |
| 24 | |
| 25 | FBE::FBEBuffer buffer(data, 16); |
| 26 | |
| 27 | FBE::FieldModel<FBE::decimal_t> model(buffer, 0); |
| 28 | FBE::decimal_t value1; |
| 29 | FBE::decimal_t value2; |
| 30 | model.get(value1); |
| 31 | model.set(value1); |
| 32 | model.get(value2); |
| 33 | if (!Compare(value1, value2)) |
| 34 | throw std::logic_error("Invalid decimal serialization!"); |
| 35 | |
| 36 | FBE::FinalModel<FBE::decimal_t> final_model(buffer, 0); |
| 37 | FBE::decimal_t value3; |
| 38 | FBE::decimal_t value4; |
| 39 | if (final_model.get(value3) != 16) |
| 40 | throw std::logic_error("Invalid decimal final serialization!"); |
| 41 | final_model.set(value3); |
| 42 | if (final_model.get(value4) != 16) |
| 43 | throw std::logic_error("Invalid decimal final serialization!"); |
| 44 | if (!Compare(value3, value4)) |
| 45 | throw std::logic_error("Invalid decimal final serialization!"); |
| 46 | |
| 47 | return value1; |
| 48 | } |
| 49 | |
| 50 | TEST_CASE("Decimal tests", "[FBE]") |
| 51 | { |
no test coverage detected