Page MenuHomePhorge

D176.1732499599.diff
No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None

D176.1732499599.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,55 @@
+/*
+ * This file is part of kazv.
+ * SPDX-FileCopyrightText: 2024 nannanko <nannanko@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#include "kazv-file.hpp"
+
+#include <kazv-defs.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{};
+ QVERIFY(dir.isValid());
+ auto rawContent = QByteArrayLiteral("Some test content");
+ QSaveFile rawFile{dir.filePath(QStringLiteral("rawFile"))};
+ QVERIFY(rawFile.open(QIODevice::WriteOnly));
+ QCOMPARE(rawFile.write(rawContent.data(), rawContent.size()),
+ rawContent.size());
+ QVERIFY(rawFile.commit());
+ auto aes = AES256CTRDesc::fromRandom(genRandom(AES256CTRDesc::randomSize));
+ KazvFile kazvFile{rawFile.fileName(), aes};
+ QVERIFY(kazvFile.open(QIODevice::ReadOnly));
+ QByteArray encryptedContent = kazvFile.readAll();
+ kazvFile.close();
+ KazvSaveFile kazvSaveFile{
+ dir.filePath(QStringLiteral("decryptedFile")), aes};
+ QVERIFY(kazvSaveFile.open(QIODevice::WriteOnly));
+ QCOMPARE(
+ kazvSaveFile.write(encryptedContent.data(), encryptedContent.size()),
+ encryptedContent.size());
+ QVERIFY(kazvSaveFile.commit());
+ QFile file{kazvSaveFile.fileName()};
+ QVERIFY(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
Sun, Nov 24, 5:53 PM (10 h, 54 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39979
Default Alt Text
D176.1732499599.diff (2 KB)

Event Timeline