testability-driver 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. data/lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb +2 -2
  2. data/lib/tdriver-devtools/tdriver-devtools.rb +1 -1
  3. data/lib/tdriver-devtools/tests/feature_tests/lib/custom_rdoc_generator.rb +3 -3
  4. data/lib/tdriver/base/behaviour/behaviours/object_behaviour_composition.rb +6 -1
  5. data/lib/tdriver/base/behaviour/behaviours/object_behaviour_description.rb +5 -3
  6. data/lib/tdriver/base/behaviour/behaviours/object_composition.rb +1 -1
  7. data/lib/tdriver/base/behaviour/factory.rb +225 -225
  8. data/lib/tdriver/base/errors.rb +1 -1
  9. data/lib/tdriver/base/state_object.rb +227 -179
  10. data/lib/tdriver/base/sut/controller.rb +2 -2
  11. data/lib/tdriver/base/sut/factory.rb +190 -182
  12. data/lib/tdriver/base/sut/generic/behaviours/application.rb +69 -25
  13. data/lib/tdriver/base/sut/generic/behaviours/controller.rb +1 -1
  14. data/lib/tdriver/base/sut/generic/behaviours/find.rb +4 -4
  15. data/lib/tdriver/base/sut/generic/behaviours/flash_behaviour.rb +3 -3
  16. data/lib/tdriver/base/sut/generic/behaviours/sut.rb +350 -165
  17. data/lib/tdriver/base/sut/generic/behaviours/switchbox_behaviour.rb +9 -9
  18. data/lib/tdriver/base/sut/generic/behaviours/verification.rb +191 -103
  19. data/lib/tdriver/base/sut/generic/commands/application.rb +1 -1
  20. data/lib/tdriver/base/sut/generic/commands/key_sequence.rb +1 -1
  21. data/lib/tdriver/base/sut/generic/commands/screen_capture.rb +1 -1
  22. data/lib/tdriver/base/sut/generic/plugin.rb +1 -1
  23. data/lib/tdriver/base/sut/sut.rb +5 -1
  24. data/lib/tdriver/base/test_object/abstract.rb +136 -151
  25. data/lib/tdriver/base/test_object/adapter.rb +293 -82
  26. data/lib/tdriver/base/test_object/behaviours/syncronization.rb +20 -17
  27. data/lib/tdriver/base/test_object/behaviours/test_object.rb +159 -532
  28. data/lib/tdriver/base/test_object/cache.rb +1 -1
  29. data/lib/tdriver/base/test_object/factory.rb +254 -605
  30. data/lib/tdriver/base/test_object/identificator.rb +1 -1
  31. data/lib/tdriver/base/test_object/loader.rb +1 -1
  32. data/lib/tdriver/base/test_object/verification.rb +17 -17
  33. data/lib/tdriver/loader.rb +20 -9
  34. data/lib/tdriver/report/report.rb +5 -0
  35. data/lib/tdriver/report/report_creator.rb +2 -2
  36. data/lib/tdriver/report/report_cucumber_listener.rb +4 -4
  37. data/lib/tdriver/report/report_cucumber_reporter.rb +4 -4
  38. data/lib/tdriver/report/report_execution_statistics.rb +22 -22
  39. data/lib/tdriver/report/report_grouping.rb +2 -2
  40. data/lib/tdriver/report/report_javascript.rb +11 -4
  41. data/lib/tdriver/report/report_test_case_run.rb +2 -2
  42. data/lib/tdriver/report/report_test_run.rb +5 -5
  43. data/lib/tdriver/report/report_test_unit.rb +74 -26
  44. data/lib/tdriver/report/report_writer.rb +70 -13
  45. data/lib/tdriver/tdriver.rb +17 -8
  46. data/lib/tdriver/util/common/array.rb +1 -1
  47. data/lib/tdriver/util/common/crc16.rb +1 -1
  48. data/lib/tdriver/util/common/environment.rb +1 -1
  49. data/lib/tdriver/util/common/file.rb +18 -9
  50. data/lib/tdriver/util/common/gem.rb +1 -1
  51. data/lib/tdriver/util/common/hash.rb +21 -0
  52. data/lib/tdriver/util/common/kernel.rb +1 -1
  53. data/lib/tdriver/util/common/loader.rb +5 -2
  54. data/lib/tdriver/util/common/numeric.rb +54 -3
  55. data/lib/tdriver/util/common/retryable.rb +30 -12
  56. data/lib/tdriver/util/common/stackable.rb +185 -0
  57. data/lib/tdriver/util/common/string.rb +21 -5
  58. data/lib/tdriver/util/{dbaccess/dbaccess.rb → database/access.rb} +4 -1
  59. data/lib/tdriver/util/{dbaccess/dbconnection.rb → database/connection.rb} +3 -0
  60. data/lib/tdriver/util/{dbaccess → database}/error.rb +0 -1
  61. data/lib/tdriver/util/{dbaccess → database}/loader.rb +5 -6
  62. data/lib/tdriver/util/{dynamic_attribute_filter.rb → filters/dynamic_attributes.rb} +1 -1
  63. data/lib/tdriver/util/hooking/hooking.rb +477 -0
  64. data/lib/tdriver/util/loader.rb +35 -29
  65. data/lib/tdriver/util/localisation/error.rb +0 -1
  66. data/lib/tdriver/util/localisation/loader.rb +1 -4
  67. data/lib/tdriver/util/localisation/localisation.rb +30 -27
  68. data/lib/tdriver/util/{common.rb → logger/loader.rb} +2 -4
  69. data/lib/tdriver/util/logger/logger.rb +574 -0
  70. data/lib/tdriver/util/operator_data/loader.rb +4 -3
  71. data/lib/tdriver/util/operator_data/operator_data.rb +5 -5
  72. data/lib/tdriver/util/parameter/parameter.rb +7 -1
  73. data/lib/tdriver/util/parameter/parameter_hash.rb +1 -1
  74. data/lib/tdriver/util/parameter/parameter_template.rb +1 -1
  75. data/lib/tdriver/util/parameter/parameter_user_api.rb +28 -20
  76. data/lib/tdriver/util/parameter/parameter_xml.rb +1 -1
  77. data/lib/tdriver/util/plugin/abstract.rb +1 -1
  78. data/lib/tdriver/util/plugin/service.rb +1 -1
  79. data/lib/tdriver/util/{localisation.rb → recorder/loader.rb} +4 -3
  80. data/lib/tdriver/util/recorder/recorder.rb +66 -0
  81. data/lib/tdriver/util/recorder/scripter.rb +258 -0
  82. data/lib/tdriver/util/{stats.rb → statistics/statistics.rb} +7 -8
  83. data/lib/tdriver/util/user_data/error.rb +0 -1
  84. data/lib/tdriver/util/user_data/loader.rb +1 -2
  85. data/lib/tdriver/util/user_data/user_data.rb +6 -6
  86. data/lib/tdriver/util/video/camera.rb +67 -0
  87. data/lib/tdriver/util/video/camera_linux.rb +139 -0
  88. data/lib/tdriver/util/video/camera_windows.rb +174 -0
  89. data/lib/tdriver/util/video/loader.rb +31 -0
  90. data/lib/tdriver/util/video/video_utils.rb +139 -0
  91. data/lib/tdriver/util/xml/abstraction.rb +56 -5
  92. data/lib/tdriver/util/xml/builder.rb +2 -5
  93. data/lib/tdriver/util/{parameter.rb → xml/comment.rb} +10 -2
  94. data/lib/tdriver/util/xml/loader.rb +32 -22
  95. data/lib/tdriver/util/xml/nil_node.rb +2 -2
  96. data/lib/tdriver/util/xml/parsers/loader.rb +0 -1
  97. data/lib/tdriver/util/xml/parsers/nokogiri/abstraction.rb +18 -44
  98. data/lib/tdriver/util/xml/parsers/nokogiri/attribute.rb +9 -13
  99. data/lib/tdriver/util/xml/parsers/nokogiri/builder.rb +9 -3
  100. data/lib/tdriver/util/xml/parsers/nokogiri/comment.rb +39 -0
  101. data/lib/tdriver/util/xml/parsers/nokogiri/document.rb +6 -11
  102. data/lib/tdriver/util/xml/parsers/nokogiri/element.rb +2 -122
  103. data/lib/tdriver/util/xml/parsers/nokogiri/loader.rb +26 -16
  104. data/lib/tdriver/util/xml/parsers/nokogiri/node.rb +203 -0
  105. data/lib/tdriver/util/xml/parsers/nokogiri/nodeset.rb +1 -2
  106. data/lib/tdriver/util/xml/parsers/nokogiri/text.rb +2 -20
  107. data/lib/tdriver/util/xml/xml.rb +52 -20
  108. data/lib/tdriver/verify/verify.rb +238 -81
  109. data/xml/behaviours/generic.xml +12 -10
  110. metadata +156 -180
  111. data/lib/tdriver/base/test_object/factory_new.rb +0 -202
  112. data/lib/tdriver/util/hooking.rb +0 -434
  113. data/lib/tdriver/util/logger.rb +0 -506
  114. data/lib/tdriver/util/recorder.rb +0 -297
  115. data/lib/tdriver/util/video_utils.rb +0 -384
  116. data/lib/tdriver/util/xml/nil_element.rb +0 -89
