Home | History | Annotate | Download | only in tests
      1 /*
      2  * Copyright  2014 Jonas dahl
      3  *
      4  * Permission is hereby granted, free of charge, to any person obtaining
      5  * a copy of this software and associated documentation files (the
      6  * "Software"), to deal in the Software without restriction, including
      7  * without limitation the rights to use, copy, modify, merge, publish,
      8  * distribute, sublicense, and/or sell copies of the Software, and to
      9  * permit persons to whom the Software is furnished to do so, subject to
     10  * the following conditions:
     11  *
     12  * The above copyright notice and this permission notice (including the
     13  * next paragraph) shall be included in all copies or substantial
     14  * portions of the Software.
     15  *
     16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
     17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
     19  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
     20  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
     21  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
     22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     23  * SOFTWARE.
     24  */
     25 
     26 #include <assert.h>
     27 
     28 #include "wayland-client.h"
     29 #include "wayland-private.h"
     30 #include "wayland-server.h"
     31 #include "test-runner.h"
     32 
     33 TEST(message_version)
     34 {
     35 	unsigned int i;
     36 	const struct {
     37 		const struct wl_message *message;
     38 		int expected_version;
     39 	} messages[] = {
     40 		{ &wl_pointer_interface.events[WL_POINTER_ENTER], 1 },
     41 		{ &wl_surface_interface.events[WL_SURFACE_ENTER], 1 },
     42 		{ &wl_pointer_interface.methods[WL_POINTER_SET_CURSOR], 1 },
     43 		{ &wl_pointer_interface.methods[WL_POINTER_RELEASE], 3 },
     44 		{ &wl_surface_interface.methods[WL_SURFACE_DESTROY], 1 },
     45 		{ &wl_surface_interface.methods[WL_SURFACE_SET_BUFFER_TRANSFORM], 2 },
     46 		{ &wl_surface_interface.methods[WL_SURFACE_SET_BUFFER_SCALE], 3 },
     47 	};
     48 
     49 	for (i = 0; i < ARRAY_LENGTH(messages); ++i) {
     50 		assert(wl_message_get_since(messages[i].message) ==
     51 		       messages[i].expected_version);
     52 	}
     53 }
     54 
     55 TEST(message_count_arrays)
     56 {
     57 	unsigned int i;
     58 	struct wl_message fake_messages[] = {
     59 		{ "empty", "", NULL },
     60 		{ "non_present", "iufsonh", NULL },
     61 		{ "leading", "aiufsonh", NULL},
     62 		{ "trailing", "iufsonha", NULL },
     63 		{ "middle", "iufasonh", NULL },
     64 		{ "multiple", "aaiufaasonhaa", NULL },
     65 		{ "leading_version", "2aaiufaasonhaa", NULL },
     66 		{ "among_nullables", "iufsa?oa?nah", NULL },
     67 		{ "all_mixed", "2aiufas?oa?na", NULL },
     68 	};
     69 	const struct {
     70 		const struct wl_message *message;
     71 		int expected_array_count;
     72 	} messages[] = {
     73 		{ &wl_pointer_interface.events[WL_POINTER_ENTER], 0 },
     74 		{ &wl_keyboard_interface.events[WL_KEYBOARD_ENTER], 1 },
     75 		{ &fake_messages[0], 0 },
     76 		{ &fake_messages[1], 0 },
     77 		{ &fake_messages[2], 1 },
     78 		{ &fake_messages[3], 1 },
     79 		{ &fake_messages[4], 1 },
     80 		{ &fake_messages[5], 6 },
     81 		{ &fake_messages[6], 6 },
     82 		{ &fake_messages[7], 3 },
     83 		{ &fake_messages[8], 4 }
     84 	};
     85 
     86 	for (i = 0; i < ARRAY_LENGTH(messages); ++i) {
     87 		assert(wl_message_count_arrays(messages[i].message) ==
     88 		       messages[i].expected_array_count);
     89 	}
     90 }
     91