Skip to content

Commit

Permalink
Added some unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Toon Schoenmakers committed May 30, 2014
1 parent 41d3d4b commit 74fd52a
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
gtest-1.7.0.zip
gtest-1.7.0/
*.o
*.a
test.out
38 changes: 38 additions & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
override CXXFLAGS += -Wall -g -O0 -pipe -std=c++11
INC += -I../ -I. -Igtest-1.7.0/include
CC := cc
CXX := c++

VALGRIND := valgrind

BINARY := test.out
DEPS := $(patsubst %.cpp, %.o, $(shell find . -name \*.cpp -type f))

all: $(BINARY)

%.o: %.cpp libgtest.a
$(CXX) $(CXXFLAGS) $(DEFINES) $(INC) -c $< -o $@

$(BINARY): $(DEPS) $(MODS) main.cpp
$(CXX) $(CXXFLAGS) $(DEFINES) $(INC) -o $(BINARY) $(DEPS) libgtest.a -pthread -lev -lreactcpp ../src/libreactcpp-curl.so

libgtest.a:
wget -q http://googletest.googlecode.com/files/gtest-1.7.0.zip
unzip -qq gtest-1.7.0.zip
$(CXX) $(CXXFLAGS) -I gtest-1.7.0/include -I gtest-1.7.0 -c gtest-1.7.0/src/gtest-all.cc
ar -rv libgtest.a gtest-all.o

.PHONY: test

test: $(BINARY)
./$(BINARY)

.PHONY: valgrind

valgrind: $(BINARY)
$(VALGRIND) $(VALGRIND_OPTS) ./$(BINARY)

.PHONY: clean

clean:
rm -rf $(BINARY) $(DEPS) $(MODS)
29 changes: 29 additions & 0 deletions test/http.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Http.cpp
*
* Http related tests
*
* @copyright 2014 Copernica BV
*/

#include <../curl.h>
#include <gtest/gtest.h>

TEST(Http, Http)
{
React::MainLoop loop;
// Timeout after 5 seconds
loop.onTimeout(5.0, [&loop]() {
loop.stop();
FAIL() << "Timeout";
});

React::Curl::CurlMulti multi(&loop);

React::Curl::Request request(&multi, "http://httpbin.org/headers");
request.execute().onComplete([&loop]() {
loop.stop();
});

loop.run();
}
15 changes: 15 additions & 0 deletions test/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Main.cpp
*
* Start point of the unit tests
*
* @copyright 2014 Copernica BV
*/

#include <gtest/gtest.h>

int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
::testing::FLAGS_gtest_shuffle = true;
return RUN_ALL_TESTS();
};

0 comments on commit 74fd52a

Please sign in to comment.