Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
2f3ed89
workshop2
prepas May 2, 2018
5eecb8b
change workshop #3
prepas May 9, 2018
30776d8
03_armstrong_number
prepas May 10, 2018
d40dad4
added 04_roman_numerals task for workshop
Vv-git May 15, 2018
9315bf6
04_roman_numerals
prepas May 16, 2018
bbc2047
04_roman_numerals
prepas May 16, 2018
2964584
fix build
May 23, 2018
90d7f02
add bank ocr
May 23, 2018
f2ec65b
update readme
May 23, 2018
c90a808
05_bank_ocr
May 23, 2018
53a576a
05_bank_ocr
May 23, 2018
b8b6010
05_bank_ocr
May 23, 2018
c196c5a
05bankocr_homework
May 23, 2018
e16c1fd
05_word_wrapp
May 30, 2018
93ee78a
added Allergies task description
driverdevteam May 31, 2018
29794bf
added 06_allergies homework
Vv-git May 31, 2018
d3929c7
modified description of 06_allergies homework
Vv-git May 31, 2018
1309882
07_coffee
Jun 6, 2018
8bc2fe2
07_coffee
Jun 6, 2018
d981f54
07_coffee
Jun 6, 2018
49abcda
07_coffee
Jun 6, 2018
d16bc86
ChatClient.mpp
Jun 13, 2018
1cd35ea
add socketwrapper
Jun 18, 2018
f9a356e
update socketwrapper
Jun 20, 2018
b91a4dc
clean_room_1\
Jun 20, 2018
7ea2542
clean_room_1
Jun 20, 2018
2c2af88
[red] added red test.
MaxKrabio Jun 27, 2018
4fe072b
[green] fixed red test.
MaxKrabio Jun 27, 2018
6d576d6
[refactoring] -> refactored.
MaxKrabio Jun 27, 2018
054f336
[red] added a new red test.
MaxKrabio Jun 27, 2018
4152178
[green] green color has been set.
MaxKrabio Jun 27, 2018
1504bdb
[red] added new red test.
MaxKrabio Jun 27, 2018
493d148
[green] fixed broken test.
MaxKrabio Jun 27, 2018
d9bced1
[refactoring]
MaxKrabio Jun 27, 2018
32c07cd
[green] fixed test to green state.
MaxKrabio Jun 27, 2018
dd0919f
[red] added red test for check the multiple spaces in string.
MaxKrabio Jun 27, 2018
a831564
[green] fixed broken test.
MaxKrabio Jun 27, 2018
fed1084
Init commit.
MaxKrabio Jul 4, 2018
96f3f49
added checklist and interfaces. fixed problem with gmock.
MaxKrabio Jul 8, 2018
3c1144d
[red] added a test for copy a not exist file.
MaxKrabio Jul 8, 2018
7d594d7
[green] added a new mock class. The interface files have been refacto…
MaxKrabio Jul 8, 2018
6cd8b8a
[red] added a new red test for copy the single file.
MaxKrabio Jul 8, 2018
b2e892a
[green] CopySingleFile test passed.
MaxKrabio Jul 8, 2018
606bcad
[refactoring] code has been refactored. Added buildPath function.
MaxKrabio Jul 8, 2018
1f08e8b
[red] Added a new red test for copy folder with subfolders.
MaxKrabio Jul 8, 2018
27d4d93
[green] Red test for copy folders recursively has been fixed.
MaxKrabio Jul 8, 2018
7c38a75
[refactoring] vars for src/dst paths moved.
MaxKrabio Jul 8, 2018
8626f6a
[red] added a new red test for capuccino.
MaxKrabio Jul 8, 2018
78fa0d8
[green] fixed capuccino test
MaxKrabio Jul 8, 2018
0f394ba
[green] added a new test for check if there no cup for capuccino.
MaxKrabio Jul 8, 2018
d3c293e
[red] added a test for latte.
MaxKrabio Jul 8, 2018
ae28eb6
[green] fixed the test for latte.
MaxKrabio Jul 8, 2018
f59cb41
[refactoring] - refactored the tests and added the milk temperature a…
MaxKrabio Jul 8, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@
#include "gtest/internal/gtest-filepath.h"
#include "gtest/internal/gtest-type-util.h"


