Changeset View
Changeset View
Standalone View
Standalone View
src/core/autotests/usersforroommodeltest.cpp
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | 36 | { | |||
---|---|---|---|---|---|
48 | roles[UsersForRoomModel::IconStatus] = QByteArrayLiteral("iconstatus"); | 48 | roles[UsersForRoomModel::IconStatus] = QByteArrayLiteral("iconstatus"); | ||
49 | roles[UsersForRoomModel::DisplayName] = QByteArrayLiteral("displayname"); | 49 | roles[UsersForRoomModel::DisplayName] = QByteArrayLiteral("displayname"); | ||
50 | QCOMPARE(w.roleNames(), roles); | 50 | QCOMPARE(w.roleNames(), roles); | ||
51 | } | 51 | } | ||
52 | 52 | | |||
53 | void UsersForRoomModelTest::shouldAddValues() | 53 | void UsersForRoomModelTest::shouldAddValues() | ||
54 | { | 54 | { | ||
55 | UsersForRoomModel w; | 55 | UsersForRoomModel w; | ||
56 | QVector<User *> users; | 56 | QVector<User> users; | ||
57 | QSignalSpy rowInsertedSpy(&w, &UsersForRoomModel::rowsInserted); | 57 | QSignalSpy rowInsertedSpy(&w, &UsersForRoomModel::rowsInserted); | ||
58 | QSignalSpy rowABTInserted(&w, &UsersForRoomModel::rowsAboutToBeInserted); | 58 | QSignalSpy rowABTInserted(&w, &UsersForRoomModel::rowsAboutToBeInserted); | ||
59 | for (int i = 0; i < 10; i++) { | 59 | for (int i = 0; i < 10; i++) { | ||
60 | User *user = new User; | 60 | User user; | ||
61 | user->setName(QStringLiteral("name%1").arg(i)); | 61 | user.setName(QStringLiteral("name%1").arg(i)); | ||
62 | user->setStatus(QStringLiteral("status%1").arg(i)); | 62 | user.setStatus(QStringLiteral("status%1").arg(i)); | ||
63 | user->setUserId(QStringLiteral("userId%1").arg(i)); | 63 | user.setUserId(QStringLiteral("userId%1").arg(i)); | ||
64 | user->setUserName(QStringLiteral("username%1").arg(i)); | 64 | user.setUserName(QStringLiteral("username%1").arg(i)); | ||
65 | users.append(user); | 65 | users.append(user); | ||
66 | } | 66 | } | ||
67 | w.setUsers(users); | 67 | w.setUsers(users); | ||
68 | QCOMPARE(w.rowCount(), 10); | 68 | QCOMPARE(w.rowCount(), 10); | ||
69 | QCOMPARE(rowInsertedSpy.count(), 1); | 69 | QCOMPARE(rowInsertedSpy.count(), 1); | ||
70 | QCOMPARE(rowABTInserted.count(), 1); | 70 | QCOMPARE(rowABTInserted.count(), 1); | ||
71 | QCOMPARE(TestModelHelpers::rowSpyToText(rowInsertedSpy), QStringLiteral("0,9")); | 71 | QCOMPARE(TestModelHelpers::rowSpyToText(rowInsertedSpy), QStringLiteral("0,9")); | ||
72 | QCOMPARE(TestModelHelpers::rowSpyToText(rowABTInserted), QStringLiteral("0,9")); | 72 | QCOMPARE(TestModelHelpers::rowSpyToText(rowABTInserted), QStringLiteral("0,9")); | ||
73 | rowABTInserted.clear(); | 73 | rowABTInserted.clear(); | ||
74 | rowInsertedSpy.clear(); | 74 | rowInsertedSpy.clear(); | ||
75 | 75 | | |||
76 | users.clear(); | 76 | users.clear(); | ||
77 | 77 | | |||
78 | for (int i = 0; i < 3; ++i) { | 78 | for (int i = 0; i < 3; ++i) { | ||
79 | User *user = new User; | 79 | User user; | ||
80 | user->setName(QStringLiteral("name%1").arg(i)); | 80 | user.setName(QStringLiteral("name%1").arg(i)); | ||
81 | user->setStatus(QStringLiteral("status%1").arg(i)); | 81 | user.setStatus(QStringLiteral("status%1").arg(i)); | ||
82 | user->setUserId(QStringLiteral("userId%1").arg(i)); | 82 | user.setUserId(QStringLiteral("userId%1").arg(i)); | ||
83 | user->setUserName(QStringLiteral("username%1").arg(i)); | 83 | user.setUserName(QStringLiteral("username%1").arg(i)); | ||
84 | users.append(user); | 84 | users.append(user); | ||
85 | } | 85 | } | ||
86 | w.clear(); | 86 | w.clear(); | ||
87 | w.setUsers(users); | 87 | w.setUsers(users); | ||
88 | QCOMPARE(w.rowCount(), 3); | 88 | QCOMPARE(w.rowCount(), 3); | ||
89 | QCOMPARE(rowInsertedSpy.count(), 1); | 89 | QCOMPARE(rowInsertedSpy.count(), 1); | ||
90 | QCOMPARE(rowABTInserted.count(), 1); | 90 | QCOMPARE(rowABTInserted.count(), 1); | ||
91 | QCOMPARE(TestModelHelpers::rowSpyToText(rowInsertedSpy), QStringLiteral("0,2")); | 91 | QCOMPARE(TestModelHelpers::rowSpyToText(rowInsertedSpy), QStringLiteral("0,2")); | ||
Show All 10 Lines | |||||
102 | QCOMPARE(rowABTInserted.count(), 0); | 102 | QCOMPARE(rowABTInserted.count(), 0); | ||
103 | QCOMPARE(TestModelHelpers::rowSpyToText(rowInsertedSpy), QString()); | 103 | QCOMPARE(TestModelHelpers::rowSpyToText(rowInsertedSpy), QString()); | ||
104 | QCOMPARE(TestModelHelpers::rowSpyToText(rowABTInserted), QString()); | 104 | QCOMPARE(TestModelHelpers::rowSpyToText(rowABTInserted), QString()); | ||
105 | } | 105 | } | ||
106 | 106 | | |||
107 | void UsersForRoomModelTest::shouldVerifyData() | 107 | void UsersForRoomModelTest::shouldVerifyData() | ||
108 | { | 108 | { | ||
109 | UsersForRoomModel w; | 109 | UsersForRoomModel w; | ||
110 | QVector<User *> users; | 110 | QVector<User> users; | ||
111 | for (int i = 0; i < 10; i++) { | 111 | for (int i = 0; i < 10; i++) { | ||
112 | User *user = new User; | 112 | User user; | ||
113 | user->setName(QStringLiteral("name%1").arg(i)); | 113 | user.setName(QStringLiteral("name%1").arg(i)); | ||
114 | user->setStatus(QStringLiteral("online")); | 114 | user.setStatus(QStringLiteral("online")); | ||
115 | user->setUserId(QStringLiteral("userId%1").arg(i)); | 115 | user.setUserId(QStringLiteral("userId%1").arg(i)); | ||
116 | user->setUserName(QStringLiteral("username%1").arg(i)); | 116 | user.setUserName(QStringLiteral("username%1").arg(i)); | ||
117 | users.append(user); | 117 | users.append(user); | ||
118 | } | 118 | } | ||
119 | w.setUsers(users); | 119 | w.setUsers(users); | ||
120 | QCOMPARE(w.rowCount(), 10); | 120 | QCOMPARE(w.rowCount(), 10); | ||
121 | 121 | | |||
122 | for (int i = 0; i < 10; ++i) { | 122 | for (int i = 0; i < 10; ++i) { | ||
123 | QCOMPARE(w.data(w.index(i), UsersForRoomModel::Name).toString(), QStringLiteral("name%1").arg(i)); | 123 | QCOMPARE(w.data(w.index(i), UsersForRoomModel::Name).toString(), QStringLiteral("name%1").arg(i)); | ||
124 | QCOMPARE(w.data(w.index(i), UsersForRoomModel::IconStatus).toString(), QStringLiteral("user-online")); | 124 | QCOMPARE(w.data(w.index(i), UsersForRoomModel::IconStatus).toString(), QStringLiteral("user-online")); | ||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |