-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Client #3
base: main
Are you sure you want to change the base?
Client #3
Changes from 13 commits
9ef9705
87ddd0e
37715c5
7fc3ae4
db999d7
82bde25
6531e16
ebfa8db
24227bb
076bc9e
b8fd891
225299d
6de03f0
985dd79
3339e88
8dc195d
f00d935
82043c9
f14559e
c099009
255bc0d
837acb2
5043f2d
8a30a02
d90ec82
20ed769
fe5ff7a
db3d341
c9caa36
d03341a
a4f47cf
2fb9365
7f9d74c
64cf698
f80127f
ea87c45
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
name: CI_client | ||
|
||
on: | ||
push: | ||
branches: [ client ] | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: install cppcheck | ||
run: sudo apt-get install -y cppcheck | ||
|
||
- name: install valgrind | ||
run: sudo apt install valgrind | ||
|
||
- name: install gcovr and lcov | ||
run: | | ||
sudo apt install gcovr | ||
sudo apt install lcov | ||
|
||
- name: run cppcheck | ||
run: cd client/src && cppcheck *.cpp | ||
|
||
- name: build | ||
run: | | ||
cd client | ||
mkdir build | ||
cd build | ||
cmake .. | ||
make | ||
|
||
- name: test socket | ||
run: | | ||
cd client/build | ||
valgrind --leak-check=full ./test/socket_tests | ||
|
||
- name: test response | ||
run: | | ||
cd client/build | ||
valgrind --leak-check=full ./test/response_tests | ||
|
||
- name: test request | ||
run: | | ||
cd client/build | ||
valgrind --leak-check=full ./test/request_tests | ||
|
||
- name: test client | ||
run: | | ||
cd client/build | ||
valgrind --leak-check=full ./test/client_tests | ||
|
||
- name: test application | ||
run: | | ||
cd client/build | ||
valgrind --leak-check=full ./test/application_tests | ||
|
||
- name: coverage | ||
run: | | ||
cd client/build | ||
make gcov | ||
make lcov | ||
- name: archive code coverage results | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: code-coverage-report_linear | ||
path: client/build/test/lcoverage |
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) |
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. использовать вектор в интерфейсе - плохая идея, т.к. при необходимости изменения придётся менять весь вызывающий код |
||
}; | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. почему всё в одном файле? |
||
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; | ||
}; |
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Request - это куда более сложная структура, чем string |
||
std::string readFromServer(); | ||
void closeCon(); | ||
|
||
private: | ||
Socket sock; | ||
}; | ||
|
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. виртуальный деструктор? |
||
}; | ||
|
||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. переделайте через цепочку ответственностей - рассматривался паттерн на семинаре по тестированию |
||
}; |
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; | ||
}; |
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; | ||
}; |
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
посмотрите доклад Джосаттиса про строчки