Use of gcsDebug instead of qDebug
[meego-garage:garage-client-services.git] / test / testcategory.cpp
1 #include "../src/garageclientservices.h"
2 #include "../src/garagesettings.h"
3 #include "../src/catalog.h"
4 #include "../src/category.h"
5 #include "../src/application.h"
6 #include "testcategory.h"
7 #include "constants.h"
8
9 using namespace MeeGoGarage;
10
11 TestCategory::TestCategory(Catalog * catalog, Category * category) :
12         m_catalog(catalog),
13         m_category(category)
14 {
15 }
16
17 TestCategory::~TestCategory()
18 {
19 }
20
21 void TestCategory::nameTest()
22 {
23     QVERIFY(!m_category->name().isEmpty());
24 }
25
26 void TestCategory::applicationListTest()
27 {
28     QSignalSpy signal(m_category, SIGNAL(applicationListUpdated()));
29     QWAITCOND(m_category->applicationList().count() <= 0 && signal.count() == 0);
30     QVERIFY2(m_category->applicationList().count() > 0, "No applications found");
31     // there may be more than one update (one for page)
32     int signalCount;
33     do {
34         signalCount = signal.count();
35         QWAITCOND(m_category->applicationList().count() != m_category->totalApplicationCount());
36         qDebug() << "requesting applications " << m_category->applicationList().count() << " of " << m_category->totalApplicationCount();
37     } while(m_category->applicationList().count() != m_category->totalApplicationCount() && signalCount < signal.count());
38     QCOMPARE(m_category->applicationList().count(), m_category->totalApplicationCount());
39 }
40
41 void TestCategory::findApplicationTest()
42 {
43     QVERIFY(m_category->findApplication("NotExistingApplication") == 0);
44     Application * application;
45     foreach(application,m_category->applicationList()) {
46         QCOMPARE(m_category->findApplication(application->name()), application);
47     }
48 }
49
50 void TestCategory::requestApplicationListTest()
51 {
52     ApplicationSearchJob * job = m_category->requestApplicationSearch();
53     QVERIFY(job);
54     QSignalSpy signalOver(job, SIGNAL(jobOver()));
55     job->start();
56     QWAITCOND(signalOver.count() <= 0);
57     QCOMPARE(signalOver.count(), 1);
58     QCOMPARE(job->state(), ApplicationSearchJob::SuccessfulState);
59     QVERIFY(job->result().count() == job->itemsPerPage() || job->result().count() == m_category->applicationList().count());
60     job->deleteLater();
61 }