Skip to content

Commit

Permalink
Merge pull request #5 from jcralmeida/testing-attribute
Browse files Browse the repository at this point in the history
Testing attribute
  • Loading branch information
Rafael Telles authored Nov 18, 2021
2 parents d64c5b3 + 05d5430 commit 04d2afc
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ add_executable(flight_odbc_driver main.cpp
flight_sql/FlightSqlConnection.cpp flight_sql/FlightSqlConnection.h)
target_link_libraries(flight_odbc_driver ${ODBC_LIBRARIES} arrow_static arrow_flight arrow_flight_sql )

add_executable(odbc_test flight_sql/FlightConnectionTest.cpp)
add_executable(odbc_test connection.cpp flight_sql/FlightConnectionTest.cpp flight_sql/FlightSqlDriver.cpp flight_sql/FlightSqlDriver.h
flight_sql/FlightSqlConnection.cpp)

target_link_libraries(odbc_test GTest::gtest GTest::gtest_main)
target_link_libraries(odbc_test GTest::gtest GTest::gtest_main arrow_static arrow_flight arrow_flight_sql)

add_test(connection_test odbc_test)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <map>
#include <vector>
#include <boost/variant.hpp>
#include <boost/optional.hpp>
#include "statement.h"

#pragma once
Expand Down Expand Up @@ -75,7 +76,7 @@ class Connection {
* @param attribute
* @return
*/
virtual Attribute GetAttribute(AttributeId attribute) = 0;
virtual boost::optional<Connection::Attribute> GetAttribute(Connection::AttributeId attribute) = 0;

virtual Info GetInfo(uint16_t info_type) = 0;
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,37 @@
#include "gtest/gtest.h"
#include "FlightSqlDriver.h"

TEST(AttributeTests, SetAndGetAttribute) {
FlightSqlDriver driver;

#include "gtest/gtest.h"
const std::shared_ptr<Connection> &connection = driver.CreateConnection();

connection->SetAttribute(Connection::CONNECTION_TIMEOUT, 200);
const boost::optional<Connection::Attribute> firstValue = connection->GetAttribute(
Connection::CONNECTION_TIMEOUT);

EXPECT_TRUE(firstValue.has_value());

EXPECT_EQ(boost::get<int>(firstValue.value()), 200);

connection->SetAttribute(Connection::CONNECTION_TIMEOUT, 300);

const boost::optional<Connection::Attribute> changeValue = connection->GetAttribute(
Connection::CONNECTION_TIMEOUT);

EXPECT_TRUE(changeValue.has_value());
EXPECT_EQ(boost::get<int>(changeValue.value()), 300);
}

TEST(AttributeTests, GetAttributeWithoutSetting) {
FlightSqlDriver driver;

const std::shared_ptr<Connection> &connection = driver.CreateConnection();

const boost::optional<Connection::Attribute> anOptional = connection->GetAttribute(
Connection::CONNECTION_TIMEOUT);

bool b = anOptional.has_value();

TEST(test1, test1) {
EXPECT_EQ(1, 1);
EXPECT_FALSE(b);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "FlightSqlConnection.h"
#include <boost/optional.hpp>

using arrow::Status;
using arrow::Result;
Expand Down Expand Up @@ -57,11 +58,12 @@ std::shared_ptr<Statement> FlightSqlConnection::CreateStatement() {
}

void FlightSqlConnection::SetAttribute(Connection::AttributeId attribute, const Connection::Attribute &value) {
attribute_.insert({attribute, value});
attribute_[attribute] = value;
}

Connection::Attribute FlightSqlConnection::GetAttribute(Connection::AttributeId attribute) {
return attribute_.find(attribute) -> second;
boost::optional<Connection::Attribute>
FlightSqlConnection::GetAttribute(Connection::AttributeId attribute) {
return boost::make_optional(attribute_.count(attribute), attribute_.find(attribute) -> second);
}

Connection::Info FlightSqlConnection::GetInfo(uint16_t info_type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class FlightSqlConnection: public Connection {

void SetAttribute(AttributeId attribute, const Attribute &value) override;

Attribute GetAttribute(AttributeId attribute) override;
boost::optional<Connection::Attribute> GetAttribute(Connection::AttributeId attribute) override;

Info GetInfo(uint16_t info_type) override;
};

0 comments on commit 04d2afc

Please sign in to comment.