MCPcopy Create free account
hub / github.com/chronoxor/FastBinaryEncoding / VerifyDecimal

Function VerifyDecimal

tests/test_decimal.cpp:15–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13}
14
15FBE::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
50TEST_CASE("Decimal tests", "[FBE]")
51{

Callers 1

test_decimal.cppFile · 0.70

Calls 3

CompareFunction · 0.85
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected