Page MenuHomePhorge

D176.1732576367.diff
No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None

D176.1732576367.diff

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

Mime Type
text/plain
Expires
Mon, Nov 25, 3:12 PM (11 h, 53 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39910
Default Alt Text
D176.1732576367.diff (2 KB)

Event Timeline