qabstracttestlogger.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtTest module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
9** Commercial License Usage -
10** Licensees holding valid commercial Qt licenses may use this file in -
11** accordance with the commercial license agreement provided with the -
12** Software or, alternatively, in accordance with the terms contained in -
13** a written agreement between you and Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/contact-us. -
16** -
17** GNU Lesser General Public License Usage -
18** Alternatively, this file may be used under the terms of the GNU Lesser -
19** General Public License version 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include <QtTest/private/qabstracttestlogger_p.h> -
43#include <QtTest/qtestassert.h> -
44 -
45#include <QtCore/qbytearray.h> -
46 -
47#include <stdio.h> -
48#include <stdlib.h> -
49#include <stdarg.h> -
50 -
51#ifndef Q_OS_WIN -
52#include <unistd.h> -
53#endif -
54 -
55QT_BEGIN_NAMESPACE -
56 -
57QAbstractTestLogger::QAbstractTestLogger(const char *filename) -
58{ -
59 if (!filename) {
partially evaluated: !filename
TRUEFALSE
yes
Evaluation Count:399
no
Evaluation Count:0
0-399
60 stream = stdout;
executed (the execution status of this line is deduced): stream = stdout;
-
61 return;
executed: return;
Execution Count:399
399
62 } -
63#if defined(_MSC_VER) && _MSC_VER >= 1400 && !defined(Q_OS_WINCE) -
64 if (::fopen_s(&stream, filename, "wt")) { -
65#else -
66 stream = ::fopen(filename, "wt");
never executed (the execution status of this line is deduced): stream = ::fopen(filename, "wt");
-
67 if (!stream) {
never evaluated: !stream
0
68#endif -
69 fprintf(stderr, "Unable to open file for logging: %s\n", filename);
never executed (the execution status of this line is deduced): fprintf(stderr, "Unable to open file for logging: %s\n", filename);
-
70 ::exit(1);
never executed: ::exit(1);
0
71 } -
72}
never executed: }
0
73 -
74QAbstractTestLogger::~QAbstractTestLogger() -
75{ -
76 QTEST_ASSERT(stream);
never executed: qt_assert("stream","qabstracttestlogger.cpp",76);
executed: }
Execution Count:396
partially evaluated: !(stream)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:396
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:396
0-396
77 if (stream != stdout) {
partially evaluated: stream != stdout
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:396
0-396
78 fclose(stream);
never executed (the execution status of this line is deduced): fclose(stream);
-
79 }
never executed: }
0
80 stream = 0;
executed (the execution status of this line is deduced): stream = 0;
-
81}
executed: }
Execution Count:396
396
82 -
83void QAbstractTestLogger::filterUnprintable(char *str) const -
84{ -
85 char *idx = str;
executed (the execution status of this line is deduced): char *idx = str;
-
86 while (*idx) {
evaluated: *idx
TRUEFALSE
yes
Evaluation Count:4337162
yes
Evaluation Count:69974
69974-4337162
87 if (((*idx < 0x20 && *idx != '\n' && *idx != '\t') || *idx > 0x7e))
evaluated: *idx < 0x20
TRUEFALSE
yes
Evaluation Count:71762
yes
Evaluation Count:4265400
evaluated: *idx != '\n'
TRUEFALSE
yes
Evaluation Count:23
yes
Evaluation Count:71739
evaluated: *idx != '\t'
TRUEFALSE
yes
Evaluation Count:12
yes
Evaluation Count:11
partially evaluated: *idx > 0x7e
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4337150
0-4337150
88 *idx = '?';
executed: *idx = '?';
Execution Count:12
12
89 ++idx;
executed (the execution status of this line is deduced): ++idx;
-
90 }
executed: }
Execution Count:4337162
4337162
91}
executed: }
Execution Count:69974
69974
92 -
93void QAbstractTestLogger::outputString(const char *msg) -
94{ -
95 QTEST_ASSERT(stream);
never executed: qt_assert("stream","qabstracttestlogger.cpp",95);
executed: }
Execution Count:69974
partially evaluated: !(stream)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:69974
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:69974
0-69974
96 QTEST_ASSERT(msg);
never executed: qt_assert("msg","qabstracttestlogger.cpp",96);
executed: }
Execution Count:69974
partially evaluated: !(msg)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:69974
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:69974
0-69974
97 -
98 char *filtered = new char[strlen(msg) + 1];
executed (the execution status of this line is deduced): char *filtered = new char[strlen(msg) + 1];
-
99 strcpy(filtered, msg);
executed (the execution status of this line is deduced): strcpy(filtered, msg);
-
100 filterUnprintable(filtered);
executed (the execution status of this line is deduced): filterUnprintable(filtered);
-
101 -
102 ::fputs(filtered, stream);
executed (the execution status of this line is deduced): ::fputs(filtered, stream);
-
103 ::fflush(stream);
executed (the execution status of this line is deduced): ::fflush(stream);
-
104 -
105 delete [] filtered;
executed (the execution status of this line is deduced): delete [] filtered;
-
106}
executed: }
Execution Count:69974
69974
107 -
108void QAbstractTestLogger::startLogging() -
109{ -
110} -
111 -
112void QAbstractTestLogger::stopLogging() -
113{ -
114} -
115 -
116namespace QTest -
117{ -
118 -
119extern void filter_unprintable(char *str); -
120 -
121/*! -
122 \fn int QTest::qt_asprintf(QTestCharBuffer *buf, const char *format, ...); -
123 \internal -
124 */ -
125int qt_asprintf(QTestCharBuffer *str, const char *format, ...) -
126{ -
127 static const int MAXSIZE = 1024*1024*2; -
128 -
129 Q_ASSERT(str);
executed (the execution status of this line is deduced): qt_noop();
-
130 -
131 int size = str->size();
executed (the execution status of this line is deduced): int size = str->size();
-
132 -
133 va_list ap;
executed (the execution status of this line is deduced): va_list ap;
-
134 int res = 0;
executed (the execution status of this line is deduced): int res = 0;
-
135 -
136 for (;;) {
executed (the execution status of this line is deduced): for (;;) {
-
137 va_start(ap, format);
executed (the execution status of this line is deduced): __builtin_va_start(ap,format);
-
138 res = qvsnprintf(str->data(), size, format, ap);
executed (the execution status of this line is deduced): res = qvsnprintf(str->data(), size, format, ap);
-
139 va_end(ap);
executed (the execution status of this line is deduced): __builtin_va_end(ap);
-
140 str->data()[size - 1] = '\0';
executed (the execution status of this line is deduced): str->data()[size - 1] = '\0';
-
141 if (res >= 0 && res < size) {
partially evaluated: res >= 0
TRUEFALSE
yes
Evaluation Count:69264
no
Evaluation Count:0
evaluated: res < size
TRUEFALSE
yes
Evaluation Count:69171
yes
Evaluation Count:93
0-69264
142 // We succeeded -
143 break;
executed: break;
Execution Count:69171
69171
144 } -
145 // buffer wasn't big enough, try again. -
146 // Note, we're assuming that a result of -1 is always due to running out of space. -
147 size *= 2;
executed (the execution status of this line is deduced): size *= 2;
-
148 if (size > MAXSIZE) {
partially evaluated: size > MAXSIZE
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:93
0-93
149 break;
never executed: break;
0
150 } -
151 if (!str->reset(size))
partially evaluated: !str->reset(size)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:93
0-93
152 break; // out of memory - take what we have
never executed: break;
0
153 }
executed: }
Execution Count:93
93
154 -
155 return res;
executed: return res;
Execution Count:69171
69171
156} -
157 -
158} -
159 -
160QT_END_NAMESPACE -
161 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial