Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx> --- server/tests/test-stream-device.c | 52 +++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/server/tests/test-stream-device.c b/server/tests/test-stream-device.c index f1707d2f8..cb3a1a4ff 100644 --- a/server/tests/test-stream-device.c +++ b/server/tests/test-stream-device.c @@ -491,6 +491,57 @@ static void test_stream_device_data_message(TestFixture *fixture, gconstpointer g_assert_cmpint(send_data_bytes, ==, 1017); } +static void test_display_info(TestFixture *fixture, gconstpointer user_data) +{ + // build a message for the streaming device + static const char address[] = "pci/a/b.cde"; + StreamMsgDeviceDisplayInfo info = { + .stream_id = GUINT32_TO_LE(0x01020304), + .device_display_id = GUINT32_TO_LE(0x0a0b0c0d), + .device_address_len = GUINT32_TO_LE(sizeof(address)), + }; + uint8_t *p = message; + p = add_stream_hdr(p, STREAM_TYPE_DEVICE_DISPLAY_INFO, sizeof(info) + sizeof(address)); + memcpy(p, &info, sizeof(info)); + p += sizeof(info); + strcpy((char*)p, address); + p += sizeof(address); + + *message_sizes_end = p - message; + ++message_sizes_end; + + // parse the message we crafted + test_kick(); + + // initialize a QXL interface + test_add_display_interface(test); + spice_qxl_set_device_info(&test->qxl_instance, "pci/0/1.2", 0, 2); + + // build the buffer to send to the agent for display information + SpiceMarshaller *m = spice_marshaller_new(); + reds_marshall_device_display_info(test->server, m); + int to_free; + size_t buf_len; + uint8_t *buf = spice_marshaller_linearize(m, 0, &buf_len, &to_free); + + // check output buffer + static const uint8_t expected_buffer[] = { + 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 10, 0, 0, 0,112, 99,105, 47, 48, 47, 49, 46, 50, 0, 0, 0, + 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 10, 0, 0, 0,112, 99, + 105, 47, 48, 47, 49, 46, 50, 0, 0, 0, 0, 0, 4, 3, 2, 1, + 13, 12, 11, 10, 12, 0, 0, 0,112, 99,105, 47, 97, 47, 98, 46, + 99,100,101, 0 + }; + g_assert_cmpint(buf_len, ==, sizeof(expected_buffer)); + g_assert_true(memcmp(buf, expected_buffer, buf_len) == 0); + + if (to_free) { + free(buf); + } + spice_marshaller_destroy(m); +} + static void test_add(const char *name, void (*func)(TestFixture *, gconstpointer), gconstpointer arg) { g_test_add(name, TestFixture, arg, test_stream_device_setup, func, test_stream_device_teardown); @@ -516,6 +567,7 @@ int main(int argc, char *argv[]) test_stream_device_huge_data, NULL); test_add("/server/stream-device-data-message", test_stream_device_data_message, NULL); + test_add("/server/display-info", test_display_info, NULL); return g_test_run(); } -- 2.20.1 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel