File: Runner.rb

package info (click to toggle)
quickfix 1.15.1%2Bdfsg-4
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye
  • size: 42,080 kB
  • sloc: cpp: 631,686; python: 129,549; ruby: 106,716; xml: 43,737; ansic: 7,668; java: 1,826; cs: 816; makefile: 544; sh: 462; sql: 313
file content (144 lines) | stat: -rw-r--r-- 3,455 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#****************************************************************************
# Copyright (c) 2001-2014
#
# This file is part of the QuickFIX FIX Engine
#
# This file may be distributed under the terms of the quickfixengine.org
# license as defined by quickfixengine.org and appearing in the file
# LICENSE included in the packaging of this file.
#
# This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
# WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# See http://www.quickfixengine.org/LICENSE for licensing information.
#
# Contact ask@quickfixengine.org if any conditions of this licensing are
# not clear to you.
#****************************************************************************

require './ReflectorClient'
require './Comparator'

def extendProcess(c)

  def c.errorAction(lineNum, line)
    report =  "    " + $!.to_s + "\n"    
    report += "    <line>" + lineNum.to_s + "</line>\n"
    raise report
  end

  def c.compareAction(e, a)
    if( !defined? @patterns )
      @patterns = "10=\\d{1,3}\n52=\\d{8}-\\d{2}:\\d{2}:\\d{2}\n";
    end
    if( !defined? @comp )
      @comp = Comparator.new(@patterns)
    end

    if( !@comp.compare(e,a) )
       e.tr!("\001", "*")
       a.tr!("\001", "*")
       report =  @comp.reason + "\n"
       report += "    <expected><![CDATA[" + e + "]]></expected>\n"
       report += "    <received><![CDATA[" + a + "]]></received>"
       raise report
    end
  end
    
  def c.patterns=(p)
    @patterns = p
  end

  c.patterns = File.open("definitions/fields.fmt", "r")
end

def printResult(test, exception)
  print "<test name='", test,  "' result='"
  if exception == nil then
    print "success'/>\n"
  else
    print "failure' >\n"
    print "  <message>\n", $!, "  </message>\n"
    #print "  <trace><![CDATA["
    #print $!.backtrace.join("]]></trace>\n  <trace><![CDATA[")
    #print "  ]]></trace>\n"
    print "</test>\n"
  end
  STDOUT.flush
end

def createProcess(file, address, port)
  newarray = [1,2,3,4,5,6,7,8,9,10]
  newarray.each do
    | num |
    begin
      socket = TCPSocket.open(address, port);
    rescue
    end
    if socket == nil 
      sleep 3
      next
    else
      socket.close
      break
    end
  end

  file.each_line do
    | line |
    if line =~ /^i\d*,?CONNECT/ then
      return ReflectorClient.new(file, address, port)
    elsif line =~ /^e\d*,?CONNECT/ then
      return ReflectorServer.new(file)
    end
  end
  return nil
end

i = 0
newarray = ARGV[2, ARGV.length-2]
exitValue = 0
total = 0
failures = 0

begin
  print "<at>\n"
  newarray.each do
    | v |
    file = File.open(v, "r")
    process = createProcess(file, ARGV[0], ARGV[1])
    if process.nil? then
      print "  <test name='", v,  "' result='", "failure' >\n"
      print "    <message><![CDATA[Test definition did "
      print "not contain iCONNECT or eCONNECT]]></message>\n"
      print "  </test>\n"
      exitValue += 1
      next
    end
    file.rewind
    extendProcess(process)

  sleep(0.1)
    total += 1
    begin
      process.start
      printResult(v, nil)
      process.stop
    rescue
      failures += 1
      exitValue += 1
      printResult(v, $!)
      process.stop
    end
  end
  print "\n<results total='", total, "' failures='", failures, "'/>\n"
  print "</at>\n"
rescue
  print "  ",$!,"\n"
  print "</at>\n"
end

exit exitValue

if not Object.respond_to?("is_testing") or not Object.is_testing then
end