Skip to content

Commit eb88551

Browse files
committed
switch to boost::test for tests
1 parent fa8f586 commit eb88551

File tree

7 files changed

+159
-218
lines changed

7 files changed

+159
-218
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ stamp-h2
4545
/riak_client.pc
4646
/riak_cxx_simple_test
4747
/riak_cxx_test_server
48+
/riak_cxx_unit_test
4849
/riak_client/config.h
4950
/test/*.o
5051

Makefile.am

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,16 @@ riakc_LDFLAGS = -lriak_client
6969
pkgconfigdir = $(libdir)/pkgconfig
7070
pkgconfig_DATA = riak_client.pc
7171

72-
check_PROGRAMS = riak_cxx_simple_test riak_cxx_test_server
72+
check_PROGRAMS = riak_cxx_unit_test
7373
TESTS = $(check_PROGRAMS)
7474

75-
riak_cxx_simple_test_SOURCES = test/test_basic.cpp
76-
riak_cxx_simple_test_CXXFLAGS = $(libriak_client_la_CXXFLAGS)
77-
riak_cxx_simple_test_LDFLAGS = -lriak_client
75+
riak_cxx_unit_test_SOURCES = test/test_riak_object.cpp test/test_basic.cpp
76+
riak_cxx_unit_test_CXXFLAGS = $(libriak_client_la_CXXFLAGS)
77+
riak_cxx_unit_test_LDFLAGS = -lriak_client -lriakboost_unit_test_framework-mt-riak_client
7878

79-
riak_cxx_test_server_SOURCES = test/test_server.cpp src/cxx/pbc_header.cpp src/cxx/pbc_message.cpp src/cxx/riakclient.pb.cc
80-
riak_cxx_test_server_CXXFLAGS = $(libriak_client_la_CXXFLAGS) -Isrc/cxx
81-
riak_cxx_test_server_LDFLAGS = $(libriak_client_la_LDFLAGS) -lriak_client
79+
#riak_cxx_test_server_SOURCES = test/test_server.cpp src/cxx/pbc_header.cpp src/cxx/pbc_message.cpp src/cxx/riakclient.pb.cc
80+
#riak_cxx_test_server_CXXFLAGS = $(libriak_client_la_CXXFLAGS) -Isrc/cxx
81+
#riak_cxx_test_server_LDFLAGS = $(libriak_client_la_LDFLAGS) -lriak_client
8282

8383
CLEANFILES = $(check_PROGRAMS)
8484
SUBDIRS = deps

Makefile.in

Lines changed: 52 additions & 115 deletions
Large diffs are not rendered by default.

deps/Makefile.am

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,24 @@ protobufs.ts: $(PROTOBUF_SRC)/Makefile
1717
cd $(PROTOBUF_SRC) && make && make install
1818
touch protobufs.ts
1919

20+
21+
boost-test.ts:
22+
cd $(BOOST_SRC) && make DEPS_CXXFLAGS=$(DEPS_CXXFLAGS) test
23+
touch boost-test.ts
24+
2025
$(PROTOBUF_SRC)/Makefile:
2126
cd $(PROTOBUF_SRC) && CXXFLAGS=$(DEPS_CXXFLAGS) ./configure \
2227
--prefix=$(BUILD_DIR) --disable-shared
2328

29+
check-local: boost-test.ts
30+
31+
2432
clean-local:
2533

2634
distclean-local:
2735
cd $(PROTOBUF_SRC) && make distclean
2836
cd $(BOOST_SRC) && make clean
2937
rm -f protobufs.ts
3038
rm -f boost.ts
39+
rm -f boost-test.ts
3140

deps/Makefile.in

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ ctags: CTAGS
224224
CTAGS:
225225

226226
check-am: all-am
227+
$(MAKE) $(AM_MAKEFLAGS) check-local
227228
check: check-am
228229
all-am: Makefile all-local
229230
installdirs:
@@ -307,17 +308,17 @@ uninstall-am:
307308

308309
.MAKE: install-am install-strip
309310

310-
.PHONY: all all-am all-local check check-am clean clean-generic \
311-
clean-libtool clean-local distclean distclean-generic \
312-
distclean-libtool distclean-local dvi dvi-am html html-am info \
313-
info-am install install-am install-data install-data-am \
314-
install-dvi install-dvi-am install-exec install-exec-am \
315-
install-html install-html-am install-info install-info-am \
316-
install-man install-pdf install-pdf-am install-ps \
317-
install-ps-am install-strip installcheck installcheck-am \
318-
installdirs maintainer-clean maintainer-clean-generic \
319-
mostlyclean mostlyclean-generic mostlyclean-libtool pdf pdf-am \
320-
ps ps-am uninstall uninstall-am
311+
.PHONY: all all-am all-local check check-am check-local clean \
312+
clean-generic clean-libtool clean-local distclean \
313+
distclean-generic distclean-libtool distclean-local dvi dvi-am \
314+
html html-am info info-am install install-am install-data \
315+
install-data-am install-dvi install-dvi-am install-exec \
316+
install-exec-am install-html install-html-am install-info \
317+
install-info-am install-man install-pdf install-pdf-am \
318+
install-ps install-ps-am install-strip installcheck \
319+
installcheck-am installdirs maintainer-clean \
320+
maintainer-clean-generic mostlyclean mostlyclean-generic \
321+
mostlyclean-libtool pdf pdf-am ps ps-am uninstall uninstall-am
321322

322323

323324
all-local: boost.ts protobufs.ts
@@ -330,17 +331,24 @@ protobufs.ts: $(PROTOBUF_SRC)/Makefile
330331
cd $(PROTOBUF_SRC) && make && make install
331332
touch protobufs.ts
332333

334+
boost-test.ts:
335+
cd $(BOOST_SRC) && make DEPS_CXXFLAGS=$(DEPS_CXXFLAGS) test
336+
touch boost-test.ts
337+
333338
$(PROTOBUF_SRC)/Makefile:
334339
cd $(PROTOBUF_SRC) && CXXFLAGS=$(DEPS_CXXFLAGS) ./configure \
335340
--prefix=$(BUILD_DIR) --disable-shared
336341

342+
check-local: boost-test.ts
343+
337344
clean-local:
338345

339346
distclean-local:
340347
cd $(PROTOBUF_SRC) && make distclean
341348
cd $(BOOST_SRC) && make clean
342349
rm -f protobufs.ts
343350
rm -f boost.ts
351+
rm -f boost-test.ts
344352
# Tell versions [3.59,3.63) of GNU make to not export all variables.
345353
# Otherwise a system limit (for SysV at least) may be exceeded.
346354
.NOEXPORT:

test/test_basic.cpp

Lines changed: 46 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -14,96 +14,47 @@
1414
limitations under the License.
1515
*/
1616

