From 658ebb0d3edd11db06ef7f2847431e5f737c7553 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Uzarski?= Date: Tue, 10 Dec 2024 20:29:55 +0100 Subject: [PATCH] IT: add test cases for interleaving by name and by index bindings --- tests/src/integration/tests/test_by_name.cpp | 66 ++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tests/src/integration/tests/test_by_name.cpp b/tests/src/integration/tests/test_by_name.cpp index 56735780..af1f5a14 100644 --- a/tests/src/integration/tests/test_by_name.cpp +++ b/tests/src/integration/tests/test_by_name.cpp @@ -111,6 +111,36 @@ class ByNameTests : public Integration { ASSERT_EQ(Float(3.3f), row.column_by_name("\"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("key", key); + statement.bind(1, Float(0.0f)); + // This should overwrite the previous value. Thus bound_values[1] = 1.1f. + statement.bind("\"abc\"", Float(1.1f)); + statement.bind("\"ABC\"", Float(2.2f)); + statement.bind("\"aBc\"", Float(3.3f)); + // This should overwrite the previous value. + // Thus, bound_values[name_to_bound_index["aBc"]] = 4.4f. + statement.bind(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("key")); + ASSERT_EQ(Float(1.1f), row.column_by_name("\"abc\"")); + ASSERT_EQ(Float(2.2f), row.column_by_name("\"ABC\"")); + ASSERT_EQ(Float(4.4f), row.column_by_name("\"aBc\"")); + } + /** * Insert all values into the table * @@ -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