language-extensions/R/test/src/RExtensionGetOutputParamTests.cpp
//----------------------------------------------------------------------------------------------
// Name: GetRawOutputParamTest
//
// Description:
//  Tests multiple binary values.
//
GetRawOutputParamTest
Description:
Tests multiple binary values.
GetRawOutputParamTest Description : Tests multiple binary values .
TEST_F(RExtensionApiTests, GetRawOutputParamTest)
	{
		string scriptString = "param1 <- c(as.raw(0x00), as.raw(0x01), as.raw(0xe2), as.raw(0x40));"
			"param2 <- charToRaw(paste(letters[1:10], collapse=''));"
			"param3 <- c(as.raw(0x01), as.raw(0x3f));"
			"param4 <- as.raw(NA);"
			"param5 <- raw()";
		InitializeSession(
			0,    inputSchemaColumnsNumber
			scriptString,
			5);   parametersNumber
		const vector<SQLCHAR> dummyValue = { };
		vector<SQLCHAR*> initParamValues(5, const_cast<SQLCHAR*>(dummyValue.data()));
		vector<SQLINTEGER> strLenOrInd(5, static_cast<SQLINTEGER>(dummyValue.size())/m_BinarySize);
		vector<SQLULEN> paramSizes = { 4, 5, 10, 5, 5 };
		vector<SQLSMALLINT> inputOutputTypes(initParamValues.size(), SQL_PARAM_INPUT_OUTPUT);
		InitRawParam(
			initParamValues,
			strLenOrInd,
			paramSizes,
			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 binary(4) value - binary length matching with type.
		const vector<SQLCHAR> BinaryValue1 = { 0x00, 0x01, 0xe2, 0x40 };
		 Test VARBINARY(5) value with length more than the type allows - expected truncation.
		 Above R script sets the parameter to 10 raw chars but we only expect 5.
		const vector<SQLCHAR> BinaryValue2 = { 0x61, 0x62, 0x63, 0x64, 0x65 };
		 Test BINARY(10) value with length less than the type allows.
		const vector<SQLCHAR> BinaryValue3 = { 0x01, 0x3f };
		 Test as.raw(NA) value returned as 00 in a VARBINARY(5) parameter.
		const vector<SQLCHAR> BinaryValue4 = { 0x00 };
		vector<SQLCHAR*> expectedParamValues = {
			const_cast<SQLCHAR*>(BinaryValue1.data()),
			const_cast<SQLCHAR*>(BinaryValue2.data()),
			const_cast<SQLCHAR*>(BinaryValue3.data()),
			const_cast<SQLCHAR*>(BinaryValue4.data()),
			 Test NULL BINARY(5) value
			nullptr };
		vector<SQLINTEGER> expectedStrLenOrInd = {
			static_cast<SQLINTEGER>(BinaryValue1.size())/m_BinarySize,
			static_cast<SQLINTEGER>(BinaryValue2.size())/m_BinarySize,
			static_cast<SQLINTEGER>(BinaryValue3.size())/m_BinarySize,
			static_cast<SQLINTEGER>(BinaryValue4.size())/m_BinarySize,
			SQL_NULL_DATA };
		GetRawOutputParam(
			expectedParamValues,
			expectedStrLenOrInd);
	}
TEST_F ( RExtensionApiTests , GetRawOutputParamTest ) { string scriptString = " " " " " " " " " " ; InitializeSession ( 0 , scriptString , 5 ) ; const vector < SQLCHAR > dummyValue = { } ; vector < SQLCHAR * > initParamValues ( 5 , const_cast < SQLCHAR * > ( dummyValue . data ( ) ) ) ; vector < SQLINTEGER > strLenOrInd ( 5 , static_cast < SQLINTEGER > ( dummyValue . size ( ) ) / m_BinarySize ) ; vector < SQLULEN > paramSizes = { 4 , 5 , 10 , 5 , 5 } ; vector < SQLSMALLINT > inputOutputTypes ( initParamValues . size ( ) , SQL_PARAM_INPUT_OUTPUT ) ; InitRawParam ( initParamValues , strLenOrInd , paramSizes , 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 < SQLCHAR > BinaryValue1 = { 0x00 , 0x01 , 0xe2 , 0x40 } ; const vector < SQLCHAR > BinaryValue2 = { 0x61 , 0x62 , 0x63 , 0x64 , 0x65 } ; const vector < SQLCHAR > BinaryValue3 = { 0x01 , 0x3f } ; const vector < SQLCHAR > BinaryValue4 = { 0x00 } ; vector < SQLCHAR * > expectedParamValues = { const_cast < SQLCHAR * > ( BinaryValue1 . data ( ) ) , const_cast < SQLCHAR * > ( BinaryValue2 . data ( ) ) , const_cast < SQLCHAR * > ( BinaryValue3 . data ( ) ) , const_cast < SQLCHAR * > ( BinaryValue4 . data ( ) ) , nullptr } ; vector < SQLINTEGER > expectedStrLenOrInd = { static_cast < SQLINTEGER > ( BinaryValue1 . size ( ) ) / m_BinarySize , static_cast < SQLINTEGER > ( BinaryValue2 . size ( ) ) / m_BinarySize , static_cast < SQLINTEGER > ( BinaryValue3 . size ( ) ) / m_BinarySize , static_cast < SQLINTEGER > ( BinaryValue4 . size ( ) ) / m_BinarySize , SQL_NULL_DATA } ; GetRawOutputParam ( expectedParamValues , expectedStrLenOrInd ) ; }
Name: GetRawOutputParamTest
Description:
Tests multiple binary values.
Name : GetRawOutputParamTest Description : Tests multiple binary values .
// Initialize with a Session that executes the above script // that sets output parameters. // // inputSchemaColumnsNumber // parametersNumber // validate // rowsNumber // dataSet // strLen_or_Ind // Test binary(4) value - binary length matching with type. // // Test VARBINARY(5) value with length more than the type allows - expected truncation. // Above R script sets the parameter to 10 raw chars but we only expect 5. // // Test BINARY(10) value with length less than the type allows. // // Test as.raw(NA) value returned as 00 in a VARBINARY(5) parameter. // // Test NULL BINARY(5) value //