-
Notifications
You must be signed in to change notification settings - Fork 1
/
CognitoSyncTests.cpp
85 lines (69 loc) · 2.09 KB
/
CognitoSyncTests.cpp
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
#include "CognitoSyncTests.h"
#include <QDebug>
#include <QUuid>
#include <memory>
#include "aws/CognitoSyncAPI.h"
#include "aws/AwsApi.h"
#include "core/LocalCache.h"
using namespace Aws;
CognitoSyncTests::CognitoSyncTests():
mLocalCache(new vector<shared_ptr<Syncable>>),
mExpectedCache(new vector<shared_ptr<Syncable>>)
{ }
bool compareCaches(const shared_ptr<vector<shared_ptr<Syncable>>>& a, const shared_ptr<vector<shared_ptr<Syncable>>>& b, bool ignoreSyncCount = true)
{
if (a->size() != b->size()) {
qDebug() << "Comaring caches failed: sizes are different";
return false;
}
for (size_t i = 0; i < a->size(); i++) {
if (
a->at(i)->uuid() == b->at(i)->uuid() &&
a->at(i)->value() == b->at(i)->value() &&
(ignoreSyncCount || (a->at(i)->syncCount() == b->at(i)->syncCount()))
) continue;
qDebug() << "Comparing caches failed : caches at(" << i << ") - do not match";
return false;
}
return true;
}
bool CognitoSyncTests::firstSyncWithV1()
{
mLocalCache->clear();
shared_ptr<Syncable> i1(new Syncable);
i1->setValue("Item 1");
mLocalCache->push_back(i1);
shared_ptr<Syncable> i2(new Syncable);
i2->setValue("Item 2");
mLocalCache->push_back(i2);
mExpectedCache->clear();
shared_ptr<Syncable> i1s(new Syncable(*i1));
i1s->setChanged(false);
mExpectedCache->push_back(i1s);
shared_ptr<Syncable> i2s(new Syncable(*i2));
i2s->setChanged(false);
mExpectedCache->push_back(i2s);
CognitoSyncAPI syncer;
syncer.syncData(mLocalCache);
if (syncer.isSuccessful()) {
qDebug() << "Test sync successfull";
if (!compareCaches(mLocalCache, mExpectedCache)) {
return false;
}
}
else {
qDebug() << "Test sync failed: " << syncer.getLastMessage();
return false;
}
return true;
}
void CognitoSyncTests::runTests()
{
if (firstSyncWithV1()) {
qDebug() << "PASS: firstSyncWithV1";
}
else {
qDebug() << "FAIL: firstSyncWithV1";
return;
}
}