| 1 | /* |
| 2 | * chewing-editor: Chewing userphrase editor |
| 3 | * Copyright (C) 2014 Chewing Development Team |
| 4 | |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | |
| 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | */ |
| 19 | #include <QApplication> |
| 20 | #include <QFileInfo> |
| 21 | |
| 22 | #include "gtest/gtest.h" |
| 23 | |
| 24 | bool verbose = false; |
| 25 | |
| 26 | void debugMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) |
| 27 | { |
| 28 | auto msg = message.toUtf8(); |
| 29 | auto file = QFileInfo{context.file}.fileName().toUtf8(); |
| 30 | |
| 31 | if (!verbose) { |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | switch(type) { |
| 36 | case QtDebugMsg: |
| 37 | fprintf(stdout, "Debug: %s (%s %s:%d)\n", msg.constData(), context.function, file.constData(), context.line); |
| 38 | break; |
| 39 | case QtWarningMsg: |
| 40 | fprintf(stderr, "Warning: %s (%s %s:%d)\n", msg.constData(), context.function, file.constData(), context.line); |
| 41 | break; |
| 42 | case QtCriticalMsg: |
| 43 | fprintf(stderr, "Critical: %s (%s %s:%d)\n", msg.constData(), context.function, file.constData(), context.line); |
| 44 | break; |
| 45 | case QtFatalMsg: |
| 46 | fprintf(stderr, "Fatal: %s (%s %s:%d)\n", msg.constData(), context.function, file.constData(), context.line); |
| 47 | abort(); |
| 48 | break; |
| 49 | default: |
| 50 | break; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | int main(int argc, char **argv) { |
| 55 | ::testing::InitGoogleTest(&argc, argv); |
| 56 | |
| 57 | qInstallMessageHandler(debugMessageHandler); |
| 58 | |
| 59 | for (int i = 0; i < argc; ++i) { |
| 60 | if (strcmp(argv[i], "-v") == 0) { |
| 61 | verbose = true; |
| 62 | } |
| 63 | |
| 64 | if (strcmp(argv[i], "-s") == 0) { |
| 65 | verbose = false; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | return RUN_ALL_TESTS(); |
| 70 | } |