Skip to content

Commit 0548dfd

Browse files
authored
CPP-837 Port set keyspace tests to Google test framework (#324)
1 parent 177c3f5 commit 0548dfd

File tree

7 files changed

+470
-554
lines changed

7 files changed

+470
-554
lines changed

cpp-driver/gtests/src/integration/objects/future.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ class Future : public Object<CassFuture, cass_future_free> {
118118
*/
119119
const CassErrorResult* error_result() { return cass_future_get_error_result(get()); }
120120

121+
/**
122+
* Get the prepared from the future
123+
*
124+
* @return A prepared statement
125+
*/
126+
const CassPrepared* prepared() { return cass_future_get_prepared(get()); }
127+
121128
/**
122129
* Wait for the future to resolve itself
123130
*

cpp-driver/gtests/src/integration/objects/prepared.hpp

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "objects/object_base.hpp"
2222

23+
#include "objects/future.hpp"
2324
#include "objects/statement.hpp"
2425

2526
namespace test { namespace driver {
@@ -36,20 +37,13 @@ class Prepared : public Object<const CassPrepared, cass_prepared_free> {
3637
: Object<const CassPrepared, cass_prepared_free>() {}
3738

3839
/**
39-
* Create the prepared object from the native driver object
40+
* Create the prepared object from a future object
4041
*
41-
* @param prepared Native driver object
42+
* @param future Wrapped driver object
4243
*/
43-
Prepared(const CassPrepared* prepared)
44-
: Object<const CassPrepared, cass_prepared_free>(prepared) {}
45-
46-
/**
47-
* Create the prepared object from a shared reference
48-
*
49-
* @param prepared Shared reference
50-
*/
51-
Prepared(Ptr prepared)
52-
: Object<const CassPrepared, cass_prepared_free>(prepared) {}
44+
Prepared(Future future)
45+
: Object<const CassPrepared, cass_prepared_free>(future.prepared())
46+
, future_(future) {}
5347

5448
/**
5549
* Bind the prepared object and create a statement
@@ -93,6 +87,30 @@ class Prepared : public Object<const CassPrepared, cass_prepared_free> {
9387
* @return Value type at the specified column index
9488
*/
9589
CassValueType value_type(const std::string& name) { return cass_data_type_type(data_type(name)); }
90+
91+
/**
92+
* Get the error code from the future
93+
*
94+
* @return Error code of the future
95+
*/
96+
CassError error_code() { return future_.error_code(); }
97+
98+
/**
99+
* Get the human readable description of the error code
100+
*
101+
* @return Error description
102+
*/
103+
const std::string error_description() { return future_.error_description(); }
104+
105+
/**
106+
* Get the error message of the future if an error occurred
107+
*
108+
* @return Error message
109+
*/
110+
const std::string error_message() { return future_.error_message(); }
111+
112+
private:
113+
Future future_;
96114
};
97115

98116
}} // namespace test::driver

cpp-driver/gtests/src/integration/objects/result.hpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,17 @@ class Row {
299299
return T(cass_row_get_column_by_name(row_, name.c_str()));
300300
}
301301

302+
/**
303+
* Get the value as a specific type for the given column index
304+
*
305+
* @param index Index of the column to retrieve
306+
* @return The value as a value type
307+
*/
308+
template <typename T>
309+
T column(size_t index) {
310+
return T(cass_row_get_column(row_, index));
311+
}
312+
302313
/**
303314
* Get the total number of columns in a row
304315
*
@@ -397,7 +408,6 @@ inline Row Result::first_row() {
397408
}
398409

399410
inline Rows Result::rows() { return Rows(cass_iterator_from_result(get()), *this); }
400-
401411
}} // namespace test::driver
402412

403413
#endif // __TEST_RESULT_HPP__

cpp-driver/gtests/src/integration/objects/session.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ class Session : public Object<CassSession, cass_session_free> {
225225
Prepared prepare(const std::string& query, bool assert_ok = true) {
226226
Future prepare_future = cass_session_prepare(get(), query.c_str());
227227
prepare_future.wait(assert_ok);
228-
return Prepared(cass_future_get_prepared(prepare_future.get()));
228+
return Prepared(prepare_future);
229229
}
230230

231231
/**
@@ -240,7 +240,7 @@ class Session : public Object<CassSession, cass_session_free> {
240240
Prepared prepare_from_existing(Statement statement, bool assert_ok = true) {
241241
Future prepare_future = cass_session_prepare_from_existing(get(), statement.get());
242242
prepare_future.wait(assert_ok);
243-
return Prepared(cass_future_get_prepared(prepare_future.get()));
243+
return Prepared(prepare_future);
244244
}
245245

246246
/**

cpp-driver/gtests/src/integration/objects/statement.hpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ class Statement : public Object<CassStatement, cass_statement_free> {
143143
}
144144

145145
/**
146-
* Sets the statement's keyspace for use with token-aware routing.
146+
* Sets the statement's keyspace
147147
*
148-
* @param keyspace Keyspace to aid in token aware routing for statement
148+
* @param keyspace Keyspace to use when executing the statement
149149
*/
150150
void set_keyspace(const std::string& keyspace) {
151151
ASSERT_EQ(CASS_OK, cass_statement_set_keyspace(get(), keyspace.c_str()));
@@ -342,6 +342,15 @@ class Batch : public Object<CassBatch, cass_batch_free> {
342342
void set_serial_consistency(CassConsistency serial_consistency) {
343343
ASSERT_EQ(CASS_OK, cass_batch_set_serial_consistency(get(), serial_consistency));
344344
}
345+
346+
/**
347+
* Sets the batch's keyspace
348+
*
349+
* @param keyspace Keyspace to use when executing the batch
350+
*/
351+
void set_keyspace(const std::string& keyspace) {
352+
ASSERT_EQ(CASS_OK, cass_batch_set_keyspace(get(), keyspace.c_str()));
353+
}
345354
};
346355

347356
}} // namespace test::driver

0 commit comments

Comments
 (0)