libisi 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +677 -0
- data/Manifest +89 -0
- data/Rakefile +34 -0
- data/lib/inifile.rb +119 -0
- data/lib/libisi.rb +948 -0
- data/lib/libisi/attribute.rb +32 -0
- data/lib/libisi/attribute/activerecord.rb +34 -0
- data/lib/libisi/attribute/base.rb +33 -0
- data/lib/libisi/base.rb +109 -0
- data/lib/libisi/bridge.rb +21 -0
- data/lib/libisi/bridge/base.rb +23 -0
- data/lib/libisi/bridge/java.rb +71 -0
- data/lib/libisi/bridge/python.rb +37 -0
- data/lib/libisi/cache.rb +21 -0
- data/lib/libisi/cache/base.rb +67 -0
- data/lib/libisi/cache/file_cache.rb +24 -0
- data/lib/libisi/chart.rb +21 -0
- data/lib/libisi/chart/base.rb +320 -0
- data/lib/libisi/chart/jfreechart.rb +682 -0
- data/lib/libisi/chart/jfreechart_generator.rb +206 -0
- data/lib/libisi/color.rb +21 -0
- data/lib/libisi/color/base.rb +66 -0
- data/lib/libisi/color/colortools.rb +92 -0
- data/lib/libisi/color/java.rb +44 -0
- data/lib/libisi/concept.rb +33 -0
- data/lib/libisi/concept/activerecord.rb +39 -0
- data/lib/libisi/concept/base.rb +58 -0
- data/lib/libisi/doc.rb +35 -0
- data/lib/libisi/doc/base.rb +414 -0
- data/lib/libisi/doc/html.rb +85 -0
- data/lib/libisi/doc/text.rb +98 -0
- data/lib/libisi/doc/wiki.rb +55 -0
- data/lib/libisi/environment.rb +21 -0
- data/lib/libisi/environment/base.rb +36 -0
- data/lib/libisi/environment/http.rb +105 -0
- data/lib/libisi/environment/rails.rb +27 -0
- data/lib/libisi/environment/root.rb +23 -0
- data/lib/libisi/fake_logger/logger.rb +61 -0
- data/lib/libisi/function/base.rb +30 -0
- data/lib/libisi/hal.rb +558 -0
- data/lib/libisi/instance.rb +27 -0
- data/lib/libisi/instance/activerecord.rb +21 -0
- data/lib/libisi/instance/base.rb +42 -0
- data/lib/libisi/log.rb +237 -0
- data/lib/libisi/mail/base.rb +32 -0
- data/lib/libisi/mail/tmail.rb +120 -0
- data/lib/libisi/parameter/base.rb +41 -0
- data/lib/libisi/property.rb +27 -0
- data/lib/libisi/property/base.rb +28 -0
- data/lib/libisi/reciever/base.rb +31 -0
- data/lib/libisi/reciever/socket.rb +31 -0
- data/lib/libisi/relation.rb +23 -0
- data/lib/libisi/request.rb +22 -0
- data/lib/libisi/request/base.rb +29 -0
- data/lib/libisi/request/http.rb +129 -0
- data/lib/libisi/response/base.rb +27 -0
- data/lib/libisi/task/base.rb +27 -0
- data/lib/libisi/task/http.rb +90 -0
- data/lib/libisi/tee.rb +296 -0
- data/lib/libisi/ui/base.rb +116 -0
- data/lib/libisi/ui/console.rb +238 -0
- data/lib/libisi/ui/kde.rb +94 -0
- data/lib/libisi/ui/nobody.rb +29 -0
- data/lib/libisi/ui/rails.rb +150 -0
- data/lib/libisi/ui/x11.rb +55 -0
- data/lib/libisi/uri.rb +42 -0
- data/lib/libisi/uri/activerecord.rb +152 -0
- data/lib/libisi/uri/base.rb +115 -0
- data/lib/libisi/uri/file.rb +43 -0
- data/lib/libisi/uri/ldap.rb +72 -0
- data/lib/libisi/uri/mysql.rb +98 -0
- data/lib/libisi/value.rb +31 -0
- data/lib/libisi/value/attribute_value.rb +19 -0
- data/lib/libisi/value/base.rb +55 -0
- data/lib/libisi/value/property_value.rb +19 -0
- data/lib/libisi/value/relation_value.rb +19 -0
- data/lib/ordered_hash.rb +228 -0
- data/libisi.gemspec +31 -0
- data/test/bridge_test.rb +77 -0
- data/test/cache_test.rb +65 -0
- data/test/chart_test.rb +179 -0
- data/test/color_test.rb +64 -0
- data/test/concept_test.rb +56 -0
- data/test/doc_test.rb +172 -0
- data/test/fixtures/test.db +0 -0
- data/test/ordered_hash_test.rb +39 -0
- data/test/profile_test.rb +36 -0
- data/test/request_test.rb +121 -0
- data/test/test +0 -0
- data/test/ui_test.rb +62 -0
- metadata +244 -0
data/test/color_test.rb
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Copyright (C) 2007-2010 Logintas AG Switzerland
|
|
2
|
+
#
|
|
3
|
+
# This file is part of Libisi.
|
|
4
|
+
#
|
|
5
|
+
# Libisi is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# Libisi is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU General Public License
|
|
16
|
+
# along with Libisi. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
|
|
18
|
+
$LOAD_PATH.insert(0,File.dirname(__FILE__) + "/../lib/")
|
|
19
|
+
require 'test/unit'
|
|
20
|
+
require "libisi"
|
|
21
|
+
init_libisi
|
|
22
|
+
require "libisi/color"
|
|
23
|
+
|
|
24
|
+
class ColorTest < Test::Unit::TestCase
|
|
25
|
+
|
|
26
|
+
COLORS = {
|
|
27
|
+
"#ff0000" => ["red","Red","RED",:red],
|
|
28
|
+
"#d3d3d3" => ["light_gray","lightgray","LightGRay",:light_gray,:lightgray],
|
|
29
|
+
"#aabbcc" => ["#aabbcc","#aabbcc","aabbcc"],
|
|
30
|
+
"#aabbcc" => ["#abc","#abc","abc"],
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
def test_java
|
|
34
|
+
COLORS.each {|rgb, colors|
|
|
35
|
+
colors.each {|color|
|
|
36
|
+
assert Color.create("java",color), "Could not create java color #{color}"
|
|
37
|
+
assert_equal rgb, Color.create("java",color).html, "Expected java color #{color} to be #{rgb}"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_colortool
|
|
43
|
+
COLORS.each {|rgb, colors|
|
|
44
|
+
colors.each {|color|
|
|
45
|
+
assert Color.create("colortools",color), "Could not create colortools color #{color}"
|
|
46
|
+
assert_equal rgb, Color.create("colortools",color).html, "Expected colortools color #{color} to be #{rgb}"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
assert_equal "#f12f3f", Color.create("colortools","#f12f3f").html
|
|
51
|
+
c = Color.create("colortools","#f12f3f")
|
|
52
|
+
assert_equal [241,47,63], c.rgb
|
|
53
|
+
assert_equal "#f12f3f", c.html
|
|
54
|
+
c.html = "ff2f3f"
|
|
55
|
+
assert_equal [255,47,63], c.rgb
|
|
56
|
+
c.red = 241
|
|
57
|
+
assert_equal [241,47,63], c.rgb
|
|
58
|
+
c.green = 222
|
|
59
|
+
assert_equal [241,222,63], c.rgb
|
|
60
|
+
c.blue = 7
|
|
61
|
+
assert_equal [241,222,7], c.rgb
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Copyright (C) 2007-2010 Logintas AG Switzerland
|
|
2
|
+
#
|
|
3
|
+
# This file is part of Libisi.
|
|
4
|
+
#
|
|
5
|
+
# Libisi is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# Libisi is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU General Public License
|
|
16
|
+
# along with Libisi. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
|
|
18
|
+
$LOAD_PATH.insert(0,File.dirname(__FILE__) + "/../lib/")
|
|
19
|
+
require 'test/unit'
|
|
20
|
+
require "libisi"
|
|
21
|
+
init_libisi
|
|
22
|
+
require "libisi/concept"
|
|
23
|
+
require "libisi/instance"
|
|
24
|
+
|
|
25
|
+
class ConceptTest < Test::Unit::TestCase
|
|
26
|
+
|
|
27
|
+
def test_concept
|
|
28
|
+
assert c = Concept.create(String)
|
|
29
|
+
# a base ruby class has no attributes
|
|
30
|
+
assert_equal [], c.attributes
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_activerecord
|
|
34
|
+
sqlite = Uri.create("sqlite3://localhost/#{File.dirname(__FILE__) + "/fixtures/test.db/t1"}")
|
|
35
|
+
first_record = sqlite.find(:first)
|
|
36
|
+
ar_class = first_record.class
|
|
37
|
+
|
|
38
|
+
assert c = Concept.create(ar_class)
|
|
39
|
+
assert c.class == ActiverecordConcept
|
|
40
|
+
assert_equal ["data", "num", "t1key", "timeEnter"],
|
|
41
|
+
c.attribute_names.sort
|
|
42
|
+
|
|
43
|
+
assert c.value_accessors
|
|
44
|
+
|
|
45
|
+
attrs = c.attributes.sort_by {|a| a.name}
|
|
46
|
+
assert_equal [:text, :float, :integer, :date],attrs.map {|a| a.type}
|
|
47
|
+
|
|
48
|
+
assert inst = Instance.create(first_record)
|
|
49
|
+
assert val = inst.value("data")
|
|
50
|
+
|
|
51
|
+
assert_equal "", val.inspect
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
end
|
data/test/doc_test.rb
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# Copyright (C) 2007-2010 Logintas AG Switzerland
|
|
2
|
+
#
|
|
3
|
+
# This file is part of Libisi.
|
|
4
|
+
#
|
|
5
|
+
# Libisi is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# Libisi is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU General Public License
|
|
16
|
+
# along with Libisi. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
|
|
18
|
+
$LOAD_PATH.insert(0,File.dirname(__FILE__) + "/../lib/")
|
|
19
|
+
require 'test/unit'
|
|
20
|
+
require "libisi"
|
|
21
|
+
init_libisi
|
|
22
|
+
require "libisi/chart"
|
|
23
|
+
|
|
24
|
+
class ChartTest < Test::Unit::TestCase
|
|
25
|
+
|
|
26
|
+
# TODO
|
|
27
|
+
# test_doc("text", "text")
|
|
28
|
+
# test_doc("html")
|
|
29
|
+
# test_doc("html", "html")
|
|
30
|
+
# test_doc("text", "html")
|
|
31
|
+
# test_doc("html","text")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_text
|
|
35
|
+
do_test("text")
|
|
36
|
+
end
|
|
37
|
+
def test_html
|
|
38
|
+
do_test("html")
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def do_test(doc, together_with = nil)
|
|
42
|
+
Doc.change(doc)
|
|
43
|
+
output_document = Pathname.new("/tmp/test.#{together_with}")
|
|
44
|
+
|
|
45
|
+
if together_with
|
|
46
|
+
output_document.delete if output_document.exist?
|
|
47
|
+
add_output(output_document)
|
|
48
|
+
# the output to file should be first
|
|
49
|
+
$doc.children = $doc.children.reverse if $doc.class == Tee
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
title_call_count = 0
|
|
53
|
+
td_call_count = 0
|
|
54
|
+
table_call_count = 0
|
|
55
|
+
$doc.title("Title 1") {
|
|
56
|
+
title_call_count += 1
|
|
57
|
+
raise "Called title block the 2nd time" if title_call_count == 2
|
|
58
|
+
$doc.table(:columns => ["a","bb","ccc"]) {|col, index|
|
|
59
|
+
$log.debug("Called table block #{col} #{index}")
|
|
60
|
+
table_call_count += 1
|
|
61
|
+
# raise "Called table block the 1st time" if table_call_count == 1
|
|
62
|
+
raise "Called table block the 4th time" if table_call_count == 4
|
|
63
|
+
raise "col is nil" if col.nil?
|
|
64
|
+
|
|
65
|
+
# still a problem here:
|
|
66
|
+
# table calls td td, td td, td td in 3 blocks (see doc/base.rb)
|
|
67
|
+
# the teed will call td td td td td,, because it exits not
|
|
68
|
+
# out of the table call function
|
|
69
|
+
$doc.td {
|
|
70
|
+
td_call_count += 1
|
|
71
|
+
raise "Called td block the 4th time" if td_call_count == 4
|
|
72
|
+
col + "1"
|
|
73
|
+
}
|
|
74
|
+
$doc.td { col + "2" }
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
raise "Call count is not 3 its #{table_call_count}" unless td_call_count == 3
|
|
78
|
+
raise "Call count is not 3 its #{td_call_count}" unless td_call_count == 3
|
|
79
|
+
|
|
80
|
+
$doc.title("Title 2") {
|
|
81
|
+
$doc.title("Title 2.1") {
|
|
82
|
+
$doc.table(:items => ["x","yy","zzz"]) {|item, index|
|
|
83
|
+
raise "item is nil" if item.nil?
|
|
84
|
+
$doc.th { item.upcase }
|
|
85
|
+
$doc.td { item + "a"}
|
|
86
|
+
$doc.td { item + "b"}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
$doc.table(:items => ["x","yy","zzz"]) {|item|
|
|
90
|
+
raise "item is nil" if item.nil?
|
|
91
|
+
$doc.th { item.upcase }
|
|
92
|
+
$doc.td { item + "a"}
|
|
93
|
+
$doc.td { item + "b"}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
$doc.title("Title 2.2") {
|
|
97
|
+
$doc.table(:columns => ["a","bb","ccc"], :items => ["xxx","yy","z"]) {|item, col, item_index, column_index|
|
|
98
|
+
raise "item is nil" if item.nil?
|
|
99
|
+
raise "col is nil" if col.nil?
|
|
100
|
+
"#{item}.#{col}"
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
gba = ["aaa","bbb","ccc","aaab","aaac","bbbd"]
|
|
107
|
+
|
|
108
|
+
$doc.table(:items => gba, :group_bys => [lambda {|e| e.length},lambda {|e| e[0..1] }])
|
|
109
|
+
$doc.table(:items => gba, :group_bys => [lambda {|e| e.length},lambda {|e| e[0..1] }]) {|e|
|
|
110
|
+
$doc.td {e.upcase}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
call_times = 0
|
|
114
|
+
$doc.table(:items => gba,
|
|
115
|
+
:columns => ["length","first", "item_text1","item_text2"],
|
|
116
|
+
:group_bys => [lambda {|e| e.length},lambda {|e| e[0..0] }]) {|e,col,i1,i2|
|
|
117
|
+
call_times += 1
|
|
118
|
+
raise "Block called #{call_times} times instead of 19" if call_times == 20
|
|
119
|
+
[e,col, i1,i2].inspect
|
|
120
|
+
}
|
|
121
|
+
raise "Block called #{call_times} times instead of 19" if call_times != 19
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
gba = ["aaa","bbb","ccc","aaab","aaac","bbbd","aaA","AaA"]
|
|
125
|
+
# ok, some more complicated grouping with different options
|
|
126
|
+
options =
|
|
127
|
+
$doc.table(:items => gba,
|
|
128
|
+
:style => "border:1 solid black;",
|
|
129
|
+
:writer => Pathname.new("/tmp/test.html").open("w"),
|
|
130
|
+
:before_group_function0 => Proc.new {|options|
|
|
131
|
+
$doc.tr { $doc.th(:colspan => 5) { "BeforeTotal0 #{options[:group_items].inspect}"}}
|
|
132
|
+
},
|
|
133
|
+
:after_group_function0 => Proc.new {|options|
|
|
134
|
+
$doc.tr { $doc.th(:colspan => 5) { "Total0 #{options[:group_items].inspect}"}}
|
|
135
|
+
},
|
|
136
|
+
:before_group_function1 => Proc.new {|options|
|
|
137
|
+
$doc.tr { $doc.th(:colspan => 5) { "BeforeTotal1 #{options[:group_items].inspect}"}}
|
|
138
|
+
},
|
|
139
|
+
:after_group_function1 => Proc.new {|options|
|
|
140
|
+
$doc.tr { $doc.th(:colspan => 5) { "Total1 #{options[:group_items].inspect}"}}
|
|
141
|
+
},
|
|
142
|
+
:span_grouping => true,
|
|
143
|
+
:columns => [
|
|
144
|
+
[:length, ["length","textagain"]],
|
|
145
|
+
[:capitalize, ["capitalized", "again"]],
|
|
146
|
+
[nil, ["item"]]
|
|
147
|
+
].to_hash
|
|
148
|
+
) {|object, column, item_index, column_index, options|
|
|
149
|
+
# call_times += 1
|
|
150
|
+
# raise "Block called #{call_times} times instead of 19" if call_times == 20
|
|
151
|
+
# [e,col, i1,i2].inspect
|
|
152
|
+
#p column
|
|
153
|
+
# "Col:" + column.inspect +
|
|
154
|
+
# " Obj:" + object.inspect +
|
|
155
|
+
" Gk:" + options[:group_keys].inspect +
|
|
156
|
+
# " Ge:" + options[:group_elements].inspect +
|
|
157
|
+
" Gi:" + options[:group_items].inspect +
|
|
158
|
+
# " Gci:" + options[:group_column_index].inspect +
|
|
159
|
+
""
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
$doc.end_doc
|
|
164
|
+
$doc.close
|
|
165
|
+
p benchmark("bla") { "jk" }
|
|
166
|
+
if together_with
|
|
167
|
+
raise "#{o.to_s} does not exist!" unless output_document.exist?
|
|
168
|
+
raise "#{o.to_s} has size zero" if output_document.size == 0
|
|
169
|
+
raise "Output not equal to fixture" unless system("diff fixtures/output.#{together_with} #{output_document}")
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
end
|
|
Binary file
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Copyright (C) 2007-2010 Logintas AG Switzerland
|
|
2
|
+
#
|
|
3
|
+
# This file is part of Libisi.
|
|
4
|
+
#
|
|
5
|
+
# Libisi is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# Libisi is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU General Public License
|
|
16
|
+
# along with Libisi. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
|
|
18
|
+
$LOAD_PATH.insert(0,File.dirname(__FILE__) + "/../lib/")
|
|
19
|
+
require 'test/unit'
|
|
20
|
+
require "libisi"
|
|
21
|
+
init_libisi
|
|
22
|
+
require "libisi/chart"
|
|
23
|
+
|
|
24
|
+
class ChartOrderedHash < Test::Unit::TestCase
|
|
25
|
+
|
|
26
|
+
def test_array_to_hash
|
|
27
|
+
test_array = [[:key1, "value1"],[:keyb,"value2"],["key3",[[:a,"v"],[:b,"w"]]]]
|
|
28
|
+
|
|
29
|
+
assert test_array.can_be_a_hash?
|
|
30
|
+
|
|
31
|
+
assert_equal '{:key1=>"value1", :keyb=>"value2", "key3"=>[[:a, "v"], [:b, "w"]]}',
|
|
32
|
+
test_array.to_hash.inspect
|
|
33
|
+
|
|
34
|
+
assert_equal '{:key1=>"value1", :keyb=>"value2", "key3"=>{:a=>"v", :b=>"w"}}',
|
|
35
|
+
test_array.to_hash(true).inspect
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Copyright (C) 2007-2010 Logintas AG Switzerland
|
|
2
|
+
#
|
|
3
|
+
# This file is part of Libisi.
|
|
4
|
+
#
|
|
5
|
+
# Libisi is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# Libisi is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU General Public License
|
|
16
|
+
# along with Libisi. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
|
|
18
|
+
$LOAD_PATH.insert(0,File.dirname(__FILE__) + "/../lib/")
|
|
19
|
+
require 'test/unit'
|
|
20
|
+
require "libisi"
|
|
21
|
+
init_libisi
|
|
22
|
+
|
|
23
|
+
class ProfileTest < Test::Unit::TestCase
|
|
24
|
+
|
|
25
|
+
def test_prof
|
|
26
|
+
with_temp_directory {
|
|
27
|
+
self.profiling = FileUtils.pwd.to_s
|
|
28
|
+
10.times { 1 + 1}
|
|
29
|
+
self.profiling_stop
|
|
30
|
+
assert Pathname.new("RubyProf_RubyProf::CallTreePrinter.txt").exist?
|
|
31
|
+
assert Pathname.new("RubyProf_RubyProf::FlatPrinter.txt").exist?
|
|
32
|
+
assert Pathname.new("RubyProf_RubyProf::GraphHtmlPrinter.html").exist?
|
|
33
|
+
assert Pathname.new("RubyProf_RubyProf::GraphPrinter.txt").exist?
|
|
34
|
+
}
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# Copyright (C) 2007-2010 Logintas AG Switzerland
|
|
2
|
+
#
|
|
3
|
+
# This file is part of Libisi.
|
|
4
|
+
#
|
|
5
|
+
# Libisi is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# Libisi is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU General Public License
|
|
16
|
+
# along with Libisi. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
|
|
18
|
+
$LOAD_PATH.insert(0,File.dirname(__FILE__) + "/../lib/")
|
|
19
|
+
require 'test/unit'
|
|
20
|
+
require "libisi"
|
|
21
|
+
init_libisi
|
|
22
|
+
require "libisi/request/http"
|
|
23
|
+
require "libisi/environment/http"
|
|
24
|
+
require "libisi/function/base"
|
|
25
|
+
require "libisi/task/base"
|
|
26
|
+
require "libisi/task/http"
|
|
27
|
+
require "libisi/parameter/base"
|
|
28
|
+
require "libisi/reciever/socket"
|
|
29
|
+
|
|
30
|
+
class RequestTest < Test::Unit::TestCase
|
|
31
|
+
|
|
32
|
+
FULL_URI = URI.parse("http://www.example.com/context/function/arg1/arg2?param1=val1¶m2=val2")
|
|
33
|
+
ARGS = ["arg1","arg2"]
|
|
34
|
+
OPTIONS = {:param1 => ["val1"], :param2 => ["val2"]}
|
|
35
|
+
BODY_CONTENT = "<html></html>"
|
|
36
|
+
|
|
37
|
+
def test_http_parse
|
|
38
|
+
req = HttpRequest.from_uri(FULL_URI)
|
|
39
|
+
|
|
40
|
+
assert req
|
|
41
|
+
assert_equal HttpRequest, req.class
|
|
42
|
+
assert req.environment
|
|
43
|
+
assert_equal "http://www.example.com/", req.environment.uri.to_s
|
|
44
|
+
assert task = req.task
|
|
45
|
+
|
|
46
|
+
assert task.function
|
|
47
|
+
assert_equal "context", task.function.context
|
|
48
|
+
assert_equal "function", task.function.name
|
|
49
|
+
assert task.parameter
|
|
50
|
+
assert ARGS, task.parameter.arguments
|
|
51
|
+
assert_equal(OPTIONS, task.parameter.options)
|
|
52
|
+
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_http_parse_rev
|
|
56
|
+
param = BaseParameter.new
|
|
57
|
+
param.options = OPTIONS
|
|
58
|
+
param.arguments = ARGS
|
|
59
|
+
|
|
60
|
+
r = HttpRequest.new(HttpEnvironment.new(URI.parse("http://www.example.com/")),
|
|
61
|
+
BaseTask.new(
|
|
62
|
+
BaseFunction.new("context","function"),
|
|
63
|
+
param
|
|
64
|
+
)
|
|
65
|
+
)
|
|
66
|
+
assert_equal FULL_URI, r.environment.uri_from_task(r.task)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def test_socket
|
|
70
|
+
reciever = SocketReciever.new(3333) {|io|
|
|
71
|
+
task = HttpTask.from_browser(io)
|
|
72
|
+
# task.parameter.stdin.gets
|
|
73
|
+
}
|
|
74
|
+
success = false
|
|
75
|
+
t = Thread.new {
|
|
76
|
+
begin
|
|
77
|
+
sleep 0.1
|
|
78
|
+
req = HttpRequest.from_uri(FULL_URI)
|
|
79
|
+
req.environment = HttpEnvironment.new(URI.parse("http://127.0.0.1:3333"))
|
|
80
|
+
assert_equal BODY_CONTENT, req.execute
|
|
81
|
+
success = true
|
|
82
|
+
rescue
|
|
83
|
+
print "#{$!}\n"
|
|
84
|
+
$!.backtrace.each {|l| print "#{l}\n"}
|
|
85
|
+
end
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
p "Start recieving"
|
|
89
|
+
task = reciever.get
|
|
90
|
+
assert task
|
|
91
|
+
assert task.function.context
|
|
92
|
+
assert task.function
|
|
93
|
+
assert_equal "context", task.function.context
|
|
94
|
+
assert_equal "function", task.function.name
|
|
95
|
+
assert task.parameter
|
|
96
|
+
assert ARGS, task.parameter.arguments
|
|
97
|
+
|
|
98
|
+
opts = task.parameter.options.dup
|
|
99
|
+
input = opts.delete(:input_stream)
|
|
100
|
+
output = opts.delete(:output_stream)
|
|
101
|
+
assert_equal({:http_version => "1.1",:request_method => "GET"}.merge(OPTIONS), opts)
|
|
102
|
+
assert input
|
|
103
|
+
assert output
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
input.write("HTTP/1.0 200 OK\n\n" + BODY_CONTENT)
|
|
107
|
+
#Content-Type: text/html
|
|
108
|
+
#
|
|
109
|
+
#<html>
|
|
110
|
+
# <body>
|
|
111
|
+
# <h1>Hello World</h1>
|
|
112
|
+
# </body>
|
|
113
|
+
#</html>
|
|
114
|
+
#EOF
|
|
115
|
+
input.close_write
|
|
116
|
+
|
|
117
|
+
t.join
|
|
118
|
+
assert success, "Thread failure"
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
end
|