#make sure the relevant folder with our libraries is in the require path lib_path=File.expand_path(File.dirname(__FILE__)+"//..//lib") $:.unshift(lib_path) unless $:.include?(lib_path) require 'test/unit' require 'LibRipXplore' require 'FileCache' @@filecache=FileCache.new(File.dirname(__FILE__)+"//test_images",File.dirname(__FILE__)+"//native_files") LOG_FILE="testlog.txt" File.delete(LOG_FILE) if File.exist?(LOG_FILE) RipXploreLog.log_to(LOG_FILE) RipXploreLog.debug_logging def image_has_collection_of(url,collection_type) image=@@filecache.get_file_system_image(url) assert(image.respond_to?(collection_type),"#{url} should contain a collection of #{collection_type}") collection=image.send(collection_type) assert(collection.length>0,"#{url} should contain more than zero #{collection_type}") end def file_cache @@filecache end def get_file_from_url(url,expected_file_filename) assert(FileSystemImage.is_file_system_image_filename?(url),"#{url} should have a known file system image extension") image=@@filecache.get_file_system_image(url) 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}") native_file end 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") image=@@filecache.get_file_system_image(url) 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}") assert_not_nil(image.image_format.host_system.full_name,"all host systems should implement :full_name") return if expected_files.nil? native_file=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] assert(native_file.respond_to?(method_to_call),"#{expected_file_filename} [#{native_file.class}] should respond to :#{method_to_call}") native_file.send(method_to_call) end unless expected_file[:save_output].nil? then (method_to_call,extension)=expected_file[:save_output] assert(native_file.respond_to?(method_to_call),"#{expected_file_filename} [#{native_file.class}] should respond to :#{method_to_call}") file_cache.purge_native_file_from_cache(native_file) file_cache.force_native_file_to_cache(native_file,method_to_call,extension) 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 native_file end