1 /*
2   @copyright Russell Standish 2012
3   @author Russell Standish
4 
5   Open source licensed under the MIT license.
6 
7   Permission is hereby granted, free of charge, to any person obtaining
8   a copy of this software and associated documentation files (the
9   "Software"), to deal in the Software without restriction, including
10   without limitation the rights to use, copy, modify, merge, publish,
11   distribute, sublicense, and/or sell copies of the Software, and to
12   permit persons to whom the Software is furnished to do so, subject to
13   the following conditions:
14 
15   The above copyright notice and this permission notice shall be
16   included in all copies or substantial portions of the Software.
17 
18   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22   LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23   OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24   WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26 #include <QApplication>
27 #include <QMessageBox>
28 #include <gtest/gtest.h>
29 #include <iostream>
30 using std::cerr;
31 using std::cout;
32 using std::endl;
33 using std::string;
34 
main(int argc,char ** argv)35 int main(int argc, char **argv)
36 {
37     QApplication app { argc, argv };
38 
39     ::testing::InitGoogleTest(&argc, argv);
40 
41     return RUN_ALL_TESTS();
42 }
43 
44 typedef QMessageBox::StandardButton StandardButton;
45 unsigned numInfos = 0, numWarnings = 0;
46 
47 #ifndef _WIN32
48 // override the QmessageBox static methods to turn a failure messages into throws, and ignore
49 // warnings
information(QWidget *,const QString &,const QString & text,StandardButtons,StandardButton)50 StandardButton QMessageBox::information(QWidget *, const QString &, const QString &text,
51                                         StandardButtons, StandardButton)
52 {
53     cerr << text.toStdString() << endl;
54     numInfos++;
55     return QMessageBox::Ok;
56 }
57 
question(QWidget *,const QString &,const QString & text,StandardButtons,StandardButton)58 StandardButton QMessageBox::question(QWidget *, const QString &, const QString &text,
59                                      StandardButtons, StandardButton)
60 {
61     cerr << text.toStdString() << endl;
62     return QMessageBox::Yes;
63 }
64 
question(QWidget *,const QString &,const QString & text,int,int,int)65 int QMessageBox::question(QWidget *, const QString &, const QString &text, int, int, int)
66 {
67     cerr << text.toStdString() << endl;
68     return QMessageBox::Yes;
69 }
70 
warning(QWidget *,const QString &,const QString & text,StandardButtons,StandardButton)71 StandardButton QMessageBox::warning(QWidget *, const QString &, const QString &text,
72                                     StandardButtons, StandardButton)
73 {
74     cerr << text.toStdString() << endl;
75     numWarnings++;
76     return QMessageBox::Ok;
77 }
78 
critical(QWidget *,const QString &,const QString & text,StandardButtons,StandardButton)79 StandardButton QMessageBox::critical(QWidget *, const QString &, const QString &text,
80                                      StandardButtons, StandardButton)
81 {
82     throw std::runtime_error(text.toStdString());
83 }
84 #endif
85