started implementation of System::Process
[god.git] / test / test_system_process.rb
blobe8569da3a08d70e0c87dc1cbc1b121479aafd9b1
1 require 'test_helper'
3 class TestSystemProcessCreation < Test::Unit::TestCase
4   def test_new_should_succeed_for_existing_pid
5     pid = Process.pid
6     assert_nothing_raised do
7       @process = System::Process.new(pid)
8     end
9   end
10 end
12 class TestSystemProcess < Test::Unit::TestCase
13   def setup
14     pid = Process.pid
15     @process = System::Process.new(pid)
16   end
17   
18   def test_exists_should_return_true_for_running_process
19     assert_equal true, @process.exists?
20   end
21   
22   def test_exists_should_return_false_for_non_existant_process
23     assert_equal false, System::Process.new(0).exists?
24   end
25   
26   def test_memory
27     assert_kind_of Integer, @process.memory
28     assert @process.memory > 0
29   end
30   
31   def test_percent_cpu
32     assert_kind_of Float, @process.percent_mem
33   end
34   
35   def test_percent_cpu
36     assert_kind_of Float, @process.percent_cpu
37   end
38   
39   def test_cpu_time
40     assert_kind_of Integer, @process.cpu_time
41   end
42   
43   def test_time_string_to_seconds
44     assert_equal 0, @process.bypass.time_string_to_seconds('0:00:00')
45     assert_equal 0, @process.bypass.time_string_to_seconds('0:00:55')
46     assert_equal 27, @process.bypass.time_string_to_seconds('0:27:32')
47     assert_equal 75, @process.bypass.time_string_to_seconds('1:15:13')
48     assert_equal 735, @process.bypass.time_string_to_seconds('12:15:13')
49   end
50 end