This commit is contained in:
Ilusha 2024-03-16 12:07:49 +03:00
parent 65cb26a627
commit 1ead32d84a
71 changed files with 199 additions and 282 deletions

View file

@ -8,11 +8,11 @@ file(GLOB HEADERS "./public/*.hpp")
add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS})
target_include_directories(${PROJECT_NAME} PUBLIC ./public/)
target_include_directories(${PROJECT_NAME} PRIVATE ${BINDINGS_INCLUDE})
target_link_libraries(${PROJECT_NAME} PUBLIC Strings)
target_link_libraries(${PROJECT_NAME} PUBLIC Modules)
### -------------------------- Tests -------------------------- ###
enable_testing()
file(GLOB TEST_SOURCES "./tests/*.cpp")
add_executable(${PROJECT_NAME}Tests ${TEST_SOURCES})
target_link_libraries(${PROJECT_NAME}Tests ${PROJECT_NAME} UnitTest++)
add_test(NAME ${PROJECT_NAME}Tests COMMAND ${PROJECT_NAME}Tests)
add_executable(Test${PROJECT_NAME} ${TEST_SOURCES})
target_link_libraries(Test${PROJECT_NAME} ${PROJECT_NAME} UnitTest++)
add_test(NAME Test${PROJECT_NAME} COMMAND Test${PROJECT_NAME})

View file

@ -1,6 +0,0 @@
#include "ConnectionCommon.hpp"
static tp::ModuleManifest* sModuleDependencies[] = { &tp::gModuleStrings, nullptr };
tp::ModuleManifest tp::gModuleConnection = ModuleManifest("Storage", nullptr, nullptr, sModuleDependencies);

View file

@ -7,7 +7,8 @@
using namespace tp;
bool LocalConnection::Location::exists() const {
FILE* file = fopen(mLocation.read(), "r");
// TODO : fixme
FILE* file = fopen(mLocation.c_str(), "r");
if (file) {
// File exists, close it and return 1
fclose(file);
@ -23,10 +24,8 @@ bool LocalConnection::connect(const Location& location, const Type& connectionIn
auto handle = new LocalConnectionContext();
switch (connectionInfo.getType()) {
case Type::READ: handle->open(location.getLocation().read(), true); break;
case Type::WRITE: handle->open(location.getLocation().read(), false); break;
case Type::READ: handle->open(location.getLocation().c_str(), true); break;
case Type::WRITE: handle->open(location.getLocation().c_str(), false); break;
default: break;
};

View file

@ -1,10 +1,9 @@
#pragma once
#include "Strings.hpp"
#include "Module.hpp"
#include <string>
namespace tp {
extern ModuleManifest gModuleConnection;
class Connection {
public:
typedef ualni SizeBytes;

View file

@ -9,20 +9,20 @@ namespace tp {
class LocalConnection : public Connection {
public:
class Location {
String mLocation;
std::string mLocation;
public:
Location() :
mLocation("tmp"){};
explicit Location(const String& location) :
explicit Location(const std::string& location) :
mLocation(location) {}
void setLocation(const String& location) { mLocation = location; }
[[nodiscard]] const String& getLocation() const { return mLocation; }
void setLocation(const std::string& location) { mLocation = location; }
[[nodiscard]] const std::string& getLocation() const { return mLocation; }
[[nodiscard]] bool exists() const;
};
public:
LocalConnection(){ MODULE_SANITY_CHECK(gModuleConnection) };
LocalConnection() = default;
virtual ~LocalConnection() {
if (mStatus.isOpened()) LocalConnection::disconnect();

View file

@ -1,6 +1,6 @@
#pragma once
#include "Common.hpp"
#include "Module.hpp"
namespace tp {
class ServerContext;

View file

@ -1,7 +1,6 @@
#pragma once
#include "ConnectionCommon.hpp"
#include "List.hpp"
namespace tp {
@ -17,7 +16,7 @@ namespace tp {
};
public:
RemoteConnection(){ MODULE_SANITY_CHECK(gModuleConnection) };
RemoteConnection() = default;
virtual ~RemoteConnection() {
if (mStatus.isOpened()) RemoteConnection::disconnect();

View file

@ -14,14 +14,14 @@ SUITE(Connection) {
{
LocalConnection file;
file.connect(LocalConnection::Location(String("tmp2.txt")), LocalConnection::Type(false));
file.connect(LocalConnection::Location(std::string("tmp2.txt")), LocalConnection::Type(false));
file.writeBytes(data, 6);
file.disconnect();
}
{
LocalConnection file;
file.connect(LocalConnection::Location(String("tmp2.txt")), LocalConnection::Type(true));
file.connect(LocalConnection::Location(std::string("tmp2.txt")), LocalConnection::Type(true));
file.readBytes(dataRead, 6);
file.disconnect();
}
@ -35,17 +35,5 @@ SUITE(Connection) {
}
int main() {
tp::ModuleManifest* deps[] = { &tp::gModuleConnection, nullptr };
tp::ModuleManifest testModule("ConnectionTest", nullptr, nullptr, deps);
if (!testModule.initialize()) {
return 1;
}
bool res = UnitTest::RunAllTests();
testModule.deinitialize();
return res;
return UnitTest::RunAllTests();
}