language-extensions/R/test/src/RExtensionGetOutputParamTests.cpp
//----------------------------------------------------------------------------------------------
// Name: GetTinyIntOutputParamTest
//
// Description:
//  Tests multiple tiny int values.
//
GetTinyIntOutputParamTest
Description:
Tests multiple tiny int values.
GetTinyIntOutputParamTest Description : Tests multiple tiny int values .
TEST_F(RExtensionApiTests, GetTinyIntOutputParamTest)
	{
		string scriptString = "param1 <- as.integer(" + to_string(m_MaxTinyInt) + ");"
			"param2 <- as.integer(" + to_string(m_MinTinyInt) + ");"
			"param3 <- as.integer(123);"
			"param4 <- as.integer(NA);"
			"param5 <- as.integer();"
			"param6 <- as.integer(-1)";
		InitializeSession(
			0,    inputSchemaColumnsNumber
			scriptString,
			6);   parametersNumber
		vector<shared_ptr<SQLCHAR>> initParamValues = {
			make_shared<SQLCHAR>(0),
			make_shared<SQLCHAR>(0),
			make_shared<SQLCHAR>(0),
			make_shared<SQLCHAR>(0),
			nullptr,
			make_shared<SQLCHAR>(0)};
		vector<SQLINTEGER> strLenOrInd = { 0, 0, 0, 0, SQL_NULL_DATA, 0 };
		vector<SQLSMALLINT> inputOutputTypes(initParamValues.size(), SQL_PARAM_INPUT_OUTPUT);
		InitParam<SQLCHAR, Rcpp::IntegerVector, SQL_C_UTINYINT>(
			initParamValues,
			strLenOrInd,
			inputOutputTypes,
			false);   validate
		SQLUSMALLINT outputSchemaColumnsNumber = 0;
		SQLRETURN result = (*sm_executeFuncPtr)(
			*m_sessionId,
			m_taskId,
			0,        rowsNumber
			nullptr,  dataSet
			nullptr,  strLen_or_Ind
			&outputSchemaColumnsNumber);
		ASSERT_EQ(result, SQL_SUCCESS);
		EXPECT_EQ(outputSchemaColumnsNumber, 0);
		 Test max, min, normal, NA, NULL, (-1) overflowing to max TINYINT values
		vector<shared_ptr<SQLCHAR>> expectedParamValues = {
			make_shared<SQLCHAR>(m_MaxTinyInt),
			make_shared<SQLCHAR>(m_MinTinyInt),
			make_shared<SQLCHAR>(123),
			 When value is NA, expectedParamValue is type casted to '\0'.
			 even though in R it is NA_INTEGER which is larger than what SQLCHAR can hold.
			make_shared<SQLCHAR>('\0'),
			nullptr,
			make_shared<SQLCHAR>(m_MaxTinyInt)};
		vector<SQLINTEGER> expectedStrLenOrInd = { m_TinyIntSize, m_TinyIntSize, m_TinyIntSize,
			SQL_NULL_DATA, SQL_NULL_DATA, m_TinyIntSize };
		GetOutputParam<SQLCHAR>(
			expectedParamValues,
			expectedStrLenOrInd);
	}
TEST_F ( RExtensionApiTests , GetTinyIntOutputParamTest ) { string scriptString = " " + to_string ( m_MaxTinyInt ) + " " " " + to_string ( m_MinTinyInt ) + " " " " " " " " " " ; InitializeSession ( 0 , scriptString , 6 ) ; vector < shared_ptr < SQLCHAR > > initParamValues = { make_shared < SQLCHAR > ( 0 ) , make_shared < SQLCHAR > ( 0 ) , make_shared < SQLCHAR > ( 0 ) , make_shared < SQLCHAR > ( 0 ) , nullptr , make_shared < SQLCHAR > ( 0 ) } ; vector < SQLINTEGER > strLenOrInd = { 0 , 0 , 0 , 0 , SQL_NULL_DATA , 0 } ; vector < SQLSMALLINT > inputOutputTypes ( initParamValues . size ( ) , SQL_PARAM_INPUT_OUTPUT ) ; InitParam < SQLCHAR , Rcpp :: IntegerVector , SQL_C_UTINYINT > ( initParamValues , strLenOrInd , inputOutputTypes , false ) ; SQLUSMALLINT outputSchemaColumnsNumber = 0 ; SQLRETURN result = ( * sm_executeFuncPtr ) ( * m_sessionId , m_taskId , 0 , nullptr , nullptr , & outputSchemaColumnsNumber ) ; ASSERT_EQ ( result , SQL_SUCCESS ) ; EXPECT_EQ ( outputSchemaColumnsNumber , 0 ) ; vector < shared_ptr < SQLCHAR > > expectedParamValues = { make_shared < SQLCHAR > ( m_MaxTinyInt ) , make_shared < SQLCHAR > ( m_MinTinyInt ) , make_shared < SQLCHAR > ( 123 ) , make_shared < SQLCHAR > ( ' \0 ' ) , nullptr , make_shared < SQLCHAR > ( m_MaxTinyInt ) } ; vector < SQLINTEGER > expectedStrLenOrInd = { m_TinyIntSize , m_TinyIntSize , m_TinyIntSize , SQL_NULL_DATA , SQL_NULL_DATA , m_TinyIntSize } ; GetOutputParam < SQLCHAR > ( expectedParamValues , expectedStrLenOrInd ) ; }
Name: GetTinyIntOutputParamTest
Description:
Tests multiple tiny int values.
Name : GetTinyIntOutputParamTest Description : Tests multiple tiny int values .
// Initialize with a Session that executes the above script // that sets output parameters. // // inputSchemaColumnsNumber // parametersNumber // validate // rowsNumber // dataSet // strLen_or_Ind // Test max, min, normal, NA, NULL, (-1) overflowing to max TINYINT values // // When value is NA, expectedParamValue is type casted to '\0'. // even though in R it is NA_INTEGER which is larger than what SQLCHAR can hold. //