#################################################################### # tc_unix.rb # # Test case for the Sys::Filesystem.stat method and related stuff. #################################################################### base = File.basename(Dir.pwd) if base == 'test' || base =~ /filesystem/i require 'fileutils' require 'rbconfig' Dir.chdir('..') if base == 'test' Dir.mkdir('sys') rescue nil file = 'filesystem.' + Config::CONFIG['DLEXT'] FileUtils.cp(file, 'sys') $LOAD_PATH.unshift(Dir.pwd) end require 'test/unit' require 'sys/filesystem' include Sys class TC_Filesystem_Unix < Test::Unit::TestCase def setup @dir = "/" @stat = Filesystem.stat(@dir) @size = 58720256 end def test_version assert_equal('0.1.0', Filesystem::VERSION) end def test_stat_path assert_respond_to(@stat, :path) assert_equal("/", @stat.path) end def test_stat_block_size assert_respond_to(@stat, :block_size) assert_kind_of(Fixnum, @stat.block_size) end def test_stat_fragment_size assert_respond_to(@stat, :fragment_size) assert_kind_of(Fixnum, @stat.fragment_size) end def test_stat_blocks assert_respond_to(@stat, :blocks) assert_kind_of(Fixnum, @stat.blocks) end def test_stat_blocks_free assert_respond_to(@stat, :blocks_free) assert_kind_of(Fixnum, @stat.blocks_free) end def test_stat_blocks_available assert_respond_to(@stat, :blocks_available) assert_kind_of(Fixnum, @stat.blocks_available) end def test_stat_files assert_respond_to(@stat, :files) assert_respond_to(@stat, :inodes) # Alias assert_kind_of(Fixnum, @stat.files) end def test_stat_files_free assert_respond_to(@stat, :files_free) assert_respond_to(@stat, :inodes_free) # Alias assert_kind_of(Fixnum, @stat.files_free) end def test_stat_files_available assert_respond_to(@stat, :files_available) assert_respond_to(@stat, :inodes_available) # Alias assert_kind_of(Fixnum, @stat.files_available) end def test_stat_filesystem_id assert_respond_to(@stat, :filesystem_id) assert_kind_of(Fixnum, @stat.filesystem_id) end def test_stat_flags assert_respond_to(@stat, :flags) assert_kind_of(Fixnum, @stat.flags) end def test_stat_name_max assert_respond_to(@stat, :name_max) assert_kind_of(Fixnum, @stat.name_max) end unless RUBY_PLATFORM.match('linux') def test_stat_base_type assert_respond_to(@stat, :base_type) assert_kind_of(String, @stat.base_type) end end def test_stat_constants assert_not_nil(Filesystem::Stat::RDONLY) assert_not_nil(Filesystem::Stat::NOSUID) unless RUBY_PLATFORM.match('linux') assert_not_nil(Filesystem::Stat::NOTRUNC) end end def test_stat_expected_errors assert_raises(ArgumentError){ Filesystem.stat } end def test_fixnum_methods assert_respond_to(@size, :to_kb) assert_respond_to(@size, :to_mb) assert_respond_to(@size, :to_gb) assert_equal(57344, @size.to_kb) assert_equal(56, @size.to_mb) assert_equal(0, @size.to_gb) end def teardown @dir = nil @stat = nil end end