1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/lowlevellibsandfws/pluginfw/Framework/SimpleTests/t_hashcheck.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,729 @@
1.4 +// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Contains tests to exercise the hash checking feature for removable drives
1.18 +//
1.19 +//
1.20 +
1.21 +
1.22 +#include <ecom/ecom.h>
1.23 +#include "../EcomTestUtils/EcomTestUtils.h"
1.24 +#include <hash.h>
1.25 +#include <swi/swispubsubdefs.h>
1.26 +#include "../Example/EComHashExample.h"
1.27 +#include "../EcomTestUtils/TPropertyManager.h"
1.28 +
1.29 +using namespace Swi;
1.30 +
1.31 +LOCAL_D RTest test(_L("t_hashcheck.exe"));
1.32 +
1.33 +LOCAL_D CTrapCleanup* TheTrapCleanup = NULL;
1.34 +
1.35 +LOCAL_D CActiveScheduler* TheActiveScheduler = NULL;
1.36 +
1.37 +LOCAL_D RFs TheFs;
1.38 +
1.39 +#define UNUSED_VAR(a) a = a
1.40 +
1.41 +// Implementaion IDs used for testing
1.42 +const TUid KUidTestInterface = {0x10009E34};
1.43 +const TUid KUidTestImplementation = {0x10009E35};
1.44 +
1.45 +// Plugins used in tests.
1.46 +_LIT(KEComHashExampleDllOnZ, "z:\\RAMOnly\\EComHashExample.dll");
1.47 +_LIT(KEComHashExampleRscOnZ, "z:\\RAMOnly\\EComHashExample.rsc");
1.48 +
1.49 +_LIT(KEComAllRSCFilesName, "\\Resource\\Plugins\\*.rsc");
1.50 +_LIT(KEComRscDirName, "\\Resource\\Plugins");
1.51 +
1.52 +#if defined(__WINSCW__) // X: on emulator
1.53 +_LIT(KEComHashExampleDllOnRemovableDrive, "X:\\sys\\bin\\EComHashExample.dll");
1.54 +_LIT(KEComHashExampleRscOnRemovableDrive, "X:\\resource\\plugins\\EComHashExample.rsc");
1.55 +#else // E: on hardware
1.56 +_LIT(KEComHashExampleDllOnRemovableDrive, "E:\\sys\\bin\\EComHashExample.dll");
1.57 +_LIT(KEComHashExampleRscOnRemovableDrive, "E:\\resource\\plugins\\EComHashExample.rsc");
1.58 +#endif
1.59 +
1.60 +// hash files
1.61 +_LIT(KEComTempHashFileOnC, "c:\\EComTempHashFile.dll");
1.62 +_LIT(KEComTempCorruptHashFileOnC, "c:\\EComTempCorruptHashFile.dll");
1.63 +_LIT(KEComHashExampleHashFileOnRemovableDrive, "c:\\sys\\hash\\EComHashExample.dll");
1.64 +_LIT(KEComCorruptHash, "12345678912345678900");
1.65 +
1.66 +const TInt KHashFileReadSize = 1024*8;
1.67 +
1.68 +void CreateTempHashFileL()
1.69 + {
1.70 + // Create valid hash file for the DLL to be used during this test.
1.71 + TInt readsize = KHashFileReadSize;
1.72 + HBufC8* block0 = HBufC8::NewLC(readsize);
1.73 + TPtr8 fileblock0(block0->Des());
1.74 + CSHA1* hasher=CSHA1::NewL();
1.75 + CleanupStack::PushL(hasher);
1.76 +
1.77 + RFile file;
1.78 + CleanupClosePushL(file);
1.79 + User::LeaveIfError(file.Open(TheFs, KEComHashExampleDllOnZ, EFileRead));
1.80 +
1.81 + TInt size;
1.82 + User::LeaveIfError(file.Size(size));
1.83 + TInt offset=0;
1.84 + do {
1.85 + if((size - offset) < readsize)
1.86 + readsize = (size - offset);
1.87 + User::LeaveIfError(file.Read(offset, fileblock0, readsize));
1.88 + hasher->Update(fileblock0);
1.89 + offset+=readsize;
1.90 + }
1.91 + while(offset < size);
1.92 +
1.93 + CleanupStack::PopAndDestroy(1); // file
1.94 +
1.95 + TBuf8<SHA1_HASH> hash;
1.96 + hash=hasher->Final();
1.97 +
1.98 + CleanupStack::PopAndDestroy(2); // block0, hasher
1.99 +
1.100 + // write hash to file
1.101 + RFile tempHashFile;
1.102 + CleanupClosePushL(tempHashFile);
1.103 + User::LeaveIfError(tempHashFile.Replace(TheFs, KEComTempHashFileOnC, EFileWrite));
1.104 + tempHashFile.Write(hash);
1.105 + CleanupStack::PopAndDestroy(1); // tempHashFile
1.106 + }
1.107 +
1.108 +void DeleteTempHashFileL()
1.109 + {
1.110 + TRAPD(err, EComTestUtils::FileManDeleteFileL(KEComTempHashFileOnC));
1.111 + test(err == KErrNone);
1.112 + }
1.113 +
1.114 +void CreateTempCorruptHashFileL()
1.115 + {
1.116 + // write corrupt hash to file
1.117 + TBuf8<SHA1_HASH> hash;
1.118 + hash.Append(KEComCorruptHash);
1.119 + RFile tempHashFile;
1.120 + CleanupClosePushL(tempHashFile);
1.121 + User::LeaveIfError(tempHashFile.Replace(TheFs, KEComTempCorruptHashFileOnC, EFileWrite));
1.122 + tempHashFile.Write(hash);
1.123 + CleanupStack::PopAndDestroy(1); // tempHashFile
1.124 + }
1.125 +
1.126 +void DeleteTempCorruptHashFileL()
1.127 + {
1.128 + TRAPD(err, EComTestUtils::FileManDeleteFileL(KEComTempCorruptHashFileOnC));
1.129 + test(err == KErrNone);
1.130 + }
1.131 +
1.132 +void CopyHashFile()
1.133 + {
1.134 + TRAPD(err, EComTestUtils::FileManCopyFileL(KEComTempHashFileOnC,
1.135 + KEComHashExampleHashFileOnRemovableDrive));
1.136 + test(err == KErrNone);
1.137 + }
1.138 +
1.139 +void DeleteHashFile()
1.140 + {
1.141 + TRAPD(err, EComTestUtils::FileManDeleteFileL(KEComHashExampleHashFileOnRemovableDrive));
1.142 + UNUSED_VAR(err);
1.143 +
1.144 + // If ECOM server is already running we need to allow some time for re-discovery
1.145 + // to complete.
1.146 + WAIT_FOR3s;
1.147 + }
1.148 +
1.149 +void CopyCorruptHashFile()
1.150 + {
1.151 + TRAPD(err, EComTestUtils::FileManCopyFileL(KEComTempCorruptHashFileOnC,
1.152 + KEComHashExampleHashFileOnRemovableDrive));
1.153 + test(err == KErrNone);
1.154 + }
1.155 +
1.156 +void CopyPlugins()
1.157 + {
1.158 + TRAPD(err, EComTestUtils::FileManCopyFileL(KEComHashExampleDllOnZ, KEComHashExampleDllOnRemovableDrive));
1.159 + test(err == KErrNone);
1.160 + TRAP(err, EComTestUtils::FileManCopyFileL(KEComHashExampleRscOnZ, KEComHashExampleRscOnRemovableDrive));
1.161 + test(err == KErrNone);
1.162 +
1.163 + // If ECOM server is already running we need to allow some time for re-discovery
1.164 + // to complete.
1.165 + WAIT_FOR3s;
1.166 + }
1.167 +
1.168 +void DeletePlugins()
1.169 + {
1.170 + TRAPD(err, EComTestUtils::FileManDeleteFileL(KEComHashExampleDllOnRemovableDrive));
1.171 + UNUSED_VAR(err);
1.172 + TRAP(err, EComTestUtils::FileManDeleteFileL(KEComHashExampleRscOnRemovableDrive));
1.173 + UNUSED_VAR(err);
1.174 +
1.175 + // If ECOM server is already running we need to allow some time for re-discovery
1.176 + // to complete.
1.177 + WAIT_FOR3s;
1.178 + }
1.179 +
1.180 +
1.181 +void DeleteRSCFolderOnDrive(TUint aDriveNum)
1.182 + {
1.183 + TInt err=KErrNone;
1.184 + TDriveUnit aDrive(aDriveNum);
1.185 +
1.186 + TBuf<256> resourceFileName;
1.187 + resourceFileName.Append(aDrive.Name());
1.188 + resourceFileName.Append(KEComAllRSCFilesName);
1.189 + TRAP(err, EComTestUtils::FileManDeleteFileL(resourceFileName));
1.190 +
1.191 + TBuf<256> resourceDirName;
1.192 + resourceDirName.Append(aDrive.Name());
1.193 + resourceDirName.Append(KEComRscDirName);
1.194 + TRAP(err, EComTestUtils::FileManDeleteDirL(resourceDirName));
1.195 + }
1.196 +
1.197 +TBool IsImplementationListedL()
1.198 + {
1.199 + RImplInfoPtrArray implArray;
1.200 + REComSession::ListImplementationsL(KUidTestInterface, implArray);
1.201 +
1.202 + TBool found = EFalse;
1.203 + TInt count = implArray.Count();
1.204 + while(count)
1.205 + {
1.206 + count--;
1.207 + if(implArray[count]->ImplementationUid() == KUidTestImplementation)
1.208 + {
1.209 + found = ETrue;
1.210 + break;
1.211 + }
1.212 + }
1.213 + REComSession::FinalClose();
1.214 + implArray.ResetAndDestroy();
1.215 + return found;
1.216 + }
1.217 +
1.218 +TInt IsImplementationCreatedL()
1.219 + {
1.220 + TUid dtor_ID_Key;
1.221 + TAny* ptr = NULL;
1.222 + TRAPD(err, ptr = REComSession::CreateImplementationL(KUidTestImplementation, dtor_ID_Key));
1.223 +
1.224 + CImplementationHashExample* implPtr = reinterpret_cast <CImplementationHashExample*> (ptr);
1.225 +
1.226 + if(err == KErrNone)
1.227 + {
1.228 + REComSession::DestroyedImplementation(dtor_ID_Key);
1.229 + delete implPtr;
1.230 + }
1.231 +
1.232 + REComSession::FinalClose();
1.233 + return err;
1.234 + }
1.235 +
1.236 +void DoPreInstall()
1.237 + {
1.238 + // Install in progress
1.239 + PropertyManager::SetProperty(KUidSystemCategory, KSAUidSoftwareInstallKeyValue, ESASwisInstall);
1.240 + CopyHashFile();
1.241 + WAIT_FOR1s;
1.242 +
1.243 + // Install successful
1.244 + PropertyManager::SetProperty(KUidSystemCategory, KSAUidSoftwareInstallKeyValue, ESASwisInstall);
1.245 + WAIT_FOR3s;
1.246 +
1.247 + // Reset
1.248 + PropertyManager::SetProperty(KUidSystemCategory, KSAUidSoftwareInstallKeyValue, ESASwisNone);
1.249 + WAIT_FOR1s;
1.250 + }
1.251 +
1.252 +void DoCorruptPreInstall()
1.253 + {
1.254 + // Install in progress
1.255 + PropertyManager::SetProperty(KUidSystemCategory, KSAUidSoftwareInstallKeyValue, ESASwisInstall);
1.256 + CopyCorruptHashFile();
1.257 + WAIT_FOR1s;
1.258 +
1.259 + // Install successful
1.260 + PropertyManager::SetProperty(KUidSystemCategory, KSAUidSoftwareInstallKeyValue, ESASwisInstall);
1.261 + WAIT_FOR3s;
1.262 +
1.263 + // Reset
1.264 + PropertyManager::SetProperty(KUidSystemCategory, KSAUidSoftwareInstallKeyValue, ESASwisNone);
1.265 + WAIT_FOR1s;
1.266 + }
1.267 +
1.268 +void DoPreUninstall()
1.269 + {
1.270 + // Uninstall in progress
1.271 + PropertyManager::SetProperty(KUidSystemCategory, KSAUidSoftwareInstallKeyValue, ESASwisUninstall);
1.272 + DeleteHashFile();
1.273 + WAIT_FOR1s;
1.274 +
1.275 + // Uninstall successful
1.276 + PropertyManager::SetProperty(KUidSystemCategory, KSAUidSoftwareInstallKeyValue, ESASwisUninstall);
1.277 + WAIT_FOR3s;
1.278 +
1.279 + // Reset
1.280 + PropertyManager::SetProperty(KUidSystemCategory, KSAUidSoftwareInstallKeyValue, ESASwisNone);
1.281 + WAIT_FOR1s;
1.282 + }
1.283 +
1.284 +/**
1.285 +@SYMTestCaseID SYSLIB-ECOM-CT-1922
1.286 +@SYMTestCaseDesc Test that implementation on removable drive is not available
1.287 + when no hash file has been installed.
1.288 +@SYMTestPriority High
1.289 +@SYMTestActions Copy plugins to removable drive.
1.290 + Call ListImplementations() and CreateImplementation()
1.291 + Check implementation is unavailable.
1.292 +@SYMTestExpectedResults The test must not fail.
1.293 +@SYMDEF PDEF090578
1.294 +*/
1.295 +LOCAL_C void TestNoHashFileInstalledL()
1.296 + {
1.297 + test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-1922 "));
1.298 + __UHEAP_MARK;
1.299 +
1.300 + // Test ListImplementations()
1.301 + CopyPlugins();
1.302 + TBool implListed = IsImplementationListedL();
1.303 +
1.304 + // Check implementation
1.305 + // On the emulator RLibrary::GetInfo() always returns KErrNotFound for DLL's
1.306 + // on the X drive. Because of this the implementation will not be listed.
1.307 + //
1.308 + // On hardware ECOM uses RLoader::CheckLibraryHash() to determine if the hash
1.309 + // is available for the DLL. In this case there is no hash so the implementation is
1.310 + // not listed.
1.311 + test(!implListed);
1.312 +
1.313 + // Test CreateImplementation()
1.314 + TInt implCreated = IsImplementationCreatedL();
1.315 +
1.316 + // Check implementation
1.317 + // On the emulator RLibrary::GetInfo() always returns KErrNotFound for DLL's
1.318 + // on the X drive. Because of this the implementation will not be created.
1.319 + //
1.320 + // On hardware ECOM uses RLoader::CheckLibraryHash() to determine if the hash
1.321 + // is available for the DLL. In this case there is no hash so the implementation is
1.322 + // not created.
1.323 + test(implCreated == KErrNotFound);
1.324 +
1.325 + DeletePlugins();
1.326 + __UHEAP_MARKEND;
1.327 + }
1.328 +
1.329 +/**
1.330 +@SYMTestCaseID SYSLIB-ECOM-CT-1923
1.331 +@SYMTestCaseDesc Test that implementation on removable drive is available
1.332 + when a Pre Install occurs exists.
1.333 +@SYMTestPriority High
1.334 +@SYMTestActions Copy plugins to removable drive.
1.335 + Call ListImplementations() and CreateImplementation()
1.336 + Check implementation is unavailable.
1.337 + Emulate pre-install.
1.338 + Call ListImplementations() and CreateImplementation()
1.339 + Check implementation is available.
1.340 + Emulate uninstall.
1.341 + Call ListImplementations() and CreateImplementation()
1.342 + Check implementation is unavailable.
1.343 +@SYMTestExpectedResults The test must not fail.
1.344 +@SYMDEF PDEF090578
1.345 +*/
1.346 +LOCAL_C void TestPreInstallL()
1.347 + {
1.348 + test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-1923 "));
1.349 + __UHEAP_MARK;
1.350 +
1.351 + // Only copy plugins - during pre-install plugins exists before the install occurs
1.352 + CopyPlugins();
1.353 +
1.354 + // Test ListImplementations()
1.355 + TBool implListed = IsImplementationListedL();
1.356 +
1.357 + // Check implementation
1.358 + // On the emulator RLibrary::GetInfo() always returns KErrNotFound for DLL's
1.359 + // on the X drive. Because of this the implementation will not be listed.
1.360 + //
1.361 + // On hardware ECOM uses RLoader::CheckLibraryHash() to determine if the hash
1.362 + // is available for the DLL. In this case there is no hash because install has not occurred
1.363 + // so the implementation is not listed.
1.364 + test(!implListed);
1.365 +
1.366 + // Test CreateImplementation()
1.367 + // No hash so no implementation should be created.
1.368 + TInt implCreated = IsImplementationCreatedL();
1.369 +
1.370 + // Check implementation
1.371 + // On the emulator RLibrary::GetInfo() always returns KErrNotFound for DLL's
1.372 + // on the X drive. Because of this the implementation will not be created.
1.373 + //
1.374 + // On hardware ECOM uses RLoader::CheckLibraryHash() to determine if the hash
1.375 + // is available for the DLL. In this case there is no hash because install has not occurred
1.376 + // so the implementation is not created.
1.377 + test(implCreated == KErrNotFound);
1.378 +
1.379 + // Do install
1.380 + DoPreInstall();
1.381 +
1.382 + // Test ListImplementations()
1.383 + implListed = IsImplementationListedL();
1.384 +
1.385 + _LIT(KMessage3,"Pre-Install 3: List = %d");
1.386 + RDebug::Print(KMessage3, implListed);
1.387 + // Check implementation
1.388 +#if defined(__WINSCW__)
1.389 + // On the emulator RLibrary::GetInfo() always returns KErrNotFound for DLL's
1.390 + // on the X drive. Because of this the implementation will not be listed.
1.391 + //
1.392 + test(!implListed);
1.393 +#else
1.394 + // On hardware ECOM uses RLoader::CheckLibraryHash() to determine if the hash
1.395 + // is available for the DLL. In this case there is a hash so the implementation is
1.396 + // listed.
1.397 + test(implListed);
1.398 +#endif
1.399 +
1.400 + // Test CreateImplementation()
1.401 + implCreated = IsImplementationCreatedL();
1.402 +
1.403 + // Check implementation was created
1.404 +#if defined(__WINSCW__)
1.405 + // On the emulator RLibrary::GetInfo() always returns KErrNotFound for DLL's
1.406 + // on the X drive. Because of this the implementation will not be created.
1.407 + //
1.408 + test(implCreated == KErrNotFound);
1.409 +#else
1.410 + // On hardware ECOM uses RLoader::CheckLibraryHash() to determine if the hash
1.411 + // is available for the DLL. In this case there is a hash so the implementation is
1.412 + // created.
1.413 + test(implCreated == KErrNone);
1.414 +#endif
1.415 +
1.416 + __UHEAP_MARKEND;
1.417 + }
1.418 +
1.419 +/**
1.420 +@SYMTestCaseID SYSLIB-ECOM-CT-1924
1.421 +@SYMTestCaseDesc Test that implementation on removable drive is unavailable
1.422 + after an uninstall occurs.
1.423 +@SYMTestPriority High
1.424 +@SYMTestActions Emulate uninstall.
1.425 + Call ListImplementations() and CreateImplementation()
1.426 + Check implementation is unavailable.
1.427 +@SYMTestExpectedResults The test must not fail.
1.428 +@SYMDEF PDEF090578
1.429 +*/
1.430 +LOCAL_C void TestPreUninstallL()
1.431 + {
1.432 + test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-1924 "));
1.433 + __UHEAP_MARK;
1.434 +
1.435 + // Do uninstall
1.436 + DoPreUninstall();
1.437 +
1.438 + // Test ListImplementations()
1.439 + TBool implListed = IsImplementationListedL();
1.440 +
1.441 + // Check implementation
1.442 + // On the emulator RLibrary::GetInfo() always returns KErrNotFound for DLL's
1.443 + // on the X drive. Because of this the implementation will not be listed.
1.444 + //
1.445 + // On hardware ECOM uses RLoader::CheckLibraryHash() to determine if the hash
1.446 + // is available for the DLL. In this case there is no hash so the implementation is
1.447 + // not listed.
1.448 + test(!implListed);
1.449 +
1.450 + // Test CreateImplementation()
1.451 + TInt implCreated = IsImplementationCreatedL();
1.452 +
1.453 + // Check implementation
1.454 + // On the emulator RLibrary::GetInfo() always returns KErrNotFound for DLL's
1.455 + // on the X drive. Because of this the implementation will not be created.
1.456 + //
1.457 + // On hardware ECOM uses RLoader::CheckLibraryHash() to determine if the hash
1.458 + // is available for the DLL. In this case there is no hash so the implementation is
1.459 + // not created.
1.460 + test(implCreated == KErrNotFound);
1.461 +
1.462 + DeletePlugins();
1.463 + __UHEAP_MARKEND;
1.464 + }
1.465 +
1.466 +/**
1.467 +@SYMTestCaseID SYSLIB-ECOM-CT-1925
1.468 +@SYMTestCaseDesc Test that implementation on removable drive is unavailable
1.469 + if the hash is corrupted for the DLL.
1.470 +@SYMTestPriority High
1.471 +@SYMTestActions Emulate pre-install with a corrupted hash file.
1.472 + Call ListImplementations() and CreateImplementation()
1.473 + Check implementation is unavailable.
1.474 +@SYMTestExpectedResults The test must not fail.
1.475 +@SYMDEF PDEF090578
1.476 +*/
1.477 +LOCAL_C void TestCorruptHashL()
1.478 + {
1.479 + test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-1925 "));
1.480 + __UHEAP_MARK;
1.481 +
1.482 + // Only copy plugins - during pre-install plugins exists before the install occurs
1.483 + CopyPlugins();
1.484 +
1.485 + // Do pre install
1.486 + DoCorruptPreInstall();
1.487 +
1.488 + // Test ListImplementations()
1.489 + TBool implListed = IsImplementationListedL();
1.490 +
1.491 + // Check implementation
1.492 + // On the emulator RLibrary::GetInfo() always returns KErrNotFound for DLL's
1.493 + // on the X drive. Because of this the implementation will not be listed.
1.494 + //
1.495 + // On hardware ECOM uses RLoader::CheckLibraryHash() to determine if the hash
1.496 + // is available for the DLL. In this case the hash file is corrupted so the implementation is
1.497 + // not listed.
1.498 + test(!implListed);
1.499 +
1.500 + // Test CreateImplementation()
1.501 + TInt implCreated = IsImplementationCreatedL();
1.502 +
1.503 + // Check implementation
1.504 + // On the emulator RLibrary::GetInfo() always returns KErrNotFound for DLL's
1.505 + // on the X drive. Because of this the implementation will not be created.
1.506 + //
1.507 + // On hardware ECOM uses RLoader::CheckLibraryHash() to determine if the hash
1.508 + // is available for the DLL. In this case the hash file is corrupted so the implementation is
1.509 + // not created.
1.510 + test(implCreated == KErrNotFound);
1.511 +
1.512 + DeletePlugins();
1.513 + DeleteHashFile();
1.514 + __UHEAP_MARKEND;
1.515 + }
1.516 +
1.517 +/**
1.518 +@SYMTestCaseID SYSLIB-ECOM-CT-1926
1.519 +@SYMTestCaseDesc Test that implementation on removable drive is available
1.520 + when a full Install occurs exists.
1.521 +@SYMTestPriority High
1.522 +@SYMTestActions Copy plugins to removable drive.
1.523 + Emulate pre-install.
1.524 + Call ListImplementations() and CreateImplementation()
1.525 + Check implementation is available.
1.526 +@SYMTestExpectedResults The test must not fail.
1.527 +@SYMDEF PDEF090578
1.528 +*/
1.529 +LOCAL_C void TestFullInstallL()
1.530 + {
1.531 + test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-1926 "));
1.532 + __UHEAP_MARK;
1.533 +
1.534 + // Only copy plugins - during pre-install plugins exists before the install occurs
1.535 + CopyPlugins();
1.536 + // Do install
1.537 + DoPreInstall();
1.538 +
1.539 + // Test ListImplementations()
1.540 + TBool implListed = IsImplementationListedL();
1.541 +
1.542 + // Test CreateImplementation()
1.543 + TInt implCreated = IsImplementationCreatedL();
1.544 +
1.545 +#if defined(__WINSCW__)
1.546 + // On the emulator RLibrary::GetInfo() always returns KErrNotFound for DLL's
1.547 + // on the X drive. Because of this the implementation will not be listed and
1.548 + // the implementation will not be created.
1.549 + test(!implListed);
1.550 + test(implCreated == KErrNotFound);
1.551 +#else
1.552 + // On hardware ECOM uses RLoader::CheckLibraryHash() to determine if the hash
1.553 + // is available for the DLL. In this case there is a valid hash so the implementation is
1.554 + // listed and created.
1.555 + test(implListed);
1.556 + test(implCreated == KErrNone);
1.557 +#endif
1.558 +
1.559 + __UHEAP_MARKEND;
1.560 + }
1.561 +/**
1.562 +@SYMTestCaseID SYSLIB-ECOM-CT-1927
1.563 +@SYMTestCaseDesc Test that implementation on removable drive is unavailable
1.564 + after an uninstall occurs.
1.565 +@SYMTestPriority High
1.566 +@SYMTestActions Emulate uninstall.
1.567 + Call ListImplementations() and CreateImplementation()
1.568 + Check implementation is unavailable.
1.569 +@SYMTestExpectedResults The test must not fail.
1.570 +@SYMDEF PDEF09057
1.571 +*/
1.572 +LOCAL_C void TestFullUninstallL()
1.573 + {
1.574 + test.Next(_L(" @SYMTestCaseID:SYSLIB-ECOM-CT-1927 "));
1.575 + __UHEAP_MARK;
1.576 +
1.577 + //Clean up DLL on remove drive
1.578 + DeletePlugins();
1.579 +
1.580 + //Clean up the hash file related the DLL
1.581 + DoPreUninstall();
1.582 +
1.583 + // Test ListImplementations()
1.584 + TBool implListed = IsImplementationListedL();
1.585 +
1.586 + // Check implementation
1.587 + // On the emulator RLibrary::GetInfo() always returns KErrNotFound for DLL's
1.588 + // on the X drive. Because of this the implementation will not be listed.
1.589 + //
1.590 + // On hardware ECOM uses RLoader::CheckLibraryHash() to determine if the hash
1.591 + // is available for the DLL. In this case there is no plugin and no hash so the implementation
1.592 + // is not listed.
1.593 + test(!implListed);
1.594 +
1.595 + // Test CreateImplementation()
1.596 + TInt implCreated = IsImplementationCreatedL();
1.597 + // Check implementation
1.598 + // On the emulator RLibrary::GetInfo() always returns KErrNotFound for DLL's
1.599 + // on the X drive. Because of this the implementation will not be created.
1.600 + //
1.601 + // On hardware ECOM uses RLoader::CheckLibraryHash() to determine if the hash
1.602 + // is available for the DLL. In this case there is no plugins and no hash file so the
1.603 + // implementation is not created.
1.604 + test(implCreated == KErrNotFound);
1.605 +
1.606 + __UHEAP_MARKEND;
1.607 + }
1.608 +
1.609 +typedef void (*ClassFuncPtrL) (void);
1.610 +
1.611 +/**
1.612 +Wrapper function to call all test functions
1.613 +
1.614 +@param testFuncL pointer to test function
1.615 +@param aTestDesc test function name
1.616 +*/
1.617 +LOCAL_C void DoBasicTestL(ClassFuncPtrL testFuncL, const TDesC& aTestDesc)
1.618 + {
1.619 + test.Next(aTestDesc);
1.620 +
1.621 + __UHEAP_MARK;
1.622 + // find out the number of open handles
1.623 + TInt startProcessHandleCount;
1.624 + TInt startThreadHandleCount;
1.625 + RThread().HandleCount(startProcessHandleCount, startThreadHandleCount);
1.626 +
1.627 + //Call the test function
1.628 + (*testFuncL)();
1.629 +
1.630 + // check that no handles have leaked
1.631 + TInt endProcessHandleCount;
1.632 + TInt endThreadHandleCount;
1.633 + RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
1.634 +
1.635 + test(startThreadHandleCount == endThreadHandleCount);
1.636 +
1.637 + __UHEAP_MARKEND;
1.638 + }
1.639 +
1.640 +LOCAL_C void DoTestsL()
1.641 + {
1.642 + __UHEAP_MARK;
1.643 +
1.644 +//If it is hardware and E: drive deosn't exist, don't run the test.
1.645 +#if (!defined(__WINSCW__))
1.646 + if(!TheFs.IsValidDrive(EDriveE))
1.647 + {
1.648 + test.Printf(_L("E: drive doesn't exist, the test won't be able to run \n"));
1.649 + return;
1.650 + }
1.651 +#endif
1.652 +
1.653 + // Basic tests
1.654 + test.Next(_L("Basic Test Suite"));
1.655 + test.Start(_L("Basic Test Suite"));
1.656 + DoBasicTestL(&TestPreInstallL, _L("TestPreInstallL"));
1.657 + DoBasicTestL(&TestPreUninstallL, _L("TestPreUninstallL"));
1.658 +
1.659 + DoBasicTestL(&TestFullInstallL, _L("TestFullInstallL"));
1.660 + DoBasicTestL(&TestFullUninstallL, _L("TestFullUninstallL"));
1.661 +
1.662 + DoBasicTestL(&TestNoHashFileInstalledL, _L("TestNoHashFileInstalledL"));
1.663 + DoBasicTestL(&TestCorruptHashL, _L("TestCorruptHashL"));
1.664 + test.End();
1.665 +
1.666 + __UHEAP_MARKEND;
1.667 + }
1.668 +
1.669 +
1.670 +//Initialise the Active Scheduler
1.671 +//
1.672 +LOCAL_C void SetupL()
1.673 + {
1.674 + // Construct and install the Active Scheduler. The Active Schedular is needed
1.675 + // by components used by this test as they are ActiveObjects.
1.676 + TheActiveScheduler = new(ELeave)CActiveScheduler;
1.677 + CActiveScheduler::Install(TheActiveScheduler);
1.678 +
1.679 + // create hash files
1.680 + CreateTempHashFileL();
1.681 + CreateTempCorruptHashFileL();
1.682 +
1.683 + //Define swinstall property
1.684 + PropertyManager::DefineProperty(KUidSystemCategory, KSAUidSoftwareInstallKeyValue,RProperty::EInt);
1.685 +
1.686 + // Initialise swinstall property
1.687 + PropertyManager::SetProperty(KUidSystemCategory, KSAUidSoftwareInstallKeyValue, ESASwisNone);
1.688 + }
1.689 +
1.690 +GLDEF_C TInt E32Main()
1.691 + {
1.692 + __UHEAP_MARK;
1.693 +
1.694 + test.Printf(_L("\n"));
1.695 + test.Title();
1.696 + test.Start(_L("Hash Tests"));
1.697 +
1.698 + TheTrapCleanup = CTrapCleanup::New();
1.699 +
1.700 + //Delete swinstall property if it already exists
1.701 + PropertyManager::DeleteProperty(KUidSystemCategory, KSAUidSoftwareInstallKeyValue);
1.702 +
1.703 + TInt err = TheFs.Connect();
1.704 + test(err == KErrNone);
1.705 + TRAP(err, SetupL());
1.706 + test(err == KErrNone);
1.707 +
1.708 +
1.709 + // Perform tests.
1.710 + TRAP(err,DoTestsL());
1.711 + test(err==KErrNone);
1.712 +
1.713 + DeleteTempHashFileL();
1.714 + DeleteTempCorruptHashFileL();
1.715 +
1.716 + //Delete swinstall property
1.717 + PropertyManager::DeleteProperty(KUidSystemCategory, KSAUidSoftwareInstallKeyValue);
1.718 +
1.719 +#if !defined(__WINSCW__)
1.720 + DeleteRSCFolderOnDrive(EDriveE);
1.721 +#endif
1.722 +
1.723 + delete TheActiveScheduler;
1.724 + TheFs.Close();
1.725 + delete TheTrapCleanup;
1.726 +
1.727 + test.End();
1.728 + test.Close();
1.729 +
1.730 + __UHEAP_MARKEND;
1.731 + return (KErrNone);
1.732 + }