File: testkget.cpp

package info (click to toggle)
kget 4%3A25.12.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,112 kB
  • sloc: cpp: 33,019; xml: 811; makefile: 9; sh: 6
file content (85 lines) | stat: -rw-r--r-- 2,740 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* This file is part of the KDE project

   Copyright (C) 2009 Dario Massarin <nekkar@libero.it>

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.
*/

#include "testkget.h"
#include "core/kget.h"
#include "core/transfergrouphandler.h"
#include "core/transfertreemodel.h"

TestKGet::TestKGet()
    : QObject(nullptr)
    , m_addedGH(nullptr)
{
    connect(KGet::model(), &TransferTreeModel::groupAddedEvent, this, &TestKGet::addedTransferGroupEvent);
    connect(KGet::model(), &TransferTreeModel::groupRemovedEvent, this, &TestKGet::removedTransferGroupEvent);
}

void TestKGet::addedTransferGroupEvent(TransferGroupHandler *group)
{
    m_addedGH = group;
}

void TestKGet::removedTransferGroupEvent(TransferGroupHandler *group)
{
    m_removedGH = group;
}

void TestKGet::simpleTest()
{
    QVERIFY(1 == 1);
}

void TestKGet::transferGroupTest()
{
    KGet::delGroup(KGet::findGroup("testGroup")); // In case you already have one

    m_addedGH = nullptr;
    m_removedGH = nullptr;

    // Add Group
    QVERIFY(KGet::addGroup("testGroup"));
    QVERIFY(m_addedGH != nullptr); // Should already have received the added group notification

    // Verify default Group parameters
    QVERIFY(m_addedGH->name() == "testGroup");
    QVERIFY(m_addedGH->status() == JobQueue::Running);
    QVERIFY(m_addedGH->size() == 0);
    QVERIFY(m_addedGH->totalSize() == 0);
    QVERIFY(m_addedGH->downloadedSize() == 0);
    QVERIFY(m_addedGH->uploadedSize() == 0);
    QVERIFY(m_addedGH->percent() == 0);
    QVERIFY(m_addedGH->downloadSpeed() == 0);
    QVERIFY(m_addedGH->uploadSpeed() == 0);

    // Delete newly added Group
    KGet::delGroup(KGet::findGroup("testGroup"), false);
    QVERIFY(m_removedGH != nullptr); // Should already have received the removed group notification

    QVERIFY(m_removedGH->name() == "testGroup");
}

void TestKGet::transferGroupRepetitiveAddTest()
{
    for (int i = 0; i < 100; i++) {
        // Adding...
        QVERIFY(KGet::addGroup("testGroup" + QString::number(i)));
        QVERIFY(m_addedGH != nullptr); // Should already have received the added group notification
        QVERIFY(m_addedGH->name() == "testGroup" + QString::number(i));
    }

    for (int i = 0; i < 100; i++) {
        // Removing...
        KGet::delGroup(KGet::findGroup("testGroup" + QString::number(i)), false);
        QVERIFY(m_removedGH != nullptr); // Should already have received the removed group notification
        QVERIFY(m_removedGH->name() == "testGroup" + QString::number(i));
    }
}

#include "moc_testkget.cpp"