File indexing completed on 2022-10-04 15:34:12

0001 /*
0002     SPDX-FileCopyrightText: 2016-2017 Leslie Zhai <lesliezhai@llvm.org.cn>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include <QTest>
0007 
0008 #include "k3bexternalbinmanagertest.h"
0009 #include "k3bcore.h"
0010 #include "k3bjob.h"
0011 #include "k3bexternalbinmanager.h"
0012 #include "k3bburnprogressdialog.h"
0013 #include "k3bdefaultexternalprograms.h"
0014 
0015 class MyBurnJob : public K3b::BurnJob 
0016 {
0017     Q_OBJECT
0018 
0019 public:
0020     MyBurnJob(K3b::JobHandler* hdl, QObject* parent = Q_NULLPTR)
0021         : K3b::BurnJob(hdl, parent) 
0022     {
0023         qDebug() << "DEBUG:" << __PRETTY_FUNCTION__;
0024         const K3b::ExternalBin* cdrecordBin = k3bcore->externalBinManager()->binObject("cdrecord");
0025         qDebug() << "DEBUG:" << __PRETTY_FUNCTION__ << cdrecordBin;
0026     }
0027     ~MyBurnJob() override
0028     {
0029         qDebug() << "DEBUG:" << __PRETTY_FUNCTION__;
0030     }
0031 
0032 public Q_SLOTS:
0033     void start() override { jobStarted(); jobFinished(true); }
0034     void cancel() override { emit canceled(); }
0035 
0036 private:
0037     bool prepareWriter() 
0038     {
0039         qDebug() << "DEBUG:" << __PRETTY_FUNCTION__;
0040         const K3b::ExternalBin* cdrecordBin = k3bcore->externalBinManager()->binObject("cdrecord");
0041         if (!cdrecordBin)
0042             qWarning() << "ERROR:" << __PRETTY_FUNCTION__ << cdrecordBin;
0043         return true;
0044     }
0045 };
0046 
0047 QTEST_GUILESS_MAIN(ExternalBinManagerTest)
0048 
0049 ExternalBinManagerTest::ExternalBinManagerTest()
0050     : QObject()
0051     , m_core(new K3b::Application::Core(this))
0052 {
0053 }
0054 
0055 void ExternalBinManagerTest::testBinObject()
0056 {
0057     K3b::ExternalBinManager* binManager = new K3b::ExternalBinManager;
0058     K3b::addDefaultPrograms(binManager);
0059     binManager->search();
0060     qDebug() << "DEBUG:" << __PRETTY_FUNCTION__ << binManager->foundBin("cdrecord");
0061     if (binManager->binObject("ooo") && binManager->binObject("ooo")->hasFeature("fff")) {
0062         qDebug() << __PRETTY_FUNCTION__ << "it *NEVER* happened!";
0063     }
0064     // ooo binObject directly return 0
0065     // then hasFeature will segfault!
0066     // there are a lot of *unchecking* binObject is nullptr issue in k3b-2.0.3!!!
0067     //if (binManager->binObject("ooo")->hasFeature("fff")) {
0068     //}
0069 }
0070 
0071 void ExternalBinManagerTest::testMyBurnJob() 
0072 {
0073     QSKIP("currently segfaulting");
0074     K3b::BurnProgressDialog* dlg = new K3b::BurnProgressDialog;
0075     MyBurnJob* job = new MyBurnJob(dlg, this);
0076     dlg->setJob(job);
0077     // TODO: it needs CdrskinWritter for job->setWritingApp
0078     dlg->startJob(job);
0079 }
0080 
0081 #include "k3bexternalbinmanagertest.moc"