os/persistentdata/featuremgmt/featuremgr/test/rtest/src/t_fmgroom.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include <e32test.h>
sl@0
    17
#include <bautils.h>
sl@0
    18
#include <featmgr.h>
sl@0
    19
#include <featureuids.h>
sl@0
    20
#include <featurecontrol.h>
sl@0
    21
#include <featdiscovery.h>
sl@0
    22
#include <featurenotifier.h>
sl@0
    23
#include "../../../src/clientdll/featmgrresourcetester.h"
sl@0
    24
sl@0
    25
using namespace NFeature;
sl@0
    26
sl@0
    27
sl@0
    28
const TInt KInvalidFeatureId    = 90901671;
sl@0
    29
const TUid KInvalidFeatureUid   = {KInvalidFeatureId};
sl@0
    30
sl@0
    31
static TInt TheProcessHandleCount = 0;
sl@0
    32
static TInt TheThreadHandleCount = 0;
sl@0
    33
static TInt TheAllocatedCellsCount = 0;
sl@0
    34
sl@0
    35
#ifdef _DEBUG
sl@0
    36
static const TInt KBurstRate = 20;
sl@0
    37
#endif
sl@0
    38
sl@0
    39
enum TFeatMgrOomTestMode
sl@0
    40
    {
sl@0
    41
    EFeatMgrOomServerTestMode,
sl@0
    42
    EFeatMgrOomClientTestMode,
sl@0
    43
    };
sl@0
    44
sl@0
    45
///////////////////////////////////////////////////////////////////////////////////////
sl@0
    46
sl@0
    47
static RTest TheTest(_L("t_fmgroom"));
sl@0
    48
sl@0
    49
sl@0
    50
sl@0
    51
///////////////////////////////////////////////////////////////////////////////////////
sl@0
    52
///////////////////////////////////////////////////////////////////////////////////////
sl@0
    53
//Test macros and functions
sl@0
    54
void Check1(TInt aValue, TInt aLine)
sl@0
    55
    {
sl@0
    56
    if(!aValue)
sl@0
    57
        {
sl@0
    58
        RDebug::Print(_L("*** Expression evaluated to false. Line %d\r\n"), aLine);
sl@0
    59
        TheTest(EFalse, aLine);
sl@0
    60
        }
sl@0
    61
    }
sl@0
    62
void Check2(TInt aValue, TInt aExpected, TInt aLine)
sl@0
    63
    {
sl@0
    64
    if(aValue != aExpected)
sl@0
    65
        {
sl@0
    66
        RDebug::Print(_L("*** Expected: %d, got: %d. Line %d\r\n"), aExpected, aValue, aLine);
sl@0
    67
        TheTest(EFalse, aLine);
sl@0
    68
        }
sl@0
    69
    }
sl@0
    70
#define TEST(arg) ::Check1((arg), __LINE__)
sl@0
    71
#define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__)
sl@0
    72
sl@0
    73
///////////////////////////////////////////////////////////////////////////////////////
sl@0
    74
sl@0
    75
static void MarkHandles()
sl@0
    76
    {
sl@0
    77
    RThread().HandleCount(TheProcessHandleCount, TheThreadHandleCount);
sl@0
    78
    }
sl@0
    79
sl@0
    80
static void MarkAllocatedCells()
sl@0
    81
    {
sl@0
    82
    TheAllocatedCellsCount = User::CountAllocCells();
sl@0
    83
    }
sl@0
    84
sl@0
    85
static void CheckAllocatedCells()
sl@0
    86
    {
sl@0
    87
    TInt allocatedCellsCount = User::CountAllocCells();
sl@0
    88
    TEST2(allocatedCellsCount, TheAllocatedCellsCount);
sl@0
    89
    }
sl@0
    90
sl@0
    91
static void CheckHandles()
sl@0
    92
    {
sl@0
    93
    TInt endProcessHandleCount;
sl@0
    94
    TInt endThreadHandleCount;
sl@0
    95
    
sl@0
    96
    RThread().HandleCount(endProcessHandleCount, endThreadHandleCount);
sl@0
    97
sl@0
    98
    TEST2(TheProcessHandleCount, endProcessHandleCount);
sl@0
    99
    TEST2(TheThreadHandleCount, endThreadHandleCount);
sl@0
   100
    }
sl@0
   101
sl@0
   102
