Add unit test for float encoding

PR #3369 <https://github.com/Genymobile/scrcpy/pull/3369>
This commit is contained in:
Romain Vimont 2022-08-03 15:23:39 +02:00
parent fd3483c837
commit 1ab6c19486

View file

@ -67,6 +67,17 @@ static void test_read64be(void) {
assert(val == 0xABCD1234567890EF);
}
static void test_float_to_u16fp(void) {
assert(sc_float_to_u16fp(0.0f) == 0);
assert(sc_float_to_u16fp(0.03125f) == 0x800);
assert(sc_float_to_u16fp(0.0625f) == 0x1000);
assert(sc_float_to_u16fp(0.125f) == 0x2000);
assert(sc_float_to_u16fp(0.25f) == 0x4000);
assert(sc_float_to_u16fp(0.5f) == 0x8000);
assert(sc_float_to_u16fp(0.75f) == 0xc000);
assert(sc_float_to_u16fp(1.0f) == 0xffff);
}
int main(int argc, char *argv[]) {
(void) argc;
(void) argv;
@ -77,5 +88,7 @@ int main(int argc, char *argv[]) {
test_read16be();
test_read32be();
test_read64be();
test_float_to_u16fp();
return 0;
}