Update contrib.
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Prototype HCR test driver library
18 // -- INCLUDES ----------------------------------------------------------------
21 #include "hcr_debug.h"
23 #include <kernel/kern_priv.h>
31 #include <drivers/hcr.h>
33 #define TEST_MEMGET(s, d, l) kumemget(d, s, l)
34 #define TEST_MEMPUT(d, s, l) kumemput(d, s, l)
36 #include "HcrImageData_102400.h"
37 // -- CLASSES -----------------------------------------------------------------
39 class DHcrTestFactory : public DLogicalDevice
42 virtual TInt Install();
43 virtual void GetCaps(TDes8& aDes) const;
44 virtual TInt Create(DLogicalChannelBase*& aChannel);
48 class DHcrTestChannel : public DLogicalChannelBase
52 virtual ~DHcrTestChannel();
54 // Inherited from DObject
55 virtual TInt RequestUserHandle(DThread* aThread, TOwnerType aType);
57 // Inherited from DLogicalChannelBase
58 virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
59 virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2);
62 static void TestTrace(DHcrTestChannel* aSelf);
70 class HCRInternalTestObserver
73 HCRInternalTestObserver() : iHcrInt(0) { return; } ;
74 HCRInternalTestObserver(HCR::HCRInternal* aSubject) :
75 iHcrInt(aSubject) { return; } ;
76 ~HCRInternalTestObserver() { return; } ;
78 TInt PrintAttirbutes();
82 HCR::TRepository* GetVariantImgRepos();
83 HCR::TRepository* GetCoreImgRepos();
84 HCR::TRepository* GetOverrideImgRepos();
86 HCR::MVariant* GetVariant() {return iHcrInt->iVariant;};
87 TInt SwitchRepository(const TText * aFileName, const HCR::HCRInternal::TReposId aId=HCR::HCRInternal::ECoreRepos);
89 TInt CheckIntegrity(void);
90 TInt FindSetting(const TSettingId& aId, TSettingType aType, TSettingRef& aSetting);
94 HCR::HCRInternal* iHcrInt;
98 TInt Testfunc1(TSuperPage* aSuperPagePtr);
101 TInt HCR::HCRInternalTestObserver::PrintAttirbutes()
103 HCR_TRACE1("HCRInternalTestObserver initialised, iVariant=0x%0x\n", iHcrInt->iVariant);
107 TInt HCR::HCRInternalTestObserver::PrintState()
109 HCR_TRACE2("iVariant =0x%08X, iVariantStore =0x%08X, \n", iHcrInt->iVariant, iHcrInt->iVariantStore);
110 HCR_TRACE2("iCoreImgStore=0x%08X, iOverrideStore=0x%08X, \n", iHcrInt->iCoreImgStore, iHcrInt->iOverrideStore);
115 HCR::TRepository* HCR::HCRInternalTestObserver::GetVariantImgRepos()
117 return iHcrInt->iVariantStore;
120 HCR::TRepository* HCR::HCRInternalTestObserver::GetCoreImgRepos()
122 return iHcrInt->iCoreImgStore;
124 HCR::TRepository* HCR::HCRInternalTestObserver::GetOverrideImgRepos()
126 return iHcrInt->iOverrideStore;
128 TInt HCR::HCRInternalTestObserver::SwitchRepository(const TText * aFileName, const HCR::HCRInternal::TReposId aId)
130 NKern::ThreadEnterCS();
131 TInt retVal = iHcrInt->SwitchRepository(aFileName, aId);
132 NKern::ThreadLeaveCS();
137 TInt HCR::HCRInternalTestObserver::CheckIntegrity(void)
139 TInt retVal = iHcrInt->CheckIntegrity();
143 TInt HCR::HCRInternalTestObserver::FindSetting(const TSettingId& aId, TSettingType aType, TSettingRef& aSetting)
145 TInt retVal = iHcrInt->FindSetting( aId, aType, aSetting);
149 // -- GLOBALS -----------------------------------------------------------------
153 static HCR::HCRInternal gTestHcrInt;
154 static HCR::HCRInternalTestObserver gObserver;
156 // -- METHODS -----------------------------------------------------------------
161 TInt DHcrTestFactory::Install()
163 HCR_FUNC("DHcrTestFactory::Install");
164 return SetName(&RHcrTest::Name());
167 void DHcrTestFactory::GetCaps(TDes8& aDes) const
169 HCR_FUNC("DHcrTestFactory::GetCaps");
170 Kern::InfoCopy(aDes,0,0);
173 TInt DHcrTestFactory::Create(DLogicalChannelBase*& aChannel)
175 HCR_FUNC("DHcrTestFactory::Create");
177 aChannel=new DHcrTestChannel();
184 // -- METHODS -----------------------------------------------------------------
189 DHcrTestChannel::DHcrTestChannel()
191 HCR_FUNC("DHcrTestChannel");
194 DHcrTestChannel::~DHcrTestChannel()
196 HCR_FUNC("~DHcrTestChannel");
199 TInt DHcrTestChannel::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
201 HCR_FUNC("DHcrTestChannel::DoCreate");
203 iClient = &Kern::CurrentThread();
207 TInt DHcrTestChannel::RequestUserHandle(DThread* aThread, TOwnerType aType)
209 HCR_FUNC("DHcrTestChannel::RequestUserHandle");
211 if (aType!=EOwnerThread || aThread!=iClient)
212 return KErrAccessDenied;
216 TInt DHcrTestChannel::Request(TInt aReqNo, TAny* a1, TAny* /*a2*/ )
218 HCR_FUNC("DHcrTestChannel::Request");
223 case RHcrTest::ECtrlSanityTestWordSettings:
228 case RHcrTest::ECtrlSanityTestLargeSettings:
233 case RHcrTest::ECtrlGetWordSetting:
236 TEST_MEMGET(a1, args, sizeof(args));
238 HCR::TCategoryUid category = (HCR::TCategoryUid) args[0];
240 HCR::TElementId key = (HCR::TElementId) args[1];
242 TInt type = (TInt) args[2];
244 const TText * fileInSysBinName = (const TText *)"filerepos.dat";
245 TInt err = gObserver.SwitchRepository(fileInSysBinName, HCR::HCRInternal::ECoreRepos);
247 HCR_TRACE_RETURN(err);
249 // Negative tests on HCR::TRepositoryFile; aNum will be 0
250 HCR::TRepository* repos = gObserver.GetCoreImgRepos();;
251 __NK_ASSERT_DEBUG(repos != NULL);
254 HCR::SSettingId* ids[1];// = new HCR::SSettingId*[1];
258 HCR::TSettingType* types[1];
260 NKern::ThreadEnterCS();
261 ids[0] = new HCR::SSettingId();
262 vals[0] = new TInt32();
263 errs[0] = new TInt();
264 types[0] = new HCR::TSettingType();
266 if(ids[0] == NULL || vals[0] == NULL || errs[0] == NULL || types[0] == NULL)
272 NKern::ThreadLeaveCS();
273 HCR_TRACE_RETURN(KErrNoMemory);
276 ids[0]->iCat = category;
279 // Negative tests on HCR::TRepositoryFile; aNum will be 0
280 TInt r = repos->GetWordSettings(0, ids, vals, types, errs);
281 // only expected errors are KErrNotFound or KErrNone
282 // thest if there is other error; if yes fail the test
283 if(r != KErrNotFound && r != KErrNone && r < KErrNone)
289 NKern::ThreadLeaveCS();
293 // Negative testing on HCR::TRepositoryFile; try to get words for large value
294 if(type > HCR::ETypeLinAddr)
296 r = repos->GetWordSettings(1, ids, vals, types, errs);
297 if(r != KErrArgument && r != KErrNotFound && r < KErrNone)
303 NKern::ThreadLeaveCS();
308 HCR::TRepositoryCompiled* compiledRepos = reinterpret_cast<HCR::TRepositoryCompiled*>(gObserver.GetVariantImgRepos());
309 __NK_ASSERT_DEBUG(compiledRepos != NULL);
311 ids[0]->iCat = KHCRUID_TestCategory1;
314 // Negative tests on HCR::TRepositoryCompiled; aNum will be 0
315 r = compiledRepos->GetWordSettings(0, ids, vals, types, errs);
316 if(r != KErrNotFound && r != KErrNone && r < KErrNone)
322 NKern::ThreadLeaveCS();
326 // Negative testing on HCR::TRepositoryFile; try to get words for large value
327 if(type > HCR::ETypeLinAddr)
329 r = compiledRepos->GetWordSettings(1, ids, vals, types, errs);
330 if(r != KErrArgument && r != KErrNotFound && r < KErrNone)
336 NKern::ThreadLeaveCS();
345 NKern::ThreadLeaveCS();
350 case RHcrTest::ECtrlGetLargeSetting:
355 case RHcrTest::ECtrlGetManyWordSettings:
360 case RHcrTest::ECtrlGetManyLargeSettings:
365 case RHcrTest::ECtrlSwitchRepository:
369 // Clear and reset iCoreImgStore
370 HCR_TRACE1("--- value of iCoreImgStore:0x%08x before clear", gObserver.GetCoreImgRepos());
371 err = gObserver.SwitchRepository(NULL, HCR::HCRInternal::ECoreRepos);
373 HCR_TRACE1("--- value of iCoreImgStore:0x%08x after clear", gObserver.GetCoreImgRepos());
374 if( err != KErrNone )
379 // Clear and reset iOverrideStore
380 HCR_TRACE1("--- value of iOverrideStore:0x%08x before clear", gObserver.GetOverrideImgRepos());
381 err = gObserver.SwitchRepository(NULL, HCR::HCRInternal::EOverrideRepos);
383 HCR_TRACE1("--- value of iOverrideStore:0x%08x after clear", gObserver.GetOverrideImgRepos());
384 if( err != KErrNone )
389 // Switch iCoreImgStore to a repositore store located in \sys\bin directory
390 const TText * fileInSysBinName = (const TText *)"d_hcrsim_own.ldd";
391 err = gObserver.SwitchRepository(fileInSysBinName, HCR::HCRInternal::ECoreRepos);
393 HCR_TRACE_RETURN(err);
396 // Switch iOverrideStore to a repositore store located in \sys\Data directory
397 const TText * fileInSysDataName = (const TText *)"EMPTY.DAT";
398 err = gObserver.SwitchRepository(fileInSysDataName, HCR::HCRInternal::EOverrideRepos);
400 HCR_TRACE_RETURN(err);
402 // Try to switch iCoreImgStore to a not existing one and check the SwitchRepository()
403 // keeps its original value.
404 HCR::TRepository* oldRepos = gObserver.GetCoreImgRepos();
405 HCR_TRACE1("--- value of iCoreImgStore:0x%08x before try to switch to a not exist", oldRepos);
406 const TText * wrongFileName = (const TText *)"hcr.ldl";
407 err = gObserver.SwitchRepository(wrongFileName, HCR::HCRInternal::ECoreRepos);
408 if ( err != KErrNotFound)
409 HCR_TRACE_RETURN(err);
413 HCR::TRepository* newRepos = gObserver.GetCoreImgRepos();
414 HCR_TRACE1("--- value of iCoreImgStore:0x%08x after try to switch to a not exist", newRepos);
415 if ( oldRepos != newRepos )
416 HCR_TRACE_RETURN(KErrGeneral);
418 // Switch iOverrideStore to a new, existing repository, different the current and check the
419 // iOverrideStore value changed.
420 oldRepos = gObserver.GetOverrideImgRepos();
421 HCR_TRACE1("--- value of iOverrideStore:0x%08x before try to switch to existing one", oldRepos);
422 err = gObserver.SwitchRepository(fileInSysBinName, HCR::HCRInternal::EOverrideRepos);
423 if ( err != KErrNone)
424 HCR_TRACE_RETURN(err);
426 newRepos = gObserver.GetOverrideImgRepos();
427 HCR_TRACE1("--- value of iOverrideStore:0x%08x after try to switch to existing on", newRepos);
428 if ( oldRepos == newRepos )
429 HCR_TRACE_RETURN(KErrGeneral);
434 case RHcrTest::ECtrlNegativeTestsLargeValues:
436 //Test that HCR::TRepositoryCompiled::GetLargeValue & HCR::TRepositoryFile::GetLargeValue return KErrArgument
438 TEST_MEMGET(a1, args, sizeof(args));
439 // Retrieve structures from client
440 TInt expectedError = (TUint) args[0];
442 const TText * fileInSysBinName = (const TText *)"filerepos.dat";
443 TInt err = gObserver.SwitchRepository(fileInSysBinName, HCR::HCRInternal::ECoreRepos);
445 HCR_TRACE_RETURN(err);
447 // Do test for HCR::TRepositoryFile
448 HCR::TRepository* repos = gObserver.GetCoreImgRepos();;
449 __NK_ASSERT_DEBUG(repos != NULL);
451 HCR::UValueLarge value;
452 HCR::TSettingRef ref(0,0);
453 HCR::TSettingId id(1,1); //word setting value in repository
454 err = repos->FindSetting(id, ref);
457 err = repos->GetLargeValue(ref, value);
458 if(err != expectedError)
460 HCR_TRACE_RETURN(err);
464 //Do test for HCR::TRepositoryCompiled
465 HCR::TRepositoryCompiled* compiledRepos = reinterpret_cast<HCR::TRepositoryCompiled*>(gObserver.GetVariantImgRepos());
466 if (compiledRepos == 0)
468 HCR_TRACE_RETURN(KErrGeneral);
471 id = HCR::TSettingId(KHCRUID_TestCategory1,1);
472 err = compiledRepos->FindSetting(id, ref);
475 err = compiledRepos->GetLargeValue(ref, value);
476 if(err != expectedError)
478 HCR_TRACE_RETURN(err);
486 case RHcrTest::ECtrlCheckOverrideReposIntegrity:
488 HCR::TRepository* overrideRepos = gObserver.GetOverrideImgRepos(); // Shadowed SMR/HCR
491 if( 0 != overrideRepos )
493 err = overrideRepos->CheckIntegrity();
499 case RHcrTest::ECtrlCheckOverrideRepos102400Content:
501 HCR::TRepository* overrideRepos = gObserver.GetOverrideImgRepos(); // Shadowed SMR/HCR
504 if( 0 != overrideRepos )
506 for( TInt index = 0; index < itemsSize; ++index)
508 HCR::TSettingId id(items[index].iCategoryUID, items[index].iElementID);
509 HCR_TRACE3("--- index:%5d, iCategoryUID:0x%08x, iElementID:0x%08x"
511 , items[index].iCategoryUID
512 , items[index].iElementID
514 HCR::TSettingRef val(overrideRepos, 0);
515 HCR::TSettingType type = (HCR::TSettingType)items[index].iType;
516 TInt r = gObserver.FindSetting(id, type, val);
522 HCR::UValueWord valueWord;
523 r = overrideRepos->GetValue(val, valueWord);
524 HCR_TRACE1("--- value:0x%08x", valueWord.iUInt32);
525 if( valueWord.iUInt32 != items[index].iValue)
535 case RHcrTest::ECtrlSwitchFileRepository:
539 TEST_MEMGET(a1, args, sizeof(args));
540 const TText* fileRepName = (TText*) args[0];
542 r = gObserver.SwitchRepository(fileRepName, HCR::HCRInternal::ECoreRepos);
551 case RHcrTest::ECtrlCompiledFindSettingsInCategory:
554 //Do test for HCR::TRepositoryCompiled
558 //It's a pre-condition to enter critical section before
559 //kernel memory allocation
560 NKern::ThreadEnterCS();
561 TInt32* pFirst = new TInt32;
562 TInt32* pLast = new TInt32;
563 //We've done with allocation, exit CS
564 NKern::ThreadLeaveCS();
566 if(!pFirst || !pLast)
568 HCR_TRACE_RETURN(KErrNoMemory);
571 TEST_MEMGET(a1, args, sizeof(args));
572 HCR::TCategoryUid catUid = (HCR::TCategoryUid)args[0];
575 HCR::TRepositoryCompiled* compiledRepos =
576 reinterpret_cast<HCR::TRepositoryCompiled*>(gObserver.GetVariantImgRepos());
577 if (compiledRepos == 0)
579 HCR_TRACE_RETURN(KErrGeneral);
582 //This function return the result of operation r and first element and
583 //last element in the category written back to the user side test code
584 //variable referenced by pFirst and pLast pointers
585 r = compiledRepos->FindNumSettingsInCategory(catUid,
588 TEST_MEMPUT(args[1], pFirst, sizeof(TInt32));
589 TEST_MEMPUT(args[2], pLast, sizeof(TInt32));
592 {HCR_TRACE_RETURN(r);}
597 case RHcrTest::ECtrlFileFindSettingsInCategory:
601 TEST_MEMGET(a1, args, sizeof(args));
602 HCR::TCategoryUid catUid = (HCR::TCategoryUid)args[0];
604 //It's a pre-condition to enter critical section before
605 //kernel memory allocation
606 NKern::ThreadEnterCS();
607 TInt32* pFirst = new TInt32;
608 TInt32* pLast = new TInt32;
609 //We've done with allocation, exit CS
610 NKern::ThreadLeaveCS();
612 if(!pFirst || !pLast)
614 HCR_TRACE_RETURN(KErrNoMemory);
618 // Do test for HCR::TRepositoryFile
619 HCR::TRepository* repos = gObserver.GetCoreImgRepos();
620 __NK_ASSERT_DEBUG(repos != NULL);
622 //This function return the result of operation r and first element and
623 //last element in the category written back to the user side test code
624 //variable referenced by pFirst and pLast pointers
625 r = repos->FindNumSettingsInCategory(catUid,
628 TEST_MEMPUT(args[1], pFirst, sizeof(TInt32));
629 TEST_MEMPUT(args[2], pLast, sizeof(TInt32));
632 {HCR_TRACE_RETURN(r);}
643 return KErrNotSupported;
647 // -- GLOBALS -----------------------------------------------------------------
650 DECLARE_STANDARD_LDD()
652 HCR_FUNC("D_HCR_DECLARE_STANDARD_LDD");
654 // Try to initialise without a varian; KErrGeneral error should be returned
655 new(&gTestHcrInt) HCR::HCRInternal(NULL);
656 TInt err = gTestHcrInt.Initialise();
657 if (err != KErrGeneral)
661 // Taken from HCR_PIL.CPP InitExtension() method
663 HCR::MVariant* varPtr = CreateHCRVariant();
667 new(&gTestHcrInt) HCR::HCRInternal(varPtr);
669 err = gTestHcrInt.Initialise();
673 new(&gObserver) HCR::HCRInternalTestObserver(&gTestHcrInt);
675 // ===== Above would be moved to DoRequest for test caes....
677 return new DHcrTestFactory;