Skip to content

Commit

Permalink
Add a CXXTest unittest framework
Browse files Browse the repository at this point in the history
  • Loading branch information
eliran-stratoscale committed Jun 26, 2016
1 parent 13fe813 commit e8459e5
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "cxxtest"]
path = cxxtest
url = https://github.com/CxxTest/cxxtest
33 changes: 24 additions & 9 deletions build.Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ all: all-targets

CONFIGURATION ?= RELEASE
SHELL ?= /bin/bash
COMMON_CXXFLAGS = -Ic -Icpp -I/usr/include/python2.7 -Ibuild/cpp-netlib-0.11.1-final -std=gnu++0x -Werror -Wall
COMMON_CXXFLAGS = -Ic -Icpp -I/usr/include/python2.7 -Ibuild/cpp-netlib-0.11.1-final -Icxxtest -std=gnu++0x -Werror -Wall
COMMON_CFLAGS = -Ic -Werror -Wall

DEBUG_CXXFLAGS = -ggdb -DDEBUG
Expand Down Expand Up @@ -36,12 +36,12 @@ $(error BOOST static libraries were not found)
endif
BOOST_MT = $(shell if [ -e $(STATIC_BOOST_LIBS_DIR)/libboost_thread-mt.a ]; then echo '-mt'; fi)


include targets.Makefile

define template_per_OBJECT
-include $(1).deps
endef
#endef template_per_OBJECT
endef #endef template_per_OBJECT

