########################################################### # tc_sunos.rb # # Test suite for sys-cpu on Solaris. This should only be # run *after* the make process. ########################################################### base = File.basename(Dir.pwd) if base == "test" || base =~ /sys-cpu/ require "ftools" Dir.chdir ".." if base == "test" Dir.mkdir("sys") unless File.exist?("sys") if File.exist?("cpu.so") File.copy("cpu.so","sys") else puts "No cpu.so file found. Please run extconf.rb and make first" exit end $LOAD_PATH.unshift Dir.pwd end require "sys/cpu" require "test/unit" include Sys # I could really use a mock object here class TC_SunOS < Test::Unit::TestCase def test_cpu_freq assert_respond_to(CPU, :freq) assert_nothing_raised{ CPU.freq } assert_nothing_raised{ CPU.freq(0) } assert_kind_of(Integer, CPU.freq(0)) end def test_cpu_type assert_respond_to(CPU, :type) assert_nothing_raised{ CPU.type } assert_kind_of(String, CPU.type) end def test_fpu_type assert_respond_to(CPU, :fpu_type) assert_nothing_raised{ CPU.fpu_type } assert_kind_of(String, CPU.fpu_type) end def test_load_avg assert_respond_to(CPU, :load_avg) assert_nothing_raised{ CPU.load_avg } assert_kind_of(Array, CPU.load_avg) assert_equal(3, CPU.load_avg.length) assert_kind_of(Float, CPU.load_avg.first) end def test_cpu_model assert_respond_to(CPU, :model) assert_nothing_raised{ CPU.model } assert_kind_of(String, CPU.model) end def test_num_cpu assert_respond_to(CPU, :num_cpu) assert_nothing_raised{ CPU.num_cpu } assert_kind_of(Integer, CPU.num_cpu) end def test_state assert_respond_to(CPU, :state) assert_nothing_raised{ CPU.state } assert_nothing_raised{ CPU.state(0) } assert_kind_of(String, CPU.state(0)) end def test_exceptions assert_raises(Sys::CPUError){ CPU.state(55) } assert_raises(TypeError){ CPU.state("yo") } assert_raises(Sys::CPUError){ CPU.freq(999) } assert_raises(TypeError){ CPU.freq("yo") } end end