enum RelationToSource {
kReference, // The NativeArray references the native array.
kCopy // The NativeArray makes a copy of the native array and
// owns the copy.
};
// Due to C++ preprocessor weirdness, we need double indirection to
// concatenate two tokens when one of them is __LINE__. Writing
//
Expand Down
Binary file added tdd_intro/cleanroom/ChatClient.mpp
Binary file not shown.
6 changes: 5 additions & 1 deletion tdd_intro/cleanroom/chatclient/chatclient.pro
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ CONFIG -= app_bundle
CONFIG -= qt

SOURCES += \
test.cpp
test.cpp \
socketwrapper.cpp

LIBS += \
Ws2_32.lib \
Mswsock.lib \
AdvApi32.lib

HEADERS += \
socketwrapper.h
107 changes: 107 additions & 0 deletions tdd_intro/cleanroom/chatclient/socketwrapper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#define WIN32_LEAN_AND_MEAN
#define _WINSOCK_DEPRECATED_NO_WARNINGS

#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <exception>
#include <vector>
#include <string>
#include <sstream>
#include <memory>

#include "SocketWrapper.h"

namespace
{
std::string GetExceptionString(const std::string& message, int errorCode)
{
std::stringstream stream;
stream << message;
stream << errorCode;
stream << std::endl;
return stream.str();
}
}

SocketWrapper::SocketWrapper()
: m_socket(INVALID_SOCKET)
{
m_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (m_socket == INVALID_SOCKET)
{
throw std::runtime_error(GetExceptionString("Failed to create socket to listen on.", WSAGetLastError()));
}
}

SocketWrapper::SocketWrapper(SOCKET & other)
: m_socket(other)
{
}

SocketWrapper::~SocketWrapper()
{
closesocket(m_socket);
}

void SocketWrapper::Bind(const std::string& addr, int16_t port)
{
sockaddr_in addres;
addres.sin_family = AF_INET;
addres.sin_addr.s_addr = inet_addr(addr.data());
addres.sin_port = htons(port);
if (bind(m_socket, reinterpret_cast<sockaddr*>(&addres), sizeof(addres)) == SOCKET_ERROR)
{
throw std::runtime_error(GetExceptionString("Failed to bind socket to address.", WSAGetLastError()));
}
}

void SocketWrapper::Listen()
{
if (listen(m_socket, SOMAXCONN) == SOCKET_ERROR)
{
throw std::runtime_error(GetExceptionString("Failed to listen on socket.", WSAGetLastError()));
}
}

ISocketWrapperPtr SocketWrapper::Accept()
{
// SOCKET other = accept(m_socket, nullptr, nullptr);
// if (other == INVALID_SOCKET)
// {
// throw std::runtime_error(GetExceptionString("Failed to connect to client.", WSAGetLastError()));
// }
// return SocketWrapper(other);
return nullptr;
}

ISocketWrapperPtr SocketWrapper::Connect(const std::string& addr, int16_t port)
{
// sockaddr_in addres;
// addres.sin_family = AF_INET;
// addres.sin_addr.s_addr = inet_addr(addr.data());
// addres.sin_port = htons(port);
// SOCKET other = connect(m_socket, reinterpret_cast<sockaddr*>(&addres), sizeof(addres));
// if (other == INVALID_SOCKET)
// {
// throw std::runtime_error(GetExceptionString("Failed to connect to server.", WSAGetLastError()));
// }
// return SocketWrapper(other);
return nullptr;
}

void SocketWrapper::Read(std::string& buffer)
{
std::vector<char> bufferTmp;
bufferTmp.resize(buffer.size());
if (SOCKET_ERROR == recv(m_socket, bufferTmp.data(), bufferTmp.size(), 0))
{
throw std::runtime_error(GetExceptionString("Failed to connect to server.", WSAGetLastError()));
}
buffer.assign(bufferTmp.begin(), bufferTmp.end());
}