define template_per_TARGET
template_per_TARGET_target = $$(if $$(filter %.cpp,$$($(1))), \
Expand Down Expand Up @@ -89,30 +89,45 @@ endif

build/cpp/%.o: cpp/%.cpp
@mkdir -p $(@D)
@echo 'C++ ' $@
@echo 'C++ ' $@
$(Q)g++ $(CXXFLAGS) $($(subst /,_,$(subst .,_,$*))_o_CFLAGS) -MMD -MF $@.deps -c $< -o $@

build/c/%.o: c/%.c
@mkdir -p $(@D)
@echo 'C ' $@
@echo 'C ' $@
$(Q)gcc $(CFLAGS) $($(subst /,_,$(subst .,_,$*))_o_CFLAGS) -MMD -MF $@.deps -c $< -o $@

build/cpp/%.bin:
@mkdir -p $(@D)
@echo 'LINK++ ' $@
@echo 'LINK++ ' $@
$(Q)g++ $(LDFLAGS) -o $@ $^ $($*_LDFLAGS) $($*_LIBRARIES)

build/c/%.bin:
@mkdir -p $(@D)
@echo 'LINK ' $@
@echo 'LINK ' $@
$(Q)gcc $(LDFLAGS) -o $@ $^ $($*_LDFLAGS) $($*_LIBRARIES)

build/cpp/%.so:
@mkdir -p $(@D)
@echo 'LINK++ ' $@
@echo 'LINK++ ' $@
$(Q)g++ -shared $(LDFLAGS) -o $@ $^ $($*_LDFLAGS) $($*_LIBRARIES)

build/c/%.so:
@mkdir -p $(@D)
@echo 'LINK ' $@
@echo 'LINK ' $@
$(Q)gcc -shared $(LDFLAGS) -o $@ $^ $($*_LDFLAGS) $($*_LIBRARIES)

build/cpp/Unittests/runner_Test%.o: build/cpp/Unittests/runner_%.cpp
@mkdir -p $(@D)
@echo 'C++ ' $@
$(Q)g++ $(CXXFLAGS) $($(subst /,_,$(subst .,_,$*))_o_CFLAGS) -MMD -MF $@.deps -c $< -o $@

build/cpp/Unittests/runner_Test%.cpp: cpp/Unittests/Test%.cpp
@mkdir -p $(@D)
@echo 'CXXTESTGEN ' $@
$(Q)cxxtest/bin/cxxtestgen --error-printer -o $@ $^

build/cpp/runner_Test%.bin:
@mkdir -p $(@D)
@echo 'LINKTEST++ ' $@
$(Q)g++ $(LDFLAGS) -o $@ $^ $($*_LDFLAGS) $(runner_Test$*_LIBRARIES) $(CXXFLAGS)
32 changes: 32 additions & 0 deletions cpp/Unittests/MockTCPConnection.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <string>
#include <Osmosis/TCPConnection.h>
#include <Osmosis/Stream/AckOps.h>

namespace Osmosis
{
TCPConnection::TCPConnection( const std::string & hostname, unsigned short port ):
_socket( _ioService ),
_endpoint(),
_tcpSocket( _socket )
{
std::cout << "Nothing happens here";
}

TCPSocket & TCPConnection::socket()
{
return _tcpSocket;
}

void TCPConnection::connect()
{
}

void TCPConnection::sendHandshake()
{
Stream::AckOps( _tcpSocket ).wait( "Handshake" );
}

void TCPConnection::setTCPNoDelay()
{
}
}
38 changes: 38 additions & 0 deletions cpp/Unittests/TestProtocolVersionNegotiator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <iostream>
#include <boost/asio.hpp>
#include <Osmosis/Tongue.h>
#include <cxxtest/TestSuite.h>
#include <Osmosis/TCPConnection.h>
#include <Osmosis/Stream/AckOps.h>
#include <Osmosis/Chain/Remote/ProtocolVersionNegotiator.h>

std::mutex globalTraceLock;

namespace Osmosis {
namespace Stream
{

AckOps::AckOps( TCPSocket & socket ):
_socket( socket )
{}

void AckOps::wait( const char * waitReason )
{
}

void AckOps::sendAck()
{
}

}
}

class ProtocolVersionNegotiatorTest : public CxxTest::TestSuite
{
public:
void test_ProtocolNegotiation(void)
{
boost::asio::io_service ioService;
boost::asio::ip::tcp::socket boostSocket(ioService);
}
};
40 changes: 40 additions & 0 deletions cpp/Unittests/test_osmosis_main.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <mutex>
#include <cxxtest/TestSuite.h>
#include <Osmosis/Chain/Remote/ProtocolVersionNegotiator.h>

std::mutex globalTraceLock;

namespace Osmosis
{
class TCPConnection
{
public:
TCPConnection( const std::string & hostname, unsigned short port )
{
std::cout << "TCPConnection mock constructor";
}

TCPSocket & socket() {

}

void connect();

private:

void sendHandshake();

void setTCPNoDelay();

TCPConnection( const TCPConnection & rhs ) = delete;
TCPConnection & operator= ( const TCPConnection & rhs ) = delete;
};
} // namespace Osmosis

class ProtocolVersionNegotiatorTest : public CxxTest::TestSuite
{
public:
void test_ProtocolNegotiation(void)
{
}
};
1 change: 1 addition & 0 deletions cxxtest
Submodule cxxtest added at 191add
9 changes: 8 additions & 1 deletion targets.Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
TARGET_osmosis = $(shell find cpp/Osmosis/ -iname "*.cpp")
osmosis_SOURCES = $(shell find cpp/Osmosis/ -type f -iname "*.cpp" -not -iname "Test*.cpp" -not -iname "runner_*.cpp" -not -iname "*main.cpp")
#osmosis_bin_sources = $(shell find cpp/Osmosis/ -type f -iname "*.cpp" -not -iname "Test*.cpp" -not -iname "*main.cpp")
TARGET_osmosis = ${osmosis_SOURCES} cpp/Osmosis/main.cpp
osmosis_LIBRARIES = -pthread \
$(STATIC_BOOST_LIBS_DIR)/libboost_regex$(BOOST_MT).a \
$(STATIC_BOOST_LIBS_DIR)/libboost_filesystem$(BOOST_MT).a \
Expand All @@ -9,3 +11,8 @@ osmosis_LIBRARIES = -pthread \

TARGET_testtaskqueue = cpp/Common/WhiteboxTests/testtaskqueue.cpp
testtaskqueue_LIBRARIES = -pthread $(STATIC_BOOST_LIBS_DIR)/libboost_system$(BOOST_MT).a

TARGET_runner_TestProtocolVersionNegotiator = \
build/cpp/Unittests/runner_TestProtocolVersionNegotiator.cpp \
cpp/Unittests/MockTCPConnection.cpp
runner_TestProtocolVersionNegotiator_LIBRARIES = ${osmosis_LIBRARIES}

0 comments on commit e8459e5

Please sign in to comment.