Skip to content

Commit

Permalink
IT: add test cases for interleaving by name and by index bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
muzarski committed Dec 10, 2024
1 parent 90b157d commit 658ebb0
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions tests/src/integration/tests/test_by_name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,36 @@ class ByNameTests : public Integration {
ASSERT_EQ(Float(3.3f), row.column_by_name<Float>("\"aBc\""));
}

/**
* Insert and validate
*
* @param statement Insert statement to use (case sensitive format)
*/
void insert_and_validate_interleaving(Statement statement) {
// Insert values into the table by name
TimeUuid key = uuid_generator_.generate_timeuuid();
statement.bind<TimeUuid>("key", key);
statement.bind<Float>(1, Float(0.0f));
// This should overwrite the previous value. Thus bound_values[1] = 1.1f.
statement.bind<Float>("\"abc\"", Float(1.1f));
statement.bind<Float>("\"ABC\"", Float(2.2f));
statement.bind<Float>("\"aBc\"", Float(3.3f));
// This should overwrite the previous value.
// Thus, bound_values[name_to_bound_index["aBc"]] = 4.4f.
statement.bind<Float>(3, Float(4.4f));
session_.execute(statement);

// Validate the inserts into the table
Result result = session_.execute(default_select_all());
ASSERT_EQ(1u, result.row_count());
ASSERT_EQ(7u, result.column_count());
Row row = result.first_row();
ASSERT_EQ(key, row.column_by_name<TimeUuid>("key"));
ASSERT_EQ(Float(1.1f), row.column_by_name<Float>("\"abc\""));
ASSERT_EQ(Float(2.2f), row.column_by_name<Float>("\"ABC\""));
ASSERT_EQ(Float(4.4f), row.column_by_name<Float>("\"aBc\""));
}

/**
* Insert all values into the table
*
Expand Down Expand Up @@ -294,6 +324,42 @@ CASSANDRA_INTEGRATION_TEST_F(ByNameTests, SimpleCaseSensitive) {
insert_and_validate_case_sensitive(statement);
}

/**
* Perform interleaving `by name` and `by index` binding
* using a prepared statement and validate
*
* @test_category queries:prepared
* @since core:1.0.0
* @expected_result Cassandra values are inserted using
* interleaving by name and by index bindng and validated
*/
CASSANDRA_INTEGRATION_TEST_F(ByNameTests, PreparedInterleaving) {
CHECK_FAILURE;

// Prepare, create, insert and validate
Prepared prepared =
session_.prepare(format_string(INSERT_CASE_SENSITIVE_FORMAT, table_name_.c_str()));
insert_and_validate_interleaving(prepared.bind());
}

/**
* Perform interleaving `by name` and `by index` binding
* using a simple statement and validate
*
* @test_category queries:basic
* @since core:2.1.0
* @expected_result Cassandra values are inserted using
* interleaving by name and by index bindng and validated
*/
CASSANDRA_INTEGRATION_TEST_F(ByNameTests, SimpleInterleaving) {
CHECK_FAILURE;
SKIP_IF_CASSANDRA_VERSION_LT(2.1.0);

// Prepare, create, insert and validate
Statement statement(format_string(INSERT_CASE_SENSITIVE_FORMAT, table_name_.c_str()), 4);
insert_and_validate_interleaving(statement);
}

/**
* Perform `by name` references using a prepared statement to insert multiple
* value and validate
Expand Down

0 comments on commit 658ebb0

Please sign in to comment.