17-
#include "test_common.hpp"
17+
#define BOOST_TEST_MODULE pbc_test
18+
#include <boost/test/unit_test.hpp>
1819
#include <riak_client/cxx/riak_client.hpp>
1920
#include <boost/lexical_cast.hpp>
2021
#include <iostream>
2122
#include <algorithm>
22-
#include <assert.h>
2323
#include <cstdio>
2424

2525
using std::string;
2626

2727
static const std::string TEST_BUCKET("riak-cxx-test");
2828
static const std::string TEST_KEY("riak-cxx-test");
2929

30-
bool test_pbc_client()
30+
BOOST_AUTO_TEST_CASE (test_pbc_client)
3131
{
32-
TEST_INIT t(__FUNCTION__, __FILE__, __LINE__);
3332
riak::client_ptr c = riak::new_client("127.0.0.1", "8087");
34-
assert(c->ping());
33+
bool ping = c->ping();
34+
BOOST_REQUIRE(ping);
3535
c->client_id(42);
36-
assert(c->client_id() == 42);
37-
riak::server_info info = c->get_server_info();
38-
return true;
36+
BOOST_REQUIRE(c->client_id() == 42);
3937
}
4038

41-
bool test_list_buckets()
39+
BOOST_AUTO_TEST_CASE (test_set_bucket)
4240
{
43-
TEST_INIT t(__FUNCTION__, __FILE__, __LINE__);
44-
riak::client_ptr c = riak::new_client("127.0.0.1", "8087");
45-
riak::string_vector v = c->list_buckets();
46-
assert(std::find(v.begin(), v.end(), TEST_BUCKET) != v.end());
47-
return true;
48-
}
49-
50-
bool test_list_keys()
51-
{
52-
TEST_INIT t(__FUNCTION__, __FILE__, __LINE__);
53-
riak::client_ptr c = riak::new_client("127.0.0.1", "8087");
54-
riak::string_vector v = c->list_keys(TEST_BUCKET);
55-
assert(v.size() > 0);
56-
return true;
57-
58-
}
59-
60-
bool test_del()
61-
{
62-
TEST_INIT t(__FUNCTION__, __FILE__, __LINE__);
63-
riak::client_ptr c = riak::new_client("127.0.0.1", "8087");
64-
riak::string_vector v = c->list_keys(TEST_BUCKET);
65-
for (riak::string_vector::size_type i=0;
66-
i < v.size(); ++i)
67-
{
68-
assert(c->del(TEST_BUCKET, v[i], 3));
69-
}
70-
return true;
71-
}
72-
73-
74-
bool test_set_bucket()
75-
{
76-
TEST_INIT t(__FUNCTION__, __FILE__, __LINE__);
7741
riak::client_ptr c = riak::new_client("127.0.0.1", "8087");
7842
riak::bucket_properties properties;
7943
properties.allow_mult(true);
8044
properties.n_val(3);
81-
return c->set_bucket(TEST_BUCKET, properties);
45+
BOOST_REQUIRE(c->set_bucket(TEST_BUCKET, properties) == true);
8246
}
8347

84-
bool test_fetch_bucket()
48+
BOOST_AUTO_TEST_CASE (test_fetch_bucket)
8549
{
86-
TEST_INIT t(__FUNCTION__, __FILE__, __LINE__);
8750
riak::client_ptr c = riak::new_client("127.0.0.1", "8087");
8851
riak::bucket_properties result = c->fetch_bucket(TEST_BUCKET);
89-
assert(result.allow_mult() == true);
90-
assert(result.n_val() == 3);
91-
return true;
92-
52+
BOOST_REQUIRE(result.allow_mult());
53+
BOOST_REQUIRE(result.n_val() == 3);
9354
}
9455

95-
bool test_fetch()
56+
BOOST_AUTO_TEST_CASE (test_put)
9657
{
97-
TEST_INIT t(__FUNCTION__, __FILE__, __LINE__);
98-
riak::client_ptr c(riak::new_client("127.0.0.1", "8087"));
99-
riak::result_ptr fr(c->fetch(TEST_BUCKET, TEST_KEY, 3));
100-
assert(fr->contents()[0].value() == TEST_KEY);
101-
return true;
102-
}
103-
104-
bool test_put()
105-
{
106-
TEST_INIT t(__FUNCTION__, __FILE__, __LINE__);
10758
std::cout << riak::tss_client_id() << std::endl;
10859
riak::client_ptr c = riak::new_client("127.0.0.1", "8087");
10960
c->client_id(42);
@@ -120,49 +71,59 @@ bool test_put()
12071
}
12172
else
12273
o = fetch_result->choose_sibling(0);
123-
o->debug_print();
12474
riak::string_map usermeta(o->update_metadata().usermeta());
12575
usermeta["foo"] = "bar";
12676
riak::riak_metadata md(usermeta);
12777
o->update_metadata(md);
12878
riak::result_ptr r(c->store(o, sp));
12979
riak::object_ptr o2(r->choose_sibling(0));
130-
o2->debug_print();
131-
return true;
13280
}
13381

