sal-tools-analyze 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,16 @@
1
+ #!/opt/local/bin/ruby
2
+
3
+ require 'minitest/unit'
4
+ require_relative '../lib/sal/command'
5
+ require_relative '../lib/sal/code'
6
+
7
+ class TestCommand < MiniTest::Unit::TestCase
8
+
9
+ def test_function
10
+ assert_equal(false, Sal::Command.is_code_line?("Message Actions"))
11
+ assert_equal(true, Sal::Command.is_code_line?("Set bOk = TRUE"))
12
+ end
13
+
14
+ end
15
+
16
+ MiniTest::Unit.autorun
@@ -0,0 +1,37 @@
1
+ #!/opt/local/bin/ruby
2
+
3
+ require 'minitest/unit'
4
+ require_relative '../lib/sal/external'
5
+ require_relative '../lib/sal/code'
6
+
7
+ class TestExternal < MiniTest::Unit::TestCase
8
+
9
+ def test_item_external
10
+ name = "vti41.dll"
11
+ code = "Library name: #{name}"
12
+ line = ".head 3 + #{code}\r\n"
13
+ item = Sal::Item.new(line)
14
+
15
+ extlib = Sal::External.new(item)
16
+
17
+ assert_equal(item, extlib.item)
18
+ assert_equal(name, extlib.name)
19
+ end
20
+
21
+ def test_external_none_in_file
22
+ code = Sal::Code.new('data/test.40.text.app')
23
+ libs = code.externals
24
+ assert_equal(0, libs.count)
25
+ end
26
+
27
+ def test_external_in_file
28
+ code = Sal::Code.new('data/test.41.text.externalfunctions.app')
29
+ libs = code.externals
30
+ assert_equal(1, libs.count)
31
+ funcs = libs[0].functions
32
+ assert_equal(11, funcs.count)
33
+ end
34
+
35
+ end
36
+
37
+ MiniTest::Unit.autorun
@@ -0,0 +1,76 @@
1
+ #!/opt/local/bin/ruby
2
+
3
+ require 'minitest/unit'
4
+ require_relative '../lib/sal/externalfunction'
5
+
6
+ class TestExternalFunction < MiniTest::Unit::TestCase
7
+
8
+ def get_sample_external
9
+ item = Sal::Item.new(".head 3 + Library name: Test.dll\r\n")
10
+ item.childs << Sal::Item.new(".head 4 - ThreadSafe: No\r\n")
11
+ item.childs << get_sample_external_function_item
12
+ return item
13
+ end
14
+
15
+ def get_sample_external_function_item
16
+ item = Sal::Item.new(".head 4 + Function: Func1\r\n")
17
+ item.childs << Sal::Item.new(".head 5 - Description: ...\r\n")
18
+ item.childs << Sal::Item.new(".head 5 - Export Ordinal: 111\r\n")
19
+ returns = Sal::Item.new(".head 5 + Returns\r\n")
20
+ returns.childs << Sal::Item.new(".head 6 - Number: LONG\r\n")
21
+ item.childs << returns
22
+ parameters = Sal::Item.new(".head 5 + Parameters\r\n")
23
+ parameters.childs << Sal::Item.new(".head 6 - Date/Time: HARRAY\r\n")
24
+ parameters.childs << Sal::Item.new(".head 6 - ! Number: HARRAY\r\n")
25
+ parameters.childs << Sal::Item.new(".head 6 - Date/Time: DATETIME\r\n")
26
+ item.childs << parameters
27
+ return item
28
+ end
29
+
30
+ def test_item_file_include
31
+ f1_name = "Func1"
32
+ f1_code = "Function: #{f1_name}"
33
+ f1_line = ".head 4 + #{f1_code}\r\n"
34
+ f1_item = Sal::Item.new(f1_line)
35
+
36
+ x1_code = "! Description"
37
+ x1_line = ".head 4 - #{x1_code}\r\n"
38
+ x1_item = Sal::Item.new(x1_line)
39
+
40
+ l_name = "Test.dll"
41
+ l_code = "Library name: #{l_name}"
42
+ l_line = ".head 3 + #{l_code}\r\n"
43
+ l_item = Sal::Item.new(l_line)
44
+
45
+ l_item.childs << f1_item
46
+ l_item.childs << x1_item
47
+
48
+ assert_equal(2, l_item.childs.count)
49
+ extlib = Sal::External.new(l_item)
50
+
51
+ assert_equal(l_item, extlib.item)
52
+ assert_equal(l_name, extlib.name)
53
+
54
+ assert_equal(1, extlib.functions.count)
55
+
56
+ extfunc = extlib.functions[0]
57
+ assert_equal(f1_name, extfunc.name)
58
+ end
59
+
60
+ def test_item_ordinal
61
+ item = get_sample_external
62
+ library = Sal::External.new(item)
63
+ refute_equal(nil, library)
64
+ assert_equal(1, library.functions.count)
65
+
66
+ function = library.functions[0]
67
+ refute_equal(nil, function)
68
+ assert_equal("Func1", function.name)
69
+ assert_equal(111, function.ordinal)
70
+ assert_equal("Test.dll::Func1", function.key)
71
+ assert_equal(2, function.parameters.count)
72
+ assert_equal(Sal::Item, function.parameters[0].class)
73
+ end
74
+ end
75
+
76
+ MiniTest::Unit.autorun
@@ -0,0 +1,58 @@
1
+ #!/opt/local/bin/ruby
2
+
3
+ require 'minitest/unit'
4
+ require_relative '../lib/sal/format'
5
+
6
+ class TestFileFormat < MiniTest::Unit::TestCase
7
+
8
+ def setup
9
+ @files = []
10
+ @files << "data/test.40.indented.app"
11
+ @files << "data/test.40.text.app"
12
+ @files << "data/test.40.normal.app"
13
+ @files << "data/test.41.indented.app"
14
+ @files << "data/test.41.text.app"
15
+ @files << "data/test.41.normal.app"
16
+ @files << "data/test.21.text.sql.app"
17
+ end
18
+
19
+ def test_file_format
20
+ @files.grep(/\.indented\./).each do | file |
21
+ assert_equal( Sal::Format::INDENTED, Sal::Format.get_from_file(file) )
22
+ end
23
+
24
+ @files.grep(/\.text\./).each do | file |
25
+ assert_equal( Sal::Format::TEXT, Sal::Format.get_from_file(file) )
26
+ end
27
+
28
+ @files.grep(/\.normal\./).each do | file |
29
+ assert_equal( Sal::Format::NORMAL, Sal::Format.get_from_file(file) )
30
+ end
31
+ end
32
+
33
+ def test_get_from_code
34
+ assert_equal( Sal::Format::TEXT,
35
+ Sal::Format.get_from_code(".head 1 - Outline Version - 4.0.34"))
36
+ assert_equal( Sal::Format::INDENTED,
37
+ Sal::Format.get_from_code("Outline Version - 4.0.34"))
38
+ assert_equal( Sal::Format::NORMAL,
39
+ Sal::Format.get_from_code("01234567890"))
40
+ end
41
+
42
+ def test_check_constants
43
+ assert_equal( Sal::Format::TEXT, :t )
44
+ refute_equal( Sal::Format::TEXT, "t" )
45
+ assert_equal( Sal::Format::NORMAL, :n )
46
+ refute_equal( Sal::Format::NORMAL, "n" )
47
+ assert_equal( Sal::Format::INDENTED, :i )
48
+ refute_equal( Sal::Format::INDENTED, "i" )
49
+ end
50
+
51
+ def test_get_from_line
52
+ assert_equal( Sal::Format::TEXT, Sal::Format.get_from_line(".head 5 - ..."))
53
+ assert_equal( Sal::Format::INDENTED, Sal::Format.get_from_line("Application Description"))
54
+ assert_equal( Sal::Format::INDENTED, Sal::Format.get_from_line(" Design-time Settings"))
55
+ end
56
+ end
57
+
58
+ MiniTest::Unit.autorun
@@ -0,0 +1,22 @@
1
+ #!/opt/local/bin/ruby
2
+
3
+ require 'minitest/unit'
4
+ require_relative '../lib/sal/function'
5
+
6
+ class TestFunction < MiniTest::Unit::TestCase
7
+
8
+ def test_function
9
+ name = "Name"
10
+ code = "Function: #{name}"
11
+ line = ".head 5 + #{code}\r\n"
12
+ item = Sal::Item.new(line)
13
+
14
+ func = Sal::Function.new(item)
15
+
16
+ assert_equal(item, func.item)
17
+ assert_equal(name, func.name)
18
+ end
19
+
20
+ end
21
+
22
+ MiniTest::Unit.autorun
data/test/test_item.rb ADDED
@@ -0,0 +1,123 @@
1
+ #!/opt/local/bin/ruby
2
+
3
+ require 'minitest/unit'
4
+ require_relative '../lib/sal/item'
5
+ require_relative '../lib/sal/code'
6
+
7
+ class TestItem < MiniTest::Unit::TestCase
8
+
9
+ def setup
10
+ @lines = []
11
+ @lines << ".head 0 + Application Description: Gupta SQLWindows Standard Application Template\r\n"
12
+ @lines << ".head 1 + ! Outline Version - 4.0.34\r\n"
13
+ @lines << ".head 2 + Set bCommented = TRUE\r\n"
14
+ @lines << ".head 3 - ! Set bCommented = TRUE\r\n"
15
+
16
+ @items = []
17
+ parent = nil
18
+ @lines.each do | line |
19
+ item = Sal::Item.new(line, Sal::Format::TEXT)
20
+ item.parent = parent unless parent.nil?
21
+ parent.childs << item unless parent.nil?
22
+ parent = item
23
+ @items << item
24
+ end
25
+ end
26
+
27
+ def test_item_outline_version_text
28
+ code = "Outline Version - 4.0.34"
29
+ line = ".head 1 - #{code}\r\n"
30
+ item = Sal::Item.new(line)
31
+
32
+ assert_equal(line, item.line)
33
+ assert_equal(Sal::Format::TEXT, item.format)
34
+ assert_equal(1, item.level)
35
+ assert_equal(false, item.commented?)
36
+ assert_equal(nil, item.parent)
37
+ assert_equal(0, item.childs.count)
38
+ assert_equal(code, item.code)
39
+ assert_equal(true, item.analyzed?)
40
+ assert_equal(-1, item.code_line_nr)
41
+ assert_equal(nil, item.tag)
42
+ end
43
+
44
+ def test_item_outline_version_indented
45
+ # code = "Outline Version - 4.0.34"
46
+ # line = "\t#{code}\r\n"
47
+ # item = Sal::Item.new(line)
48
+
49
+ # assert_equal(line, item.line)
50
+ # assert_equal(Sal::Format::INDENTED, item.format)
51
+ # assert_equal(1, item.level)
52
+ # assert_equal(false, item.commented?)
53
+ # assert_equal(nil, item.parent)
54
+ # assert_equal(0, item.childs.count)
55
+ # assert_equal(code, item.code)
56
+ # assert_equal(true, item.analyzed?)
57
+ # assert_equal(-1, item.code_line_nr)
58
+ # assert_equal(nil, item.tag)
59
+ end
60
+
61
+ def test_item_file_include
62
+ code = "File Include: qckttip.apl"
63
+ line = ".head 2 - #{code}\r\n"
64
+ item = Sal::Item.new(line)
65
+
66
+ assert_equal(line, item.line)
67
+ assert_equal(line, item.original)
68
+ assert_equal(Sal::Format::TEXT, item.format)
69
+ assert_equal(2, item.level)
70
+ assert_equal(false, item.commented?)
71
+ assert_equal(nil, item.parent)
72
+ assert_equal(0, item.childs.count)
73
+ assert_equal(true, item.analyzed?)
74
+ assert_equal(code, item.code)
75
+ assert_equal(-1, item.code_line_nr)
76
+ assert_equal(nil, item.tag)
77
+ end
78
+
79
+ def test_item_commented
80
+ commented = 0
81
+ item_commented = 0
82
+
83
+ @items.each do | item |
84
+ commented += 1 if item.commented?
85
+ item_commented += 1 if item.item_commented?
86
+ end
87
+
88
+ assert_equal(3, commented)
89
+ assert_equal(2, item_commented)
90
+ end
91
+
92
+ def test_item_count
93
+ assert_equal(1, @items.find_all {|item| item.level == 1 }.length)
94
+ end
95
+
96
+ def test_is_code_line
97
+ counter = 0
98
+ @items.each do | item |
99
+ counter += 1 if item.is_code_line?
100
+ end
101
+ assert_equal(1, counter, "Count of code lines in sample code")
102
+ end
103
+
104
+ def test_item_code_multiline
105
+ code = Sal::Code.new("data/test.40.text.multiline.app")
106
+ code.items.each do | item |
107
+ if item.code =~ /^Set /
108
+ assert_equal(2, item.code.each_line.to_a.length)
109
+ end
110
+ end
111
+ end
112
+
113
+ def test_item_comment
114
+ code = "File Include: qckttip.apl"
115
+ line = ".head 2 - #{code}\r\n"
116
+ item = Sal::Item.new(line)
117
+ item.item_comment
118
+ assert_equal("! #{code}", item.code)
119
+ end
120
+
121
+ end
122
+
123
+ MiniTest::Unit.autorun
@@ -0,0 +1,38 @@
1
+ #!/opt/local/bin/ruby
2
+
3
+ require 'minitest/unit'
4
+ require_relative '../lib/sal/library'
5
+ require_relative '../lib/sal/code'
6
+ require_relative '../lib/sal/item'
7
+
8
+ class TestLibrary < MiniTest::Unit::TestCase
9
+
10
+ def test_item_file_include
11
+ name = "qckttip.apl"
12
+ code = "File Include: #{name}"
13
+ line = ".head 2 - #{code}\r\n"
14
+ item = Sal::Item.new(line)
15
+
16
+ library = Sal::Library.new(item)
17
+
18
+ assert_equal(item, library.item)
19
+ assert_equal(name, library.name)
20
+ end
21
+
22
+ def test_libraries
23
+ libraries = Sal::Code.new("data/test.40.text.app").libraries
24
+ assert_equal(2, libraries.length)
25
+ assert_equal("qckttip.apl", libraries[0].name)
26
+ assert_equal("vt.apl", libraries[1].name)
27
+ end
28
+
29
+ def test_get_name
30
+ item = Sal::Item.new("")
31
+ lib = Sal::Library.new(item)
32
+ assert_equal("test", lib.send(:get_name,"File Include: test"))
33
+ assert_equal("test", lib.send(:get_name,"File Include: test ! jacka"))
34
+ end
35
+
36
+ end
37
+
38
+ MiniTest::Unit.autorun
@@ -0,0 +1,80 @@
1
+ #!/opt/local/bin/ruby
2
+
3
+ require 'minitest/unit'
4
+ require_relative '../lib/sal/version'
5
+
6
+ class TestVersion < MiniTest::Unit::TestCase
7
+
8
+ def test_file_to_td
9
+
10
+ # unit tests für versionen von 0 bis 100
11
+ i = 0
12
+ test_empty = Array.new
13
+ test_empty += (0..25).to_a
14
+ test_empty += [29, 30, 33, 36]
15
+ test_empty += (38..100).to_a
16
+ test_empty.each do | test |
17
+ i += 1
18
+ begin
19
+ Sal::Version.file_to_td(test)
20
+ assert false
21
+ rescue RuntimeError
22
+ assert true
23
+ end
24
+ end
25
+
26
+ assert_equal("1.1", Sal::Version.file_to_td(26))
27
+ assert_equal("1.5", Sal::Version.file_to_td(27))
28
+ assert_equal("2.0", Sal::Version.file_to_td(28))
29
+ # assert_equal("2.1", Sal::Version.file_to_td(28))
30
+ assert_equal("3.0", Sal::Version.file_to_td(31))
31
+ assert_equal("3.1", Sal::Version.file_to_td(32))
32
+ assert_equal("4.0", Sal::Version.file_to_td(34))
33
+ assert_equal("4.1", Sal::Version.file_to_td(35))
34
+ # assert_equal("5.0", Sal::Version.file_to_td(37))
35
+ assert_equal("5.1", Sal::Version.file_to_td(37))
36
+
37
+ # unknown versions
38
+
39
+ # assert_equal( "4.2", Sal::Version.file_to_td(??))
40
+ # assert_equal( "5.2", Sal::Version.file_to_td(??))
41
+ # assert_equal( "6.0", Sal::Version.file_to_td(??))
42
+ end
43
+
44
+ def test_td_to_file
45
+ assert_equal(26, Sal::Version.td_to_file("1.1"))
46
+ assert_equal(27, Sal::Version.td_to_file("1.5"))
47
+ assert_equal(28, Sal::Version.td_to_file("2.0"))
48
+ assert_equal(28, Sal::Version.td_to_file("2.1"))
49
+ assert_equal(31, Sal::Version.td_to_file("3.0"))
50
+ assert_equal(32, Sal::Version.td_to_file("3.1"))
51
+ assert_equal(34, Sal::Version.td_to_file("4.0"))
52
+ assert_equal(35, Sal::Version.td_to_file("4.1"))
53
+ assert_equal(37, Sal::Version.td_to_file("5.0"))
54
+ assert_equal(37, Sal::Version.td_to_file("5.1"))
55
+
56
+ # unknown versions
57
+
58
+ # assert_equal(??, Sal::Version.td_to_file("4.2"))
59
+ # assert_equal(??, Sal::Version.td_to_file("5.2"))
60
+ # assert_equal(??, Sal::Version.td_to_file("6.0"))
61
+ end
62
+
63
+ def test_initialize
64
+ assert_equal(26, Sal::Version.new("1.1").file)
65
+ assert_equal("1.1", Sal::Version.new(26).td)
66
+ end
67
+
68
+ def test_from_code
69
+ assert_equal(26, Sal::Version.from_code(".head 1 - Outline Version - 4.0.26").file)
70
+ assert_equal(26, Sal::Version.from_code("Outline Version - 4.0.26").file)
71
+ end
72
+
73
+ def test_to_code
74
+ version = Sal::Version.new(27)
75
+ assert_equal("Outline Version - 4.0.27", version.to_code("Outline Version - 4.0.26"))
76
+ end
77
+
78
+ end
79
+
80
+ MiniTest::Unit.autorun