language-extensions/R/test/src/RExtensionGetOutputParamTests.cpp
//----------------------------------------------------------------------------------------------
// Name: GetNCharOutputParamTest
//
// Description:
//  Tests multiple nchar/nvarchar values.
//
GetNCharOutputParamTest
Description:
Tests multiple nchar/nvarchar values.
GetNCharOutputParamTest Description : Tests multiple nchar / nvarchar values .
TEST_F(RExtensionApiTests, GetNCharOutputParamTest)
	{
		int paramsNumber = 8;
		vector<char> chineseString = { -28, -67, -96, -27, -91, -67 };
		string dummystring = string(chineseString.data(), 6);
		string scriptString = "param1 <- 'HELLO';"
			"param2 <- 'RExtension';"
			"param3 <- '';"
			"param4 <- 'WORLD';"
			"param5 <- '" + dummystring + "';"
			"param6 <- 'Mix " + dummystring + "';"
			"param7 <- as.character(NA);"
			"param8 <- as.character();";
		 Initialize with a Session that executes the above script
		 that sets output parameters.
		InitializeSession(
			0,   inputSchemaColumnsNumber
			scriptString,
			paramsNumber);
		 Note: The behavior of fixed and varying character types is same when it comes to output
		 parameters. So it doesn't matter if they are initialized as fixed or varying.
		vector<bool> isFixedType = { true, false, true, true, true, false, true, true };
		vector<SQLULEN> paramSizes = { 5, 6, 5, 10, 2, 6, 5, 5 };
		vector<const wchar_t*> initParamValues(8, L"");
		vector<SQLSMALLINT> inputOutputTypes(paramsNumber, SQL_PARAM_INPUT_OUTPUT);
		InitCharParam<wchar_t, SQL_C_WCHAR>(
			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);
		vector<const wchar_t*> expectedParamValues = {
			 Test simple NCHAR(5) value with exact string length as the type allows i.e. here 5.
			L"HELLO",
			 Test NVARCHAR(6) value with string length more than the type allows - expected truncation.
			 Above python script sets the parameter to "RExtension" but we only expect "RExten".
			L"RExten",
			 Test a 0 length string
			L"",
			 Test NCHAR(10) value with string length less than the type allows.
			L"WORLD",
			 Test a Unicode string
			L"你好",
			 Test a mixture of one-byte and multi-byte Unicode string
			L"Mix 你好",
			nullptr,
			nullptr};
		vector<SQLINTEGER> expectedStrLenOrInd = {
			static_cast<SQLINTEGER>(5 * sizeof(wchar_t)),
			static_cast<SQLINTEGER>(6 * sizeof(wchar_t)),
			static_cast<SQLINTEGER>(0 * sizeof(wchar_t)),
			static_cast<SQLINTEGER>(5 * sizeof(wchar_t)),
			static_cast<SQLINTEGER>(2 * sizeof(wchar_t)),
			static_cast<SQLINTEGER>(6 * sizeof(wchar_t)),
			SQL_NULL_DATA,
			SQL_NULL_DATA
		};
		GetNCharOutputParam(
			expectedParamValues,
			expectedStrLenOrInd);
	}
TEST_F ( RExtensionApiTests , GetNCharOutputParamTest ) { int paramsNumber = 8 ; vector < char > chineseString = { -28 , -67 , -96 , -27 , -91 , -67 } ; string dummystring = string ( chineseString . data ( ) , 6 ) ; string scriptString = " " " " " " " " " " + dummystring + " " " " + dummystring + " " " " " " ; InitializeSession ( 0 , scriptString , paramsNumber ) ; vector < bool > isFixedType = { true , false , true , true , true , false , true , true } ; vector < SQLULEN > paramSizes = { 5 , 6 , 5 , 10 , 2 , 6 , 5 , 5 } ; vector < const wchar_t * > initParamValues ( 8 , L" " ) ; vector < SQLSMALLINT > inputOutputTypes ( paramsNumber , SQL_PARAM_INPUT_OUTPUT ) ; InitCharParam < wchar_t , SQL_C_WCHAR > ( 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 ) ; vector < const wchar_t * > expectedParamValues = { L" " , L" " , L" " , L" " , L" L" nullptr , nullptr } ; vector < SQLINTEGER > expectedStrLenOrInd = { static_cast < SQLINTEGER > ( 5 * sizeof ( wchar_t ) ) , static_cast < SQLINTEGER > ( 6 * sizeof ( wchar_t ) ) , static_cast < SQLINTEGER > ( 0 * sizeof ( wchar_t ) ) , static_cast < SQLINTEGER > ( 5 * sizeof ( wchar_t ) ) , static_cast < SQLINTEGER > ( 2 * sizeof ( wchar_t ) ) , static_cast < SQLINTEGER > ( 6 * sizeof ( wchar_t ) ) , SQL_NULL_DATA , SQL_NULL_DATA } ; GetNCharOutputParam ( expectedParamValues , expectedStrLenOrInd ) ; }
Name: GetNCharOutputParamTest
Description:
Tests multiple nchar/nvarchar values.
Name : GetNCharOutputParamTest Description : Tests multiple nchar / nvarchar values .
// Construct the values that correspond to 你好 // // 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 they are initialized as fixed or varying. // // validate // rowsNumber // dataSet // strLen_or_Ind // Test simple NCHAR(5) value with exact string length as the type allows i.e. here 5. // // Test NVARCHAR(6) value with string length more than the type allows - expected truncation. // Above python script sets the parameter to "RExtension" but we only expect "RExten". // // Test a 0 length string // // Test NCHAR(10) value with string length less than the type allows. // // Test a Unicode string // // Test a mixture of one-byte and multi-byte Unicode string //