示例#1
0
文件: t_unpack.c 项目: laishi/verse
END_TEST


/**
 * \brief Unit test of packing real64 values
 */
START_TEST ( test_UnPack_Real64 )
{
	size_t buf_pos = 0;
	unsigned char buffer[REAL64_BUF_SIZE] = {
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	/*  0.0 */
			0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*  1.0 */
			0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	/*  2.0 */
			0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	/* -2.0 */
			0x3f, 0xd5, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,	/*  1/3 */
			0,
	};
	real64 expected_results[REAL64_TV_SIZE] = {
			0.0,
			1.0,
			2.0,
			-2.0,
			1.0/3.0,
			0,
	};
	real64 results[REAL64_TV_SIZE] = {0,};
	int i = 0;

	buf_pos += vnp_raw_unpack_real64((void*)&buffer[buf_pos],
			&results[i++]);
	buf_pos += vnp_raw_unpack_real64((void*)&buffer[buf_pos],
			&results[i++]);
	buf_pos += vnp_raw_unpack_real64((void*)&buffer[buf_pos],
			&results[i++]);
	buf_pos += vnp_raw_unpack_real64((void*)&buffer[buf_pos],
			&results[i++]);
	buf_pos += vnp_raw_unpack_real64((void*)&buffer[buf_pos],
			&results[i++]);

	fail_unless( buf_pos == 5*8,
			"Size of real64 buffer: %d != 40",
			buf_pos);

	for(i = 0; i < REAL64_TV_SIZE; i++) {
		fail_unless( results[i] == expected_results[i],
				"Test vector of real64 differs at position: %d (%f != %f)",
				i, results[i], expected_results[i]);
	}
}
示例#2
0
unsigned int v_unpack_c_key_set(const char *buf, size_t buffer_length)
{
	unsigned int i, buffer_pos = 0;
	VNodeID node_id;
	VLayerID curve_id;
	uint32 key_id;
	uint8 dimensions;
	real64 pre_value[4], value[4], pos, post_value[4];
	uint32 post_pos[4], pre_pos[4];
	
	if(buffer_length < 11)
		return -1;
	buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &node_id);
	buffer_pos += vnp_raw_unpack_uint16(&buf[buffer_pos], &curve_id);
	buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &key_id);
	buffer_pos += vnp_raw_unpack_uint8(&buf[buffer_pos], &dimensions);
	if(dimensions != 0 && dimensions < 5)
	{
		void (* func_c_key_set)(void *user_data, VNodeID node_id, VLayerID curve_id, uint32 key_id, uint8 dimensions, real64 *pre_value, uint32 *pre_pos, real64 *value, real64 pos, real64 *post_value, uint32 *post_pos);
		for(i = 0; i < dimensions; i++)
			buffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &pre_value[i]);	
		for(i = 0; i < dimensions; i++)
			buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &pre_pos[i]);	
		for(i = 0; i < dimensions; i++)
			buffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &value[i]);	
		buffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &pos);	
		for(i = 0; i < dimensions; i++)
			buffer_pos += vnp_raw_unpack_real64(&buf[buffer_pos], &post_value[i]);	
		for(i = 0; i < dimensions; i++)
			buffer_pos += vnp_raw_unpack_uint32(&buf[buffer_pos], &post_pos[i]);
	#if defined V_PRINT_RECEIVE_COMMANDS
		switch(dimensions)
		{
		case 1:
			printf("receive: verse_send_c_key_set(node_id = %u curve_id = %u key_id = %u dimensions = %u pre_value = %f pre_pos = %u value = %f pos = %f, pre_value = %f pre_pos = %u ); callback = %p\n", node_id, curve_id, key_id, dimensions, pre_value[0], pre_pos[0], value[0], pos, pre_value[0], pre_pos[0], v_fs_get_user_func(130));
		break;
		case 2:
			printf("receive: verse_send_c_key_set(node_id = %u curve_id = %u key_id = %u dimensions = %u pre_value = {%f, %f} pre_pos = {%u, %u} value = {%f, %f} pos = %f, pre_value = {%f, %f} pre_pos = {%u, %u}); callback = %p\n",
				node_id, curve_id, key_id, dimensions, 
				pre_value[0], pre_value[1], 
				pre_pos[0], pre_pos[1], 
				value[0], value[1], pos, 
				pre_value[0], pre_value[1],  
				pre_pos[0], pre_pos[1], v_fs_get_user_func(130));
		break;
		case 3:
			printf("receive: verse_send_c_key_set(node_id = %u curve_id = %u key_id = %u dimensions = %u pre_value = {%f, %f, %f} pre_pos = {%u, %u, %u} value = {%f, %f, %f} pos = %f, pre_value = {%f, %f, %f} pre_pos = {%u, %u, %u}); callback = %p\n",
				node_id, curve_id, key_id, dimensions, 
				pre_value[0], pre_value[1], pre_value[2],  
				pre_pos[0], pre_pos[1], pre_pos[2],  
				value[0], value[1], value[2], pos, 
				pre_value[0], pre_value[1], pre_value[2],  
				pre_pos[0], pre_pos[1], pre_pos[2], v_fs_get_user_func(130));
			
		break;
		case 4:
			printf("receive: verse_send_c_key_set(node_id = %u curve_id = %u key_id = %u dimensions = %u pre_value = {%f, %f, %f, %f} pre_pos = {%u, %u, %u, %u} value = {%f, %f, %f, %f} pos = %f, pre_value = {%f, %f, %f, %f} pre_pos = {%u, %u, %u, %u}); callback = %p\n",
				node_id, curve_id, key_id, dimensions, 
				pre_value[0], pre_value[1], pre_value[2], pre_value[3], 
				pre_pos[0], pre_pos[1], pre_pos[2], pre_pos[3], 
				value[0], value[1], value[2], value[3], pos, 
				pre_value[0], pre_value[1], pre_value[2], pre_value[3], 
				pre_pos[0], pre_pos[1], pre_pos[2], pre_pos[3], v_fs_get_user_func(130));		
		break;
		}
	#endif
		func_c_key_set = v_fs_get_user_func(130);
		if(func_c_key_set != NULL)
			func_c_key_set(v_fs_get_user_data(130), node_id, curve_id, key_id, dimensions, pre_value, pre_pos, value, pos, post_value, post_pos);
		return buffer_pos;
	}else
	{
		void (* alias_c_key_destroy)(void *user_data, VNodeID node_id, VLayerID curve_id, uint32 key_id);
		alias_c_key_destroy = v_fs_get_alias_user_func(130);
		printf("receive: verse_send_c_key_destroy(node_id = %u curve_id = %u key_id = %u); callback = %p\n", node_id, curve_id, key_id, alias_c_key_destroy);
		if(alias_c_key_destroy != NULL)
			alias_c_key_destroy(v_fs_get_alias_user_data(130), node_id, curve_id, key_id);
		return buffer_pos;
	}
}