Skip to content

Commit

Permalink
added tests and reworked code
Browse files Browse the repository at this point in the history
  • Loading branch information
kaverhovsky committed Nov 12, 2020
1 parent 9ef9705 commit 87ddd0e
Show file tree
Hide file tree
Showing 19 changed files with 666 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/blank.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,37 @@ jobs:

- name: build
run: |
cd client
mkdir build
cd build
cmake ..
make
- name: test socket
run: |
cd build
valgrind --leak-check=full ./test/socket_tests
- name: test client lib
run: |
cd build
valgrind --leak-check=full ./test/response_tests
- name: test client lib
run: |
cd build
valgrind --leak-check=full ./test/request_tests
- name: test client lib
run: |
cd build
valgrind --leak-check=full ./test/client_tests
- name: test client lib
run: |
cd build
valgrind --leak-check=full ./test/application_tests
- name: coverage
run: |
cd build
Expand Down
8 changes: 8 additions & 0 deletions client/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.16.3)

project(link_share)

add_subdirectory(src)

enable_testing()
add_subdirectory(test)
62 changes: 62 additions & 0 deletions client/include/application.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#pragma once

#include "client.hpp"
#include <memory>
#include <list>


class UserInfo{
public:
UserInfo();
UserInfo(std::string& nm, std::string& psw);
~UserInfo();

private:
std::string name;
std::string password;
};


class Link {
public:
Link(std::string& name, std::string& url, std::string& tag);
~Link();
std::string addSnapshot();

private:
std::string linkname;
std::string url;
std::vector<std::string> tags;
std::vector<std::string> snapshotPaths;
};


class Room{
public:
Room(std::string& roomName, std::string& roomId);
void addLink(std::string& newLink);
void removeLink(std::string& linkName);
void addParticipant(std::string& newPart);
void removeParticipant(std::string& partName);
std::string archiveLink(std::string& linkName);
private:
std::string roomName;
std::string roomId;
std::string roomHost;
std::vector<std::string> participants;
std::vector<Link> links;
};




class Application {
public:
Application();
~Application();

private:
Client client;
UserInfo info;
std::vector<Room> rooms;
};
22 changes: 22 additions & 0 deletions client/include/client.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include "socket.hpp"

#include <netinet/in.h>
#include <string>
#include <vector>


class Client {
public:
Client();
~Client();
void connect(const std::string& host, int port);
void writeToServer(std::string& req);
std::string readFromServer();
void closeCon();

private:
Socket sock;
};

97 changes: 97 additions & 0 deletions client/include/request.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#pragma once

#include <string>
#include <memory>
#include <iostream>
#include <vector>


typedef enum ReqExitStatus {
REQ_SUCCESS,
REQ_FAILURE
}ReqExitStatus;


class Request {
public:
virtual ReqExitStatus buildRequestFromInput(std::istream& s) = 0;
virtual std::string RequestToString() = 0;
};

class LogInReq : public Request {
public:
ReqExitStatus buildRequestFromInput(std::istream& s) override;
std::string RequestToString() override;
private:
std::string name;
std::string password;
};

class LogOutReq : public Request {
public:
ReqExitStatus buildRequestFromInput(std::istream& s) override;
std::string RequestToString() override;
private:
};

class CreateRoomReq : public Request {
public:
ReqExitStatus buildRequestFromInput(std::istream& s) override;
std::string RequestToString() override;
private:
std::string roomName;
std::string roomHost;
std::vector<std::string> participants;
};

class RemoveRoomReq : public Request {
public:
ReqExitStatus buildRequestFromInput(std::istream& s) override;
std::string RequestToString() override;
private:
std::string name;
};

class AddLinkReq : public Request {
public:
ReqExitStatus buildRequestFromInput(std::istream& s) override;
std::string RequestToString() override;
private:
std::string linkName;
std::string url;
std::string tag;
};

class RemoveLinkReq : public Request {
public:
ReqExitStatus buildRequestFromInput(std::istream&s) override;
std::string RequestToString() override;
private:
std::string linkName;
};

class ArchiveLinkReq : public Request {
public:
ReqExitStatus buildRequestFromInput(std::istream& s) override;
std::string RequestToString() override;
private:
std::string linkName;
};


using requestPtr = std::shared_ptr<Request>;

class RequestHandler {
public:
RequestHandler();
requestPtr HandleInput(std::string& which);
private:
requestPtr _LogInReq;
requestPtr _LogOutReq;
requestPtr _CreateRoomReq;
requestPtr _RemoveRoomReq;
requestPtr _AddLinkReq;
requestPtr _RemoveLinkReq;
requestPtr _LinkReq;
requestPtr _ArchiveLinkReq;
};
80 changes: 80 additions & 0 deletions client/include/response.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#pragma once

#include <string>
#include <iostream>
#include <memory>
#include <vector>
#include <application.hpp>
#include <request.hpp>

typedef enum RespExitStatus {
RESP_SUCCESS,
RESP_FAILURE
}RespExitStatus;


class Response {
public:
virtual RespExitStatus buildResponse(std::string& responseBody) = 0;
virtual RespExitStatus doLogic(const Request& req, Application& app) = 0;
};

class LogInResp : public Response{
public:
RespExitStatus buildResponse(std::string& responseBody) override;
RespExitStatus doLogic(const Request& req, Application& app) override;
};

class LogOutResp : public Response{
public:
RespExitStatus buildResponse(std::string& responseBody) override;
RespExitStatus doLogic(const Request& req, Application& app) override;
};

class CreateRoomResp : public Response{
public:
RespExitStatus buildResponse(std::string& responseBody) override;
RespExitStatus doLogic(const Request& req, Application& app) override;
};

class RemoveRoomResp : public Response{
public:
RespExitStatus buildResponse(std::string& responseBody) override;
RespExitStatus doLogic(const Request& req, Application& app) override;
};

class AddLinkResp : public Response{
public:
RespExitStatus buildResponse(std::string& responseBody) override;
RespExitStatus doLogic(const Request& req, Application& app) override;
};

class RemoveLinkResp : public Response{
public:
RespExitStatus buildResponse(std::string& responseBody) override;
RespExitStatus doLogic(const Request& req, Application& app) override;
};

class ArchiveLinkResp : public Response{
public:
RespExitStatus buildResponse(std::string& responseBody) override;
RespExitStatus doLogic(const Request& req, Application& app) override;
private:
std::string body;
};


using responsePtr = std::shared_ptr<Response>;

class ResponseHandler {
public:
ResponseHandler();
responsePtr HandleInput(std::string& resposeBody);
private:
responsePtr _LogInResp;
responsePtr _LogOutResp;
responsePtr _CreateRoomResp;
responsePtr _RemoveRoomResp;
responsePtr _AddLinkResp;
responsePtr _RemoveLinkResp;
};
21 changes: 21 additions & 0 deletions client/include/socket.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include <unistd.h> // close()
#include <memory>
#include <string>


class Socket
{
public:
Socket();
Socket(int _sd);
~Socket();

void connect(const std::string& host, int port);
void send(const std::string& str);
std::string recv();
void close();
private:
int sd;
};
4 changes: 4 additions & 0 deletions client/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
add_library(client STATIC application.cpp client.cpp request.cpp response.cpp socket.cpp)
target_include_directories(client PUBLIC "${PROJECT_SOURCE_DIR}/include")

add_definitions(-Wall -Werror -Wpedantic)
23 changes: 23 additions & 0 deletions client/src/application.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "application.hpp"

UserInfo::UserInfo() : name(""), password("") {}
UserInfo::UserInfo(std::string& nm, std::string& psw) {}
UserInfo::~UserInfo() {}


Room::Room(std::string& roomName, std::string& roomId) {}
void Room::addLink(std::string& newLink) {}
void Room::removeLink(std::string& linkName) {}
void Room::addParticipant(std::string& newPart) {}
void Room::removeParticipant(std::string& partName) {}
std::string Room::archiveLink(std::string& linkName) {return "str";}



Link::Link(std::string& name, std::string& url, std::string& tag) {}
Link::~Link() {}
std::string Link::addSnapshot() { return "str"; }


Application::Application() : client(), info(), rooms() {}
Application::~Application() {}
15 changes: 15 additions & 0 deletions client/src/client.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "client.hpp"

Client::Client() : sock() {}

Client::~Client() {}

void Client::connect(const std::string& host, int port) {}

std::string Client::readFromServer() { return "we"; }

void Client::writeToServer(std::string& req) {}

void Client::closeCon() {}


Loading

0 comments on commit 87ddd0e

Please sign in to comment.