Example #1
0
void convert_inplace_test_do_it( dl_ctx_t       dl_ctx,        dl_typeid_t type,
        						 unsigned char* store_buffer,  size_t      store_size,
								 unsigned char* out_buffer,    size_t*     out_size,
								 unsigned int   conv_ptr_size, dl_endian_t conv_endian )
{
	/*
		About test
			since converting pointersizes from smaller to bigger can't be done inplace this test differs
			depending on conversion.
			tests will use inplace convert if possible, otherwise it checks that the operation returns
			DL_ERROR_UNSUPORTED_OPERATION as it should.

			ie. if our test is only converting endian we do both conversions inplace, otherwise we
			do the supported operation inplace.
	*/

	unsigned char convert_buffer[2048];
	memset( convert_buffer, 0xFE, sizeof(convert_buffer) );
	size_t convert_size = 0;

	if( conv_ptr_size <= sizeof(void*) )
	{
		memcpy( convert_buffer, store_buffer, store_size );
		EXPECT_DL_ERR_OK( dl_convert_inplace( dl_ctx, type, convert_buffer, store_size, conv_endian, conv_ptr_size, &convert_size ) );
		memset( convert_buffer + convert_size, 0xFE, sizeof(convert_buffer) - convert_size );
	}
	else
	{
		// check that error is correct
		EXPECT_DL_ERR_EQ( DL_ERROR_UNSUPPORTED_OPERATION, dl_convert_inplace( dl_ctx, type, store_buffer, store_size, conv_endian, conv_ptr_size, &convert_size ) );

		// convert with ordinary convert
		EXPECT_DL_ERR_OK( dl_convert_calc_size( dl_ctx, type, store_buffer, store_size, conv_ptr_size, &convert_size ) );
		EXPECT_DL_ERR_OK( dl_convert( dl_ctx, type, store_buffer, store_size, convert_buffer, convert_size, conv_endian, conv_ptr_size, 0x0 ) );
	}

	EXPECT_EQ( (unsigned char)0xFE, convert_buffer[convert_size] ); // no overwrite on the generated text plox!
	EXPECT_INSTANCE_INFO( convert_buffer, convert_size, conv_ptr_size, conv_endian, type );


	// convert back!
	if( conv_ptr_size < sizeof(void*))
	{
		// check that error is correct
		EXPECT_DL_ERR_EQ( DL_ERROR_UNSUPPORTED_OPERATION, dl_convert_inplace( dl_ctx, type, convert_buffer, store_size, DL_ENDIAN_HOST, sizeof(void*), out_size ) );

		// convert with ordinary convert
		EXPECT_DL_ERR_OK( dl_convert_calc_size( dl_ctx, type, convert_buffer, convert_size, sizeof(void*), out_size ) );
		EXPECT_DL_ERR_OK( dl_convert( dl_ctx, type, convert_buffer, convert_size, out_buffer, *out_size, DL_ENDIAN_HOST, sizeof(void*), 0x0 ) );
	}
	else
	{
		memcpy( out_buffer, convert_buffer, convert_size );
		EXPECT_DL_ERR_OK( dl_convert_inplace( dl_ctx, type, out_buffer, convert_size, DL_ENDIAN_HOST, sizeof(void*), out_size ) );
		memset( out_buffer + *out_size, 0xFE, OUT_BUFFER_SIZE - *out_size );
	}
}
Example #2
0
TEST_F(DLError, buffer_to_small_returned)
{
	Pods p;
	unsigned char packed[1024];

	EXPECT_DL_ERR_EQ( DL_ERROR_OK,              dl_instance_store( Ctx, Pods::TYPE_ID, &p, packed,  0, 0x0 ) ); // pack to 0-size out_buffer is ok, calculating size
	EXPECT_DL_ERR_EQ( DL_ERROR_BUFFER_TO_SMALL, dl_instance_store( Ctx, Pods::TYPE_ID, &p, packed, 10, 0x0 ) ); // test buffer smaller than header
	EXPECT_DL_ERR_EQ( DL_ERROR_BUFFER_TO_SMALL, dl_instance_store( Ctx, Pods::TYPE_ID, &p, packed, 21, 0x0 ) ); // test buffer to small
}
Example #3
0
TEST_F(DLReflect, type_lookup)
{
	dl_typeid_t type_id = 0;
	EXPECT_DL_ERR_OK( dl_reflect_get_type_id(Ctx, "Pods2", &type_id) );
	EXPECT_TRUE(Pods2::TYPE_ID == type_id);
	EXPECT_DL_ERR_OK( dl_reflect_get_type_id(Ctx, "StructArray1", &type_id) );
	EXPECT_TRUE(StructArray1::TYPE_ID == type_id);
	EXPECT_DL_ERR_OK( dl_reflect_get_type_id(Ctx, "StringInlineArray", &type_id) );
	EXPECT_TRUE(StringInlineArray::TYPE_ID == type_id);
	EXPECT_DL_ERR_OK( dl_reflect_get_type_id(Ctx, "TestBits", &type_id) );
	EXPECT_TRUE(TestBits::TYPE_ID == type_id);

	EXPECT_DL_ERR_EQ( DL_ERROR_TYPE_NOT_FOUND, dl_reflect_get_type_id(Ctx, "bloobloo", &type_id) );
	EXPECT_DL_ERR_EQ( DL_ERROR_TYPE_NOT_FOUND, dl_reflect_get_type_id(Ctx, "bopp", &type_id) );
}
Example #4
0
TEST_F(DLError, typelib_version_mismatch_returned)
{
	static const unsigned char typelib[] =
	{
		#include "generated/unittest.bin.h"
	};

	unsigned char modded_type_lib[sizeof(typelib)];

	memcpy( modded_type_lib, typelib, sizeof(typelib) );

	EXPECT_EQ(4u, sizeof(unsigned int));

	union
	{
		unsigned char* lib;
		unsigned int*  version;
	} conv;
	conv.lib = modded_type_lib;
	// testing that errors are returned correctly by modding data.
	unsigned int* lib_version = conv.version + 1;

	EXPECT_EQ(4u, *lib_version);

	*lib_version = 0xFFFFFFFF;

	dl_ctx_t tmp_ctx = 0;
	dl_create_params_t p;
	DL_CREATE_PARAMS_SET_DEFAULT(p);
	EXPECT_DL_ERR_OK( dl_context_create( &tmp_ctx, &p ) );
	EXPECT_DL_ERR_EQ( DL_ERROR_VERSION_MISMATCH, dl_context_load_type_library( tmp_ctx, modded_type_lib, sizeof(modded_type_lib) ) );
	EXPECT_DL_ERR_OK( dl_context_destroy( tmp_ctx ) );
}
Example #5
0
TEST_F( DLUtil, load_binary_from_text_error )
{
	EXPECT_DL_ERR_OK( dl_util_store_to_file( Ctx,
											 Pods::TYPE_ID,
											 TEMP_FILE_NAME,
											 DL_UTIL_FILE_TYPE_TEXT,
											 DL_ENDIAN_HOST,
											 sizeof(void*),
											 &p ) );

	union { Pods* p2; void* vp; } conv;
	conv.p2 = 0x0;
	dl_typeid_t stored_type;

	EXPECT_DL_ERR_EQ( DL_ERROR_UTIL_FILE_TYPE_MISMATCH, dl_util_load_from_file( Ctx,
																				Pods::TYPE_ID,
																				TEMP_FILE_NAME,
																				DL_UTIL_FILE_TYPE_BINARY,
																				&conv.vp,
																				&stored_type ) );

	EXPECT_EQ( 0x0, conv.p2 ); // should be untouched
}
Example #6
0
TEST_F( DLUtil, dl_util_load_non_existing_file )
{
	EXPECT_DL_ERR_EQ( DL_ERROR_UTIL_FILE_NOT_FOUND,
					  dl_util_load_from_file( Ctx, 0, "whobb whobb whoob", DL_UTIL_FILE_TYPE_AUTO, 0, 0 ) );
}