summaryrefslogtreecommitdiffstats
path: root/tests/test-marshallers.c
blob: d2c80e579b2ef55e1a8f9eb43c2f32255c5bfbc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <glib.h>
#include <string.h>

#include "common/marshaller.h"
#include "generated_test_marshallers.h"

static uint8_t expected_data[] = { 0x02, 0x00, 0x00, 0x00, /* data_size */
                                   0x08, 0x00, 0x00, 0x00, /* data offset */
                                   0xef, 0xcd, 0xab, 0x90, 0x78, 0x56, 0x34, 0x12, /* data */
                                   0xef, 0xcd, 0xab, 0x90, 0x78, 0x56, 0x34, 0x12, /* data */
};

int main(int argc, char **argv)
{
    SpiceMarshaller *marshaller;
    SpiceMsgMainShortDataSubMarshall *msg;
    size_t len;
    int free_res;
    uint8_t *data;

    msg = spice_malloc0(sizeof(SpiceMsgMainShortDataSubMarshall) + 2 * sizeof(uint64_t));
    msg->data_size = 2;
    msg->data[0] = 0x1234567890abcdef;
    msg->data[1] = 0x1234567890abcdef;

    marshaller = spice_marshaller_new();
    spice_marshall_msg_main_ShortDataSubMarshall(marshaller, msg);
    spice_marshaller_flush(marshaller);
    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);
    if (free_res) {
        free(data);
    }
    spice_marshaller_destroy(marshaller);
    free(msg);

    return 0;
}