ptools 1.3.3 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
metadata.gz.sig CHANGED
Binary file
@@ -1,65 +0,0 @@
1
- #####################################################################
2
- # test_binary.rb
3
- #
4
- # Test case for the File.binary? method. You should run this test
5
- # via the 'rake test_binary' task.
6
- #####################################################################
7
- require 'rubygems'
8
- require 'test-unit'
9
- require 'ptools'
10
-
11
- class TC_Ptools_Binary < Test::Unit::TestCase
12
- def self.startup
13
- if File::ALT_SEPARATOR
14
- @@bin_file = File.join(ENV['windir'], 'notepad.exe')
15
- else
16
- @@bin_file = '/bin/ls'
17
- end
18
-
19
- @@dirname = File.dirname(__FILE__)
20
- end
21
-
22
- def setup
23
- @txt_file = File.join(@@dirname, 'txt', 'english.txt')
24
- @uni_file = File.join(@@dirname, 'txt', 'korean.txt')
25
- @png_file = File.join(@@dirname, 'img', 'test.png')
26
- @jpg_file = File.join(@@dirname, 'img', 'test.jpg')
27
- @gif_file = File.join(@@dirname, 'img', 'test.gif')
28
- end
29
-
30
- test "File.binary? basic functionality" do
31
- assert_respond_to(File, :binary?)
32
- assert_nothing_raised{ File.binary?(@txt_file) }
33
- end
34
-
35
- test "File.binary? returns true for binary files" do
36
- assert_true(File.binary?(@@bin_file))
37
- end
38
-
39
- test "File.binary? returns false for text files" do
40
- assert_false(File.binary?(@txt_file))
41
- assert_false(File.binary?(@uni_file))
42
- end
43
-
44
- test "File.binary? returns false for image files" do
45
- assert_false(File.binary?(@png_file))
46
- assert_false(File.binary?(@jpg_file))
47
- assert_false(File.binary?(@gif_file))
48
- end
49
-
50
- test "File.binary? raises an error if the file cannot be found" do
51
- assert_raise_kind_of(SystemCallError){ File.binary?('bogus') }
52
- end
53
-
54
- test "File.binary? only accepts one argument" do
55
- assert_raise_kind_of(ArgumentError){ File.binary?(@txt_file, @@bin_file) }
56
- end
57
-
58
- def teardown
59
- @txt_file = nil
60
- @uni_file = nil
61
- @png_file = nil
62
- @jpg_file = nil
63
- @gif_file = nil
64
- end
65
- end
@@ -1,38 +0,0 @@
1
- #####################################################################
2
- # test_constants.rb
3
- #
4
- # Tests the constants that have been defined for our package. This
5
- # test case should be run via the 'rake test_constants' task.
6
- #####################################################################
7
- require 'rubygems'
8
- require 'test-unit'
9
- require 'rbconfig'
10
- require 'ptools'
11
-
12
- class TC_Ptools_Constants < Test::Unit::TestCase
13
- def self.startup
14
- @@windows = File::ALT_SEPARATOR
15
- end
16
-
17
- test "PTOOLS_VERSION constant is set to expected value" do
18
- assert_equal('1.3.3', File::PTOOLS_VERSION)
19
- end
20
-
21
- test "IMAGE_EXT constant is set to array of values" do
22
- assert_equal(%w[.bmp .gif .jpeg .jpg .png], File::IMAGE_EXT.sort)
23
- end
24
-
25
- test "WINDOWS constant is defined on MS Windows" do
26
- omit_unless(@@windows, "Skipping on Unix systems")
27
- assert_not_nil(File::MSWINDOWS)
28
- end
29
-
30
- test "WIN32EXTS constant is defiend on MS Windows" do
31
- omit_unless(@@windows, "Skipping on Unix systems")
32
- assert_not_nil(File::WIN32EXTS)
33
- end
34
-
35
- def self.shutdown
36
- @@windows = nil
37
- end
38
- end
@@ -1,48 +0,0 @@
1
- ######################################################################
2
- # test_head.rb
3
- #
4
- # Test case for the File.head method. This test should be run via
5
- # the 'rake test_head' task.
6
- ######################################################################
7
- require 'test-unit'
8
- require 'ptools'
9
-
10
- class TC_FileHead < Test::Unit::TestCase
11
- def self.startup
12
- Dir.chdir('test') if File.exist?('test')
13
- File.open('test_file1.txt', 'w'){ |fh| 25.times{ |n| fh.puts "line#{n+1}" } }
14
- end
15
-
16
- def setup
17
- @test_file = 'test_file1.txt'
18
- @expected_head1 = ["line1\n","line2\n","line3\n","line4\n","line5\n"]
19
- @expected_head1.push("line6\n","line7\n","line8\n","line9\n","line10\n")
20
- @expected_head2 = ["line1\n","line2\n","line3\n","line4\n","line5\n"]
21
- end
22
-
23
- def test_head_basic
24
- assert_respond_to(File, :head)
25
- assert_nothing_raised{ File.head(@test_file) }
26
- assert_nothing_raised{ File.head(@test_file, 5) }
27
- assert_nothing_raised{ File.head(@test_file){} }
28
- end
29
-
30
- def test_head_expected_results
31
- assert_kind_of(Array, File.head(@test_file))
32
- assert_equal(@expected_head1, File.head(@test_file))
33
- assert_equal(@expected_head2, File.head(@test_file, 5))
34
- end
35
-
36
- def test_head_expected_errors
37
- assert_raises(ArgumentError){ File.head(@test_file, 5, "foo") }
38
- assert_raises(Errno::ENOENT){ File.head("bogus") }
39
- end
40
-
41
- def teardown
42
- @test_file = nil
43
- end
44
-
45
- def self.shutdown
46
- File.delete('test_file1.txt') if File.exist?('test_file1.txt')
47
- end
48
- end
@@ -1,57 +0,0 @@
1
- #####################################################################
2
- # test_image.rb
3
- #
4
- # Test case for the File.image? method. You should run this test
5
- # via the 'rake test:image' task.
6
- #####################################################################
7
- require 'test-unit'
8
- require 'ptools'
9
-
10
- class TC_Ptools_Image < Test::Unit::TestCase
11
- def self.startup
12
- Dir.chdir('test') if File.exist?('test')
13
- end
14
-
15
- def setup
16
- @txt_file = File.join(Dir.pwd, 'txt', 'english.txt')
17
- @uni_file = File.join(Dir.pwd, 'txt', 'korean.txt')
18
- @jpg_file = File.join(Dir.pwd, 'img', 'test.jpg')
19
- @png_file = File.join(Dir.pwd, 'img', 'test.png')
20
- @gif_file = File.join(Dir.pwd, 'img', 'test.gif')
21
- end
22
-
23
- test "image? method basic functionality" do
24
- assert_respond_to(File, :image?)
25
- assert_nothing_raised{ File.image?(@txt_file) }
26
- assert_boolean(File.image?(@txt_file))
27
- end
28
-
29
- test "image? method returns false for a text file" do
30
- assert_false(File.image?(@txt_file))
31
- assert_false(File.image?(@uni_file))
32
- end
33
-
34
- test "image? method returns true for a gif" do
35
- assert_true(File.image?(@gif_file))
36
- end
37
-
38
- test "image? method returns true for a jpeg" do
39
- assert_true(File.image?(@jpg_file))
40
- end
41
-
42
- test "image? method returns true for a png" do
43
- assert_true(File.image?(@png_file))
44
- end
45
-
46
- test "image? method raises an error if the file does not exist" do
47
- assert_raises(Errno::ENOENT, ArgumentError){ File.image?('bogus') }
48
- end
49
-
50
- def teardown
51
- @txt_file = nil
52
- @uni_file = nil
53
- @jpg_file = nil
54
- @png_file = nil
55
- @gif_file = nil
56
- end
57
- end
@@ -1,53 +0,0 @@
1
- #####################################################################
2
- # test_is_sparse.rb
3
- #
4
- # Test case for the File.sparse? method. You should run this test
5
- # via the 'rake test:is_sparse' task.
6
- #####################################################################
7
- require 'test-unit'
8
- require 'ptools'
9
-
10
- class TC_IsSparse < Test::Unit::TestCase
11
- def self.startup
12
- Dir.chdir("test") if File.exist?("test")
13
- @@win = File::ALT_SEPARATOR
14
- @@osx = RbConfig::CONFIG['host_os'] =~ /darwin|osx/i
15
- system("dd of=test_sparse bs=1k seek=5120 count=0 2>/dev/null") unless @@win
16
- end
17
-
18
- def setup
19
- @sparse_file = 'test_sparse'
20
- @non_sparse_file = File.expand_path(File.basename(__FILE__))
21
- end
22
-
23
- test "is_sparse basic functionality" do
24
- omit_if(@@win, "File.sparse? tests skipped on MS Windows")
25
- omit_if(@@osx, "File.sparse? tests skipped on OS X")
26
-
27
- assert_respond_to(File, :sparse?)
28
- assert_nothing_raised{ File.sparse?(@sparse_file) }
29
- assert_boolean(File.sparse?(@sparse_file))
30
- end
31
-
32
- test "is_sparse returns the expected results" do
33
- omit_if(@@win, "File.sparse? tests skipped on MS Windows")
34
- omit_if(@@osx, "File.sparse? tests skipped on OS X")
35
-
36
- assert_true(File.sparse?(@sparse_file))
37
- assert_false(File.sparse?(@non_sparse_file))
38
- end
39
-
40
- test "is_sparse only accepts one argument" do
41
- omit_if(@@win, "File.sparse? tests skipped on MS Windows")
42
- assert_raise(ArgumentError){ File.sparse?(@sparse_file, @sparse_file) }
43
- end
44
-
45
- def teardown
46
- @sparse_file = nil
47
- @non_sparse_file = nil
48
- end
49
-
50
- def self.shutdown
51
- File.delete('test_sparse') if File.exist?('test_sparse')
52
- end
53
- end
@@ -1,110 +0,0 @@
1
- #####################################################################
2
- # test_nlconvert.rb
3
- #
4
- # Test case for the File.nl_convert method. You should run this
5
- # test via the 'rake test_nlconvert' task.
6
- #####################################################################
7
- require 'rubygems'
8
- require 'test-unit'
9
- require 'ptools'
10
-
11
- class TC_Ptools_NLConvert < Test::Unit::TestCase
12
- def self.startup
13
- @@dirname = File.dirname(__FILE__)
14
- @@test_file1 = File.join(@@dirname, 'test_nl_convert1.txt')
15
- @@test_file2 = File.join(@@dirname, 'test_nl_convert2.txt')
16
- File.open(@@test_file1, 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
17
- File.open(@@test_file2, 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
18
- end
19
-
20
- def setup
21
- @test_file1 = File.join(@@dirname, 'test_nl_convert1.txt')
22
- @test_file2 = File.join(@@dirname, 'test_nl_convert2.txt')
23
- @dos_file = File.join(@@dirname, 'dos_test_file.txt')
24
- @mac_file = File.join(@@dirname, 'mac_test_file.txt')
25
- @unix_file = 'nix_test_file.txt'
26
- end
27
-
28
- test "nl_for_platform basic functionality" do
29
- assert_respond_to(File, :nl_for_platform)
30
- end
31
-
32
- test "nl_for_platform" do
33
- assert_equal( "\cM\cJ", File.nl_for_platform('dos') )
34
- assert_equal( "\cJ", File.nl_for_platform('unix') )
35
- assert_equal( "\cM", File.nl_for_platform('mac') )
36
- assert_nothing_raised{ File.nl_for_platform('local') }
37
- end
38
-
39
- test "nl_convert basic functionality" do
40
- assert_respond_to(File, :nl_convert)
41
- end
42
-
43
- test "nl_convert accepts one, two or three arguments" do
44
- assert_nothing_raised{ File.nl_convert(@test_file2) }
45
- assert_nothing_raised{ File.nl_convert(@test_file2, @test_file2) }
46
- assert_nothing_raised{ File.nl_convert(@test_file2, @test_file2, "unix") }
47
- end
48
-
49
- test "nl_convert with dos platform argument works as expected" do
50
- msg = "dos file should be larger, but isn't"
51
-
52
- assert_nothing_raised{ File.nl_convert(@test_file1, @dos_file, "dos") }
53
- assert_true(File.size(@dos_file) > File.size(@test_file1), msg)
54
- assert_equal(["\cM","\cJ"], IO.readlines(@dos_file).first.split("")[-2..-1])
55
- end
56
-
57
- test "nl_convert with mac platform argument works as expected" do
58
- assert_nothing_raised{ File.nl_convert(@test_file1, @mac_file, 'mac') }
59
- assert_equal("\cM", IO.readlines(@mac_file).first.split("").last)
60
-
61
- omit_if(File::ALT_SEPARATOR)
62
- msg = "=> Mac file should be the same size (or larger), but isn't"
63
- assert_true(File.size(@mac_file) == File.size(@test_file1), msg)
64
- end
65
-
66
- test "nl_convert with unix platform argument works as expected" do
67
- msg = "unix file should be the same size (or smaller), but isn't"
68
-
69
- assert_nothing_raised{ File.nl_convert(@test_file1, @unix_file, "unix") }
70
- assert_equal("\n", IO.readlines(@unix_file).first.split("").last)
71
-
72
- if File::ALT_SEPARATOR
73
- assert_true(File.size(@unix_file) >= File.size(@test_file1), msg)
74
- else
75
- assert_true(File.size(@unix_file) <= File.size(@test_file1), msg)
76
- end
77
- end
78
-
79
- test "nl_convert requires at least one argument" do
80
- assert_raise(ArgumentError){ File.nl_convert }
81
- end
82
-
83
- test "nl_convert requires a valid platform string" do
84
- assert_raise(ArgumentError){ File.nl_convert(@test_file1, "bogus.txt", "blah") }
85
- end
86
-
87
- test "nl_convert accepts a maximum of three arguments" do
88
- assert_raise(ArgumentError){ File.nl_convert(@test_file1, @test_file2, 'dos', 1) }
89
- end
90
-
91
- test "nl_convert will fail on anything but plain files" do
92
- assert_raise(ArgumentError){ File.nl_convert(File.null_device, @test_file1) }
93
- end
94
-
95
- def teardown
96
- [@dos_file, @mac_file, @unix_file].each{ |file|
97
- File.delete(file) if File.exist?(file)
98
- }
99
- @dos_file = nil
100
- @mac_file = nil
101
- @unix_file = nil
102
- @test_file1 = nil
103
- @test_file2 = nil
104
- end
105
-
106
- def self.shutdown
107
- File.delete(@@test_file1) if File.exist?(@@test_file1)
108
- File.delete(@@test_file2) if File.exist?(@@test_file2)
109
- end
110
- end
@@ -1,40 +0,0 @@
1
- #####################################################################
2
- # test_null.rb
3
- #
4
- # Test case for the File.null method. You should run this test via
5
- # the 'rake test_null' task.
6
- #####################################################################
7
- require 'rubygems'
8
- gem 'test-unit'
9
-
10
- require 'test/unit'
11
- require 'ptools'
12
-
13
- class TC_FileNull < Test::Unit::TestCase
14
- def setup
15
- @nulls = ['/dev/null', 'NUL', 'NIL:', 'NL:']
16
- end
17
-
18
- test "null method basic functionality" do
19
- assert_respond_to(File, :null)
20
- assert_nothing_raised{ File.null }
21
- end
22
-
23
- test "null method returns expected results" do
24
- assert_kind_of(String, File.null)
25
- assert(@nulls.include?(File.null))
26
- end
27
-
28
- test "null method does not accept any arguments" do
29
- assert_raises(ArgumentError){ File.null(1) }
30
- end
31
-
32
- test "null_device is an alias for null" do
33
- assert_respond_to(File, :null_device)
34
- assert_alias_method(File, :null_device, :null)
35
- end
36
-
37
- def teardown
38
- @nulls = nil
39
- end
40
- end
@@ -1,124 +0,0 @@
1
- #####################################################################
2
- # test_tail.rb
3
- #
4
- # Test case for the File.tail method. This test should be run via
5
- # the 'rake test_tail' task.
6
- #####################################################################
7
- require 'test-unit'
8
- require 'ptools'
9
-
10
- class TC_FileTail < Test::Unit::TestCase
11
- def self.startup
12
- @@dirname = File.dirname(__FILE__)
13
-
14
- @@test_file1 = File.join(@@dirname, 'test_file1.txt')
15
- @@test_file64 = File.join(@@dirname, 'test_file64.txt')
16
- @@test_file128 = File.join(@@dirname, 'test_file128.txt')
17
-
18
- @@test_file_trail = File.join(@@dirname, 'test_file_trail.txt')
19
- @@test_file_trail_nl = File.join(@@dirname, 'test_file_trail_nl.txt')
20
-
21
- File.open(@@test_file1, 'w'){ |fh|
22
- 25.times{ |n| fh.puts "line#{n+1}" }
23
- }
24
-
25
- # Trailing newline test
26
- File.open(@@test_file_trail, 'w'){ |fh|
27
- 2.times{ |n| fh.puts "trail#{n+1}" }
28
- fh.write "trail3"
29
- }
30
- File.open(@@test_file_trail_nl, 'w'){ |fh|
31
- 3.times{ |n| fh.puts "trail#{n+1}" }
32
- }
33
-
34
- # Larger files
35
- test_tail_fmt_str = "line data data data data data data data %5s"
36
-
37
- File.open(@@test_file64, 'w'){ |fh|
38
- 2000.times{ |n|
39
- fh.puts test_tail_fmt_str % (n+1).to_s
40
- }
41
- }
42
-
43
- File.open(@@test_file128, 'w'){ |fh|
44
- 4500.times{ |n|
45
- fh.puts test_tail_fmt_str % (n+1).to_s
46
- }
47
- }
48
- end
49
-
50
- def setup
51
- @test_file = @@test_file1
52
- @test_trail = @@test_file_trail
53
- @test_trail_nl = @@test_file_trail_nl
54
- @test_file_64 = @@test_file64
55
- @test_file_128 = @@test_file128
56
-
57
- @expected_tail1 = %w{
58
- line16 line17 line18 line19 line20
59
- line21 line22 line23 line24 line25
60
- }
61
-
62
- @expected_tail2 = ["line21","line22","line23","line24","line25"]
63
-
64
- @expected_tail_more = []
65
- 25.times{ |n| @expected_tail_more.push "line#{n+1}" }
66
-
67
- @expected_tail_trail = %w{ trail2 trail3 }
68
-
69
- @test_tail_fmt_str = "line data data data data data data data %5s"
70
- end
71
-
72
- def test_tail_basic
73
- assert_respond_to(File, :tail)
74
- assert_nothing_raised{ File.tail(@test_file) }
75
- assert_nothing_raised{ File.tail(@test_file, 5) }
76
- assert_nothing_raised{ File.tail(@test_file){} }
77
- end
78
-
79
- def test_tail_expected_return_values
80
- assert_kind_of(Array, File.tail(@test_file))
81
- assert_equal(@expected_tail1, File.tail(@test_file))
82
- assert_equal(@expected_tail2, File.tail(@test_file, 5))
83
- end
84
-
85
- def test_more_lines_than_file
86
- assert_equal( @expected_tail_more, File.tail(@test_file, 30) )
87
- end
88
-
89
- def test_tail_expected_errors
90
- assert_raises(ArgumentError){ File.tail }
91
- assert_raises(ArgumentError){ File.tail(@test_file, 5, 5) }
92
- end
93
-
94
- def test_no_trailing_newline
95
- assert_equal( @expected_tail_trail, File.tail(@test_trail, 2) )
96
- assert_equal( @expected_tail_trail, File.tail(@test_trail_nl, 2) )
97
- end
98
-
99
- def test_tail_larger_than_64k
100
- expected_tail_64k=[]
101
- 2000.times{ |n| expected_tail_64k.push( @test_tail_fmt_str % (n+1).to_s ) }
102
- assert_equal( expected_tail_64k, File.tail(@test_file_64, 2000) )
103
- end
104
-
105
- def test_tail_larger_than_128k
106
- expected_tail_128k = []
107
- 4500.times{ |n| expected_tail_128k.push( @test_tail_fmt_str % (n+1).to_s ) }
108
- assert_equal( expected_tail_128k, File.tail(@test_file_128, 4500) )
109
- end
110
-
111
- def teardown
112
- @test_file = nil
113
- @expected_tail1 = nil
114
- @expected_tail2 = nil
115
- end
116
-
117
- def self.shutdown
118
- File.delete(@@test_file1) if File.exist?(@@test_file1)
119
- File.delete(@@test_file64) if File.exist?(@@test_file64)
120
- File.delete(@@test_file128) if File.exist?(@@test_file128)
121
- File.delete(@@test_file_trail_nl) if File.exist?(@@test_file_trail_nl)
122
- File.delete(@@test_file_trail) if File.exist?(@@test_file_trail)
123
- end
124
- end