mirror of
				https://gitlab.freedesktop.org/wayland/wayland.git
				synced 2025-11-03 09:01:42 -05:00 
			
		
		
		
	connection-test: Store expected result in struct marshal_data
This commit is contained in:
		
							parent
							
								
									0ca52cce98
								
							
						
					
					
						commit
						33ad8a3315
					
				
					 1 changed files with 25 additions and 23 deletions
				
			
		| 
						 | 
					@ -146,6 +146,11 @@ struct marshal_data {
 | 
				
			||||||
	uint32_t read_mask;
 | 
						uint32_t read_mask;
 | 
				
			||||||
	uint32_t write_mask;
 | 
						uint32_t write_mask;
 | 
				
			||||||
	uint32_t buffer[10];
 | 
						uint32_t buffer[10];
 | 
				
			||||||
 | 
						union {
 | 
				
			||||||
 | 
							uint32_t u;
 | 
				
			||||||
 | 
							int32_t i;
 | 
				
			||||||
 | 
							const char *s;
 | 
				
			||||||
 | 
						} value;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
| 
						 | 
					@ -244,30 +249,24 @@ TEST(connection_marshal)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
validate_demarshal_u(void *data, struct wl_object *object, uint32_t u)
 | 
					validate_demarshal_u(struct marshal_data *data,
 | 
				
			||||||
 | 
							     struct wl_object *object, uint32_t u)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint32_t *msg = data;
 | 
						assert(data->value.u == u);
 | 
				
			||||||
 | 
					 | 
				
			||||||
	assert(object->id = msg[0]);
 | 
					 | 
				
			||||||
	assert(msg[2] == u);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
validate_demarshal_i(void *data, struct wl_object *object, int32_t i)
 | 
					validate_demarshal_i(struct marshal_data *data,
 | 
				
			||||||
 | 
							     struct wl_object *object, int32_t i)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint32_t *msg = data;
 | 
						assert(data->value.i == i);
 | 
				
			||||||
 | 
					 | 
				
			||||||
	assert(object->id = msg[0]);
 | 
					 | 
				
			||||||
	assert((int32_t) msg[2] == i);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
validate_demarshal_s(void *data, struct wl_object *object, const char *s)
 | 
					validate_demarshal_s(struct marshal_data *data,
 | 
				
			||||||
 | 
							     struct wl_object *object, const char *s)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint32_t *msg = data;
 | 
						assert(strcmp(data->value.s, s) == 0);
 | 
				
			||||||
 | 
					 | 
				
			||||||
	assert(object->id = msg[0]);
 | 
					 | 
				
			||||||
	assert(strcmp(s, "superdude") == 0);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
| 
						 | 
					@ -288,31 +287,33 @@ demarshal(struct marshal_data *data, const char *format,
 | 
				
			||||||
	object.id = msg[0];
 | 
						object.id = msg[0];
 | 
				
			||||||
	closure = wl_connection_demarshal(data->read_connection,
 | 
						closure = wl_connection_demarshal(data->read_connection,
 | 
				
			||||||
					  size, &objects, &message);
 | 
										  size, &objects, &message);
 | 
				
			||||||
	wl_closure_invoke(closure, &object, func, msg);
 | 
						wl_closure_invoke(closure, &object, func, data);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEST(connection_demarshal)
 | 
					TEST(connection_demarshal)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct marshal_data data;
 | 
						struct marshal_data data;
 | 
				
			||||||
	uint32_t msg[10];
 | 
						uint32_t msg[10];
 | 
				
			||||||
	static const char text[] = "superdude";
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	setup_marshal_data(&data);
 | 
						setup_marshal_data(&data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						data.value.u = 8000;
 | 
				
			||||||
	msg[0] = 400200;	/* object id */
 | 
						msg[0] = 400200;	/* object id */
 | 
				
			||||||
	msg[1] = 12;		/* size = 12, opcode = 0 */
 | 
						msg[1] = 12;		/* size = 12, opcode = 0 */
 | 
				
			||||||
	msg[2] = 8000;
 | 
						msg[2] = data.value.u;
 | 
				
			||||||
	demarshal(&data, "u", msg, (void *) validate_demarshal_u);
 | 
						demarshal(&data, "u", msg, (void *) validate_demarshal_u);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						data.value.i = -557799;
 | 
				
			||||||
	msg[0] = 400200;
 | 
						msg[0] = 400200;
 | 
				
			||||||
	msg[1] = 12;
 | 
						msg[1] = 12;
 | 
				
			||||||
	msg[2] = -557799;
 | 
						msg[2] = data.value.i;
 | 
				
			||||||
	demarshal(&data, "i", msg, (void *) validate_demarshal_i);
 | 
						demarshal(&data, "i", msg, (void *) validate_demarshal_i);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						data.value.s = "superdude";
 | 
				
			||||||
	msg[0] = 400200;
 | 
						msg[0] = 400200;
 | 
				
			||||||
	msg[1] = 24;
 | 
						msg[1] = 24;
 | 
				
			||||||
	msg[2] = 10;
 | 
						msg[2] = 10;
 | 
				
			||||||
	memcpy(&msg[3], text, msg[2]);
 | 
						memcpy(&msg[3], data.value.s, msg[2]);
 | 
				
			||||||
	demarshal(&data, "s", msg, (void *) validate_demarshal_s);
 | 
						demarshal(&data, "s", msg, (void *) validate_demarshal_s);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	release_marshal_data(&data);
 | 
						release_marshal_data(&data);
 | 
				
			||||||
| 
						 | 
					@ -352,7 +353,7 @@ marshal_demarshal(struct marshal_data *data,
 | 
				
			||||||
	object.id = msg[0];
 | 
						object.id = msg[0];
 | 
				
			||||||
	closure = wl_connection_demarshal(data->read_connection,
 | 
						closure = wl_connection_demarshal(data->read_connection,
 | 
				
			||||||
					  size, &objects, &message);
 | 
										  size, &objects, &message);
 | 
				
			||||||
	wl_closure_invoke(closure, &object, func, msg);
 | 
						wl_closure_invoke(closure, &object, func, data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	wl_closure_destroy(closure);
 | 
						wl_closure_destroy(closure);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -363,8 +364,9 @@ TEST(connection_marshal_demarshal)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	setup_marshal_data(&data);
 | 
						setup_marshal_data(&data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	marshal_demarshal(&data, (void *) validate_demarshal_s, 24,
 | 
						data.value.s = "cookie robots";
 | 
				
			||||||
			  "s", "superdude");
 | 
						marshal_demarshal(&data, (void *) validate_demarshal_s,
 | 
				
			||||||
 | 
								  28, "s", data.value.s);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	release_marshal_data(&data);
 | 
						release_marshal_data(&data);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue