Class: Qt::Test

Inherits:
Base show all
Defined in:
lib/qttest/qttest.rb,
ext/ruby/qttest/qttest.rb

Class Method Summary collapse

Methods inherited from Base

#%, #&, #*, #**, #+, #-, #-@, #/, #<, #<<, #<=, #==, #>, #>=, #>>, #QCOMPARE, #QEXPECT_FAIL, #QFAIL, #QSKIP, #QTEST, #QVERIFY, #QVERIFY2, #QWARN, #^, ancestors, #is_a?, #methods, private_slots, #protected_methods, #public_methods, q_classinfo, q_signal, q_slot, signals, #singleton_methods, slots, #|, #~

Class Method Details

.current_bindingObject



69
70
71
# File 'lib/qttest/qttest.rb', line 69

def self.current_binding
    @@current_binding
end

.current_binding=(b) ⇒ Object



73
74
75
# File 'lib/qttest/qttest.rb', line 73

def self.current_binding=(b)
    @@current_binding = b
end

.qExec(*args) ⇒ Object



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

def self.qExec(*args)
  test_functions = []
  meta = args[0].metaObject
  className = meta.className
  for i in 0...meta.methodCount
    sl = meta.method(i)
    if Test.validSlot?(sl)
        test_functions << sl.signature.sub("()", "").to_sym
    end
  end
  
  # Trap calls to the test functions and save their binding, so that
  # the various test methods, like QVERIFY(), can evaluate the code strings
  # passed to them in the context of the test function
  trace_func = set_trace_func proc { |event, file, line, id, binding, klass|
    if event == 'call' && klass.name == className && test_functions.include?(id)
      Test.current_binding = binding
    end
  }
  
  if args.length == 2 && args[1].kind_of?(Array)
    super(args[0], args[1].length + 1, [$0] + args[1])
  else
    super(*args)
  end
  
  set_trace_func(trace_func)
end

.validSlot?(sl) ⇒ Boolean

This is the isValidSlot() function in testlib/qtestcase.cpp translated to Ruby. Probably could be a bit shorter in Ruby..

Returns:



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

def self.validSlot?(sl)
  if sl.access != Qt::MetaMethod::Private || !sl.parameterTypes.empty? ||
     sl.typeName != "" || sl.methodType != Qt::MetaMethod::Slot
    return false
  end
  
  sig = sl.signature
  len = sig.length
  
  if len < 2
    return false
  end
  
  if sig[len - 2, 1] != '(' || sig[len - 1, 1] != ')'
    return false
  end
  
  if len > 7 && sig[len - 7, len] == "_data()"
    return false
  end
  
  if sig == "initTestCase()" || sig == "cleanupTestCase()" ||
     sig == "cleanup()" || sig == "init()"
    return false
  end

  return true
end