void SocketWrapper::Write(const std::string& buffer)
{
send(m_socket, buffer.data(), buffer.size(), 0);
}
35 changes: 35 additions & 0 deletions tdd_intro/cleanroom/chatclient/socketwrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once
#include <cstdint>
#include <windows.h>
#include <memory>

class ISocketWrapper;
using ISocketWrapperPtr = std::shared_ptr<ISocketWrapper>;

class ISocketWrapper
{
public:
virtual void Bind(const std::string& addr, int16_t port) = 0;
virtual void Listen()= 0;
virtual ISocketWrapperPtr Accept() = 0;
virtual ISocketWrapperPtr Connect(const std::string& addr, int16_t port)= 0;
virtual void Read(std::string& buffer)= 0;
virtual void Write(const std::string& buffer)= 0;
};

class SocketWrapper : public ISocketWrapper
{
public:
SocketWrapper();
explicit SocketWrapper(SOCKET& other);
~SocketWrapper();
void Bind(const std::string& addr, int16_t port);
void Listen();
ISocketWrapperPtr Accept();
ISocketWrapperPtr Connect(const std::string& addr, int16_t port);
void Read(std::string& buffer);
void Write(const std::string& buffer);

private:
SOCKET m_socket;
};
81 changes: 81 additions & 0 deletions tdd_intro/cleanroom/chatclient/test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include "socketwrapper.h"

using namespace testing;
/*
Expand Down Expand Up @@ -38,3 +39,83 @@ Implement chat application, that communicates via TCP sockets.
* If user enters '!exit!' message, application must close connection and exit
* If user runs app with 'me' nickname - error with text "Username me is reserved and can not be used" is displayed and application exits
*/

class MockSocketWrapper : public ISocketWrapper
{
public:
MOCK_METHOD2(Bind, void(const std::string& addr, int16_t port));
MOCK_METHOD0(Listen, void());
MOCK_METHOD0(Accept, ISocketWrapperPtr());
MOCK_METHOD2(Connect, ISocketWrapperPtr(const std::string& addr, int16_t port));
MOCK_METHOD1(Read, void(std::string& buffer));
MOCK_METHOD1(Write, void(const std::string& buffer));

};

class Channel
{
public:
explicit Channel(ISocketWrapper& wrapper): m_wrapper(wrapper) {}
void Send(const std::string& message) { m_wrapper.Write(message);}
void Receive(std::string& message) { m_wrapper.Read(message);}

private:
ISocketWrapper& m_wrapper;
};

void ClientHandshake(Channel& channel, const std::string& login)
{
std::string buffer;
channel.Send(login + ":HELLO");
channel.Receive(buffer);

}

void ServerHandshake(Channel& channel, const std::string& login)
{
std::string buffer;
channel.Receive(buffer);
channel.Send(login + ":HELLO!");
}

TEST(SocketWrapperTest, Sending)
{
MockSocketWrapper socket;
Channel channel(socket);

EXPECT_CALL(socket, Write("Hello")).Times(1);
channel.Send("Hello");
}

TEST(SocketWrapperTest, Receiving)
{
MockSocketWrapper socket;
Channel channel(socket);

std::string buffer;
EXPECT_CALL(socket, Read(_)).WillOnce(SetArgReferee<0>("Hello"));
channel.Receive(buffer);

EXPECT_EQ("Hello", buffer);
}

TEST(SocketWrapperTest, ClientHandshake)
{
MockSocketWrapper socket;
Channel channel(socket);
InSequence sequence;
EXPECT_CALL(socket, Write("metizik:HELLO")).Times(1);
EXPECT_CALL(socket, Read(_)).Times(1);
ClientHandshake(channel, "metizik");
}

TEST(SocketWrapperTest, ServerHandshake)
{
MockSocketWrapper socket;
Channel channel(socket);
EXPECT_CALL(socket, Read(_)).Times(1);
EXPECT_CALL(socket, Write("user:HELLO!")).Times(1);
ServerHandshake(channel, "user");
}


Loading