File indexing completed on 2024-09-08 04:30:31
0001 /* This file is part of the KDE project 0002 0003 Copyright (C) 2009 Dario Massarin <nekkar@libero.it> 0004 0005 This program is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU General Public 0007 License as published by the Free Software Foundation; either 0008 version 2 of the License, or (at your option) any later version. 0009 */ 0010 0011 #include "testkget.h" 0012 #include "core/kget.h" 0013 #include "core/transfergrouphandler.h" 0014 #include "core/transfertreemodel.h" 0015 0016 TestKGet::TestKGet() 0017 : QObject(nullptr) 0018 , m_addedGH(nullptr) 0019 { 0020 connect(KGet::model(), &TransferTreeModel::groupAddedEvent, this, &TestKGet::addedTransferGroupEvent); 0021 connect(KGet::model(), &TransferTreeModel::groupRemovedEvent, this, &TestKGet::removedTransferGroupEvent); 0022 } 0023 0024 void TestKGet::addedTransferGroupEvent(TransferGroupHandler *group) 0025 { 0026 m_addedGH = group; 0027 } 0028 0029 void TestKGet::removedTransferGroupEvent(TransferGroupHandler *group) 0030 { 0031 m_removedGH = group; 0032 } 0033 0034 void TestKGet::simpleTest() 0035 { 0036 QVERIFY(1 == 1); 0037 } 0038 0039 void TestKGet::transferGroupTest() 0040 { 0041 KGet::delGroup(KGet::findGroup("testGroup")); // In case you already have one 0042 0043 m_addedGH = nullptr; 0044 m_removedGH = nullptr; 0045 0046 // Add Group 0047 QVERIFY(KGet::addGroup("testGroup")); 0048 QVERIFY(m_addedGH != nullptr); // Should already have received the added group notification 0049 0050 // Verify default Group parameters 0051 QVERIFY(m_addedGH->name() == "testGroup"); 0052 QVERIFY(m_addedGH->status() == JobQueue::Running); 0053 QVERIFY(m_addedGH->size() == 0); 0054 QVERIFY(m_addedGH->totalSize() == 0); 0055 QVERIFY(m_addedGH->downloadedSize() == 0); 0056 QVERIFY(m_addedGH->uploadedSize() == 0); 0057 QVERIFY(m_addedGH->percent() == 0); 0058 QVERIFY(m_addedGH->downloadSpeed() == 0); 0059 QVERIFY(m_addedGH->uploadSpeed() == 0); 0060 0061 // Delete newly added Group 0062 KGet::delGroup(KGet::findGroup("testGroup"), false); 0063 QVERIFY(m_removedGH != nullptr); // Should already have received the removed group notification 0064 0065 QVERIFY(m_removedGH->name() == "testGroup"); 0066 } 0067 0068 void TestKGet::transferGroupRepetitiveAddTest() 0069 { 0070 for (int i = 0; i < 100; i++) { 0071 // Adding... 0072 QVERIFY(KGet::addGroup("testGroup" + QString::number(i))); 0073 QVERIFY(m_addedGH != nullptr); // Should already have received the added group notification 0074 QVERIFY(m_addedGH->name() == "testGroup" + QString::number(i)); 0075 } 0076 0077 for (int i = 0; i < 100; i++) { 0078 // Removing... 0079 KGet::delGroup(KGet::findGroup("testGroup" + QString::number(i)), false); 0080 QVERIFY(m_removedGH != nullptr); // Should already have received the removed group notification 0081 QVERIFY(m_removedGH->name() == "testGroup" + QString::number(i)); 0082 } 0083 } 0084 0085 #include "moc_testkget.cpp"