TEST_F(DLReflect, type_strings) { // tests that all strings in tlds is reflected as expected... test types/members and enums from both unittest.tld and unittest2.tld that is both loaded in Ctx. dl_type_info_t Pods2_type_info; dl_type_info_t BugTest1_InArray_type_info; EXPECT_DL_ERR_OK( dl_reflect_get_type_info( Ctx, Pods2_TYPE_ID, &Pods2_type_info ) ); EXPECT_DL_ERR_OK( dl_reflect_get_type_info( Ctx, BugTest1_InArray_TYPE_ID, &BugTest1_InArray_type_info ) ); EXPECT_EQ( 2u, Pods2_type_info.member_count ); EXPECT_EQ( 3u, BugTest1_InArray_type_info.member_count ); EXPECT_STREQ( "Pods2", Pods2_type_info.name ); EXPECT_STREQ( "BugTest1_InArray", BugTest1_InArray_type_info.name ); // ... and members ... dl_member_info_t Pods2_members[2]; dl_member_info_t BugTest1_InArray_members[3]; EXPECT_DL_ERR_OK( dl_reflect_get_type_members( Ctx, Pods2_TYPE_ID, Pods2_members, 2 ) ); EXPECT_DL_ERR_OK( dl_reflect_get_type_members( Ctx, BugTest1_InArray_TYPE_ID, BugTest1_InArray_members, 3 ) ); EXPECT_STREQ( "Int1", Pods2_members[0].name ); EXPECT_STREQ( "Int2", Pods2_members[1].name ); EXPECT_STREQ( "u64_1", BugTest1_InArray_members[0].name ); EXPECT_STREQ( "u64_2", BugTest1_InArray_members[1].name ); EXPECT_STREQ( "u16", BugTest1_InArray_members[2].name ); }
TEST_F( DLUtil, auto_detect_text_file_format ) { 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_OK( dl_util_load_from_file( Ctx, 0, // check autodetection of type TEMP_FILE_NAME, DL_UTIL_FILE_TYPE_AUTO, &conv.vp, &stored_type ) ); dl_typeid_t expect = Pods::TYPE_ID; EXPECT_EQ( expect, stored_type ); check_loaded( conv.p2 ); free( conv.p2 ); }
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 ) ); }
TEST_F( DLUtil, store_load_text ) { // write struct to temp-file 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; // read struct from temp-flle. EXPECT_DL_ERR_OK( dl_util_load_from_file( Ctx, Pods::TYPE_ID, TEMP_FILE_NAME, DL_UTIL_FILE_TYPE_TEXT, &conv.vp, &stored_type ) ); dl_typeid_t expect = Pods::TYPE_ID; EXPECT_EQ( expect, stored_type ); check_loaded( conv.p2 ); free( conv.p2 ); }
TEST_F(DLReflect, is_union_reflected) { dl_type_info_t info; memset( &info, 0x0, sizeof(dl_type_info_t) ); EXPECT_DL_ERR_OK( dl_reflect_get_type_info( Ctx, Pods_TYPE_ID, &info ) ); EXPECT_FALSE( info.is_union ); EXPECT_DL_ERR_OK( dl_reflect_get_type_info( Ctx, test_union_simple_TYPE_ID, &info ) ); EXPECT_TRUE( info.is_union ); }
TEST_F(DLReflect, pods) { dl_type_info_t Info; dl_member_info_t Members[128]; memset( &Info, 0x0, sizeof(dl_type_info_t) ); EXPECT_DL_ERR_OK(dl_reflect_get_type_info( Ctx, Pods::TYPE_ID, &Info )); EXPECT_DL_ERR_OK(dl_reflect_get_type_members( Ctx, Pods::TYPE_ID, Members, DL_ARRAY_LENGTH(Members) )); EXPECT_EQ ((uint32_t)Pods::TYPE_ID, Info.tid ); EXPECT_STREQ("Pods", Info.name); EXPECT_EQ (10u, Info.member_count); EXPECT_STREQ("i8", Members[0].name); EXPECT_EQ (DL_TYPE_ATOM_POD, Members[0].type & DL_TYPE_ATOM_MASK); EXPECT_EQ (DL_TYPE_STORAGE_INT8, Members[0].type & DL_TYPE_STORAGE_MASK); EXPECT_STREQ("i16" , Members[1].name); EXPECT_EQ (DL_TYPE_ATOM_POD, Members[1].type & DL_TYPE_ATOM_MASK); EXPECT_EQ (DL_TYPE_STORAGE_INT16, Members[1].type & DL_TYPE_STORAGE_MASK); EXPECT_STREQ("i32", Members[2].name); EXPECT_EQ (DL_TYPE_ATOM_POD, Members[2].type & DL_TYPE_ATOM_MASK); EXPECT_EQ (DL_TYPE_STORAGE_INT32, Members[2].type & DL_TYPE_STORAGE_MASK); EXPECT_STREQ("i64", Members[3].name); EXPECT_EQ (DL_TYPE_ATOM_POD, Members[3].type & DL_TYPE_ATOM_MASK); EXPECT_EQ (DL_TYPE_STORAGE_INT64, Members[3].type & DL_TYPE_STORAGE_MASK); EXPECT_STREQ("u8", Members[4].name); EXPECT_EQ (DL_TYPE_ATOM_POD, Members[4].type & DL_TYPE_ATOM_MASK); EXPECT_EQ (DL_TYPE_STORAGE_UINT8, Members[4].type & DL_TYPE_STORAGE_MASK); EXPECT_STREQ("u16", Members[5].name); EXPECT_EQ (DL_TYPE_ATOM_POD, Members[5].type & DL_TYPE_ATOM_MASK); EXPECT_EQ (DL_TYPE_STORAGE_UINT16, Members[5].type & DL_TYPE_STORAGE_MASK); EXPECT_STREQ("u32", Members[6].name); EXPECT_EQ (DL_TYPE_ATOM_POD, Members[6].type & DL_TYPE_ATOM_MASK); EXPECT_EQ (DL_TYPE_STORAGE_UINT32, Members[6].type & DL_TYPE_STORAGE_MASK); EXPECT_STREQ("u64", Members[7].name); EXPECT_EQ (DL_TYPE_ATOM_POD, Members[7].type & DL_TYPE_ATOM_MASK); EXPECT_EQ (DL_TYPE_STORAGE_UINT64, Members[7].type & DL_TYPE_STORAGE_MASK); EXPECT_STREQ("f32", Members[8].name); EXPECT_EQ (DL_TYPE_ATOM_POD, Members[8].type & DL_TYPE_ATOM_MASK); EXPECT_EQ (DL_TYPE_STORAGE_FP32, Members[8].type & DL_TYPE_STORAGE_MASK); EXPECT_STREQ("f64", Members[9].name); EXPECT_EQ (DL_TYPE_ATOM_POD, Members[9].type & DL_TYPE_ATOM_MASK); EXPECT_EQ (DL_TYPE_STORAGE_FP64, Members[9].type & DL_TYPE_STORAGE_MASK); }
TEST_F(DLError, version_mismatch_returned) { unused u; size_t dummy; unsigned char packed[sizeof(unused) * 10]; // large enough buffer! unsigned char swaped[sizeof(unused) * 10]; // large enough buffer! unsigned char bus_buffer[sizeof(unused) * 10]; // large enough buffer! char bus_text[sizeof(unused) * 10]; // large enough buffer! dl_endian_t other_endian = DL_ENDIAN_HOST == DL_ENDIAN_LITTLE ? DL_ENDIAN_BIG : DL_ENDIAN_LITTLE; EXPECT_DL_ERR_OK( dl_instance_store( Ctx, unused::TYPE_ID, &u, packed, DL_ARRAY_LENGTH(packed), 0x0 ) ); EXPECT_DL_ERR_OK( dl_convert( Ctx, unused::TYPE_ID, packed, DL_ARRAY_LENGTH(packed), swaped, DL_ARRAY_LENGTH(swaped), other_endian, sizeof(void*), 0x0 ) ); // testing that errors are returned correctly by modding data. union { unsigned int* instance_version; unsigned char* instance; } conv; conv.instance = packed; unsigned int* instance_version; instance_version = conv.instance_version + 1; EXPECT_EQ(1u, *instance_version); *instance_version = 0xFFFFFFFF; conv.instance = swaped; instance_version = conv.instance_version + 1; EXPECT_EQ(0x01000000u, *instance_version); *instance_version = 0xFFFFFFFF; // test all functions in... #define EXPECT_DL_ERR_VERSION_MISMATCH( err ) EXPECT_DL_ERR_EQ( DL_ERROR_VERSION_MISMATCH, err ) Pods p; // dl.h EXPECT_DL_ERR_VERSION_MISMATCH( dl_instance_load( Ctx, unused::TYPE_ID, &p, sizeof(Pods), packed, DL_ARRAY_LENGTH(packed), 0x0 ) ); // dl_convert.h EXPECT_DL_ERR_VERSION_MISMATCH( dl_convert( Ctx, unused::TYPE_ID, packed, DL_ARRAY_LENGTH(packed), bus_buffer, DL_ARRAY_LENGTH(bus_buffer), other_endian, sizeof(void*), 0x0 ) ); EXPECT_DL_ERR_VERSION_MISMATCH( dl_convert( Ctx, unused::TYPE_ID, swaped, DL_ARRAY_LENGTH(swaped), bus_buffer, DL_ARRAY_LENGTH(bus_buffer), DL_ENDIAN_HOST, sizeof(void*), 0x0 ) ); EXPECT_DL_ERR_VERSION_MISMATCH( dl_convert_inplace( Ctx, unused::TYPE_ID, packed, DL_ARRAY_LENGTH(packed), other_endian, sizeof(void*), 0x0 ) ); EXPECT_DL_ERR_VERSION_MISMATCH( dl_convert_inplace( Ctx, unused::TYPE_ID, swaped, DL_ARRAY_LENGTH(swaped), DL_ENDIAN_HOST, sizeof(void*), 0x0 ) ); EXPECT_DL_ERR_VERSION_MISMATCH( dl_convert_calc_size( Ctx, unused::TYPE_ID, packed, DL_ARRAY_LENGTH(packed), sizeof(void*), &dummy ) ); EXPECT_DL_ERR_VERSION_MISMATCH( dl_convert_calc_size( Ctx, unused::TYPE_ID, swaped, DL_ARRAY_LENGTH(swaped), sizeof(void*), &dummy ) ); // dl_txt.h EXPECT_DL_ERR_VERSION_MISMATCH( dl_txt_unpack( Ctx, unused::TYPE_ID, packed, DL_ARRAY_LENGTH(packed), bus_text, DL_ARRAY_LENGTH(bus_text), 0x0 ) ); EXPECT_DL_ERR_VERSION_MISMATCH( dl_txt_unpack_calc_size( Ctx, unused::TYPE_ID, packed, DL_ARRAY_LENGTH(packed), &dummy ) ); #undef EXPECT_DL_ERR_VERSION_MISMATCH }
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) ); }
void SetUp() { dl_create_params_t p; DL_CREATE_PARAMS_SET_DEFAULT(p); p.error_msg_func = error_msg_handler; EXPECT_DL_ERR_OK( dl_context_create( &ctx, &p ) ); }
void pack_text_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 ) { // unpack binary to txt char text_buffer[2048]; memset(text_buffer, 0xFE, sizeof(text_buffer)); size_t text_size = 0; EXPECT_DL_ERR_OK( dl_txt_unpack_calc_size( dl_ctx, type, store_buffer, store_size, &text_size ) ); EXPECT_DL_ERR_OK( dl_txt_unpack( dl_ctx, type, store_buffer, store_size, text_buffer, text_size, 0x0 ) ); EXPECT_EQ( (unsigned char)0xFE, (unsigned char)text_buffer[text_size] ); // no overwrite on the generated text plox! // printf("%s\n", text_buffer); // pack txt to binary EXPECT_DL_ERR_OK( dl_txt_pack_calc_size( dl_ctx, text_buffer, out_size ) ); EXPECT_DL_ERR_OK( dl_txt_pack( dl_ctx, text_buffer, out_buffer, *out_size, 0x0 ) ); }
void inplace_load_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 ) { // copy stored instance into temp-buffer unsigned char inplace_buffer[4096]; memset( inplace_buffer, 0xFE, DL_ARRAY_LENGTH(inplace_buffer) ); memcpy( inplace_buffer, store_buffer, store_size ); // load inplace void* loaded_instance = 0x0; size_t consumed = 0; EXPECT_DL_ERR_OK( dl_instance_load_inplace( dl_ctx, type, inplace_buffer, store_size, &loaded_instance, &consumed )); EXPECT_EQ( store_size, consumed ); EXPECT_EQ( (unsigned char)0xFE, (unsigned char)inplace_buffer[store_size + 1] ); // no overwrite by inplace load! // store to out-buffer EXPECT_DL_ERR_OK( dl_instance_calc_size( dl_ctx, type, loaded_instance, out_size ) ); EXPECT_DL_ERR_OK( dl_instance_store( dl_ctx, type, loaded_instance, out_buffer, *out_size, 0x0 ) ); }
void convert_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 ) { // calc size to convert unsigned char convert_buffer[2048]; memset(convert_buffer, 0xFE, sizeof(convert_buffer)); size_t convert_size = 0; EXPECT_DL_ERR_OK( dl_convert_calc_size( dl_ctx, type, store_buffer, store_size, conv_ptr_size, &convert_size ) ); // convert to other pointer 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 ); // calc size to re-convert to host pointer size EXPECT_DL_ERR_OK( dl_convert_calc_size( dl_ctx, type, convert_buffer, convert_size, sizeof(void*), out_size ) ); // re-convert to host pointer size EXPECT_DL_ERR_OK( dl_convert( dl_ctx, type, convert_buffer, convert_size, out_buffer, *out_size, DL_ENDIAN_HOST, sizeof(void*), 0x0 ) ); }
TEST_F(DLError, type_mismatch_returned) { // testing that DL_ERROR_TYPE_MISMATCH is returned if provided type is not matching type stored in instance unused u; size_t dummy; unsigned char packed[sizeof(unused) * 10]; // large enough buffer! unsigned char swaped[sizeof(unused) * 10]; // large enough buffer! unsigned char bus_buffer[sizeof(unused) * 10]; // large enough buffer! char bus_text[sizeof(unused) * 10]; // large enough buffer! dl_endian_t other_endian = DL_ENDIAN_HOST == DL_ENDIAN_LITTLE ? DL_ENDIAN_BIG : DL_ENDIAN_LITTLE; EXPECT_DL_ERR_OK( dl_instance_store( Ctx, unused::TYPE_ID, &u, packed, DL_ARRAY_LENGTH(packed), 0x0 ) ); EXPECT_DL_ERR_OK( dl_convert( Ctx, unused::TYPE_ID, packed, DL_ARRAY_LENGTH(packed), swaped, DL_ARRAY_LENGTH(swaped), other_endian, sizeof(void*), 0x0 ) ); // test all functions in... #define EXPECT_DL_ERR_TYPE_MISMATCH( err ) EXPECT_DL_ERR_EQ( DL_ERROR_TYPE_MISMATCH, err ) Pods p; // dl.h EXPECT_DL_ERR_TYPE_MISMATCH( dl_instance_load( Ctx, Pods::TYPE_ID, &p, sizeof(Pods), packed, DL_ARRAY_LENGTH(packed), 0x0 ) ); // dl_convert.h EXPECT_DL_ERR_TYPE_MISMATCH( dl_convert( Ctx, Pods::TYPE_ID, packed, DL_ARRAY_LENGTH(packed), bus_buffer, DL_ARRAY_LENGTH(bus_buffer), other_endian, sizeof(void*), 0x0 ) ); EXPECT_DL_ERR_TYPE_MISMATCH( dl_convert( Ctx, Pods::TYPE_ID, swaped, DL_ARRAY_LENGTH(swaped), bus_buffer, DL_ARRAY_LENGTH(bus_buffer), DL_ENDIAN_HOST, sizeof(void*), 0x0 ) ); EXPECT_DL_ERR_TYPE_MISMATCH( dl_convert_inplace( Ctx, Pods::TYPE_ID, packed, DL_ARRAY_LENGTH(packed), other_endian, sizeof(void*), 0x0 ) ); EXPECT_DL_ERR_TYPE_MISMATCH( dl_convert_inplace( Ctx, Pods::TYPE_ID, swaped, DL_ARRAY_LENGTH(swaped), DL_ENDIAN_HOST, sizeof(void*), 0x0 ) ); EXPECT_DL_ERR_TYPE_MISMATCH( dl_convert_calc_size( Ctx, Pods::TYPE_ID, packed, DL_ARRAY_LENGTH(packed), sizeof(void*), &dummy ) ); EXPECT_DL_ERR_TYPE_MISMATCH( dl_convert_calc_size( Ctx, Pods::TYPE_ID, swaped, DL_ARRAY_LENGTH(swaped), sizeof(void*), &dummy ) ); // dl_txt.h EXPECT_DL_ERR_TYPE_MISMATCH( dl_txt_unpack( Ctx, Pods::TYPE_ID, packed, DL_ARRAY_LENGTH(packed), bus_text, DL_ARRAY_LENGTH(bus_text), 0x0 ) ); EXPECT_DL_ERR_TYPE_MISMATCH( dl_txt_unpack_calc_size( Ctx, Pods::TYPE_ID, packed, DL_ARRAY_LENGTH(packed), &dummy ) ); #undef EXPECT_DL_ERR_TYPE_MISMATCH }
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 ); } }
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 ); }
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 }
void TearDown() { EXPECT_DL_ERR_OK( dl_context_destroy( ctx ) ); }