language-extensions/R/test/src/RExtensionLibraryApiTests.cpp
//----------------------------------------------------------------------------------------------
// Name: RExtensionLibraryApiTests::InstallAndTest
//
// Description:
//  Installs a package and tests it.
//  If we expect a successful install, then we check the version and location.
//  We then try loading the library and check whether it loads as we expect.
//
:InstallAndTest
Description:
Installs a package and tests it.
If we expect a successful install, then we check the version and location.
We then try loading the library and check whether it loads as we expect.
: InstallAndTest Description : Installs a package and tests it . If we expect a successful install then we check the version and location . We then try loading the library and check whether it loads as we expect .
void RExtensionLibraryApiTests::InstallAndTest(
		string extLibName,
		string pathToPackage,
		string installDir,
		string expectedVersion,
		string expectedLocation,
		bool   successfulInstall,
		bool   successfulLoad)
	{
		SQLCHAR *libError = nullptr;
		SQLINTEGER libErrorLength = 0;
		SQLRETURN result = (*sm_installExternalLibraryFuncPtr)(
			*m_sessionId,
			static_cast<SQLCHAR *>(static_cast<void *>(
				const_cast<char *>(extLibName.c_str()))),
			extLibName.length(),
			static_cast<SQLCHAR *>(static_cast<void *>(
				const_cast<char *>(pathToPackage.c_str()))),
			pathToPackage.length(),
			static_cast<SQLCHAR *>(static_cast<void *>(
				const_cast<char *>(installDir.c_str()))),
			installDir.length(),
			&libError,
			&libErrorLength);
		if (successfulInstall)
		{
			EXPECT_EQ(result, SQL_SUCCESS);
			EXPECT_EQ(libError, nullptr);
			EXPECT_EQ(libErrorLength, 0);
			try
			{
				DetachLibrary(extLibName);
				string location = GetLocationOfLibrary(extLibName);
				if (expectedLocation.empty())
				{
					expectedLocation = fs::path(installDir).string();
				}
				fs::path fullExpectedLocation = fs::path(expectedLocation) / extLibName;
				string normalizedExpectedLocation =
					Utilities::NormalizePathString(fullExpectedLocation.string());
				string normalizedFoundLocation = Utilities::NormalizePathString(location);
				EXPECT_TRUE(normalizedFoundLocation.compare(normalizedExpectedLocation) == 0);
				string version = GetVersionOfLibrary(extLibName);
				EXPECT_EQ(version, expectedVersion);
				string loadScript = "library('" + extLibName + "');";
				sm_executeScriptFuncPtr(loadScript);
				EXPECT_TRUE(successfulLoad);
			}
			catch (...)
			{
				EXPECT_FALSE(successfulLoad);
			}
			DetachLibrary(extLibName);
		}
		else
		{
			EXPECT_EQ(result, SQL_ERROR);
		}
	}
void RExtensionLibraryApiTests :: InstallAndTest ( string extLibName , string pathToPackage , string installDir , string expectedVersion , string expectedLocation , bool successfulInstall , bool successfulLoad ) { SQLCHAR * libError = nullptr ; SQLINTEGER libErrorLength = 0 ; SQLRETURN result = ( * sm_installExternalLibraryFuncPtr ) ( * m_sessionId , static_cast < SQLCHAR * > ( static_cast < void * > ( const_cast < char * > ( extLibName . c_str ( ) ) ) ) , extLibName . length ( ) , static_cast < SQLCHAR * > ( static_cast < void * > ( const_cast < char * > ( pathToPackage . c_str ( ) ) ) ) , pathToPackage . length ( ) , static_cast < SQLCHAR * > ( static_cast < void * > ( const_cast < char * > ( installDir . c_str ( ) ) ) ) , installDir . length ( ) , & libError , & libErrorLength ) ; if ( successfulInstall ) { EXPECT_EQ ( result , SQL_SUCCESS ) ; EXPECT_EQ ( libError , nullptr ) ; EXPECT_EQ ( libErrorLength , 0 ) ; try { DetachLibrary ( extLibName ) ; string location = GetLocationOfLibrary ( extLibName ) ; if ( expectedLocation . empty ( ) ) { expectedLocation = fs :: path ( installDir ) . string ( ) ; } fs :: path fullExpectedLocation = fs :: path ( expectedLocation ) / extLibName ; string normalizedExpectedLocation = Utilities :: NormalizePathString ( fullExpectedLocation . string ( ) ) ; string normalizedFoundLocation = Utilities :: NormalizePathString ( location ) ; EXPECT_TRUE ( normalizedFoundLocation . compare ( normalizedExpectedLocation ) == 0 ) ; string version = GetVersionOfLibrary ( extLibName ) ; EXPECT_EQ ( version , expectedVersion ) ; string loadScript = " " + extLibName + " " ; sm_executeScriptFuncPtr ( loadScript ) ; EXPECT_TRUE ( successfulLoad ) ; } catch ( ... ) { EXPECT_FALSE ( successfulLoad ) ; } DetachLibrary ( extLibName ) ; } else { EXPECT_EQ ( result , SQL_ERROR ) ; } }
Name: RExtensionLibraryApiTests::InstallAndTest
Description:
Installs a package and tests it.
Name : RExtensionLibraryApiTests :: InstallAndTest Description : Installs a package and tests it .
// Load the library, this will throw an exception if the load fails. //