require 'testhelper' class ImageSniffing < Test::Unit::TestCase def sniff_url(url,expected_image_format,expected_file_system,expected_files=nil) assert(FileSystemImage.is_file_system_image_filename?(url),"#{url} should have a known file system image extension") file=@@filecache.get(url) RipXploreLog.info("checking #{file.path}") image=RipXplore.best_fit_from_file(file) assert_equal(expected_file_system,image.file_system,"validation of file system for #{url}") assert_kind_of(expected_image_format,image.image_format,"validation of image format for #{url}") return if expected_files.nil? expected_files.each do |expected_file| expected_file_filename=expected_file[:filename] RipXploreLog.info("validating #{expected_file_filename}") raise "no native files identified in image" if image.files.nil? || image.files.length==0 raise "image.files should of type FileContainer but was #{image.files.class} (file system=#{image.file_system})" unless image.files.kind_of?(FileContainer) native_file=image.files[expected_file_filename] assert_not_nil(native_file,"#{expected_file_filename} should exist in #{url} - files found: #{image.catalog}") expected_native_file_type=expected_file[:expected_native_file_type] unless expected_native_file_type.nil? then assert_kind_of(expected_native_file_type,native_file,"native file type of #{expected_file_filename} should be as specified") end unless expected_file[:load_address].nil? then assert(expected_file[:load_address]==native_file.load_address,"load address of #{expected_file_filename} should be $#{"%04x" % expected_file[:load_address]} but was $#{"%04X" % native_file.load_address}") end unless expected_file[:can_execute].nil? then method_to_call=expected_file[:can_execute] native_file.send(method_to_call) end expected_file_text_starts_with=expected_file[:text_starts_with] unless expected_file_text_starts_with.nil? then assert(native_file.respond_to?(:to_text),"#{expected_file_filename} should respond to :to_text") assert_equal(expected_file_text_starts_with,native_file.to_text[0,expected_file_text_starts_with.length],"start of #{expected_file_filename} should be as specified") end expected_file_listing_starts_with=expected_file[:listing_starts_with] unless expected_file_listing_starts_with.nil? then assert(native_file.respond_to?(:to_listing),"#{expected_file_filename} should respond to :to_listing") assert_equal(expected_file_listing_starts_with,native_file.to_listing[0,expected_file_listing_starts_with.length],"start of #{expected_file_filename} should be as specified") end end end def test_sniffing sniff_url("http://www.zimmers.net/anonftp/pub/cbm/c64/programming/BASIC-Programming-Tools.DaveJB.d64.gz",D64,CbmDos, [{:filename=>"p&p.asm",:text_starts_with=>"; *** peek&poke *\n; (c) dave - 9"}] ) sniff_url("http://www.zimmers.net/anonftp/pub/cbm/c64/programming/Logo-utilities.d64.gz",D64,CbmDos, [{:filename=>"while.logo",:text_starts_with=>"to help\n nd"}] ) sniff_url("http://www.atariarchives.org/oldhackers/OHJFM00A.ATR",Atr,AtariDos,[ {:filename=>"HELP.DOC",:expected_native_file_type=>AtariText,:text_starts_with=>" The OL' HACKERS Disk Newsletter Help\n"}, {:filename=>"GDRIVES.TXT",:expected_native_file_type=>AtariText,:text_starts_with=>" Life Insurance For Your Disk Drives\n by Ron Fetzer\n\n Are you"}, {:filename=>'DUP.SYS',:expected_native_file_type=>AtariBinary,:load_address=>0x1F0C,:can_execute=>:to_listing}, {:filename=>"WELCOME.BAS",:expected_native_file_type=>AtariBasic,:listing_starts_with=>"10 DIM CIO$(20),SCR$(958):POKE 82,0:POKE 752,1:PRINT \"}\":POKE 559,0:POKE 709,12:POKE 710,20:POKE 712,24\n20 CIO$="}, ]) sniff_url("http://www.atariarchives.org/oldhackers/OHJFM00B.ATR",Atr,AtariDos,[ {:filename=>"LABEL.TUR",:expected_native_file_type=>AtariBasic,:can_execute=>:to_listing}, {:filename=>"SUBATACK.TUR",:expected_native_file_type=>AtariBasic,:can_execute=>:to_listing}, ]) sniff_url("http://ape.dyndns.org:8085/A-J/Bank_Street_Writer.atr",Atr,AtariDos, [ {:filename=>'UTILA.SYS',:expected_native_file_type=>AtariBasic,:can_execute=>:to_listing}, ]) sniff_url("http://www.classic-computers.org.nz/system-80/disks/NEWDOS_80sssd_jv1.DSK",Trs80Jv1Dsk,TrsDos,[ {:filename=>'CHAINTST/JCL',:expected_native_file_type=>Trs80Jcl,:listing_starts_with=>"/./2THIS MESSAGE SHOULD NOT BE PRINTED"}, {:filename=>'EDTASM/CMD',:expected_native_file_type=>Trs80Cmd,:load_address=>0x5200} ]) sniff_url("http://www.classic-computers.org.nz/system-80/disks/BASIC-games-1_80sssd_jv1.DSK",Trs80Jv1Dsk,TrsDos,[ {:filename=>'RATS/BAS',:expected_native_file_type=>Trs80LevelIIBasic,:listing_starts_with=>"1 CLS:FORS=0TO44STEP4:FORJ=0TO126STEP6:SET(J,S):NEXTJ,S:FORI=0TO34:READJ:NEXT"} ]) sniff_url("http://www.classic-computers.org.nz/system-80/disks/pascal_80sssd_jv1.DSK",Trs80Jv1Dsk,TrsDos, [ {:filename=>'MAILIST/SRC',:expected_native_file_type=>Trs80PascalSource,:listing_starts_with=>' '} ]) sniff_url("http://www.classic-computers.org.nz/system-80/disks/dunjon_80sssd_jv1.DSK",Trs80Jv1Dsk,TrsDos, [ {:filename=>'INN2/',:expected_native_file_type=>Trs80LevelIIBasic} ]) sniff_url("http://www.zimmers.net/anonftp/pub/cbm/c64/magazines/Ahoy/1986-01.d64.gz",D64,CbmDos,[ {:filename=>"sketcher.s",:expected_native_file_type=>C64PrgText,:text_starts_with=>"*\n* SKETCHER"} ]) sniff_url("http://www.zimmers.net/anonftp/pub/cbm/demodisks/c128/cpm.system.622-3282252.d64.gz",D64,CbmDos) sniff_url("http://www.zimmers.net/anonftp/pub/cbm/c128/programming/d-ass.d64.gz",D64,CbmDos, [{:filename=>"DOUBLE-ASS",:expected_native_file_type=>C64Prg,:can_execute=>:to_disassembly}] ) sniff_url("http://www.zimmers.net/anonftp/pub/cbm/c64/magazines/Ahoy/best-1985.d64.gz",D64,CbmDos,[ {:filename=>"gameloader d'85",:expected_native_file_type=>C64BasicPrg,:load_address=>0x0801,:listing_starts_with=>"1 REM ********"} ]) sniff_url("http://www.jamtronix.com/dsks/EARTHDEF.DSK",A2DskPhysicalOrder,AppleDos,[ {:filename=>"HELLO",:expected_native_file_type=>Applesoft,:listing_starts_with=>"10 REM"}]) sniff_url("http://mirrors.apple2.org.za/ftp.apple.asimov.net/images/disk_utils/cracking_techniques_1982.dsk.gz",A2DskPhysicalOrder,AppleDos,[ {:filename=>"HELLO",:expected_native_file_type=>Applesoft,:listing_starts_with=>'10 PRINT "** DOCTOR DOS **'}]) sniff_url("http://mirrors.apple2.org.za/ftp.apple.asimov.net/images/masters/dos33_with_adt.dsk",A2DskPhysicalOrder,AppleDos,[ {:filename=>"APPLESOFT",:expected_native_file_type=>IntegerBASIC,:listing_starts_with=>"10 REM"}, {:filename=>"CHAIN",:expected_native_file_type=>AppleBinary,:load_address=>0x0808,:can_execute=>:to_listing}, {:filename=>"APPLE PROMS",:expected_native_file_type=>AppleText,:text_starts_with=>"75\nDEL 1000,1250"} ]) sniff_url("http://www.jamtronix.com/dsks/AAL_1.DSK",A2DskPhysicalOrder,AppleDos,[ {:filename=>"DIVIDE BY TEN",:expected_native_file_type=>ScAsm,:listing_starts_with=>"930 .LIST OFF"}]) sniff_url("http://mirrors.apple2.org.za/ftp.apple.asimov.net/images/disk_utils/APTEST.DSK",A2DskPhysicalOrder,AppleDos) sniff_url("http://www.jamtronix.com/dsks/dosmaster.po",A2DskPhysicalOrder,ProDos) sniff_url("http://mirrors.apple2.org.za/ftp.apple.asimov.net/images/disk_utils/copy_ii+_v7.1.do.gz",A2DskDosOrder,ProDos) sniff_url("http://mirrors.apple2.org.za/ftp.apple.asimov.net/images/disk_utils/prosel_utilities.dsk.gz",A2DskDosOrder,ProDos,[ {:filename=>"UTIL/CONFIG.RAMDRV",:expected_native_file_type=>Applesoft,:listing_starts_with=>"10 REM ProSel Ram.Drive editor"}]) sniff_url("http://mirrors.apple2.org.za/ftp.apple.asimov.net/images/disk_utils/problock3.DSK",A2DskDosOrder,ProDos,[ {:filename=>"READ.ME",:expected_native_file_type=>AppleText,:text_starts_with=>"This disk contains all the files required"}]) sniff_url("http://mirrors.apple2.org.za/landover.no-ip.com/Applications/Apple%20Works%20V5.0%20(1993)(Beagle%20Bros)(Disks%205%20of%206).dsk",A2DskDosOrder,ProDos,[ {:filename=>"AW.INITS/NARNIA.KNAVES",:expected_native_file_type=>AppleWorksWP,:text_starts_with=>"This bonus screen blanker for AfterWork"}]) sniff_url("http://www.jamtronix.com/dsks/NADOL.DSK",A2DskPhysicalOrder,NADOLDos,[ {:filename=>"NADOL",:expected_native_file_type=>NADOLFile}, {:filename=>"LOGO",:expected_native_file_type=>AppleHiResPic}, {:filename=>"BRICKOUT",:expected_native_file_type=>NADOLTokens,:listing_starts_with=>"; LORES BRICK-OUT GAME"}]) sniff_url("http://www.apple2.org.za/mirrors/ftp.apple.asimov.net/images/educational/camps.dsk.gz",A2DskDosOrder,PascalDos, [{:filename=>"CAMPS.FOTO",:expected_native_file_type=>AppleHiResPic,:can_execute=>:to_png}]) sniff_url("http://mirrors.apple2.org.za/landover.no-ip.com/Applications/Algebra%20Mentor%20(19xx)(John%20C.%20Miller)(Disk%206%20of%207%20Side%20A)(Student%20Disk%206).dsk",A2DskDosOrder,PascalDos, [{:filename=>"SYSTEM.MISCINFO",:expected_native_file_type=>PascalFile}, ]) sniff_url("http://mirrors.apple2.org.za/apple.cabi.net/Z80.CPM/STARCPM.DSK",A2DskPhysicalOrder,AppleCPM,[ {:filename=>"STAR.DOC",:expected_native_file_type=>CPMFile}, ]) sniff_url("http://mirrors.apple2.org.za/ftp.apple.asimov.net/images/cpm/CPM1.PO",A2DskDosOrder,AppleCPM,[ {:filename=>"CONFIGIO.BAS",:expected_native_file_type=>MBasic,:listing_starts_with=>"1 '\n2 ' I/O CONFIGURATION UTILITY"}, ]) sniff_url("http://mirrors.apple2.org.za/ftp.apple.asimov.net/images/games/file_based/White_Disks/white_03b.dsk.gz",A2DskPhysicalOrder,AppleDos,[ {:filename=>"RIP.PIC",:expected_native_file_type=>AppleHiResPic,:can_execute=>:to_png}]) sniff_url("http://ftp.strassenbahn.tk:81/inntram-public/off-topic/c64/www.c64.ch/samar_digital_s1.g64",G64,CbmDos,[ {:filename=>'skip intro-part1'} ]) end end