2
/***************************************************************************
3
qttest.rb - QtTest ruby client lib
6
copyright : (C) 2008 by Richard Dale
7
email : richard.j.dale@gmail.com
8
***************************************************************************/
10
/***************************************************************************
12
* This program is free software; you can redistribute it and/or modify *
13
* it under the terms of the GNU General Public License as published by *
14
* the Free Software Foundation; either version 2 of the License, or *
15
* (at your option) any later version. *
17
***************************************************************************/
22
def self.init_all_classes
23
getClassList.each do |c|
24
classname = Qt::Internal::normalize_classname(c)
25
id = Qt::Internal::findClass(c);
26
Qt::Internal::insert_pclassid(classname, id)
27
Qt::Internal::cpp_names[classname] = c
28
klass = Qt::Internal::isQObject(c) ? Qt::Internal::create_qobject_class(classname, Qt) : Qt::Internal::create_qt_class(classname, Qt)
29
Qt::Internal::classes[classname] = klass unless klass.nil?
38
# This is the isValidSlot() function in testlib/qtestcase.cpp translated
39
# to Ruby. Probably could be a bit shorter in Ruby..
40
def self.validSlot?(sl)
41
if sl.access != Qt::MetaMethod::Private || !sl.parameterTypes.empty? ||
42
sl.typeName != "" || sl.methodType != Qt::MetaMethod::Slot
53
if sig[len - 2, 1] != '(' || sig[len - 1, 1] != ')'
57
if len > 7 && sig[len - 7, len] == "_data()"
61
if sig == "initTestCase()" || sig == "cleanupTestCase()" ||
62
sig == "cleanup()" || sig == "init()"
69
def self.current_binding
73
def self.current_binding=(b)
79
meta = args[0].metaObject
80
className = meta.className
81
for i in 0...meta.methodCount
83
if Test.validSlot?(sl)
84
test_functions << sl.signature.sub("()", "").to_sym
88
# Trap calls to the test functions and save their binding, so that
89
# the various test methods, like QVERIFY(), can evaluate the code strings
90
# passed to them in the context of the test function
91
trace_func = set_trace_func proc { |event, file, line, id, binding, klass|
92
if event == 'call' && klass.name == className && test_functions.include?(id)
93
Test.current_binding = binding
97
if args.length == 2 && args[1].kind_of?(Array)
98
super(args[0], args[1].length + 1, [$0] + args[1])
103
set_trace_func(trace_func)
108
def QVERIFY(statement)
109
file, line = caller(1)[0].split(':')
110
if !Qt::Test.qVerify(eval(statement, Qt::Test.current_binding), statement, "", file, line.to_i)
111
return eval('return', Qt::Test.current_binding)
116
file, line = caller(1)[0].split(':')
117
Qt::Test.qFail(message, file, line.to_i)
118
return eval('return', Qt::Test.current_binding)
121
def QVERIFY2(statement, description)
122
file, line = caller(1)[0].split(':')
123
if eval(statement, Qt::Test.current_binding)
124
if !Qt::Test.qVerify(true, statement, description, file, line.to_i)
125
return eval('return', Qt::Test.current_binding)
128
if !Qt::Test.qVerify(false, statement, description, file, line.to_i)
129
return eval('return', Qt::Test.current_binding)
134
def QCOMPARE(actual, expected)
135
file, line = caller(1)[0].split(':')
136
if !Qt::Test.qCompare(eval(actual, Qt::Test.current_binding), eval(expected, Qt::Test.current_binding), actual, expected, file, line.to_i)
137
return eval('return', Qt::Test.current_binding)
141
def QSKIP(statement, mode)
142
file, line = caller(1)[0].split(':')
143
Qt::Test.qSkip(statement, mode, file, line.to_i)
144
return eval('return', Qt::Test.current_binding)
147
def QEXPECT_FAIL(dataIndex, comment, mode)
148
file, line = caller(1)[0].split(':')
149
if !Qt::Test.qExpectFail(dataIndex, comment, mode, file, line.to_i)
150
return eval('return', Qt::Test.current_binding)
154
def QTEST(actual, testElement)
155
file, line = caller(1)[0].split(':')
156
if !Qt::Test.qTest(eval(actual, Qt::Test.current_binding), eval(testElement, Qt::Test.current_binding), actual, testElement, file, line.to_i)
157
return eval('return', Qt::Test.current_binding)