Class: SodaTestCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/SodaTestCheck.rb

Constant Summary collapse

CONFIG_FILE =
File.dirname(__FILE__)

Instance Method Summary collapse

Constructor Details

#initialize(sodatest, reportobj) ⇒ SodaTestCheck

Returns a new instance of SodaTestCheck.



43
44
45
46
47
48
49
50
# File 'lib/SodaTestCheck.rb', line 43

def initialize(sodatest, reportobj)
   err = 0
   sodadata = nil
   @SODA_ELEMENTS_FILE = "#{CONFIG_FILE}/SodaElements.xml"
   $ERROR_COUNT = 0
   @report = reportobj
   @sodatest = sodatest
end

Instance Method Details

#CheckObject



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
# File 'lib/SodaTestCheck.rb', line 54

def Check()
   err = 0
   elements_root = nil
   elements_data = nil
   sodadata = nil
   msg = ""
   
   if (!File.exist?(@SODA_ELEMENTS_FILE))
      msg = "Error: can't find needed file: '#{@SODA_ELEMENTS_FILE}'!\n"
      @report.ReportFailure(msg)
      return false
   end

   elements_root = ParseSodaElementsXML()
   if (elements_root == nil)
      return false
   end

   elements_data = ElementsXMLToData(elements_root)
   if (elements_data.empty?)
      msg = "Error: XML element data is empty!\n"
      @report.ReportFailure(msg)
      return false
   end

   err = CheckFileformat(@sodatest)
   if (err != 0)
      return false
   end

   sodadata = ProcessSodaTestFile(@sodatest)
   if (sodadata == nil)
      return false
   end

   CheckTest(sodadata, elements_data)
   if ($ERROR_COUNT > 0) 
      return false
   else
      return true
   end
end

#CheckFileformat(file) ⇒ Object

CheckFileformat – method

This function checks to make sure that the test file format is not DOS.

Input:

file: the file to check.

Output:

returns -1 on error, else 0 on success.


331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# File 'lib/SodaTestCheck.rb', line 331

def CheckFileformat(file)
   err = 0

   begin 
      fd = File.open(file, "r")
      line = fd.readline()
      fd.close()

      if (line =~ /\r\n$/)
         @report.ReportFailure("File is in DOS format!\n")
         err += 1
      end
   rescue Exception => e
      @report.ReportException(e, @sodatest)
      err += 1
   ensure
   end

   err = -1 if (err > 0)

   return err
end

#ParseSodaElementsXMLObject

ParseSodaElementsXML – method

This finction parses the SodaElements.xml file.

Input:

None.

Output:

returns the doc.root from the XML parser, or nil on error.


109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/SodaTestCheck.rb', line 109

def ParseSodaElementsXML()
   parser = nil
   doc = nil
   kids = nil
   fd = nil

   begin
      fd = File.new(@SODA_ELEMENTS_FILE)
      doc = REXML::Document.new(fd)
      doc = doc.root
   rescue Exception => e
      doc = nil
      @report.ReportException(e, @sodatest)
   ensure
   end

   return nil if (doc == nil)
   return doc
end