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