mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/spice-common
synced 2025-12-29 08:28:08 +00:00
test-marshallers: Test demarshalling
Generate demarshallers code and check it too. Signed-off-by: Frediano Ziglio <fziglio@redhat.com> Acked-by: Christophe Fergeau <cfergeau@redhat.com>
This commit is contained in:
parent
c25c75b552
commit
c2f2096d90
@ -20,6 +20,7 @@ test_logging_LDADD = \
|
||||
test_marshallers_SOURCES = \
|
||||
generated_test_marshallers.c \
|
||||
generated_test_marshallers.h \
|
||||
generated_test_demarshallers.c \
|
||||
test-marshallers.c \
|
||||
test-marshallers.h \
|
||||
$(NULL)
|
||||
@ -37,6 +38,7 @@ test_marshallers_LDADD = \
|
||||
TEST_MARSHALLERS = \
|
||||
generated_test_marshallers.c \
|
||||
generated_test_marshallers.h \
|
||||
generated_test_demarshallers.c \
|
||||
$(NULL)
|
||||
|
||||
BUILT_SOURCES = $(TEST_MARSHALLERS)
|
||||
@ -57,6 +59,8 @@ generated_test_marshallers.c: $(srcdir)/test-marshallers.proto $(MARSHALLERS_DEP
|
||||
$(AM_V_GEN)$(PYTHON) $(top_srcdir)/spice_codegen.py --generate-marshallers --server --include test-marshallers.h $< $@ >/dev/null
|
||||
generated_test_marshallers.h: $(srcdir)/test-marshallers.proto $(MARSHALLERS_DEPS)
|
||||
$(AM_V_GEN)$(PYTHON) $(top_srcdir)/spice_codegen.py --generate-marshallers --server --include test-marshallers.h -H $< $@ >/dev/null
|
||||
generated_test_demarshallers.c: $(srcdir)/test-marshallers.proto $(MARSHALLERS_DEPS)
|
||||
$(AM_V_GEN)$(PYTHON) $(top_srcdir)/spice_codegen.py --generate-demarshallers --client --include test-marshallers.h $< $@ >/dev/null
|
||||
|
||||
EXTRA_DIST = \
|
||||
$(TEST_MARSHALLERS) \
|
||||
|
||||
@ -15,15 +15,22 @@ static uint8_t expected_data[] = { 123, /* dummy byte */
|
||||
0x21, 0x43, 0x65, 0x87, 0x09, 0xba, 0xdc, 0xfe, /* data */
|
||||
};
|
||||
|
||||
typedef void (*message_destructor_t)(uint8_t *message);
|
||||
uint8_t * spice_parse_msg(uint8_t *message_start, uint8_t *message_end,
|
||||
uint32_t channel, uint16_t message_type, int minor,
|
||||
size_t *size_out, message_destructor_t *free_message);
|
||||
|
||||
int main(int argc G_GNUC_UNUSED, char **argv G_GNUC_UNUSED)
|
||||
{
|
||||
SpiceMarshaller *marshaller;
|
||||
SpiceMsgMainShortDataSubMarshall *msg;
|
||||
size_t len;
|
||||
size_t len, msg_len;
|
||||
int free_res;
|
||||
uint8_t *data;
|
||||
message_destructor_t free_message;
|
||||
|
||||
msg = spice_malloc0(sizeof(SpiceMsgMainShortDataSubMarshall) + 2 * sizeof(uint64_t));
|
||||
msg = g_new0(SpiceMsgMainShortDataSubMarshall, 1);
|
||||
msg->data = g_new(uint64_t, 2);
|
||||
msg->dummy_byte = 123;
|
||||
msg->data_size = 2;
|
||||
msg->data[0] = 0x1234567890abcdef;
|
||||
@ -35,11 +42,27 @@ int main(int argc G_GNUC_UNUSED, char **argv G_GNUC_UNUSED)
|
||||
data = spice_marshaller_linearize(marshaller, 0, &len, &free_res);
|
||||
g_assert_cmpint(len, ==, G_N_ELEMENTS(expected_data));
|
||||
g_assert_true(memcmp(data, expected_data, len) == 0);
|
||||
|
||||
g_free(msg->data);
|
||||
g_free(msg);
|
||||
|
||||
// test demarshaller
|
||||
msg = (SpiceMsgMainShortDataSubMarshall *) spice_parse_msg(data, data + len, 1, 1, 0,
|
||||
&msg_len, &free_message);
|
||||
|
||||
g_assert_nonnull(msg);
|
||||
g_assert_cmpint(msg->dummy_byte, ==, 123);
|
||||
g_assert_cmpint(msg->data_size, ==, 2);
|
||||
g_assert_nonnull(msg->data);
|
||||
g_assert_cmpint(msg->data[0], ==, 0x1234567890abcdef);
|
||||
g_assert_cmpint(msg->data[1], ==, 0xfedcba0987654321);
|
||||
|
||||
free_message((uint8_t *) msg);
|
||||
|
||||
if (free_res) {
|
||||
free(data);
|
||||
}
|
||||
spice_marshaller_destroy(marshaller);
|
||||
free(msg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
typedef struct {
|
||||
uint32_t data_size;
|
||||
uint8_t dummy_byte;
|
||||
uint64_t data[];
|
||||
uint64_t *data;
|
||||
} SpiceMsgMainShortDataSubMarshall;
|
||||
|
||||
#endif /* _H_TEST_MARSHALLERS */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user