language-extensions/R/test/src/RExtensionGetOutputParamTests.cpp
//----------------------------------------------------------------------------------------------
// Name: GetCharOutputParamTest
//
// Description:
//  Tests multiple character values.
//
GetCharOutputParamTest
Description:
Tests multiple character values.
GetCharOutputParamTest Description : Tests multiple character values .
TEST_F(RExtensionApiTests, GetCharOutputParamTest)
	{
		int paramsNumber = 6;
		string scriptString = "param1 <- 'HELLO';"
			"param2 <- 'RExtension';"
			"param3 <- '';"
			"param4 <- 'WORLD';"
			"param5 <- as.character(NA);"
			"param6 <- as.character();";
		InitializeSession(
			0,    inputSchemaColumnsNumber
			scriptString,
			paramsNumber);
		vector<const char*> initParamValues(paramsNumber, "");
		vector<SQLULEN> paramSizes = { 5, 6, 5, 10, 5, 5 };
		 Note: The behavior of fixed and varying character types is same when it comes to output
		 parameters. So it doesn't matter if we initialize these output parameters as fixed type.
		vector<bool> isFixedType = { true, false, true, false, true, true };
		vector<SQLSMALLINT> inputOutputTypes(paramsNumber, SQL_PARAM_INPUT_OUTPUT);
		InitCharParam<char, SQL_C_CHAR>(
			initParamValues,
			paramSizes,
			isFixedType,
			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);
		const vector<string> ExpectedParamValueStrings = {
			 Test simple CHAR(5) value with exact string length as the type allows i.e. here 5.
			"HELLO",
			 Test VARCHAR(6) value with string length more than the type allows - expected truncation.
			 Above R script sets the parameter to "RExtension" but we only expect "RExten".
			"RExten",
			 Test a 0 length string
			"",
			 Test CHAR(10) value with string length less than the type allows.
			"WORLD"};
		vector<SQLCHAR*> expectedParamValues = {
			static_cast<SQLCHAR*>(
				static_cast<void*>(const_cast<char *>(ExpectedParamValueStrings[0].c_str()))),
			static_cast<SQLCHAR*>(
				static_cast<void*>(const_cast<char *>(ExpectedParamValueStrings[1].c_str()))),
			static_cast<SQLCHAR*>(
				static_cast<void*>(const_cast<char *>(ExpectedParamValueStrings[2].c_str()))),
			static_cast<SQLCHAR*>(
				static_cast<void*>(const_cast<char *>(ExpectedParamValueStrings[3].c_str()))),
			 Test NA returned in a VARCHAR(5) parameter.
			nullptr,
			 Test nullptr CHAR(5) value.
			nullptr };
		vector<SQLINTEGER> expectedStrLenOrInd = {
			static_cast<SQLINTEGER>(ExpectedParamValueStrings[0].length()),
			static_cast<SQLINTEGER>(ExpectedParamValueStrings[1].length()),
			static_cast<SQLINTEGER>(ExpectedParamValueStrings[2].length()),
			static_cast<SQLINTEGER>(ExpectedParamValueStrings[3].length()),
			SQL_NULL_DATA,
			SQL_NULL_DATA};
		GetCharOutputParam(
			expectedParamValues,
			expectedStrLenOrInd);
	}
TEST_F ( RExtensionApiTests , GetCharOutputParamTest ) { int paramsNumber = 6 ; string scriptString = " " " " " " " " " " " " ; InitializeSession ( 0 , scriptString , paramsNumber ) ; vector < const char * > initParamValues ( paramsNumber , " " ) ; vector < SQLULEN > paramSizes = { 5 , 6 , 5 , 10 , 5 , 5 } ; vector < bool > isFixedType = { true , false , true , false , true , true } ; vector < SQLSMALLINT > inputOutputTypes ( paramsNumber , SQL_PARAM_INPUT_OUTPUT ) ; InitCharParam < char , SQL_C_CHAR > ( initParamValues , paramSizes , isFixedType , 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 ) ; const vector < string > ExpectedParamValueStrings = { " " , " " , " " , " " } ; vector < SQLCHAR * > expectedParamValues = { static_cast < SQLCHAR * > ( static_cast < void * > ( const_cast < char * > ( ExpectedParamValueStrings [ 0 ] . c_str ( ) ) ) ) , static_cast < SQLCHAR * > ( static_cast < void * > ( const_cast < char * > ( ExpectedParamValueStrings [ 1 ] . c_str ( ) ) ) ) , static_cast < SQLCHAR * > ( static_cast < void * > ( const_cast < char * > ( ExpectedParamValueStrings [ 2 ] . c_str ( ) ) ) ) , static_cast < SQLCHAR * > ( static_cast < void * > ( const_cast < char * > ( ExpectedParamValueStrings [ 3 ] . c_str ( ) ) ) ) , nullptr , nullptr } ; vector < SQLINTEGER > expectedStrLenOrInd = { static_cast < SQLINTEGER > ( ExpectedParamValueStrings [ 0 ] . length ( ) ) , static_cast < SQLINTEGER > ( ExpectedParamValueStrings [ 1 ] . length ( ) ) , static_cast < SQLINTEGER > ( ExpectedParamValueStrings [ 2 ] . length ( ) ) , static_cast < SQLINTEGER > ( ExpectedParamValueStrings [ 3 ] . length ( ) ) , SQL_NULL_DATA , SQL_NULL_DATA } ; GetCharOutputParam ( expectedParamValues , expectedStrLenOrInd ) ; }
Name: GetCharOutputParamTest
Description:
Tests multiple character values.
Name : GetCharOutputParamTest Description : Tests multiple character values .
// Initialize with a Session that executes the above script // that sets output parameters. // // inputSchemaColumnsNumber // Note: The behavior of fixed and varying character types is same when it comes to output // parameters. So it doesn't matter if we initialize these output parameters as fixed type. // // validate // rowsNumber // dataSet // strLen_or_Ind // Test simple CHAR(5) value with exact string length as the type allows i.e. here 5. // // Test VARCHAR(6) value with string length more than the type allows - expected truncation. // Above R script sets the parameter to "RExtension" but we only expect "RExten". // // Test a 0 length string // // Test CHAR(10) value with string length less than the type allows. // // Test NA returned in a VARCHAR(5) parameter. // // Test nullptr CHAR(5) value. //