language-extensions/R/test/src/RExtensionGetOutputParamTests.cpp
//----------------------------------------------------------------------------------------------
// Name: GetLogicalOutputParamTest
//
// Description:
//  Tests multiple logical (bit) values.
//
GetLogicalOutputParamTest
Description:
Tests multiple logical (bit) values.
GetLogicalOutputParamTest Description : Tests multiple logical ( bit ) values .
TEST_F(RExtensionApiTests, GetLogicalOutputParamTest)
	{
		int parametersNumber = 7;
		string scriptString = "param1 <- TRUE;"
			"param2 <- FALSE;"
			"param3 <- NA;"
			"param4 <- as.logical(0);"
			 param5 is TRUE
			"param5 <- as.logical(2);"
			 param6 is NA
			"param6 <- as.logical('1');"
			"param7 <- as.logical();";
		 Initialize with a Session that executes the above script
		 that sets output parameters.
		InitializeSession(
			0,    inputSchemaColumnsNumber
			scriptString,
			parametersNumber);   parametersNumber
		vector<shared_ptr<SQLCHAR>> initParamValues = {
			make_shared<SQLCHAR>(0),
			make_shared<SQLCHAR>(0),
			make_shared<SQLCHAR>(0),
			make_shared<SQLCHAR>(0),
			make_shared<SQLCHAR>(0),
			make_shared<SQLCHAR>(0),
			nullptr };
		vector<SQLINTEGER> strLenOrInd(parametersNumber, 0);
		strLenOrInd[parametersNumber - 1] = SQL_NULL_DATA;
		vector<SQLSMALLINT> inputOutputTypes(parametersNumber, SQL_PARAM_INPUT_OUTPUT);
		InitParam<SQLCHAR, Rcpp::LogicalVector, SQL_C_BIT>(
			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 '1', '0', NA, 0, >1 and NULL BIT values.
		 When testing out of range NA value with respect to R,
		 returned paramValue is '\0' even though parameter is NA in R
		 since type casting NA (which is -2'147'483'648) to SQLCHAR returns \0.
		vector<shared_ptr<SQLCHAR>> expectedParamValues = {
			 TRUE
			make_shared<SQLCHAR>(1),
			 FALSE
			make_shared<SQLCHAR>(0),
			 NA
			make_shared<SQLCHAR>('\0'),
			 as.logical(0)
			make_shared<SQLCHAR>(0),
			 as.logical(2)
			make_shared<SQLCHAR>(1),
			 as.logical('1') - NA in R
			make_shared<SQLCHAR>('\0'),
			nullptr };
		vector<SQLINTEGER> expectedStrLenOrInd = {
			m_LogicalSize, m_LogicalSize, SQL_NULL_DATA,
			m_LogicalSize, m_LogicalSize, SQL_NULL_DATA, SQL_NULL_DATA };
		GetOutputParam<SQLCHAR>(
			expectedParamValues,
			expectedStrLenOrInd);
	}
TEST_F ( RExtensionApiTests , GetLogicalOutputParamTest ) { int parametersNumber = 7 ; string scriptString = " " " " " " " " " " " " " " ; InitializeSession ( 0 , scriptString , parametersNumber ) ; vector < shared_ptr < SQLCHAR > > initParamValues = { make_shared < SQLCHAR > ( 0 ) , make_shared < SQLCHAR > ( 0 ) , make_shared < SQLCHAR > ( 0 ) , make_shared < SQLCHAR > ( 0 ) , make_shared < SQLCHAR > ( 0 ) , make_shared < SQLCHAR > ( 0 ) , nullptr } ; vector < SQLINTEGER > strLenOrInd ( parametersNumber , 0 ) ; strLenOrInd [ parametersNumber - 1 ] = SQL_NULL_DATA ; vector < SQLSMALLINT > inputOutputTypes ( parametersNumber , SQL_PARAM_INPUT_OUTPUT ) ; InitParam < SQLCHAR , Rcpp :: LogicalVector , SQL_C_BIT > ( 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 < SQLCHAR > > expectedParamValues = { make_shared < SQLCHAR > ( 1 ) , make_shared < SQLCHAR > ( 0 ) , make_shared < SQLCHAR > ( ' \0 ' ) , make_shared < SQLCHAR > ( 0 ) , make_shared < SQLCHAR > ( 1 ) , make_shared < SQLCHAR > ( ' \0 ' ) , nullptr } ; vector < SQLINTEGER > expectedStrLenOrInd = { m_LogicalSize , m_LogicalSize , SQL_NULL_DATA , m_LogicalSize , m_LogicalSize , SQL_NULL_DATA , SQL_NULL_DATA } ; GetOutputParam < SQLCHAR > ( expectedParamValues , expectedStrLenOrInd ) ; }
Name: GetLogicalOutputParamTest
Description:
Tests multiple logical (bit) values.
Name : GetLogicalOutputParamTest Description : Tests multiple logical ( bit ) values .
// param4 is FALSE // // param5 is TRUE // // param6 is NA // // Initialize with a Session that executes the above script // that sets output parameters. // // inputSchemaColumnsNumber // parametersNumber // validate // rowsNumber // dataSet // strLen_or_Ind // Test '1', '0', NA, 0, >1 and NULL BIT values. // When testing out of range NA value with respect to R, // returned paramValue is '\0' even though parameter is NA in R // since type casting NA (which is -2'147'483'648) to SQLCHAR returns \0. // // TRUE // // FALSE // // NA // // as.logical(0) // // as.logical(2) // // as.logical('1') - NA in R //