@@ -17,49 +17,55 @@
17
17
  ##
18
18
  ############################################################################
19
19
 
20
-
21
20
  require 'singleton'
21
+
22
22
  require 'rubygems'
23
23
 
24
- # Hooking module - should be loaded first due to above modules uses its functions
25
- require File.expand_path( File.join( File.dirname( __FILE__ ), 'hooking.rb' ) )
24
+ [
25
+ # hooking module - should be loaded first due to above modules uses its functions
26
+ 'hooking/hooking.rb',
27
+
28
+ # common utility modules
29
+ 'common/loader.rb',
30
+
31
+ # logger module
32
+ 'logger/logger.rb',
26
33
 
27
- # generic/common utility modules
28
- require File.expand_path( File.join( File.dirname( __FILE__ ), 'common/loader.rb' ) )
34
+ # parameter modules
35
+ 'xml/loader.rb',
29
36
 
30
- # Logger module
31
- require File.expand_path( File.join( File.dirname( __FILE__ ), 'logger.rb' ) )
37
+ # statistics module
38
+ 'statistics/statistics.rb',
32
39
 
33
- # Parameter modules
34
- require File.expand_path( File.join( File.dirname( __FILE__ ), 'xml/loader.rb' ) )
40
+ # dynamic attribute filter module
41
+ 'filters/dynamic_attributes.rb',
35
42
 
36
- # Statistics module
37
- require File.expand_path( File.join( File.dirname( __FILE__ ), 'stats.rb' ) )
43
+ # plugin service modules
44
+ 'plugin/loader.rb',
38
45
 
39
- # Dynamic attribute filter module
40
- require File.expand_path( File.join( File.dirname( __FILE__ ), 'dynamic_attribute_filter' ) )
46
+ # parameter modules
47
+ 'parameter/loader.rb',
41
48
 
42
- # Plugin service & abstract class
43
- require File.expand_path( File.join( File.dirname( __FILE__ ), 'plugin/loader.rb' ) )
49
+ # database access module
50
+ 'database/loader.rb',
44
51
 
45
- # Parameter modules
46
- require File.expand_path( File.join( File.dirname( __FILE__ ), 'parameter/loader.rb' ) )
52
+ # localisation module
53
+ 'localisation/loader.rb',
47
54
 
48
- # DBAccess module
49
- require File.expand_path( File.join( File.dirname( __FILE__ ), 'dbaccess/loader.rb' ) )
55
+ # user data module
56
+ 'user_data/loader.rb',
50
57
 
51
- # Localisation module
52
- require File.expand_path( File.join( File.dirname( __FILE__ ), 'localisation/loader.rb' ) )
58
+ # operator data module
59
+ 'operator_data/loader.rb',
53
60
 
54
- # User Data module
55
- require File.expand_path( File.join( File.dirname( __FILE__ ), 'user_data/loader.rb' ) )
61
+ # recorder and scripter modules
62
+ 'recorder/loader.rb',
56
63
 
57
- # Operator Data module
58
- require File.expand_path( File.join( File.dirname( __FILE__ ), 'operator_data/loader.rb' ) )
64
+ # video capture/util modules
65
+ 'video/loader.rb'
59
66
 
60
- # Recorder module
61
- require File.expand_path( File.join( File.dirname( __FILE__ ), 'recorder.rb' ) )
67
+ ].each{ | filename |
62
68
 
63
- # Video utils module
64
- require File.expand_path( File.join( File.dirname( __FILE__ ), 'video_utils.rb' ) )
69
+ require File.expand_path( File.join( File.dirname( __FILE__ ), filename ) )
65
70
 
71
+ }
@@ -17,7 +17,6 @@
17
17
  ##
