language-extensions/R/test/src/RExtensionGetOutputParamTests.cpp
//----------------------------------------------------------------------------------------------
// Name: GetSmallIntOutputParamTest
//
// Description:
//  Tests multiple small int values.
//
GetSmallIntOutputParamTest
Description:
Tests multiple small int values.
GetSmallIntOutputParamTest Description : Tests multiple small int values .
TEST_F(RExtensionApiTests, GetSmallIntOutputParamTest)
	{
		string scriptString = "param1 <- as.integer(" + to_string(m_MaxSmallInt) + ");"
			"param2 <- as.integer(" + to_string(m_MinSmallInt) + ");"
			"param3 <- as.integer(0);"
			"param4 <- as.integer(NA);"
			"param5 <- as.integer()";
		InitializeSession(
			0,    inputSchemaColumnsNumber
			scriptString,
			5);   parametersNumber
		vector<shared_ptr<SQLSMALLINT>> initParamValues = {
			make_shared<SQLSMALLINT>(0),
			make_shared<SQLSMALLINT>(0),
			make_shared<SQLSMALLINT>(0),
			make_shared<SQLSMALLINT>(0),
			nullptr };
		vector<SQLINTEGER> strLenOrInd = { 0, 0, 0, 0, SQL_NULL_DATA};
		vector<SQLSMALLINT> inputOutputTypes(initParamValues.size(), SQL_PARAM_INPUT_OUTPUT);
		InitParam<SQLSMALLINT, Rcpp::IntegerVector, SQL_C_SSHORT>(
			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_INTEGER and NULL SMALLINT values
		vector<shared_ptr<SQLSMALLINT>> expectedParamValues = {
			make_shared<SQLSMALLINT>(m_MaxSmallInt),
			make_shared<SQLSMALLINT>(m_MinSmallInt),
			make_shared<SQLSMALLINT>(0),
			 Since NA_INTEGER in R is a bigger value than the type SQLSMALLINT can hold,
			 static type casting leads to a 0 value. But this is differentiated by SQL_NULL_DATA.
			make_shared<SQLSMALLINT>(0),
			nullptr };
		vector<SQLINTEGER> expectedStrLenOrInd = { m_SmallIntSize, m_SmallIntSize, m_SmallIntSize,
			SQL_NULL_DATA, SQL_NULL_DATA};
		GetOutputParam<SQLSMALLINT>(
			expectedParamValues,
			expectedStrLenOrInd);
	}
TEST_F ( RExtensionApiTests , GetSmallIntOutputParamTest ) { string scriptString = " " + to_string ( m_MaxSmallInt ) + " " " " + to_string ( m_MinSmallInt ) + " " " " " " " " ; InitializeSession ( 0 , scriptString , 5 ) ; vector < shared_ptr < SQLSMALLINT > > initParamValues = { make_shared < SQLSMALLINT > ( 0 ) , make_shared < SQLSMALLINT > ( 0 ) , make_shared < SQLSMALLINT > ( 0 ) , make_shared < SQLSMALLINT > ( 0 ) , nullptr } ; vector < SQLINTEGER > strLenOrInd = { 0 , 0 , 0 , 0 , SQL_NULL_DATA } ; vector < SQLSMALLINT > inputOutputTypes ( initParamValues . size ( ) , SQL_PARAM_INPUT_OUTPUT ) ; InitParam < SQLSMALLINT , Rcpp :: IntegerVector , SQL_C_SSHORT > ( 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 < SQLSMALLINT > > expectedParamValues = { make_shared < SQLSMALLINT > ( m_MaxSmallInt ) , make_shared < SQLSMALLINT > ( m_MinSmallInt ) , make_shared < SQLSMALLINT > ( 0 ) , make_shared < SQLSMALLINT > ( 0 ) , nullptr } ; vector < SQLINTEGER > expectedStrLenOrInd = { m_SmallIntSize , m_SmallIntSize , m_SmallIntSize , SQL_NULL_DATA , SQL_NULL_DATA } ; GetOutputParam < SQLSMALLINT > ( expectedParamValues , expectedStrLenOrInd ) ; }
Name: GetSmallIntOutputParamTest
Description:
Tests multiple small int values.
Name : GetSmallIntOutputParamTest Description : Tests multiple small 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_INTEGER and NULL SMALLINT values // // Since NA_INTEGER in R is a bigger value than the type SQLSMALLINT can hold, // static type casting leads to a 0 value. But this is differentiated by SQL_NULL_DATA. //