File indexing completed on 2024-04-28 16:44:13
0001 /******************************************************************* 0002 * bugzillalibtest.cpp 0003 * SPDX-FileCopyrightText: 2009 Dario Andres Rodriguez <andresbajotierra@gmail.com> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 * 0007 ******************************************************************/ 0008 #include <KAboutData> 0009 #include <KLocalizedString> 0010 #include <QApplication> 0011 #include <QCommandLineParser> 0012 #include <QDebug> 0013 0014 #include "../../bugzillaintegration/bugzillalib.h" 0015 #include "../../debugpackageinstaller.h" 0016 0017 class BugzillaLibTest : public QObject 0018 { 0019 Q_OBJECT 0020 public: 0021 BugzillaLibTest(QString user, QString password) 0022 : QObject() 0023 { 0024 manager = new BugzillaManager(QStringLiteral("http://bugstest.kde.org/")); 0025 connect(manager, &BugzillaManager::loginFinished, this, &BugzillaLibTest::loginFinished); 0026 connect(manager, &BugzillaManager::loginError, this, &BugzillaLibTest::loginError); 0027 connect(manager, &BugzillaManager::reportSent, this, &BugzillaLibTest::reportSent); 0028 connect(manager, &BugzillaManager::sendReportError, this, &BugzillaLibTest::sendReportError); 0029 connect(manager, &BugzillaManager::sendReportErrorInvalidValues, this, &BugzillaLibTest::sendBR2); 0030 manager->tryLogin(user, password); 0031 qDebug() << "Login ..."; 0032 } 0033 0034 private Q_SLOTS: 0035 void loginFinished(bool ok) 0036 { 0037 qDebug() << "Login Finished" << ok; 0038 if (!ok) { 0039 return; 0040 } 0041 0042 // Uncomment to Test 0043 // FIXME provide a way to select the test from the command line 0044 0045 // Send a new bug report 0046 /* 0047 sendBR(); 0048 */ 0049 0050 // Attach a simple text to a report as a file 0051 /* 0052 manager->attachTextToReport("Bugzilla Lib Attachment Content Test", "/tmp/var", 0053 "Bugzilla Lib Attachment Description Test", 150000); 0054 */ 0055 0056 /* 0057 manager->addMeToCC(100005); 0058 */ 0059 } 0060 0061 void loginError(const QString &msg) 0062 { 0063 qDebug() << "Login Error" << msg; 0064 } 0065 0066 void sendBR() 0067 { 0068 Bugzilla::NewBug br; 0069 br.product = QStringLiteral("konqueror"); 0070 br.component = QStringLiteral("general"); 0071 br.version = QStringLiteral("undefined"); 0072 br.op_sys = QStringLiteral("Linux"); 0073 br.priority = QStringLiteral("NOR"); 0074 br.platform = QStringLiteral("random test"); 0075 br.severity = QStringLiteral("crash"); 0076 br.summary = QStringLiteral("bla bla"); 0077 br.description = QStringLiteral("bla bla large"); 0078 0079 manager->sendReport(br); 0080 qDebug() << "Trying to send bug report"; 0081 } 0082 0083 void sendBR2() 0084 { 0085 Bugzilla::NewBug br; 0086 br.product = QStringLiteral("konqueror"); 0087 br.component = QStringLiteral("general"); 0088 br.version = QStringLiteral("undefined"); 0089 br.op_sys = QStringLiteral("Linux"); 0090 br.priority = QStringLiteral("NOR"); 0091 br.platform = QStringLiteral("unspecified"); 0092 br.severity = QStringLiteral("crash"); 0093 br.summary = QStringLiteral("bla bla"); 0094 br.description = QStringLiteral("bla bla large"); 0095 0096 manager->sendReport(br); 0097 qDebug() << "Trying to send bug report"; 0098 } 0099 0100 void reportSent(int num) 0101 { 0102 qDebug() << "BR sent " << num << manager->urlForBug(num); 0103 } 0104 0105 void sendReportError(const QString &msg) 0106 { 0107 qDebug() << "Error sending bug report" << msg; 0108 } 0109 0110 private: 0111 BugzillaManager *manager; 0112 }; 0113 0114 int main(int argc, char **argv) 0115 { 0116 QApplication app(argc, argv); 0117 KAboutData aboutData(QStringLiteral("bzlibtest"), 0118 i18n("BugzillaLib Test (DrKonqi2)"), 0119 QStringLiteral("1.0"), 0120 i18n("Test application for bugtracker manager lib"), 0121 KAboutLicense::GPL, 0122 i18n("(c) 2009, DrKonqi2 Developers")); 0123 0124 QCommandLineParser parser; 0125 parser.addOption(QCommandLineOption(QStringLiteral("user"), i18nc("@info:shell", "bugstest.kde.org username"), QStringLiteral("username"))); 0126 parser.addOption(QCommandLineOption(QStringLiteral("pass"), i18nc("@info:shell", "bugstest.kde.org password"), QStringLiteral("password"))); 0127 0128 aboutData.setupCommandLine(&parser); 0129 parser.process(app); 0130 aboutData.processCommandLine(&parser); 0131 0132 if (!parser.isSet(QStringLiteral("user")) || !parser.isSet(QStringLiteral("pass"))) { 0133 qDebug() << "Provide bugstest.kde.org username and password. See help"; 0134 return 0; 0135 } 0136 0137 new BugzillaLibTest(parser.value(QStringLiteral("user")), parser.value(QStringLiteral("pass"))); 0138 return app.exec(); 0139 } 0140 0141 #include "bugzillalibtest.moc"