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
2525using std::string;
2626
2727static const std::string TEST_BUCKET (" riak-cxx-test" );
2828static 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- }
0 commit comments