18
18
  ############################################################################
19
19
 
20
-
21
20
  module MobyUtil
22
21
 
23
22
  # This error should be raised when referred language is not found
@@ -17,12 +17,9 @@
17
17
  ##
18
18
  ############################################################################
19
19
 
20
-
21
-
22
-
23
20
  # localisation related errors
24
21
  require File.expand_path( File.join( File.dirname( __FILE__ ), 'error.rb' ) )
25
22
 
26
- # localisation module implementation
23
+ # localisation module implementation - load only if needed
27
24
  require File.expand_path( File.join( File.dirname( __FILE__ ), 'localisation.rb' ) )
28
25
 
@@ -17,17 +17,18 @@
17
17
  ##
18
18
  ############################################################################
19
19
 
20
+ # TODO: refactor to use MobyUtil::XML
20
21
  require 'nokogiri'
21
22
 
22
23
  # Utility for handling localisation database
23
-
24
24
  module MobyUtil
25
25
 
26
26
  class Localisation
27
27
 
28
28
  # == Language maping cross-referenced from Nokia Shared Lancuage Codes and Symbian
29
- # http://developer.symbian.org/main/documentation/reference/s3/pdk/GUID-31C133DE-F245-5992-9A41-20A99291E72A.html
30
- # http://www2.connecting.nokia.com/nokia/terminology/terms.nsf/document/ES346PMF37?OpenDocument&ExpandSection=1#_Section1
29
+ #
30
+ # Please follow Nokia Language Guidelines.
31
+ #
31
32
  # Its also enumerated by TLanguage in e32lang.h in the Symbian code.
