Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F112550
D176.1732333177.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D176.1732333177.diff
View Options
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -31,6 +31,7 @@
kazv-abstract-list-model-test.cpp
matrix-event-list-test.cpp
matrix-event-test.cpp
+ kazv-file-test.cpp
LINK_LIBRARIES Qt${QT_MAJOR_VERSION}::Test kazvtestlib
)
diff --git a/src/tests/kazv-file-test.cpp b/src/tests/kazv-file-test.cpp
new file mode 100644
--- /dev/null
+++ b/src/tests/kazv-file-test.cpp
@@ -0,0 +1,59 @@
+/*
+ * This file is part of kazv.
+ * SPDX-FileCopyrightText: 2024 nannanko <nannanko@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#include <kazv-defs.hpp>
+#include "kazv-file.hpp"
+#include "qt-rand-adapter.hpp"
+
+#include <client/random-generator.hpp>
+#include <crypto/aes-256-ctr.hpp>
+
+#include <QObject>
+#include <QtTest>
+#include <QTemporaryDir>
+
+class KazvFileTest : public QObject
+{
+ Q_OBJECT
+
+private Q_SLOTS:
+ void testKazvFile();
+};
+
+using namespace Kazv;
+
+void KazvFileTest::testKazvFile()
+{
+ QTemporaryDir dir{};
+ dir.isValid();
+ auto rawContent = QByteArrayLiteral("Some test content");
+ QSaveFile rawFile{dir.filePath(QStringLiteral("rawFile"))};
+ rawFile.open(QIODevice::WriteOnly);
+ rawFile.write(rawContent.data(), rawContent.size());
+ rawFile.commit();
+ Kazv::RandomInterface randomGenerator = QtRandAdapter{};
+ auto aes = AES256CTRDesc::fromRandom(
+ randomGenerator.generateRange<Kazv::RandomData>(
+ Kazv::AES256CTRDesc::randomSize));
+ KazvFile kazvFile{rawFile.fileName(), aes};
+ kazvFile.open(QIODevice::ReadOnly);
+ QByteArray encryptedContent = kazvFile.readAll();
+ kazvFile.close();
+ KazvSaveFile kazvSaveFile{
+ dir.filePath(QStringLiteral("decryptedFile")), aes};
+ kazvSaveFile.open(QIODevice::WriteOnly);
+ kazvSaveFile.write(encryptedContent.data(),
+ encryptedContent.size());
+ kazvSaveFile.commit();
+ QFile file{kazvSaveFile.fileName()};
+ file.open(QIODevice::ReadOnly);
+ auto decryptedContent = file.readAll();
+ QCOMPARE(decryptedContent, rawContent);
+}
+
+QTEST_MAIN(KazvFileTest)
+
+#include "kazv-file-test.moc"
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 22, 7:39 PM (2 h, 27 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39027
Default Alt Text
D176.1732333177.diff (2 KB)
Attached To
Mode
D176: Add tests for KazvFile and KazvSaveFile
Attached
Detach File
Event Timeline
Log In to Comment