134-
#include <boost/thread.hpp>
82+
BOOST_AUTO_TEST_CASE (test_fetch)
83+
{
84+
riak::client_ptr c(riak::new_client("127.0.0.1", "8087"));
85+
riak::result_ptr fr(c->fetch(TEST_BUCKET, TEST_KEY, 3));
86+
BOOST_REQUIRE(fr->contents()[0].value() == TEST_KEY);
87+
}
13588

136-
bool test_client()
89+
BOOST_AUTO_TEST_CASE (test_list_buckets)
90+
{
91+
riak::client_ptr c = riak::new_client("127.0.0.1", "8087");
92+
riak::string_vector v = c->list_buckets();
93+
BOOST_REQUIRE(std::find(v.begin(), v.end(), TEST_BUCKET) != v.end());
94+
}
95+
96+
BOOST_AUTO_TEST_CASE (test_list_keys)
97+
{
98+
riak::client_ptr c = riak::new_client("127.0.0.1", "8087");
99+
riak::string_vector v = c->list_keys(TEST_BUCKET);
100+
BOOST_REQUIRE(v.size() > 0);
101+
}
102+
103+
BOOST_AUTO_TEST_CASE (test_del)
104+
{
105+
riak::client_ptr c = riak::new_client("127.0.0.1", "8087");
106+
riak::string_vector v = c->list_keys(TEST_BUCKET);
107+
for (riak::string_vector::size_type i=0;
108+
i < v.size(); ++i)
109+
{
110+
BOOST_REQUIRE(c->del(TEST_BUCKET, v[i], 3) == true);
111+
}
112+
}
113+
114+
BOOST_AUTO_TEST_CASE (test_client)
137115
{
138-
TEST_INIT t(__FUNCTION__, __FILE__, __LINE__);
139116
riak::cluster cluster;
140117
riak::client client(cluster.make_client());
141118
riak::basic_bucket<std::string> bucket = client.bucket<std::string>("bucket");
142119
bucket.del("foo").rw(2)();
143120
std::string value = bucket.fetch("foo").r(3)();
144-
assert(value == "");
121+
BOOST_REQUIRE(value == "");
145122
value = bucket.store("foo", "bar")
146123
.r(2)
147124
.w(2)
148125
.dw(2)();
149126
value = bucket.fetch("foo").r(3)();
150-
assert(value == "bar");
151-
return true;
127+
BOOST_REQUIRE(value == "bar");
152128
}
153129

154-
int main(int argc, char *argv[]) {
155-
if (
156-
test_client() &&
157-
test_pbc_client() &&
158-
test_set_bucket() &&
159-
test_fetch_bucket() &&
160-
test_put() &&
161-
test_fetch() &&
162-
test_list_buckets() &&
163-
test_list_keys() //&&
164-
//test_del()
165-
)
166-
return 0;
167-
return 1;
168-
}

test/test_riak_object.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <boost/test/unit_test.hpp>
2+
#include <riak_client/cxx/object/riak_metadata.hpp>
3+
4+
5+
BOOST_AUTO_TEST_CASE (test_metadata)
6+
{
7+
riak::string_map usermeta;
8+
usermeta["foo"] = "bar";
9+
riak::riak_metadata md(usermeta);
10+
md.content_type("content_type");
11+
md.charset("charset");
12+
md.encoding("encoding");
13+
md.vtag("vtag");
14+
md.lastmod(1, 1);
15+
BOOST_REQUIRE(md.usermeta().at("foo") == "bar");
16+
BOOST_REQUIRE(md.content_type() == "content_type");
17+
BOOST_REQUIRE(md.charset() == "charset");
18+
BOOST_REQUIRE(md.vtag() == "vtag");
19+
BOOST_REQUIRE(md.lastmod().first == 1);
20+
BOOST_REQUIRE(md.lastmod().second == 1);
21+
}
22+
23+
24+
25+

0 commit comments

Comments
 (0)