static void OomPreStep(TInt aFailingAllocationNo, TFeatMgrOomTestMode aMode = EFeatMgrOomClientTestMode)
sl@0
   103
    {
sl@0
   104
    if(aMode == EFeatMgrOomClientTestMode)
sl@0
   105
        {
sl@0
   106
        MarkHandles();
sl@0
   107
        MarkAllocatedCells();
sl@0
   108
        __UHEAP_MARK;
sl@0
   109
        __UHEAP_SETBURSTFAIL(RAllocator::EBurstFailNext, aFailingAllocationNo, KBurstRate);
sl@0
   110
        }
sl@0
   111
    else
sl@0
   112
        {
sl@0
   113
        TFeatMgrResourceTester::Mark();
sl@0
   114
        TFeatMgrResourceTester::SetHeapFailure(RHeap::EBurstFailNext, aFailingAllocationNo);
sl@0
   115
        }
sl@0
   116
    }
sl@0
   117
sl@0
   118
static void OomPostStep(TFeatMgrOomTestMode aMode = EFeatMgrOomClientTestMode)
sl@0
   119
    {
sl@0
   120
    if(aMode == EFeatMgrOomClientTestMode)
sl@0
   121
        {
sl@0
   122
        __UHEAP_RESET;
sl@0
   123
        __UHEAP_MARKEND;
sl@0
   124
        CheckAllocatedCells();
sl@0
   125
        CheckHandles();
sl@0
   126
        }
sl@0
   127
    else
sl@0
   128
        {
sl@0
   129
        TFeatMgrResourceTester::SetHeapFailure(RHeap::ENone, 0);
sl@0
   130
        TFeatMgrResourceTester::Check();
sl@0
   131
        }
sl@0
   132
    }
sl@0
   133
sl@0
   134
///////////////////////////////////////////////////////////////////////////////////////
sl@0
   135
sl@0
   136
/**
sl@0
   137
@SYMTestCaseID          PDS-EFM-CT-4068
sl@0
   138
@SYMTestCaseDesc        Include test case 4069 too
sl@0
   139
@SYMTestPriority        High
sl@0
   140
@SYMTestActions         
sl@0
   141
@SYMTestExpectedResults Test must not fail
sl@0
   142
@SYMDEF                 DEF144262
sl@0
   143
*/
sl@0
   144
