d221de087b3c06721d5b04b0dd4a94728df55734
[irwi] / ut / ut_remote / ut_remote.cpp
1 #include <QSettings>
2 #include "ut_remote.h"
3
4 #include <fstream>
5
6 #include <QtTest>
7 #include <QDebug>
8
9 #include "qnetworkaccessmanager.h"
10
11 #define private public
12 #include "remote.h"
13 #undef private
14
15 void reset()
16 {
17     QNetworkAccessManager::urls.clear();
18     QSettings::values.clear();
19 }
20
21 void Ut_Remote::initTestCase()
22 {
23     subject = NULL;
24 }
25
26 void Ut_Remote::cleanupTestCase()
27 {
28 }
29
30 void Ut_Remote::init()
31 {
32     subject = new Remote();
33     reset();
34 }
35
36 void Ut_Remote::cleanup()
37 {
38     if (subject != NULL) {
39         delete subject;
40         subject = NULL;
41     }
42     reset();
43 }
44
45 void Ut_Remote::testSaveToFile_normal()
46 {
47     subject->m_name = "testname";
48     subject->saveToFile();
49     QCOMPARE(QNetworkAccessManager::urls.count(), 1);
50     QCOMPARE(QNetworkAccessManager::urls[0], 
51             QString("http://mercury.wipsl.com/irwi/uploaded/testname"));
52     QSettings settings;
53     QCOMPARE(settings.value("remoteName", "fail").toString(), 
54             QString("testname"));
55 }
56
57 void Ut_Remote::testSaveToFile_emptyname()
58 {
59     subject->m_name = "";
60     subject->saveToFile();
61     QCOMPARE(QNetworkAccessManager::urls.count(), 0);
62     QSettings settings;
63     QCOMPARE(settings.value("remoteName", "testname").toString(), 
64             QString("testname"));
65 }
66
67 void Ut_Remote::testUpdateInfo()
68 {
69 }
70
71 void Ut_Remote::testSendRating()
72 {
73 }
74
75 QTEST_MAIN(Ut_Remote)
76
77