os/security/crypto/weakcrypto/test/tpadding/tpaddingNone.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 #include <padding.h>
    20 #include "tpaddingNone.h"
    21 
    22 CTestPadNone::CTestPadNone()
    23 {
    24    SetTestStepName(KPadNone);
    25 }
    26 
    27 CTestPadNone::~CTestPadNone()
    28 {
    29 }
    30 
    31 TVerdict CTestPadNone::doTestStepL()
    32 {
    33    SetTestStepResult(EPass);
    34    __UHEAP_MARK;
    35 
    36    INFO_PRINTF1(_L("Test of padding with type None"));
    37    
    38    TInt blockSize = 0; 
    39    if (GetIntFromConfig(ConfigSection(), _L("blocksize"), blockSize))
    40  		{
    41  		ERR_PRINTF1(_L("Missing parameter - blockSize"));
    42  		}
    43 
    44    // Block size is arbitrary as no padding actually occurs
    45    CPaddingNone *padding = CPaddingNone::NewLC(blockSize);
    46    for (TInt i = 1 ; i < blockSize; i++)
    47    {
    48       HBufC8 *padInData = HBufC8::NewLC(i);
    49       HBufC8 *padOutData = HBufC8::NewLC(i);
    50       TPtr8 in(padInData->Des());
    51       TPtr8 out(padOutData->Des());
    52       for (TInt j = 0; j < i; j++)
    53       {
    54 	 in.Append(_L8("a"));
    55       }
    56 
    57       // Perform the padding
    58       TRAPD(err, padding->DoPadL(in, out));
    59       TEST(err == KErrNone);
    60       
    61       // As no padding actually occurs, the in string should equal the out string
    62       TEST(in == out);
    63       CleanupStack::PopAndDestroy(2, padInData); // padInData, padOutData
    64    }
    65    
    66    CleanupStack::PopAndDestroy(); // padding
    67    __UHEAP_MARKEND;
    68    return TestStepResult();
    69 }
    70 
    71 CTestUnpadNone::CTestUnpadNone()
    72 {
    73    SetTestStepName(KUnpadNone);
    74 }
    75 
    76 CTestUnpadNone::~CTestUnpadNone()
    77 {
    78 }
    79 
    80 TVerdict CTestUnpadNone::doTestStepL()
    81 {
    82    SetTestStepResult(EPass);
    83    __UHEAP_MARK;
    84 
    85    INFO_PRINTF1(_L("Test of unpadding with type None"));
    86    
    87    TInt blockSize = 0; 
    88    if (GetIntFromConfig(ConfigSection(), _L("blocksize"), blockSize))
    89  		{
    90  		ERR_PRINTF1(_L("Missing parameter - blockSize"));
    91  		}
    92 
    93    // Block size is arbitrary as no padding actually occurs
    94    CPaddingNone *padding = CPaddingNone::NewLC(blockSize);
    95    for (TInt i = 1 ; i < blockSize; i++)
    96    {
    97       HBufC8 *padInData = HBufC8::NewLC(i);
    98       HBufC8 *padOutData = HBufC8::NewLC(i);
    99       TPtr8 in(padInData->Des());
   100       TPtr8 out(padOutData->Des());
   101       for (TInt j = 0; j < i; j++)
   102       {
   103 	 in.Append(_L8("a"));
   104       }
   105 
   106       // Perform the unpadding
   107       TRAPD(err, padding->UnPadL(in, out));
   108       TEST(err == KErrNone);
   109 
   110       // As no unpadding actually occurs, the in string should equal the out string
   111       TEST(in == out);
   112       CleanupStack::PopAndDestroy(2, padInData); // padInData, padOutData
   113    }
   114    CleanupStack::PopAndDestroy(); // padding
   115    __UHEAP_MARKEND;
   116    return TestStepResult();
   117 }
   118