#!/usr/bin/env ruby # $Id: isocopy.rb,v 1.4 2006/12/09 09:59:49 rocky Exp $ # Unit test of ISO 9660 file extraction. require "test/unit" mypath = File.expand_path(File.dirname(__FILE__)) $: << mypath + '/../lib' $: << mypath + '/../ext/cdio' $: << mypath + '/../ext/iso9660' require "cdio" require "iso9660" # The test CD image CD_IMAGE_PATH = mypath + "/../data" class ISO9660Tests < Test::Unit::TestCase def test_fs() local_filename="COPYING" cd_image_fname = CD_IMAGE_PATH + "/isofs-m1.cue" cd = ISO9660::FS::new(cd_image_fname) assert(cd != nil, "Open CD image %s" % cd_image_fname) statbuf = cd.stat("/" + local_filename) good_stat = { 'lsn' => 26, 'filename' => 'COPYING', 'type' => 1, 'secsize' => 9, 'size' => 17992 } assert_equal(statbuf, good_stat, 'CD 9660 file stats') # Get file buf_all =[] blocks = (statbuf['size'].to_f / Rubycdio::ISO_BLOCKSIZE).ceil() for i in 0 .. blocks - 1 lsn = statbuf['lsn'] + i size, buf = cd.read_data_blocks(lsn) assert_equal( true, size >= 0, "Error reading ISO 9660 file %d" % lsn ) buf_all << buf end length=statbuf['size']; test_file_contents=buf_all.join('')[0..length-1] assert_equal(FILE_CONTENTS, test_file_contents, 'File contents comparison') cd.close() end end FILE_CONTENTS=< Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. EOF