Ejemplo n.º 1
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 ) );
}
Ejemplo n.º 2
0
TEST_F( DLTypeLib, simple_read_write )
{
	static const unsigned char small_tl[] =
	{
		#include "generated/small.bin.h"
	};

	// ... load typelib ...
	EXPECT_DL_ERR_OK( dl_context_load_type_library( ctx, small_tl, sizeof(small_tl) ) );

	// ... get size ...
	size_t tl_size = 0;
	EXPECT_DL_ERR_OK( dl_context_write_type_library( ctx, 0x0, 0, &tl_size ) );

	// ... same size before and after write ...
	EXPECT_EQ( sizeof( small_tl ), tl_size );

	unsigned char* written = (unsigned char*)malloc( tl_size + 4 );
	written[ tl_size + 0 ] = 0xFE;
	written[ tl_size + 1 ] = 0xFE;
	written[ tl_size + 2 ] = 0xFE;
	written[ tl_size + 3 ] = 0xFE;

	EXPECT_DL_ERR_OK( dl_context_write_type_library( ctx, written, tl_size, &tl_size ) );

	EXPECT_EQ( sizeof( small_tl ), tl_size );
	EXPECT_EQ( 0xFE, written[ tl_size + 0 ] );
	EXPECT_EQ( 0xFE, written[ tl_size + 1 ] );
	EXPECT_EQ( 0xFE, written[ tl_size + 2 ] );
	EXPECT_EQ( 0xFE, written[ tl_size + 3 ] );

	// ... ensure equal ...
	EXPECT_EQ( 0, memcmp( written, small_tl, sizeof( small_tl ) ) );

	free( written );
}