language-extensions/R/test/src/RExtensionLibraryApiTests.cpp
//----------------------------------------------------------------------------------------------
// Name: RExtensionLibraryApiTests::UninstallAndTest
//
// Description:
//  Uninstalls and tests a package.
//  If there is a different installation of the same package, then uninstalling won't
//  fail on import, but the version in our specified dir should be gone.
//
:UninstallAndTest
Description:
Uninstalls and tests a package.
If there is a different installation of the same package, then uninstalling won't
fail on import, but the version in our specified dir should be gone.
: UninstallAndTest Description : Uninstalls and tests a package . If there is a different installation of the same package then uninstalling won ' t fail on import but the version in our specified dir should be gone .
void RExtensionLibraryApiTests::UninstallAndTest(
		string extLibName,
		string installDir,
		bool   otherInstallationExists)
	{
		SQLCHAR *libError = nullptr;
		SQLINTEGER libErrorLength = 0;
		SQLRETURN result = (*sm_uninstallExternalLibraryFuncPtr)(
			*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 *>(installDir.c_str()))),
			installDir.length(),
			&libError,
			&libErrorLength);
		try
		{
			DetachLibrary(extLibName);
			string location = GetLocationOfLibrary(extLibName);
			 We will reach here only if GetLocationOfLibrary succeeds
			 which either means other installation exists or uninstallation failed above.
			fs::path previousFullInstallLocation = fs::path(installDir) / extLibName;
			string normalizedPreviousFullInstall =
				Utilities::NormalizePathString(previousFullInstallLocation.string());
			string normalizedFoundLocation = Utilities::NormalizePathString(location);
			 If another installation exists,
			 then the uninstall should succeed and load should still work
			if (otherInstallationExists)
			{
				EXPECT_EQ(result, SQL_SUCCESS);
				EXPECT_EQ(libError, nullptr);
				EXPECT_EQ(libErrorLength, 0);
				EXPECT_TRUE(fs::exists(location));
				if (fs::exists(installDir))
				{
					EXPECT_FALSE(normalizedFoundLocation.compare(normalizedPreviousFullInstall) == 0);
				}
			}
			else
			{
				 Uninstallation failed.
				EXPECT_EQ(result, SQL_ERROR);
				EXPECT_TRUE(normalizedFoundLocation.compare(normalizedPreviousFullInstall) == 0);
			}
		}
		catch (...)
		{
			EXPECT_EQ(result, SQL_SUCCESS);
			EXPECT_EQ(libError, nullptr);
			EXPECT_EQ(libErrorLength, 0);
		}
	}
void RExtensionLibraryApiTests :: UninstallAndTest ( string extLibName , string installDir , bool otherInstallationExists ) { SQLCHAR * libError = nullptr ; SQLINTEGER libErrorLength = 0 ; SQLRETURN result = ( * sm_uninstallExternalLibraryFuncPtr ) ( * 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 * > ( installDir . c_str ( ) ) ) ) , installDir . length ( ) , & libError , & libErrorLength ) ; try { DetachLibrary ( extLibName ) ; string location = GetLocationOfLibrary ( extLibName ) ; fs :: path previousFullInstallLocation = fs :: path ( installDir ) / extLibName ; string normalizedPreviousFullInstall = Utilities :: NormalizePathString ( previousFullInstallLocation . string ( ) ) ; string normalizedFoundLocation = Utilities :: NormalizePathString ( location ) ; if ( otherInstallationExists ) { EXPECT_EQ ( result , SQL_SUCCESS ) ; EXPECT_EQ ( libError , nullptr ) ; EXPECT_EQ ( libErrorLength , 0 ) ; EXPECT_TRUE ( fs :: exists ( location ) ) ; if ( fs :: exists ( installDir ) ) { EXPECT_FALSE ( normalizedFoundLocation . compare ( normalizedPreviousFullInstall ) == 0 ) ; } } else { EXPECT_EQ ( result , SQL_ERROR ) ; EXPECT_TRUE ( normalizedFoundLocation . compare ( normalizedPreviousFullInstall ) == 0 ) ; } } catch ( ... ) { EXPECT_EQ ( result , SQL_SUCCESS ) ; EXPECT_EQ ( libError , nullptr ) ; EXPECT_EQ ( libErrorLength , 0 ) ; } }
Name: RExtensionLibraryApiTests::UninstallAndTest
Description:
Uninstalls and tests a package.
Name : RExtensionLibraryApiTests :: UninstallAndTest Description : Uninstalls and tests a package .
// Try to find the package - if it successfully loads, // the uninstall either failed or there is another // installation of the same package in a different location. // // We will reach here only if GetLocationOfLibrary succeeds // which either means other installation exists or uninstallation failed above. // // If another installation exists, // then the uninstall should succeed and load should still work // // Uninstallation failed. //