language-extensions/R/test/src/RExtensionGetOutputParamTests.cpp
//----------------------------------------------------------------------------------------------
// Name: RExtensionApiTest::GetNCharOutputParam
//
// Description:
//  Tests nchar/nvarchar output param value and strLenOrInd are as expected.
//
:GetNCharOutputParam
Description:
Tests nchar/nvarchar output param value and strLenOrInd are as expected.
: GetNCharOutputParam Description : Tests nchar / nvarchar output param value and strLenOrInd are as expected .
void RExtensionApiTests::GetNCharOutputParam(
		vector<const wchar_t*> expectedParamValues,
		vector<SQLINTEGER>     expectedStrLenOrInd)
	{
		ASSERT_EQ(expectedParamValues.size(), expectedStrLenOrInd.size());
		for (SQLUSMALLINT paramNumber = 0; paramNumber < expectedParamValues.size(); ++paramNumber)
		{
			SQLPOINTER paramValue = nullptr;
			SQLINTEGER strLen_or_Ind = 0;
			SQLRETURN result = SQL_ERROR;
			result = (*sm_getOutputParamFuncPtr)(
				*m_sessionId,
				m_taskId,
				paramNumber,
				&paramValue,
				&strLen_or_Ind);
			ASSERT_EQ(result, SQL_SUCCESS);
			EXPECT_EQ(strLen_or_Ind, expectedStrLenOrInd[paramNumber]);
			if (expectedParamValues[paramNumber] != nullptr)
			{
				EXPECT_NE(paramValue, nullptr);
				wstring paramValueString(static_cast<wchar_t*>(paramValue),
					strLen_or_Ind / sizeof(wchar_t));
				wstring expectedParamValueString(expectedParamValues[paramNumber],
					expectedStrLenOrInd[paramNumber] / sizeof(wchar_t));
				const char *paramBytes = reinterpret_cast<const char*>(paramValueString.c_str());
				const char *expectedParamBytes =
					reinterpret_cast<const char*>(expectedParamValueString.c_str());
				for(SQLINTEGER i=0; i < strLen_or_Ind; i++)
				{
					EXPECT_EQ(paramBytes[i], expectedParamBytes[i]);
				}
			}
			else
			{
				EXPECT_EQ(paramValue, nullptr);
			}
		}
	}
void RExtensionApiTests :: GetNCharOutputParam ( vector < const wchar_t * > expectedParamValues , vector < SQLINTEGER > expectedStrLenOrInd ) { ASSERT_EQ ( expectedParamValues . size ( ) , expectedStrLenOrInd . size ( ) ) ; for ( SQLUSMALLINT paramNumber = 0 ; paramNumber < expectedParamValues . size ( ) ; ++ paramNumber ) { SQLPOINTER paramValue = nullptr ; SQLINTEGER strLen_or_Ind = 0 ; SQLRETURN result = SQL_ERROR ; result = ( * sm_getOutputParamFuncPtr ) ( * m_sessionId , m_taskId , paramNumber , & paramValue , & strLen_or_Ind ) ; ASSERT_EQ ( result , SQL_SUCCESS ) ; EXPECT_EQ ( strLen_or_Ind , expectedStrLenOrInd [ paramNumber ] ) ; if ( expectedParamValues [ paramNumber ] != nullptr ) { EXPECT_NE ( paramValue , nullptr ) ; wstring paramValueString ( static_cast < wchar_t * > ( paramValue ) , strLen_or_Ind / sizeof ( wchar_t ) ) ; wstring expectedParamValueString ( expectedParamValues [ paramNumber ] , expectedStrLenOrInd [ paramNumber ] / sizeof ( wchar_t ) ) ; const char * paramBytes = reinterpret_cast < const char * > ( paramValueString . c_str ( ) ) ; const char * expectedParamBytes = reinterpret_cast < const char * > ( expectedParamValueString . c_str ( ) ) ; for ( SQLINTEGER i = 0 ; i < strLen_or_Ind ; i ++ ) { EXPECT_EQ ( paramBytes [ i ] , expectedParamBytes [ i ] ) ; } } else { EXPECT_EQ ( paramValue , nullptr ) ; } } }
Name: RExtensionApiTest::GetNCharOutputParam
Description:
Tests nchar/nvarchar output param value and strLenOrInd are as expected.
Name : RExtensionApiTest :: GetNCharOutputParam Description : Tests nchar / nvarchar output param value and strLenOrInd are as expected .
// Compare the two wstrings byte by byte because EXPECT_STREQ and EXPECT_EQ // don't work properly for wstrings in Linux with -fshort-wchar //