From 51982921651734c23cbabf0cbcb166308fafd95d Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Wed, 1 Apr 2015 21:03:16 +0300 Subject: [PATCH] tests: add function call test Test now() function. --- tests/urchin/cql_query_test.cc | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/urchin/cql_query_test.cc b/tests/urchin/cql_query_test.cc index 589a329c9f..086a40f045 100644 --- a/tests/urchin/cql_query_test.cc +++ b/tests/urchin/cql_query_test.cc @@ -10,6 +10,8 @@ #include "tests/urchin/cql_test_env.hh" #include "tests/urchin/cql_assertions.hh" #include "to_string.hh" +#include +#include SEASTAR_TEST_CASE(test_create_keyspace_statement) { return do_with_cql_env([] (auto& e) { @@ -601,3 +603,42 @@ SEASTAR_TEST_CASE(test_list_insert_update) { }); }); } + +SEASTAR_TEST_CASE(test_functions) { + return do_with_cql_env([] (auto&& e) { + return e.create_table([](auto ks_name) { + // CQL: create table cf (p1 varchar primary key, u uuid, tu timeuuid); + return schema(ks_name, "cf", + {{"p1", utf8_type}}, {{"c1", int32_type}}, {{"tu", timeuuid_type}}, {}, utf8_type); + }).then([&e] { + return e.execute_cql("insert into cf (p1, c1, tu) values ('key1', 1, now());").discard_result(); + }).then([&e] { + return e.execute_cql("insert into cf (p1, c1, tu) values ('key1', 2, now());").discard_result(); + }).then([&e] { + return e.execute_cql("insert into cf (p1, c1, tu) values ('key1', 3, now());").discard_result(); + }).then([&e] { + return e.execute_cql("select tu from cf where p1 in ('key1');"); + }).then([&e] (shared_ptr msg) { + using namespace transport::messages; + struct validator : result_message::visitor { + std::vector res; + virtual void visit(const result_message::void_message&) override { throw "bad"; } + virtual void visit(const result_message::set_keyspace&) override { throw "bad"; } + virtual void visit(const result_message::prepared&) override { throw "bad"; } + virtual void visit(const result_message::schema_change&) override { throw "bad"; } + virtual void visit(const result_message::rows& rows) override { + BOOST_REQUIRE_EQUAL(rows.rs().rows().size(), 3); + for (auto&& rw : rows.rs().rows()) { + BOOST_REQUIRE_EQUAL(rw.size(), 1); + res.push_back(rw[0]); + } + } + }; + validator v; + msg->accept(v); + // No boost::adaptors::sorted + boost::sort(v.res); + BOOST_REQUIRE_EQUAL(boost::distance(v.res | boost::adaptors::uniqued), 3); + }); + }); +}