summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniel Stone <daniel@fooishbar.org>2012-05-08 17:17:25 +0100
committerKristian Høgsberg <krh@bitplanet.net>2012-05-08 14:40:39 -0400
commitc5aba11accad178a81a373bd5d1de888b2a51101 (patch)
tree3fe6a1cdc49ddfa1fa48341d64265ef8210b0557 /tests
parentc49f632dae67ee3055e4874f028f723663486da6 (diff)
Add support for signed 24.8 decimal numbers
'fixed' is a signed decimal type which offers a sign bit, 23 bits of integer precision, and 8 bits of decimal precision. This is exposed as an opaque struct with conversion helpers to and from double and int on the C API side. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/connection-test.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/connection-test.c b/tests/connection-test.c
index 54ac423..14a58e6 100644
--- a/tests/connection-test.c
+++ b/tests/connection-test.c
@@ -20,6 +20,7 @@
* OF THIS SOFTWARE.
*/
+#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
@@ -288,6 +289,13 @@ validate_demarshal_h(struct marshal_data *data,
}
static void
+validate_demarshal_f(struct marshal_data *data,
+ struct wl_object *object, wl_fixed_t f)
+{
+ assert(data->value.i == f);
+}
+
+static void
demarshal(struct marshal_data *data, const char *format,
uint32_t *msg, void (*func)(void))
{
@@ -335,6 +343,12 @@ TEST(connection_demarshal)
memcpy(&msg[3], data.value.s, msg[2]);
demarshal(&data, "s", msg, (void *) validate_demarshal_s);
+ data.value.i = wl_fixed_from_double(-90000.2390);
+ msg[0] = 400200;
+ msg[1] = 12;
+ msg[2] = data.value.i;
+ demarshal(&data, "f", msg, (void *) validate_demarshal_f);
+
release_marshal_data(&data);
}
@@ -400,6 +414,18 @@ TEST(connection_marshal_demarshal)
marshal_demarshal(&data, (void *) validate_demarshal_h,
8, "h", data.value.h);
+ data.value.i = wl_fixed_from_double(1234.5678);
+ marshal_demarshal(&data, (void *) validate_demarshal_f,
+ 12, "f", data.value.i);
+
+ data.value.i = wl_fixed_from_double(-90000.2390);
+ marshal_demarshal(&data, (void *) validate_demarshal_f,
+ 12, "f", data.value.i);
+
+ data.value.i = wl_fixed_from_double((1 << 23) - 1 + 0.0941);
+ marshal_demarshal(&data, (void *) validate_demarshal_f,
+ 12, "f", data.value.i);
+
release_marshal_data(&data);
}