void ControlOpenOomTest(TBool aUseConnect)
sl@0
   145
    {
sl@0
   146
    TInt err = KErrNoMemory;
sl@0
   147
    TInt failingAllocationNo = 0;
sl@0
   148
    RFeatureControl ctrl;
sl@0
   149
    TheTest.Printf(_L("Iteration:\r\n"));
sl@0
   150
    while(err == KErrNoMemory)
sl@0
   151
        {
sl@0
   152
        TheTest.Printf(_L(" %d"), ++failingAllocationNo);
sl@0
   153
        OomPreStep(failingAllocationNo);
sl@0
   154
        err = aUseConnect ? ctrl.Connect() : ctrl.Open();
sl@0
   155
        ctrl.Close();
sl@0
   156
        OomPostStep();
sl@0
   157
        }
sl@0
   158
    if(err != KErrNoMemory)
sl@0
   159
        {
sl@0
   160
        TEST2(err, KErrNone);   
sl@0
   161
        }
sl@0
   162
    TheTest.Printf(_L("\r\n===OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
sl@0
   163
    }
sl@0
   164
sl@0
   165
/**
sl@0
   166
@SYMTestCaseID          PDS-EFM-CT-4070
sl@0
   167
@SYMTestCaseDesc        Include test case 4071-4077 too
sl@0
   168
@SYMTestPriority        High
sl@0
   169
@SYMTestActions         
sl@0
   170
@SYMTestExpectedResults Test must not fail
sl@0
   171
@SYMDEF                 DEF144262
sl@0
   172
*/
sl@0
   173
void ControlFeatureSupportedOomTest(TBool aUseUid, TBool aInvalidFeature, TFeatMgrOomTestMode aMode)
sl@0
   174
    {
sl@0
   175
    RFeatureControl ctrl;
sl@0
   176
    TInt err = ctrl.Open();
sl@0
   177
    TEST2(err, KErrNone);
sl@0
   178
    
sl@0
   179
    const TUid KFeatureUid(aInvalidFeature ? KInvalidFeatureUid : KConnectivity);
sl@0
   180
    TFeatureEntry fentry(KFeatureUid);
sl@0
   181
    
sl@0
   182
    err = KErrNoMemory;
sl@0
   183
    TInt failingAllocationNo = 0;
sl@0
   184
    TheTest.Printf(_L("Iteration:\r\n"));
sl@0
   185
    while(err == KErrNoMemory)
sl@0
   186
        {
sl@0
   187
        TheTest.Printf(_L(" %d"), ++failingAllocationNo);
sl@0
   188
        OomPreStep(failingAllocationNo, aMode);
sl@0
   189
        err = aUseUid ? ctrl.FeatureSupported(KFeatureUid) : ctrl.FeatureSupported(fentry);
sl@0
   190
        OomPostStep(aMode);
sl@0
   191
        }
sl@0
   192
    ctrl.Close();
sl@0
   193
    if(err != KErrNoMemory)
sl@0
   194
        {
sl@0
   195
        TEST2(err, aInvalidFeature ? KErrNotFound : KFeatureSupported);   
sl@0
   196
        }
sl@0
   197
    TheTest.Printf(_L("\r\n===OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
sl@0
   198
    }
sl@0
   199
sl@0
   200
/**
sl@0
   201
@SYMTestCaseID          PDS-EFM-CT-4078
sl@0
   202
@SYMTestCaseDesc        Include test case 4079 too
sl@0
   203
@SYMTestPriority        High
sl@0
   204
@SYMTestActions         
sl@0
   205
@SYMTestExpectedResults Test must not fail
sl@0
   206
@SYMDEF                 DEF144262
sl@0
   207
*/
sl@0
   208
void ControlListSupportedFeaturesOomTest(TFeatMgrOomTestMode aMode)
sl@0
   209
    {
sl@0
   210
    RFeatureControl ctrl;
sl@0
   211
    TInt err = ctrl.Open();
sl@0
   212
    TEST2(err, KErrNone);
sl@0
   213
    
sl@0
   214
    err = KErrNoMemory;
sl@0
   215
    TInt failingAllocationNo = 0;
sl@0
   216
    TheTest.Printf(_L("Iteration:\r\n"));
sl@0
   217
    while(err == KErrNoMemory)
sl@0
   218
        {
sl@0
   219
        TheTest.Printf(_L(" %d"), ++failingAllocationNo);
sl@0
   220
        OomPreStep(failingAllocationNo, aMode);
sl@0
   221
        const TInt KGranularity = 1;
sl@0
   222
        RFeatureUidArray farray(KGranularity);
sl@0
   223
        err = ctrl.ListSupportedFeatures(farray);
sl@0
   224
        if(err != KErrNoMemory)
sl@0
   225
            {
sl@0
   226
            TEST2(err, KErrNone);
sl@0
   227
            TInt count = farray.Count();
sl@0
   228
            TheTest.Printf(_L("===Features count: %d\r\n"), count);
sl@0
   229
            TEST(count > 0);
sl@0
   230
            }
sl@0
   231
        farray.Close();
sl@0
   232
        OomPostStep(aMode);
sl@0
   233
        }
sl@0
   234
    ctrl.Close();
sl@0
   235
    TheTest.Printf(_L("\r\n===OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
sl@0
   236
    }
sl@0
   237
sl@0
   238
/**
sl@0
   239
@SYMTestCaseID          PDS-EFM-CT-4080
sl@0
   240
@SYMTestCaseDesc        Include test case 4081 too
sl@0
   241
@SYMTestPriority        High
sl@0
   242
@SYMTestActions         
sl@0
   243
@SYMTestExpectedResults Test must not fail
sl@0
   244
@SYMDEF                 DEF144262
sl@0
   245
*/
sl@0
   246
void ControlFeaturesSupportedOomTest(TFeatMgrOomTestMode aMode)
sl@0
   247
    {
sl@0
   248
    RFeatureControl ctrl;
sl@0
   249
    TInt err = ctrl.Open();
sl@0
   250
    TEST2(err, KErrNone);
sl@0
   251
    RFeatureUidArray farray;
sl@0
   252
    err = ctrl.ListSupportedFeatures(farray);
sl@0
   253
    TEST2(err, KErrNone);
sl@0
   254
    
sl@0
   255
    err = KErrNoMemory;
sl@0
   256
    TInt failingAllocationNo = 0;
sl@0
   257
    TheTest.Printf(_L("Iteration:\r\n"));
sl@0
   258
    while(err == KErrNoMemory)
sl@0
   259
        {
sl@0
   260
        TheTest.Printf(_L(" %d"), ++failingAllocationNo);
sl@0
   261
        OomPreStep(failingAllocationNo, aMode);
sl@0
   262
        RFeatureArray farray2;
sl@0
   263
        err = KErrNone;
sl@0
   264
        for(TInt i=0;i<farray.Count() && err==KErrNone;++i)
sl@0
   265
            {
sl@0
   266
            err = farray2.Append(farray[i]); 
sl@0
   267
            }
sl@0
   268
        if(err == KErrNone)
sl@0
   269
            {
sl@0
   270
            err = ctrl.FeaturesSupported(farray2);
sl@0
   271
            }
sl@0
   272
        if(err != KErrNoMemory)
sl@0
   273
            {
sl@0
   274
            TEST2(err, KErrNone);
sl@0
   275
            TInt count = farray2.Count();
sl@0
   276
            TheTest.Printf(_L("===Features count: %d\r\n"), count);
sl@0
   277
            TEST(count > 0);
sl@0
   278
            }
sl@0
   279
        farray2.Close();
sl@0
   280
        OomPostStep(aMode);
sl@0
   281
        }
sl@0
   282
    farray.Close();
sl@0
   283
    ctrl.Close();
sl@0
   284
    TheTest.Printf(_L("\r\n===OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
sl@0
   285
    }
sl@0
   286
sl@0
   287
/**
sl@0
   288
@SYMTestCaseID          PDS-EFM-CT-4082
sl@0
   289
@SYMTestCaseDesc        Include test case 4083 too
sl@0
   290
@SYMTestPriority        High
sl@0
   291
@SYMTestActions         
sl@0
   292
@SYMTestExpectedResults Test must not fail
sl@0
   293
@SYMDEF                 DEF144262
sl@0
   294
*/
sl@0
   295
void ControlAddFeatureOomTest(TFeatMgrOomTestMode aMode)
sl@0
   296
    {
sl@0
   297
    RFeatureControl ctrl;
sl@0
   298
    TInt err = ctrl.Open();
sl@0
   299
    TEST2(err, KErrNone);
sl@0
   300
sl@0
   301
    const TUid KNewFeatureUid = {0x7888ABCE}; 
sl@0
   302
    TBitFlags32 flags;
sl@0
   303
    flags.Set(EFeatureSupported);
sl@0
   304
    flags.Set(EFeatureModifiable);    
sl@0
   305
    flags.Set(EFeaturePersisted);
sl@0
   306
    TFeatureEntry fentry(KNewFeatureUid, flags, 0x0);
sl@0
   307
    
sl@0
   308
    err = KErrNoMemory;
sl@0
   309
    TInt failingAllocationNo = 0;
sl@0
   310
    TheTest.Printf(_L("Iteration:\r\n"));
sl@0
   311
    while(err == KErrNoMemory)
sl@0
   312
        {
sl@0
   313
        TheTest.Printf(_L(" %d"), ++failingAllocationNo);
sl@0
   314
        OomPreStep(failingAllocationNo, aMode);
sl@0
   315
        err = ctrl.AddFeature(fentry);
sl@0
   316
        OomPostStep(aMode);
sl@0
   317
        if(err == KErrNoMemory)
sl@0
   318
            {
sl@0
   319
            err = ctrl.EnableFeature(fentry.FeatureUid());
sl@0
   320
            TEST2(err, KErrNotFound);
sl@0
   321
            }
sl@0
   322
        }
sl@0
   323
    TEST2(err, KErrNone);
sl@0
   324
    err = ctrl.DeleteFeature(fentry.FeatureUid());
sl@0
   325
    TEST2(err, KErrNone);
sl@0
   326
    
sl@0
   327
    ctrl.Close();
sl@0
   328
    TheTest.Printf(_L("\r\n===OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
sl@0
   329
    }
sl@0
   330
sl@0
   331
/**
sl@0
   332
@SYMTestCaseID          PDS-EFM-CT-4084
sl@0
   333
@SYMTestCaseDesc        Include test case 4085 too
sl@0
   334
@SYMTestPriority        High
sl@0
   335
@SYMTestActions         
sl@0
   336
@SYMTestExpectedResults Test must not fail
sl@0
   337
@SYMDEF                 DEF144262
sl@0
   338
*/
sl@0
   339
void ControlDeleteFeatureOomTest(TFeatMgrOomTestMode aMode)
sl@0
   340
    {
sl@0
   341
    RFeatureControl ctrl;
sl@0
   342
    TInt err = ctrl.Open();
sl@0
   343
    TEST2(err, KErrNone);
sl@0
   344
sl@0
   345
    const TUid KNewFeatureUid = {0x7888ABCE}; 
sl@0
   346
    TBitFlags32 flags;
sl@0
   347
    flags.Set(EFeatureSupported);
sl@0
   348
    flags.Set(EFeatureModifiable);
sl@0
   349
    TFeatureEntry fentry(KNewFeatureUid, flags, 0x0);
sl@0
   350
    err = ctrl.AddFeature(fentry);
sl@0
   351
    TEST2(err, KErrNone);
sl@0
   352
    
sl@0
   353
    err = KErrNoMemory;
sl@0
   354
    TInt failingAllocationNo = 0;
sl@0
   355
    TheTest.Printf(_L("Iteration:\r\n"));
sl@0
   356
    while(err == KErrNoMemory)
sl@0
   357
        {
sl@0
   358
        TheTest.Printf(_L(" %d"), ++failingAllocationNo);
sl@0
   359
        OomPreStep(failingAllocationNo, aMode);
sl@0
   360
        err = ctrl.DeleteFeature(fentry.FeatureUid());
sl@0
   361
        OomPostStep(aMode);
sl@0
   362
        if(err == KErrNoMemory)
sl@0
   363
            {
sl@0
   364
            err = ctrl.EnableFeature(fentry.FeatureUid());
sl@0
   365
            TEST2(err, KErrNone);
sl@0
   366
            }
sl@0
   367
        }
sl@0
   368
    TEST2(err, KErrNone);
sl@0
   369
    
sl@0
   370
    ctrl.Close();
sl@0
   371
    TheTest.Printf(_L("\r\n===OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
sl@0
   372
    }
sl@0
   373
sl@0
   374
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
sl@0
   375
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
sl@0
   376
sl@0
   377
class TTestFeatureObserver : public MFeatureObserver
sl@0
   378
    {
sl@0
   379
    public: 
sl@0
   380
        virtual void HandleNotifyChange(TFeatureChangeType /*aType*/, TFeatureEntry /*aFeature*/)
sl@0
   381
            {
sl@0
   382
            }
sl@0
   383
        virtual void HandleNotifyError(TInt /*aError*/)
sl@0
   384
            {
sl@0
   385
            }
sl@0
   386
    };
sl@0
   387
sl@0
   388
/**
sl@0
   389
@SYMTestCaseID          PDS-EFM-CT-4086
sl@0
   390
@SYMTestCaseDesc        Include test case 4087 too
sl@0
   391
@SYMTestPriority        High
sl@0
   392
@SYMTestActions         
sl@0
   393
@SYMTestExpectedResults Test must not fail
sl@0
   394
@SYMDEF                 DEF144262
sl@0
   395
*/
sl@0
   396
void NotifierNewLOomTest(TFeatMgrOomTestMode aMode)
sl@0
   397
    {
sl@0
   398
    CActiveScheduler* scheduler = new CActiveScheduler;
sl@0
   399
    TEST(scheduler != NULL);
sl@0
   400
    CActiveScheduler::Install(scheduler);
sl@0
   401
    
sl@0
   402
    RFeatureControl ctrl;
sl@0
   403
    TInt err = ctrl.Open();
sl@0
   404
    TEST2(err, KErrNone);
sl@0
   405
    
sl@0
   406
    TTestFeatureObserver observer;
sl@0
   407
    err = KErrNoMemory;
sl@0
   408
    TInt failingAllocationNo = 0;
sl@0
   409
    TheTest.Printf(_L("Iteration:\r\n"));
sl@0
   410
    while(err == KErrNoMemory)
sl@0
   411
        {
sl@0
   412
        TheTest.Printf(_L(" %d"), ++failingAllocationNo);
sl@0
   413
        OomPreStep(failingAllocationNo, aMode);
sl@0
   414
        CFeatureNotifier* notifier = NULL;
sl@0
   415
        TRAP(err, notifier = CFeatureNotifier::NewL(observer));
sl@0
   416
        delete notifier;
sl@0
   417
        OomPostStep(aMode);
sl@0
   418
        }
sl@0
   419
    TEST2(err, KErrNone);
sl@0
   420
    ctrl.Close();
sl@0
   421
    delete scheduler;
sl@0
   422
    TheTest.Printf(_L("\r\n===OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
sl@0
   423
    }
sl@0
   424
sl@0
   425
/**
sl@0
   426
@SYMTestCaseID          PDS-EFM-CT-4088
sl@0
   427
@SYMTestCaseDesc        Include test case 4089-4091 too
sl@0
   428
@SYMTestPriority        High
sl@0
   429
@SYMTestActions         
sl@0
   430
@SYMTestExpectedResults Test must not fail
sl@0
   431
@SYMDEF                 DEF144262
sl@0
   432
*/
sl@0
   433
void NotifierNotifyRequestOomTest(TBool aInvalidFeature, TFeatMgrOomTestMode aMode)
sl@0
   434
    {
sl@0
   435
    CActiveScheduler* scheduler = new CActiveScheduler;
sl@0
   436
    TEST(scheduler != NULL);
sl@0
   437
    CActiveScheduler::Install(scheduler);
sl@0
   438
    
sl@0
   439
    RFeatureControl ctrl;
sl@0
   440
    TInt err = ctrl.Open();
sl@0
   441
    TEST2(err, KErrNone);
sl@0
   442
    
sl@0
   443
    TTestFeatureObserver observer;
sl@0
   444
    CFeatureNotifier* notifier = NULL;
sl@0
   445
    TRAP(err, notifier = CFeatureNotifier::NewL(observer));
sl@0
   446
    TEST2(err, KErrNone);
sl@0
   447
sl@0
   448
    const TUid KFeatureUid(aInvalidFeature ? KInvalidFeatureUid : KConnectivity);
sl@0
   449
    
sl@0
   450
    err = KErrNoMemory;
sl@0
   451
    TInt failingAllocationNo = 0;
sl@0
   452
    TheTest.Printf(_L("Iteration:\r\n"));
sl@0
   453
    while(err == KErrNoMemory)
sl@0
   454
        {
sl@0
   455
        TheTest.Printf(_L(" %d"), ++failingAllocationNo);
sl@0
   456
        OomPreStep(failingAllocationNo, aMode);
sl@0
   457
        err = notifier->NotifyRequest(KFeatureUid);
sl@0
   458
        (void)notifier->NotifyCancelAll();
sl@0
   459
        OomPostStep(aMode);
sl@0
   460
        }
sl@0
   461
    TEST2(err, KErrNone);
sl@0
   462
    delete notifier;
sl@0
   463
    ctrl.Close();
sl@0
   464
    delete scheduler;
sl@0
   465
    TheTest.Printf(_L("\r\n===OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
sl@0
   466
    }
sl@0
   467
sl@0
   468
/**
sl@0
   469
@SYMTestCaseID          PDS-EFM-CT-4092
sl@0
   470
@SYMTestCaseDesc        Include test case 4093 too
sl@0
   471
@SYMTestPriority        High
sl@0
   472
@SYMTestActions         
sl@0
   473
@SYMTestExpectedResults Test must not fail
sl@0
   474
@SYMDEF                 DEF144262
sl@0
   475
*/
sl@0
   476
void NotifierNotifyRequestsOomTest(TFeatMgrOomTestMode aMode)
sl@0
   477
    {
sl@0
   478
    CActiveScheduler* scheduler = new CActiveScheduler;
sl@0
   479
    TEST(scheduler != NULL);
sl@0
   480
    CActiveScheduler::Install(scheduler);
sl@0
   481
    
sl@0
   482
    RFeatureControl ctrl;
sl@0
   483
    TInt err = ctrl.Open();
sl@0
   484
    TEST2(err, KErrNone);
sl@0
   485
    
sl@0
   486
    TTestFeatureObserver observer;
sl@0
   487
    CFeatureNotifier* notifier = NULL;
sl@0
   488
    TRAP(err, notifier = CFeatureNotifier::NewL(observer));
sl@0
   489
    TEST2(err, KErrNone);
sl@0
   490
sl@0
   491
    RFeatureUidArray features;
sl@0
   492
    err = features.Append(KConnectivity);
sl@0
   493
    TEST2(err, KErrNone);
sl@0
   494
    err = features.Append(KFax);
sl@0
   495
    TEST2(err, KErrNone);
sl@0
   496
    err = features.Append(KConnectivity);
sl@0
   497
    TEST2(err, KErrNone);
sl@0
   498
    err = features.Append(KLocationManagement);
sl@0
   499
    TEST2(err, KErrNone);
sl@0
   500
    
sl@0
   501
    err = KErrNoMemory;
sl@0
   502
    TInt failingAllocationNo = 0;
sl@0
   503
    TheTest.Printf(_L("Iteration:\r\n"));
sl@0
   504
    while(err == KErrNoMemory)
sl@0
   505
        {
sl@0
   506
        TheTest.Printf(_L(" %d"), ++failingAllocationNo);
sl@0
   507
        OomPreStep(failingAllocationNo, aMode);
sl@0
   508
        err = notifier->NotifyRequest(features);
sl@0
   509
        (void)notifier->NotifyCancelAll();
sl@0
   510
        OomPostStep(aMode);
sl@0
   511
        }
sl@0
   512
    TEST2(err, KErrNone);
sl@0
   513
    features.Close();
sl@0
   514
    delete notifier;
sl@0
   515
    ctrl.Close();
sl@0
   516
    delete scheduler;
sl@0
   517
    TheTest.Printf(_L("\r\n===OOM test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
sl@0
   518
    }
sl@0
   519
sl@0
   520
sl@0
   521
sl@0
   522
void DoTestsL()
sl@0
   523
    {
sl@0
   524
    TheTest.Start(_L("@SYMTestCaseID:PDS-EFM-CT-4068 RFeatureControl::Connect() OOM test"));
sl@0
   525
    ControlOpenOomTest(ETrue);
sl@0
   526
    TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4069 RFeatureControl::Open() OOM test"));
sl@0
   527
    ControlOpenOomTest(EFalse);
sl@0
   528
    
sl@0
   529
    TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4070 RFeatureControl::FeatureSupported(UID) + valid feature, client side OOM test"));
sl@0
   530
    ControlFeatureSupportedOomTest(ETrue, EFalse, EFeatMgrOomClientTestMode);
sl@0
   531
    TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4071 RFeatureControl::FeatureSupported(UID) + valid feature, server side OOM test"));
sl@0
   532
    ControlFeatureSupportedOomTest(ETrue, EFalse, EFeatMgrOomServerTestMode);
sl@0
   533
    
sl@0
   534
    TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4072 RFeatureControl::FeatureSupported() + valid feature, client side OOM test"));
sl@0
   535
    ControlFeatureSupportedOomTest(EFalse, EFalse, EFeatMgrOomClientTestMode);
sl@0
   536
    TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4073 RFeatureControl::FeatureSupported() + valid feature, server side OOM test"));
sl@0
   537
    ControlFeatureSupportedOomTest(EFalse, EFalse, EFeatMgrOomServerTestMode);
sl@0
   538
    
sl@0
   539
    TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4074 RFeatureControl::FeatureSupported(UID) + invalid feature, client side OOM test"));
sl@0
   540
    ControlFeatureSupportedOomTest(ETrue, ETrue, EFeatMgrOomClientTestMode);
sl@0
   541
    TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4075 RFeatureControl::FeatureSupported(UID) + invalid feature, server side OOM test"));
sl@0
   542
    ControlFeatureSupportedOomTest(ETrue, ETrue, EFeatMgrOomServerTestMode);
sl@0
   543
    
sl@0
   544
    TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4076 RFeatureControl::FeatureSupported() + invalid feature, client side OOM OOM test"));
sl@0
   545
    ControlFeatureSupportedOomTest(EFalse, ETrue, EFeatMgrOomClientTestMode);
sl@0
   546
    TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4077 RFeatureControl::FeatureSupported() + invalid feature, server side OOM OOM test"));
sl@0
   547
    ControlFeatureSupportedOomTest(EFalse, ETrue, EFeatMgrOomServerTestMode);
sl@0
   548
    
sl@0
   549
    TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4078 RFeatureControl::ListSupportedFeatures(), client side OOM test"));
sl@0
   550
    ControlListSupportedFeaturesOomTest(EFeatMgrOomClientTestMode);
sl@0
   551
    TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4079 RFeatureControl::ListSupportedFeatures(), server side OOM test"));
sl@0
   552
    ControlListSupportedFeaturesOomTest(EFeatMgrOomServerTestMode);
sl@0
   553
    
sl@0
   554
    TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4080 RFeatureControl::FeaturesSupported(), client side OOM test"));
sl@0
   555
    ControlFeaturesSupportedOomTest(EFeatMgrOomClientTestMode);
sl@0
   556
    TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4081 RFeatureControl::FeaturesSupported(),server side OOM test"));
sl@0
   557
    ControlFeaturesSupportedOomTest(EFeatMgrOomServerTestMode);
sl@0
   558
    
sl@0
   559
    TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4082 RFeatureControl::AddFeature(), client side OOM test"));
sl@0
   560
    ControlAddFeatureOomTest(EFeatMgrOomClientTestMode);
sl@0
   561
    TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4083 RFeatureControl::AddFeature(), server side OOM test"));
sl@0
   562
    ControlAddFeatureOomTest(EFeatMgrOomServerTestMode);
sl@0
   563
    
sl@0
   564
    TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4084 RFeatureControl::DeleteFeature(), client side OOM test"));
sl@0
   565
    ControlDeleteFeatureOomTest(EFeatMgrOomClientTestMode);
sl@0
   566
    TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4085 RFeatureControl::DeleteFeature(), server side OOM test"));
sl@0
   567
    ControlDeleteFeatureOomTest(EFeatMgrOomServerTestMode);
sl@0
   568
sl@0
   569
    TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4086 CFeatureNotifier::NewL(), client side OOM test"));
sl@0
   570
    NotifierNewLOomTest(EFeatMgrOomClientTestMode);
sl@0
   571
    TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4087 CFeatureNotifier::NewL(), server side OOM test"));
sl@0
   572
    NotifierNewLOomTest(EFeatMgrOomServerTestMode);
sl@0
   573
    
sl@0
   574
    TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4088 CFeatureNotifier::NotifyRequest(), valid feature, client side OOM test"));
sl@0
   575
    NotifierNotifyRequestOomTest(ETrue, EFeatMgrOomClientTestMode);
sl@0
   576
    TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4089 CFeatureNotifier::NotifyRequest(), valid feature, server side OOM test"));
sl@0
   577
    NotifierNotifyRequestOomTest(ETrue, EFeatMgrOomServerTestMode);
sl@0
   578
    
sl@0
   579
    TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4090 CFeatureNotifier::NotifyRequest(), invalid feature, client side OOM test"));
sl@0
   580
    NotifierNotifyRequestOomTest(EFalse, EFeatMgrOomClientTestMode);
sl@0
   581
    TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4091 CFeatureNotifier::NotifyRequest(), invalid feature, server side OOM test"));
sl@0
   582
    NotifierNotifyRequestOomTest(EFalse, EFeatMgrOomServerTestMode);
sl@0
   583
sl@0
   584
    TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4092 CFeatureNotifier::NotifyRequest(<array>), valid feature, client side OOM test"));
sl@0
   585
    NotifierNotifyRequestsOomTest(EFeatMgrOomClientTestMode);
sl@0
   586
    TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4093 CFeatureNotifier::NotifyRequest(<array>), valid feature, server side OOM test"));
sl@0
   587
    NotifierNotifyRequestsOomTest(EFeatMgrOomServerTestMode);
sl@0
   588
    }
sl@0
   589
sl@0
   590
TInt E32Main()
sl@0
   591
    {
sl@0
   592
    TheTest.Title();
sl@0
   593
    
sl@0
   594
    CTrapCleanup* tc = CTrapCleanup::New();
sl@0
   595
    TheTest(tc != NULL);
sl@0
   596
    
sl@0
   597
    __UHEAP_MARK;
sl@0
   598
    
sl@0
   599
    TRAPD(err, DoTestsL());
sl@0
   600
    TEST2(err, KErrNone);
sl@0
   601
sl@0
   602
    __UHEAP_MARKEND;
sl@0
   603
    
sl@0
   604
    TheTest.End();
sl@0
   605
    TheTest.Close();
sl@0
   606
    
sl@0
   607
    delete tc;
sl@0
   608
sl@0
   609
    User::Heap().Check();
sl@0
   610
    return KErrNone;
sl@0
   611
    }