From 32c7512b69f15f5c2b62ec9d73482756c268ae5a Mon Sep 17 00:00:00 2001 From: IlushaShurupov Date: Tue, 18 Jul 2023 23:48:54 +0300 Subject: [PATCH] Fix File test --- Storage/private/LocalStorage.cpp | 5 +++-- Storage/private/SystemHandle.cpp | 2 +- Storage/public/LocalStorage.hpp | 2 +- Storage/tests/TestLocalStorage.cpp | 12 ++++++------ Storage/tests/Tests.cpp | 4 ++-- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Storage/private/LocalStorage.cpp b/Storage/private/LocalStorage.cpp index 9e33fe5..fccaad7 100644 --- a/Storage/private/LocalStorage.cpp +++ b/Storage/private/LocalStorage.cpp @@ -12,11 +12,11 @@ bool File::connect(const FileLocation& location, const FileConnectionType& conne switch (connectionInfo.getType()) { case FileConnectionType::READ: - handle->open(location.getLocation().read(), true); + handle->open(location.getLocation().read(), false); break; case FileConnectionType::WRITE: - handle->open(location.getLocation().read(), false); + handle->open(location.getLocation().read(), true); break; default: @@ -31,6 +31,7 @@ bool File::connect(const FileLocation& location, const FileConnectionType& conne mStatus.setStatus(FileConnectionStatus::OPENED); mHandle = handle; + mConnectionType = connectionInfo; return true; } diff --git a/Storage/private/SystemHandle.cpp b/Storage/private/SystemHandle.cpp index 1386b2a..0c0b664 100644 --- a/Storage/private/SystemHandle.cpp +++ b/Storage/private/SystemHandle.cpp @@ -40,7 +40,7 @@ void FileSystemHandle::seekp(ualni in) { void FileSystemHandle::read(int1* in, ualni size) { auto strm = (std::fstream*) stream; - strm->write(in, size); + strm->read(in, size); } void FileSystemHandle::write(const int1* in, ualni size) { diff --git a/Storage/public/LocalStorage.hpp b/Storage/public/LocalStorage.hpp index e832db0..33e2f36 100644 --- a/Storage/public/LocalStorage.hpp +++ b/Storage/public/LocalStorage.hpp @@ -75,7 +75,7 @@ namespace tp { }; virtual ~File() { - File::disconnect(); + if (mStatus.isOpened()) File::disconnect(); } public: diff --git a/Storage/tests/TestLocalStorage.cpp b/Storage/tests/TestLocalStorage.cpp index 996782a..b4c765d 100644 --- a/Storage/tests/TestLocalStorage.cpp +++ b/Storage/tests/TestLocalStorage.cpp @@ -6,20 +6,20 @@ using namespace tp; TEST_DEF_STATIC(Simple) { - int1 data[] = { 0, 1, 2, 3, 4 }; - int1 dataRead[]{}; + const int1* data = "abcde\0"; + int1 dataRead[6]{}; { File file; - file.connect(FileLocation(String("tmp2")), FileConnectionType(false)); - file.writeBytes(data, 5); + file.connect(FileLocation(String("tmp2.txt")), FileConnectionType(false)); + file.writeBytes(data, 6); file.disconnect(); } { File file; - file.connect(FileLocation(String("tmp2")), FileConnectionType(true)); - file.readBytes(dataRead, 5); + file.connect(FileLocation(String("tmp2.txt")), FileConnectionType(true)); + file.readBytes(dataRead, 6); file.disconnect(); } diff --git a/Storage/tests/Tests.cpp b/Storage/tests/Tests.cpp index 3dec993..36f7fd5 100644 --- a/Storage/tests/Tests.cpp +++ b/Storage/tests/Tests.cpp @@ -1,12 +1,12 @@ #include "Testing.hpp" -#include "Utils.hpp" +#include "Storage.hpp" void testLocalStorage(); int main() { - tp::ModuleManifest* deps[] = { &tp::gModuleUtils, nullptr }; + tp::ModuleManifest* deps[] = { &tp::gModuleStorage, nullptr }; tp::ModuleManifest testModule("StorageTest", nullptr, nullptr, deps); if (!testModule.initialize()) {