32
33
  # The ones only on e32lang.h are commented out
33
34
  @language_code_map = {
@@ -39,7 +40,7 @@ module MobyUtil
39
40
  "Swedish" => ["sv", "06"],
40
41
  "Danish" => ["da", "07"],
41
42
  "Norwegian" => ["no", "08"],
42
- "Finish" => ["fi", "09"],
43
+ "Finnish" => ["fi", "09"],
43
44
  "English US" => ["en_US", "10"],
44
45
  # "Swiss French" => ["SF", "11"],
45
46
  # "Swiss German" => ["SG", "12"],
@@ -106,7 +107,7 @@ module MobyUtil
106
107
  # "Moldavian" => ["MO", "73"],
107
108
  "Mongolian" => ["mn", "74"],
108
109
  # "Norwegian Nynorsk" => ["nn", "75"],
109
- "Portuguese BR" => ["pt_BP", "76"],
110
+ "Portuguese BR" => ["pt_BR", "76"],
110
111
  "Punjabi" => ["pa", "77"],
111
112
  "Romanian" => ["ro", "78"],
112
113
  "Servian" => ["sr", "79"],
@@ -310,11 +311,11 @@ module MobyUtil
310
311
  language += "_"
311
312
  end
312
313
 
313
- db_type = MobyUtil::Parameter[ :localisation_db_type, nil ]
314
- host = MobyUtil::Parameter[ :localisation_server_ip ]
315
- username = MobyUtil::Parameter[ :localisation_server_username ]
316
- password = MobyUtil::Parameter[ :localisation_server_password ]
317
- database_name = MobyUtil::Parameter[ :localisation_server_database_name ]
314
+ db_type = $parameters[ :localisation_db_type, nil ]
315
+ host = $parameters[ :localisation_server_ip ]
316
+ username = $parameters[ :localisation_server_username ]
317
+ password = $parameters[ :localisation_server_password ]
318
+ database_name = $parameters[ :localisation_server_database_name ]
318
319
 
319
320
  db_connection = DBConnection.new( db_type, host, database_name, username, password )
320
321
 
@@ -393,11 +394,11 @@ module MobyUtil
393
394
 
394
395
  # Get a connection to the DB
395
396
  if db_connection.nil? or !db_connection.kind_of? MobyUtil::DBConnection
396
- db_type = MobyUtil::Parameter[ :localisation_db_type ]
397
- host = MobyUtil::Parameter[ :localisation_server_ip ]
398
- database_name = MobyUtil::Parameter[ :localisation_server_database_name ]
399
- username = MobyUtil::Parameter[ :localisation_server_username ]
400
- password = MobyUtil::Parameter[ :localisation_server_password ]
397
+ db_type = $parameters[ :localisation_db_type ]
398
+ host = $parameters[ :localisation_server_ip ]
399
+ database_name = $parameters[ :localisation_server_database_name ]
400
+ username = $parameters[ :localisation_server_username ]
401
+ password = $parameters[ :localisation_server_password ]
401
402
 
402
403
  db_connection = DBConnection.new( db_type, host, database_name, username, password )
403
404
  end
@@ -565,7 +566,7 @@ module MobyUtil
565
566
  language_number = $2
566
567
  # select returns an array of [language, codes] that suite the conditional
567
568
  # codes is the array ["NokiaCode(2-leter)", "SymbianCode(number)"]
568
- language = @language_code_map.select{|lang,codes| codes[1] == language_number}[0][1][0]
569
+ language = @language_code_map.select{|lang,codes| codes[1] == language_number}.to_a[0][1][0] # Array conversion for ruby 1.9 compatibility
569
570
  language = column_names_map[ language_number ] if !column_names_map.empty? and column_names_map.key?( language_number )
570
571
 
571
572
  io = open(file)
@@ -721,19 +722,21 @@ module MobyUtil
721
722
  # Extracs application name used for FNAME from a given filename (removes language tags and file extension)
722
723
  # Used only on .ts files
723
724
  def self.parseFName(file)
724
- fname = file.split('/').last
725
725
  #(wordlist matching)
726
- words = ["ar", "bg", "ca", "cs", "da", "de", "el", "en", "english-gb", "(apac)", "(apaccn)", "(apachk)", "(apactw)", "japanese", "thai", "us", "es", "419", "et", "eu", "fa", "fi", "fr", "gl", "he", "hi", "hr", "hu", "id", "is", "it", "ja", "ko", "lt", "lv", "mr", "ms", "nb", "nl", "pl", "pt", "br", "ro", "ru", "sk", "sl", "sr", "sv", "th", "tl", "tr", "uk", "ur", "us", "vi", "zh", "hk", "tw", "no"]
727
- match = fname.scan(/_([a-zA-Z1-9\-\(\)]*)/)
728
- if match
729
- match.each do |m|
730
- fname.gsub!("_#{m[0]}"){|s| ""} if words.include?( m[0].downcase )
731
- end
732
- end
733
- fname.gsub!(".ts"){|s| ""}
726
+ words = ["ar", "bg", "ca", "cs", "da", "de", "el", "en", "english-gb", "(apac)", "(apaccn)", "(apachk)", "(apactw)", "japanese", "thai", "us", "es", "419", "et", "eu", "fa", "fi", "fr", "gl", "he", "hi", "hr", "hu", "id", "is", "it", "ja", "ko", "lt", "lv", "mr", "ms", "nb", "nl", "pl", "pt", "br", "ro", "ru", "sk", "sl", "sr", "sv", "th", "tl", "tr", "uk", "ur", "us", "vi", "zh", "hk", "tw", "no", "gb", "cn"]
727
+
728
+ fname = file.split('/').last
729
+ fname.gsub!(".ts"){|s| ""}
730
+ fname_fragments = fname.split('_')
731
+ fname_fragments.each_index do |i|
732
+ fname_fragments[i] = "" if words.include?( fname_fragments[i].downcase )
733
+ end
734
+ fname_fragments.delete("")
735
+ fname = fname_fragments.join("_")
734
736
  language = file.split('/').last.gsub( fname + "_" ){|s| ""}.gsub(".ts"){|s| ""}
735
- return fname, language #gsub! will return nil if now subs are performed
736
- end
737
+ return fname, "" if fname == language
738
+ return fname, language
739
+ end
737
740
 
738
741
  end # class
739
742
 
@@ -17,8 +17,6 @@
17
17
  ##
18
18
  ############################################################################
19
19
 
20
-
21
- STDOUT.puts "Please require 'util/common/loader.rb' instead of 'util/common.rb'"
22
-
23
- require File.expand_path( File.join( File.dirname( __FILE__ ), 'common/loader.rb' ) )
20
+ # logger module
21
+ require File.expand_path( File.join( File.dirname( __FILE__ ), 'logger.rb' ) )
24
22
 
@@ -0,0 +1,574 @@
1
+ ############################################################################
2
+ ##
3
+ ## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4
+ ## All rights reserved.
5
+ ## Contact: Nokia Corporation (testabilitydriver@nokia.com)
6
+ ##
7
+ ## This file is part of Testability Driver.
8
+ ##
9
+ ## If you have questions regarding the use of this file, please contact
10
+ ## Nokia at testabilitydriver@nokia.com .
11
+ ##
12
+ ## This library is free software; you can redistribute it and/or
13
+ ## modify it under the terms of the GNU Lesser General Public
14
+ ## License version 2.1 as published by the Free Software Foundation
15
+ ## and appearing in the file LICENSE.LGPL included in the packaging
16
+ ## of this file.
17
+ ##
18
+ ############################################################################
19
+
20
+ module MobyUtil
21
+
22
+ class Logger
23
+
24
+ include Singleton
25
+
26
+ attr_reader :include_behaviour_info
27
+
28
+ def initialize
29
+
30
+ # Allow all levels to be reported - do not change this!
31
+ @custom_levels = ['debug', 'behaviour', 'info', 'warning', 'error', 'fatal']
32
+
33
+ #Log4r::Configurator.custom_levels *@custom_levels.collect{ | level | level.upcase }
34
+
35
+ #Log4r::Logger.root.level = Log4r::DEBUG
36
+
37
+ @enabled_stack = [ false ]
38
+
39
+ @logger_instance = nil
40
+
41
+ @logger_engine_loaded = false
42
+
43
+ end
44
+
45
+ def include_behaviour_info=( value )
46
+
47
+ value.check_type( [ TrueClass, FalseClass ], "wrong argument type $1 for include_behaviour_info (expected $2)" )
48
+
49
+ @include_behaviour_info = value
50
+
51
+ end
52
+
53
+ # allow reporting by passing level as method name, raise exception if method_id not found in @custom_levels array
54
+ def method_missing( method_id, *method_arguments )
55
+
56
+ method_id_str = method_id.to_s
57
+
58
+ if @custom_levels.include?( method_id_str )
59
+
60
+ log method_id_str, *method_arguments
61
+
62
+ else
63
+
64
+ # raise exception
65
+ super
66
+
67
+ end
68
+
69
+ end
70
+
71
+ # TODO: add documentation
72
+ def enabled
73
+
74
+ @enabled_stack[ -1 ]
75
+
76
+ end
77
+
78
+ # TODO: add documentation
79
+ def enabled=( value )
80
+
81
+ @enabled_stack[ -1 ] = value
82
+
83
+ end
84
+
85
+ # TODO: add documentation
86
+ def push_enabled( value )
87
+
88
+ # push current value to stack if given argument is other than boolean
89
+ value = @enabled_stack[ -1 ] unless [ TrueClass, FalseClass ].include?( value.class )
90
+
91
+ @enabled_stack << value
92
+
93
+ end
94
+
95
+ # TODO: add documentation
96
+ def pop_enabled
97
+
98
+ @enabled_stack.pop if @enabled_stack.count > 1
99
+
100
+ end
101
+
102
+ # TODO: add documentation
103
+ def set_report_level( report_level )
104
+
105
+ if @logger_engine_loaded
106
+
107
+ Log4r::Logger.root.level = report_level
108
+
109
+ else
110
+
111
+ nil
112
+
113
+ end
114
+
115
+ end
116
+
117
+ # TODO: add documentation
118
+ def new_logger( logger_name )
119
+
120
+ if @logger_engine_loaded
121
+
122
+ Log4r::Logger.new( logger_name )
123
+
124
+ else
125
+
126
+ nil
127
+
128
+ end
129
+
130
+ end
131
+
132
+ # TODO: add documentation
133
+ def get_logger( logger_name )
134
+
135
+ begin
136
+
137
+ if @logger_engine_loaded
138
+
139
+ Log4r::Logger.get( logger_name )
140
+
141
+ else
142
+
143
+ nil
144
+
145
+ end
146
+
147
+ rescue
148
+
149
+ Kernel::raise ArgumentError, "Logger #{ logger_name.inspect } not found"
150
+
151
+ end
152
+
153
+ end
154
+
155
+ # TODO: add documentation
156
+ def create_outputter( outputter_class, *args )
157
+
158
+ outputter_class.new *args
159
+
160
+ end
161
+
162
+ # TODO: add documentation
163
+ def add_outputter( logger_instance, outputter_instance )
164
+
165
+ logger_instance.add outputter_instance
166
+
167
+ end
168
+
169
+ # TODO: add documentation
170
+ def remove_outputter( logger_instance, outputter_instance )
171
+
172
+ logger_instance.remove outputter_instance
173
+
174
+ end
175
+
176
+ # TODO: add documentation
177
+ def set_outputter_pattern( outputter_instance, pattern )
178
+
179
+ if @logger_engine_loaded
180
+
181
+ # Allow only FileOutputter instances
182
+ Kernel::raise ArgumentError, 'Outputter instance not valid' if ![ Log4r::FileOutputter ].include?( outputter_instance.class )
183
+
184
+ # Allow only FileOutputter instances
185
+ Kernel::raise ArgumentError, 'Outputter pattern not valid, %M required by minimum' if !/\%M/.match( pattern )
186
+
187
+ # create pattern for outputter
188
+ outputter_instance.formatter = Log4r::PatternFormatter.new :pattern => pattern
189
+
190
+ end
191
+
192
+ end
193
+
194
+ # TODO: add documentation
195
+ # return logger instance
196
+ def self.[]( key )
197
+
198
+ get_logger key
199
+
200
+ end
201
+
202
+ # TODO: add documentation
203
+ def root
204
+
205
+ if @logger_engine_loaded
206
+
207
+ Log4r::Logger.global
208
+
209
+ else
210
+
211
+ nil
212
+
213
+ end
214
+
215
+ end
216
+
217
+ # TODO: add documentation
218
+ def log( level, *text_array )
219
+
220
+ if @logger_instance && enabled
221
+
222
+ # convert to lowercase string
223
+ level = level.to_s.downcase
224
+
225
+ include_behaviour_info = @include_behaviour_info
226
+
227
+ # debug log entries and logging by using TDriver.logging.info or MobyUtil::Logging.instance.info etc
228
+ if caller.first =~ /method_missing/
229
+
230
+ # get correct caller method
231
+ log_caller = caller.at( 1 )
232
+
233
+ # debug level
234
+ if log_caller =~ /hooking\.rb/
235
+
236
+ log_caller = caller.at( 3 ).first
237
+
238
+ end
239
+
240
+ elsif caller.first =~ /logger\.rb/
241
+
242
+ # do not add caller info if called from self
243
+ include_behaviour_info = false
244
+
245
+ else
246
+
247
+ # normal logging, e.g. behaviour logging from method etc
248
+ log_caller = caller.at( 0 )
249
+
250
+ end
251
+
252
+ # log text to given level if logging enabled
253
+ text_array.each{ | text |
254
+
255
+ @logger_instance.send level, ( include_behaviour_info && !text.empty? ) ? "#{ text.to_s } in #{ log_caller.to_s }" : text.to_s
256
+
257
+ }
258
+
259
+ end
260
+
261
+ end
262
+
263
+ def enable_raise_hooking
264
+
265
+ # hook Kernel.raise
266
+ def Kernel::raise( *exception )
267
+
268
+ begin
269
+
270
+ super *exception
271
+
272
+ rescue => raised_exception
273
+
274
+ raised_exception.backtrace.slice!( 0 )
275
+
276
+ $logger.log 'warning', *[ '', "(#{ raised_exception.class }) #{ raised_exception.message.split("\n") }", '', raised_exception.backtrace, '' ].flatten
277
+
278
+ super raised_exception
279
+
280
+ end
281
+
282
+ end
283
+
284
+ end
285
+
286
+ def set_debug_exceptions
287
+
288
+ if ARGV.include?( '--debug_exceptions' ) || $parameters[ :debug_exceptions, 'false' ].to_s.downcase == 'true'
289
+
290
+ ARGV.delete('--debug_exceptions')
291
+
292
+ # for debugging to see every occured exception
293
+ def Kernel.raise( *args )
294
+ #begin
295
+ # raise and catch exception
296
+ super( *args )
297
+ #rescue
298
+ # remove wrapper call from backtrace
299
+ # $!.backtrace.shift
300
+ #puts "%s: %s\nBacktrace: \n%s\n\n" % [ $!.class, $!.message, $!.backtrace.collect{ | line | " %s" % line }.join("\n") ]
301
+ # raise exception again
302
+ # super $!
303
+ #end
304
+ end
305
+
306
+ # hook Object(Kernel)#raise
307
+ ::Object.class_exec{
308
+
309
+ ::Kernel.module_exec{
310
+
311
+ alias_method :original_raise, :raise
312
+
313
+ def raise( *args )
314
+
315
+ begin
316
+
317
+ # raise and catch exception
318
+ original_raise( *args )
319
+
320
+ rescue
321
+
322
+ # remove wrapper calls from backtrace
323
+ while $!.backtrace.first =~ /(logger\.rb).*(raise)/
324
+
325
+ $!.backtrace.shift
326
+
327
+ end
328
+
329
+ puts "[debug] %s: %s\n[debug] Backtrace: \n[debug] %s\n\n" % [
330
+ $!.class,
331
+ $!.message,
332
+ $!.backtrace.collect{ | line | " ... from %s" % line }.join("\n[debug] ")
333
+ ]
334
+
335
+ # raise exception again
336
+ original_raise $!
337
+
338
+ end
339
+
340
+ end
341
+
342
+ }
343
+ }
344
+
345
+ end
346
+
347
+ end
348
+
349
+ # TODO: add documentation
350
+ def enable_logging
351
+
352
+ set_debug_exceptions # if enabled
353
+
354
+ # returns logging level as string
355
+ logging_level = Parameter[ :logging_level, nil ]
356
+
357
+ # do not enable logging if no logging level is not defined
358
+ return nil if logging_level.nil?
359
+
360
+ # raise exception if wrong format for logging level
361
+ Kernel::raise RuntimeError, "Wrong logging level format '#{ logging_level }' defined in TDriver parameter/template XML (expected numeric string)" unless logging_level.numeric?
362
+
363
+ # convert to integer
364
+ logging_level = logging_level.to_i
365
+
366
+ # raise exception if unsupported logging level
367
+ Kernel::raise RuntimeError, "Unsupported logging level '#{ logging_level }' defined in TDriver parameter/template XML (expected 0..5)" unless ( 0..5 ).include?( logging_level )
368
+
369
+ @include_behaviour_info = $parameters[ :logging_include_behaviour_info, 'false' ].to_s.to_boolean
370
+
371
+ # UI state XML parse error logging - verify that all required parameters are configured and output folder is created succesfully
372
+ if MobyUtil::KernelHelper.to_boolean( $parameters[ :logging_xml_parse_error_dump, 'false' ] ) == true
373
+
374
+ begin
375
+
376
+ if $parameters[ :logging_xml_parse_error_dump_path, nil ].nil?
377
+
378
+ warn("Warning: Configuration parameter :logging_xml_parse_error_dump_path missing, disabling the feature...")
379
+
380
+ # disable feature
381
+ raise ArgumentError
382
+
383
+ else
384
+
385
+ begin
386
+
387
+ # create error dump folder if not exist, used e.g. when xml parse error
388
+ MobyUtil::FileHelper.mkdir_path( MobyUtil::FileHelper.expand_path( $last_parameter ) )
389
+
390
+ rescue #Exception
391
+
392
+ warn("Warning: Unable to create log folder #{ $parameters[ :logging_xml_parse_error_dump_path ] } for corrupted XML UI state files")
393
+
394
+ # disable feature
395
+ raise ArgumentError
396
+
397
+ end
398
+
399
+ end
400
+
401
+ if $parameters[ :logging_xml_parse_error_dump_overwrite, nil ].nil?
402
+
403
+ warn("Warning: Configuration parameter :logging_xml_parse_error_dump_overwrite missing, using 'false' as default value")
404
+
405
+ $parameters[ :logging_xml_parse_error_dump_overwrite ] = 'false'
406
+
407
+ end
408
+
409
+ rescue ArgumentError => exception
410
+
411
+ # disable xml logging
412
+ $parameters[ :logging_xml_parse_error_dump ] = 'false'
413
+
414
+ rescue #Exception => exception
415
+
416
+ # disable xml logging
417
+ warn( "Warning: Disabling logging due to failure (#{ $!.class }: #{ $!.message })" )
418
+
419
+ $parameters[ :logging_xml_parse_error_dump ] = 'false'
420
+
421
+ end
422
+
423
+ else
424
+
425
+ warn("Warning: Configuration parameter :logging_xml_parse_error_dump missing, disabling the feature...")
426
+ $parameters[ :logging_xml_parse_error_dump ] = 'false'
427
+
428
+ end
429
+
430
+ unless logging_level.zero?
431
+
432
+ # logger output path
433
+ outputter_path = MobyUtil::FileHelper.expand_path( $parameters[ :logging_outputter_path ] )
434
+
435
+ require 'log4r'
436
+
437
+ require 'log4r/configurator'
438
+
439
+ Log4r::Configurator.custom_levels *@custom_levels.collect{ | level | level.upcase }
440
+
441
+ Log4r::Logger.root.level = Log4r::DEBUG
442
+
443
+ @logger_engine_loaded = true
444
+
445
+ # disable logging if exception is raised during
446
+ begin
447
+
448
+ # create outputter folder if not exist
449
+ MobyUtil::FileHelper.mkdir_path( outputter_path )
450
+
451
+ # create new logger instance
452
+ new_logger( 'TDriver' )
453
+
454
+ # get logger object reference
455
+ @logger_instance = get_logger( 'TDriver' )
456
+
457
+ # create unique name for logfile or use default (TDriver.log)
458
+ filename = ( MobyUtil::StringHelper.to_boolean( Parameter[ :logging_outputter_unique_filename ] ) ? "TDriver_#{ Time.now.to_i }.log" : "TDriver.log" )
459
+
460
+ # check if outputter is enabled
461
+ if MobyUtil::StringHelper.to_boolean( Parameter[ :logging_outputter_enabled ] )
462
+
463
+ # create new outputter instance type of FileOutputter
464
+ outputter = create_outputter(
465
+
466
+ # outputter type
467
+ Log4r::FileOutputter,
468
+
469
+ # outputter name
470
+ "TDriver_LOG",
471
+
472
+ # outputter filename
473
+ :filename => File.join( outputter_path, filename ),
474
+
475
+ # append to or truncate file
476
+ :trunc => MobyUtil::StringHelper.to_boolean( Parameter[ :logging_outputter_append ] ) == false,
477
+
478
+ # logging level
479
+ :level => logging_level
480
+
481
+ )
482
+
483
+ # set outputter log event write pattern
484
+ set_outputter_pattern( outputter, Parameter[ :logging_outputter_pattern ] )
485
+
486
+ # add outputter to logger instance
487
+ add_outputter( @logger_instance, outputter )
488
+
489
+ end
490
+
491
+ rescue
492
+
493
+ $parameters[ :logging_level ] = '0'
494
+
495
+ @logger_instance = nil
496
+
497
+ @enabled_stack = [ false ]
498
+
499
+ warn("Warning: Disabling logging due to failure (#{ $!.class }: #{ $!.message })")
500
+
501
+ return nil
502
+
503
+ end
504
+
505
+ # debug logging
506
+ if ( logging_level == 1 )
507
+
508
+ # enable exception capturing on debug level
509
+ enable_raise_hooking
510
+
511
+ # pass logger instance to hooking module
512
+ TDriver::Hooking.logger_instance = MobyUtil::Logger.instance
513
+
514
+ end
515
+
516
+ # enable logging
517
+ @enabled_stack = [ true ]
518
+
519
+ # log event: start logging
520
+ log( 'info' , "", "Logging engine started", "" )
521
+
522
+ end
523
+
524
+ report_status_at_exit
525
+
526
+ end
527
+
528
+ def report_status_at_exit
529
+
530
+ at_exit{
531
+
532
+ begin
533
+
534
+ exit_status = nil
535
+
536
+ case $!
537
+
538
+ when NilClass
539
+
540
+ exit_status = ['info', '', 'Execution finished succesfully', '']
541
+
542
+ when SystemExit
543
+
544
+ exit_status = ['info', '', 'Execution terminated by system exit', '' ]
545
+
546
+ else
547
+
548
+ exit_status = ['error', '', "Execution terminated with exception: %s: %s" % [ caller.first, $!.message.split("\n") ], '' ]
549
+
550
+ end
551
+
552
+ log( *exit_status )
553
+
554
+ rescue
555
+
556
+ end
557
+
558
+ }
559
+ end
560
+
561
+ def hook_methods( _base )
562
+
563
+ #STDOUT.puts "Use TDriver::Hooking instead of MobyUtil::Logging.hook_methods (#{ caller(1).first })"
564
+
565
+ TDriver::Hooking.hook_methods( _base ) #if @enabled
566
+
567
+ end
568
+
569
+ end # Logger
570
+
571
+ end # MobyUtil
572
+
573
+ # set global variable pointing to parameter class
574
+ $logger = MobyUtil::Logger.instance