diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 0000000..c70f5f9 --- /dev/null +++ b/test/.gitignore @@ -0,0 +1,5 @@ +gtest-1.7.0.zip +gtest-1.7.0/ +*.o +*.a +test.out diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..112314f --- /dev/null +++ b/test/Makefile @@ -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) \ No newline at end of file diff --git a/test/http.cpp b/test/http.cpp new file mode 100644 index 0000000..e52b682 --- /dev/null +++ b/test/http.cpp @@ -0,0 +1,29 @@ +/** + * Http.cpp + * + * Http related tests + * + * @copyright 2014 Copernica BV + */ + +#include <../curl.h> +#include + +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(); +} \ No newline at end of file diff --git a/test/main.cpp b/test/main.cpp new file mode 100644 index 0000000..8f5686e --- /dev/null +++ b/test/main.cpp @@ -0,0 +1,15 @@ +/** + * Main.cpp + * + * Start point of the unit tests + * + * @copyright 2014 Copernica BV + */ + +#include + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + ::testing::FLAGS_gtest_shuffle = true; + return RUN_ALL_TESTS(); +}; \ No newline at end of file