bool TestSuite::testParityBinaryImageWrite() { try { utils::Task::ArgumentVector arguments; utils::Path cfile = utils::Path::getTemporary(".parity.testsuite.link.XXXXXX.c"); utils::Path ofile = utils::Path::getTemporary(".parity.testsuite.link.XXXXXX.exe"); std::ofstream ofs(cfile.get().c_str()); ofs << dataCFile; ofs.close(); utils::Context::getContext().getTemporaryFiles().push_back(cfile); utils::Context::getContext().getTemporaryFiles().push_back(ofile); arguments.push_back(cfile.get()); arguments.push_back("-o"); arguments.push_back(ofile.get()); if(!executeParity(arguments, false)) throw utils::Exception("cannot execute parity for test suite!"); if(!ofile.exists()) throw utils::Exception("missing executable file from compile!"); utils::Log::verbose("doing parsed copy of %s...\n", ofile.get().c_str()); utils::MappedFile mapping(ofile, utils::ModeRead); //utils::MappedFile mapping(utils::Path("test.exe"), utils::ModeRead); binary::Image img(&mapping); utils::Log::verbose("testing original file:\n"); testFileHeader(img.getHeader()); utils::Path temp = utils::Path::getTemporary(".parity.testsuite.image.XXXXXX.exe"); utils::Context::getContext().getTemporaryFiles().push_back(temp); utils::MemoryFile file; img.update(file); file.save(temp); utils::MappedFile check_mapping(temp, utils::ModeRead); binary::Image check_img(&check_mapping); utils::Log::verbose("testing parsed copy of executable:\n"); testFileHeader(check_img.getHeader()); return true; } catch(const utils::Exception& e) { utils::Log::warning("catched: %s\n", e.what()); } return false; }
void EasyUnicodeFileLE::open( string FileName, ios_base::open_mode OpenMode ) { /*先关闭试试*/ if( F.is_open( ) ) { cout << "WARNING_EUFLE001 - Target opening file is open, and will be closed." << endl; cout << " ( File Name: " << FileName << " )" << endl; close( ); } /*初始检测操作*/ if( !Initialization( OpenMode ) ) return; /*判断读or写模式*/ JudgeReadOrWrite( OpenMode ); /*执行打开操作*/ char Name[ 1000 ]; Tools.StringToChars( FileName, Name ); F.open( Name, OpenMode | ios_base::in | ios_base::binary ); //内部要进行读取操作 if( !F.is_open( ) ) { cout << "ERROR_EUFLE004 - Cannot open file." << endl; cout << " ( File Name: " << Name << " )" << endl; system( "PAUSE" ); return; } /*头部标记处理*/ char Head[ 3 ] = "\xFF\xFE"; if( IsReadMode ) {//读入模式 if( DEBUG_FLAG ) cout << "File of in-mode." << endl; F.read( Head, 2 ); if( strcmp( Head, "\xFF\xFE" ) ) { cout << "ERROR_EUFLE005 - Not a Little-Endian Unicode file." << endl; cout << " File Name: " << Name << endl; cout << " Encode: " << testFileHeader( ) << endl; system( "PAUSE" ); return; } } else { if( DEBUG_FLAG ) cout << "File of out-mode." << endl; if( ( ios_base::trunc | OpenMode ) == OpenMode ) F.write( Head, 2 );//覆写输出模式 else { //不是覆写模式,要先验证FFFE F.seekg( 0, ios_base::beg ); F.read( Head, 2 ); if( strcmp( Head, "\xFF\xFE" ) ) { cout << "ERROR_EUFLE006 - Not a Little-Endian Unicode file." << endl; cout << " ( File Name: " << Name << " )" << endl; system( "PAUSE" ); return; } SetPointer( 0, ios_base::end ); } } return; }