Skip to content

Commit

Permalink
Merge 72f9e9a into 85d8d5c
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtazz committed Sep 7, 2015
2 parents 85d8d5c + 72f9e9a commit 7c595c0
Show file tree
Hide file tree
Showing 40 changed files with 24,389 additions and 5 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ config*
*Makefile
*Makefile.in
vendor/gtest-1.7.0/scripts/gtest-config
test-program
.libs

*autom4te.cache
*aclocal.m4
Expand All @@ -21,3 +23,9 @@ vendor/gtest-1.7.0/scripts/gtest-config
*.dirstamp
*ltmain.sh
m4

# coverage related files
*gcda
*gcno
html
coverage.info
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
language: cpp
# command to install dependencies
script: ./autogen.sh && ./configure && make check && ./test-program
script: ./autogen.sh && ./configure --enable-coverage && make test
before_script:
- ./utils/build_gtest.sh
- gem install coveralls-lcov
after_success:
- make coverage.info
- coveralls-lcov coverage.info
sudo: false
addons:
apt:
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@

1. build vendorized gtest: `./utils/build_gtest.sh`
2. build restclient-cpp: `./autogen.sh && ./configure && make check`
3. run the unit test suite: `./test-program`
3. run the unit test suite: `make test`
15 changes: 15 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,18 @@ lib_LTLIBRARIES=librestclient-cpp.la
librestclient_cpp_la_SOURCES=source/restclient.cpp
librestclient_cpp_la_CXXFLAGS=-fPIC
librestclient_cpp_la_LDFLAGS=-version-info 1:0:1

.PHONY: test check clean-coverage-files coverage-html

test: check
./test-program

clean-local:
find . -name "*.gcda" -print0 | xargs -0 rm

coverage.info: test
./utils/lcov-1.11/bin/lcov --compat-libtool --capture --directory source --output-file coverage.info
./utils/lcov-1.11/bin/lcov --compat-libtool --remove coverage.info "/usr*" -o coverage.info

coverage-html: coverage.info
./utils/lcov-1.11/bin/genhtml -t "restclient-cpp coverage report" --legend --show-details coverage.info --output-directory html
2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ AC_TYPE_SIZE_T
# Checks for library functions.

AC_CONFIG_FILES([Makefile])
AC_ARG_ENABLE(coverage,
AC_HELP_STRING([--enable-coverage],[Enable code coverage]), [CXXFLAGS=" -O0 -g -ftest-coverage -fprofile-arcs"])
AC_OUTPUT
23 changes: 20 additions & 3 deletions test/test_restclient_get.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ TEST_F(RestClientGetTest, TestRestClientGETAdditionalHeaders)
headers["Accept-Charset"] = "iso8859-2";
headers["Accept-Language"] = "en-US";
headers["User-Agent"] = "restclient-cpp";

RestClient::response res = RestClient::get("http://httpbin.org/headers", headers);

EXPECT_EQ(200, res.code);

Json::Value root;
std::istringstream str(res.body);
str >> root;
Expand Down Expand Up @@ -93,4 +93,21 @@ TEST_F(RestClientGetTest, TestRestClientGETTimeout)
EXPECT_EQ(28, res.code);
}

TEST_F(RestClientGetTest, TestRestClientGETAuth)
{
RestClient::setAuth("foo", "bar");
RestClient::response res = RestClient::get("http://httpbin.org/basic-auth/foo/bar");
EXPECT_EQ(200, res.code);

Json::Value root;
std::istringstream str(res.body);
str >> root;

EXPECT_EQ("foo", root.get("user", "no user").asString());
EXPECT_EQ(true, root.get("authenticated", false).asBool());

RestClient::clearAuth();
res = RestClient::get("http://httpbin.org/basic-auth/foo/bar");
EXPECT_EQ(401, res.code);
}

0 comments on commit 7c595c0

Please sign in to comment.