File indexing completed on 2024-12-22 05:00:58
0001 /* 0002 SPDX-FileCopyrightText: 2023 Sandro Knauß <sknauss@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "encryptionstatetest.h" 0008 #include "editor/encryptionstate.h" 0009 0010 #include <QSignalSpy> 0011 #include <QTest> 0012 0013 QTEST_GUILESS_MAIN(EncryptionStateTest) 0014 0015 void EncryptionStateTest::shouldHaveDefaults() 0016 { 0017 EncryptionState e; 0018 QCOMPARE(e.override(), false); 0019 QCOMPARE(e.hasOverride(), false); 0020 QCOMPARE(e.possibleEncrypt(), false); 0021 QCOMPARE(e.autoEncrypt(), false); 0022 QCOMPARE(e.acceptedSolution(), false); 0023 QCOMPARE(e.encrypt(), false); 0024 } 0025 0026 void EncryptionStateTest::override() 0027 { 0028 EncryptionState e; 0029 QSignalSpy spy(&e, &EncryptionState::overrideChanged); 0030 QSignalSpy spyHasOverride(&e, &EncryptionState::hasOverrideChanged); 0031 QSignalSpy spyEncrypt(&e, &EncryptionState::encryptChanged); 0032 0033 e.setOverride(false); 0034 QCOMPARE(e.override(), false); 0035 QCOMPARE(spy.count(), 1); 0036 QCOMPARE(spy.at(0).at(0), false); 0037 QCOMPARE(spyHasOverride.count(), 1); 0038 QCOMPARE(spyHasOverride.at(0).at(0), true); 0039 QCOMPARE(spyEncrypt.count(), 0); 0040 0041 e.setOverride(false); 0042 QCOMPARE(e.override(), false); 0043 QCOMPARE(spy.count(), 1); 0044 QCOMPARE(spyHasOverride.count(), 1); 0045 QCOMPARE(spyEncrypt.count(), 0); 0046 0047 e.setOverride(true); 0048 QCOMPARE(e.override(), true); 0049 QCOMPARE(spy.count(), 2); 0050 QCOMPARE(spy.at(1).at(0), true); 0051 QCOMPARE(spyHasOverride.count(), 1); 0052 QCOMPARE(spyEncrypt.count(), 1); 0053 QCOMPARE(spyEncrypt.at(0).at(0), true); 0054 0055 e.setOverride(true); 0056 QCOMPARE(e.override(), true); 0057 QCOMPARE(spy.count(), 2); 0058 QCOMPARE(spyHasOverride.count(), 1); 0059 QCOMPARE(spyEncrypt.count(), 1); 0060 0061 e.setOverride(false); 0062 QCOMPARE(e.override(), false); 0063 QCOMPARE(spy.count(), 3); 0064 QCOMPARE(spy.at(2).at(0), false); 0065 QCOMPARE(spyHasOverride.count(), 1); 0066 QCOMPARE(spyEncrypt.count(), 2); 0067 QCOMPARE(spyEncrypt.at(1).at(0), false); 0068 } 0069 0070 void EncryptionStateTest::unsetOverride() 0071 { 0072 EncryptionState e; 0073 QSignalSpy spy(&e, &EncryptionState::overrideChanged); 0074 QSignalSpy spyHasOverride(&e, &EncryptionState::hasOverrideChanged); 0075 QSignalSpy spyEncrypt(&e, &EncryptionState::encryptChanged); 0076 0077 e.unsetOverride(); 0078 QCOMPARE(e.hasOverride(), false); 0079 QCOMPARE(spy.count(), 0); 0080 QCOMPARE(spyHasOverride.count(), 0); 0081 QCOMPARE(spyEncrypt.count(), 0); 0082 0083 e.setOverride(false); 0084 QCOMPARE(e.hasOverride(), true); 0085 QCOMPARE(spy.count(), 1); 0086 QCOMPARE(spyHasOverride.count(), 1); 0087 QCOMPARE(spyEncrypt.count(), 0); 0088 0089 e.unsetOverride(); 0090 QCOMPARE(e.hasOverride(), false); 0091 QCOMPARE(spy.count(), 2); 0092 QCOMPARE(spy.at(1).at(0), false); 0093 QCOMPARE(spyHasOverride.count(), 2); 0094 QCOMPARE(spyHasOverride.at(1).at(0), false); 0095 QCOMPARE(spyEncrypt.count(), 0); 0096 } 0097 0098 void EncryptionStateTest::toggleOverride() 0099 { 0100 EncryptionState e; 0101 0102 e.setPossibleEncrypt(true); 0103 e.setAutoEncrypt(true); 0104 e.setAcceptedSolution(true); 0105 0106 QSignalSpy spy(&e, &EncryptionState::overrideChanged); 0107 QSignalSpy spyHasOverride(&e, &EncryptionState::hasOverrideChanged); 0108 QSignalSpy spyEncrypt(&e, &EncryptionState::encryptChanged); 0109 0110 e.toggleOverride(); 0111 QCOMPARE(e.hasOverride(), true); 0112 QCOMPARE(e.encrypt(), false); 0113 QCOMPARE(e.override(), false); 0114 QCOMPARE(spy.count(), 1); 0115 QCOMPARE(spy.at(0).at(0), false); 0116 QCOMPARE(spyHasOverride.count(), 1); 0117 QCOMPARE(spyHasOverride.at(0).at(0), true); 0118 QCOMPARE(spyEncrypt.count(), 1); 0119 QCOMPARE(spyEncrypt.at(0).at(0), false); 0120 0121 e.toggleOverride(); 0122 QCOMPARE(e.hasOverride(), true); 0123 QCOMPARE(e.encrypt(), true); 0124 QCOMPARE(e.override(), true); 0125 QCOMPARE(spy.count(), 2); 0126 QCOMPARE(spy.at(1).at(0), true); 0127 QCOMPARE(spyHasOverride.count(), 1); 0128 QCOMPARE(spyEncrypt.count(), 2); 0129 QCOMPARE(spyEncrypt.at(1).at(0), true); 0130 0131 e.toggleOverride(); 0132 QCOMPARE(e.hasOverride(), true); 0133 QCOMPARE(e.encrypt(), false); 0134 QCOMPARE(e.override(), false); 0135 QCOMPARE(spy.count(), 3); 0136 QCOMPARE(spy.at(2).at(0), false); 0137 QCOMPARE(spyHasOverride.count(), 1); 0138 QCOMPARE(spyEncrypt.count(), 3); 0139 QCOMPARE(spyEncrypt.at(2).at(0), false); 0140 } 0141 0142 void EncryptionStateTest::acceptedSolution() 0143 { 0144 EncryptionState e; 0145 QSignalSpy spy(&e, &EncryptionState::acceptedSolutionChanged); 0146 QSignalSpy spyEncrypt(&e, &EncryptionState::encryptChanged); 0147 0148 e.setAcceptedSolution(false); 0149 QCOMPARE(e.acceptedSolution(), false); 0150 QCOMPARE(spy.count(), 0); 0151 QCOMPARE(spyEncrypt.count(), 0); 0152 0153 e.setAcceptedSolution(true); 0154 QCOMPARE(e.acceptedSolution(), true); 0155 QCOMPARE(spy.count(), 1); 0156 QCOMPARE(spy.at(0).at(0), true); 0157 QCOMPARE(spyEncrypt.count(), 0); 0158 0159 e.setAcceptedSolution(true); 0160 QCOMPARE(e.acceptedSolution(), true); 0161 QCOMPARE(spy.count(), 1); 0162 QCOMPARE(spyEncrypt.count(), 0); 0163 0164 e.setAcceptedSolution(false); 0165 QCOMPARE(e.acceptedSolution(), false); 0166 QCOMPARE(spy.count(), 2); 0167 QCOMPARE(spy.at(1).at(0), false); 0168 QCOMPARE(spyEncrypt.count(), 0); 0169 } 0170 0171 void EncryptionStateTest::possibleEncrypt() 0172 { 0173 EncryptionState e; 0174 QSignalSpy spy(&e, &EncryptionState::possibleEncryptChanged); 0175 QSignalSpy spyEncrypt(&e, &EncryptionState::encryptChanged); 0176 0177 e.setPossibleEncrypt(false); 0178 QCOMPARE(e.possibleEncrypt(), false); 0179 QCOMPARE(spy.count(), 0); 0180 QCOMPARE(spyEncrypt.count(), 0); 0181 0182 e.setPossibleEncrypt(true); 0183 QCOMPARE(e.possibleEncrypt(), true); 0184 QCOMPARE(spy.count(), 1); 0185 QCOMPARE(spy.at(0).at(0), true); 0186 QCOMPARE(spyEncrypt.count(), 0); 0187 0188 e.setPossibleEncrypt(true); 0189 QCOMPARE(e.possibleEncrypt(), true); 0190 QCOMPARE(spy.count(), 1); 0191 QCOMPARE(spyEncrypt.count(), 0); 0192 0193 e.setPossibleEncrypt(false); 0194 QCOMPARE(e.possibleEncrypt(), false); 0195 QCOMPARE(spy.count(), 2); 0196 QCOMPARE(spy.at(1).at(0), false); 0197 QCOMPARE(spyEncrypt.count(), 0); 0198 } 0199 0200 void EncryptionStateTest::autoEncrypt() 0201 { 0202 EncryptionState e; 0203 QSignalSpy spy(&e, &EncryptionState::autoEncryptChanged); 0204 QSignalSpy spyEncrypt(&e, &EncryptionState::encryptChanged); 0205 0206 e.setAutoEncrypt(false); 0207 QCOMPARE(e.autoEncrypt(), false); 0208 QCOMPARE(spy.count(), 0); 0209 QCOMPARE(spyEncrypt.count(), 0); 0210 0211 e.setAutoEncrypt(true); 0212 QCOMPARE(e.autoEncrypt(), true); 0213 QCOMPARE(spy.count(), 1); 0214 QCOMPARE(spy.at(0).at(0), true); 0215 QCOMPARE(spyEncrypt.count(), 0); 0216 0217 e.setAutoEncrypt(true); 0218 QCOMPARE(e.autoEncrypt(), true); 0219 QCOMPARE(spy.count(), 1); 0220 QCOMPARE(spyEncrypt.count(), 0); 0221 0222 e.setAutoEncrypt(false); 0223 QCOMPARE(e.autoEncrypt(), false); 0224 QCOMPARE(spy.count(), 2); 0225 QCOMPARE(spy.at(1).at(0), false); 0226 QCOMPARE(spyEncrypt.count(), 0); 0227 } 0228 0229 void EncryptionStateTest::encrypt() 0230 { 0231 EncryptionState e; 0232 QSignalSpy spyEncrypt(&e, &EncryptionState::encryptChanged); 0233 0234 e.setPossibleEncrypt(true); 0235 e.setAutoEncrypt(true); 0236 QCOMPARE(e.encrypt(), false); 0237 QCOMPARE(spyEncrypt.count(), 0); 0238 0239 e.setAcceptedSolution(true); 0240 QCOMPARE(e.encrypt(), true); 0241 QCOMPARE(spyEncrypt.count(), 1); 0242 QCOMPARE(spyEncrypt.at(0).at(0), true); 0243 0244 e.setAutoEncrypt(false); 0245 QCOMPARE(e.encrypt(), false); 0246 QCOMPARE(spyEncrypt.count(), 2); 0247 QCOMPARE(spyEncrypt.at(1).at(0), false); 0248 0249 e.setAutoEncrypt(true); 0250 QCOMPARE(e.encrypt(), true); 0251 QCOMPARE(spyEncrypt.count(), 3); 0252 QCOMPARE(spyEncrypt.at(2).at(0), true); 0253 0254 e.setPossibleEncrypt(false); 0255 QCOMPARE(e.encrypt(), false); 0256 QCOMPARE(spyEncrypt.count(), 4); 0257 QCOMPARE(spyEncrypt.at(3).at(0), false); 0258 0259 e.setPossibleEncrypt(true); 0260 QCOMPARE(e.encrypt(), true); 0261 QCOMPARE(spyEncrypt.count(), 5); 0262 QCOMPARE(spyEncrypt.at(4).at(0), true); 0263 } 0264 0265 #include "moc_encryptionstatetest.cpp"