Esempio n. 1
0
TEST(TimeHelpersTest, DateToDaysForYear4000)
{
    SQL_DATE_STRUCT data = {4000, 01, 02};
    // expectation generated by http://www.convertunits.com/dates/from/Jan+1,+1970/to/Jan+2,+4000
    std::int64_t expected = 741443;
    EXPECT_EQ(expected, date_to_days(reinterpret_cast<char const *>(&data)));
}
Esempio n. 2
0
TEST(TimeHelpersTest, TimestampToMicrosecondsForYear4000)
{
    SQL_TIMESTAMP_STRUCT data = {4000, 01, 02, 3, 4, 5, 123456000};
    // expectation generated by unixtimestamp.com
    std::int64_t expected = 64060686245 * 1000000 + 123456;
    EXPECT_EQ(expected, timestamp_to_microseconds(reinterpret_cast<char const *>(&data)));
}
Esempio n. 3
0
TEST(TimeHelpersTest, DaysToDateForEpoch)
{
    std::int64_t const days = 0;
    SQL_TIMESTAMP_STRUCT ts;
    days_to_date(days, reinterpret_cast<char *>(&ts));
    EXPECT_EQ(1970, ts.year);
    EXPECT_EQ(1, ts.month);
    EXPECT_EQ(1, ts.day);
}
TEST(MakeDescriptionOfDescriptionTest, TimestampTypes)
{
	SQLSMALLINT const type = SQL_TYPE_TIMESTAMP;

	cpp_odbc::column_description column_description = {name, type, 0, 0, supports_null_values};
	auto const description = make_description(column_description);
	ASSERT_TRUE(dynamic_cast<turbodbc::timestamp_description const *>(description.get()));
	assert_custom_name_and_nullable_support(*description);
}
TEST(MakeDescriptionOfTypeTest, FromUnicodeProvidesExtraSpaceForLargeStrings)
{
	std::string large_string("this is a relatively large string");
	auto description = make_description(type_code::unicode, large_string.size());
	auto as_unicode_description = dynamic_cast<turbodbc::unicode_description const *>(description.get());
	ASSERT_TRUE( as_unicode_description != nullptr );

	EXPECT_GT(as_unicode_description->element_size(), 2 * (large_string.size() + 1));
}
TEST(MakeDescriptionOfDescriptionTest, BitType)
{
	SQLSMALLINT const type = SQL_BIT;

	cpp_odbc::column_description column_description = {name, type, 0, 0, supports_null_values};
	auto const description = make_description(column_description);
	ASSERT_TRUE(dynamic_cast<turbodbc::boolean_description const *>(description.get()));
	assert_custom_name_and_nullable_support(*description);
}
Esempio n. 7
0
TEST(TimeHelpersTest, DaysToDateForYear4000)
{
    // generated by http://www.convertunits.com/dates/from/Jan+1,+1970/to/Jan+2,+4000
    std::int64_t const days = 741443;
    SQL_TIMESTAMP_STRUCT ts;
    days_to_date(days, reinterpret_cast<char *>(&ts));
    EXPECT_EQ(4000, ts.year);
    EXPECT_EQ(1, ts.month);
    EXPECT_EQ(2, ts.day);
}
TEST(MakeDescriptionOfTypeTest, FromUnicodeProvidesMinimumLength)
{
	std::size_t const small_size = 2;
	auto description = make_description(type_code::unicode, small_size);
	auto as_unicode_description = dynamic_cast<turbodbc::unicode_description const *>(description.get());
	ASSERT_TRUE( as_unicode_description != nullptr );

	std::size_t const minimum_length = 10;
	EXPECT_EQ(as_unicode_description->element_size(), 2 * (minimum_length + 1));
}
Esempio n. 9
0
TEST(TimeHelpersTest, NanosecondsToTimestampForEpoch)
{
    std::int64_t const nanoseconds = 0;
    SQL_TIMESTAMP_STRUCT ts;
    nanoseconds_to_timestamp(nanoseconds, reinterpret_cast<char *>(&ts));
    EXPECT_EQ(1970, ts.year);
    EXPECT_EQ(1, ts.month);
    EXPECT_EQ(1, ts.day);
    EXPECT_EQ(0, ts.hour);
    EXPECT_EQ(0, ts.minute);
    EXPECT_EQ(0, ts.second);
    EXPECT_EQ(0, ts.fraction);
}
Esempio n. 10
0
TEST(TimeHelpersTest, NanosecondsToTimestampForYear2200)
{
    // generated by unixtimestamp.com
    std::int64_t const nanoseconds = 7258215845 * 1000000000 + 123456789;
    SQL_TIMESTAMP_STRUCT ts;
    nanoseconds_to_timestamp(nanoseconds, reinterpret_cast<char *>(&ts));
    EXPECT_EQ(2200, ts.year);
    EXPECT_EQ(1, ts.month);
    EXPECT_EQ(2, ts.day);
    EXPECT_EQ(3, ts.hour);
    EXPECT_EQ(4, ts.minute);
    EXPECT_EQ(5, ts.second);
    EXPECT_EQ(123456789, ts.fraction);
}
Esempio n. 11
0
TEST(TimeHelpersTest, MicrosecondsToTimestampForYear4000)
{
    // generated by unixtimestamp.com
    std::int64_t const microseconds = 64060686245 * 1000000 + 123456;
    SQL_TIMESTAMP_STRUCT ts;
    microseconds_to_timestamp(microseconds, reinterpret_cast<char *>(&ts));
    EXPECT_EQ(4000, ts.year);
    EXPECT_EQ(1, ts.month);
    EXPECT_EQ(2, ts.day);
    EXPECT_EQ(3, ts.hour);
    EXPECT_EQ(4, ts.minute);
    EXPECT_EQ(5, ts.second);
    EXPECT_EQ(123456000, ts.fraction);
}
Esempio n. 12
0
TEST(TimeHelpersTest, DateToDaysForEpoch)
{
    SQL_DATE_STRUCT data = {1970, 01, 01};
    EXPECT_EQ(0, date_to_days(reinterpret_cast<char const *>(&data)));
}
Esempio n. 13
0
TEST(TimeHelpersTest, TimestampToMicrosecondsForEpoch)
{
    SQL_TIMESTAMP_STRUCT data = {1970, 01, 01, 0, 0, 0, 0};
    EXPECT_EQ(0, timestamp_to_microseconds(reinterpret_cast<char const *>(&data)));
}
TEST(MakeDescriptionOfTypeTest, FromTimestamp)
{
	auto description = make_description(type_code::timestamp, size_not_important);
	ASSERT_TRUE( dynamic_cast<turbodbc::timestamp_description const *>(description.get()) );
}
TEST(MakeDescriptionOfTypeTest, FromBool)
{
	auto description = make_description(type_code::boolean, size_not_important);
	ASSERT_TRUE( dynamic_cast<turbodbc::boolean_description const *>(description.get()) );
}
TEST(MakeDescriptionOfTypeTest, FromDouble)
{
	auto description = make_description(type_code::floating_point, size_not_important);
	ASSERT_TRUE( dynamic_cast<turbodbc::floating_point_description const *>(description.get()) );
}