cryptoservices/filebasedcertificateandkeystores/test/tkeystore/t_list.cpp
changeset 15 da2ae96f639b
parent 8 35751d3474b7
equal deleted inserted replaced
10:afc583cfa176 15:da2ae96f639b
    48 
    48 
    49 CListKeys::~CListKeys()
    49 CListKeys::~CListKeys()
    50 	{
    50 	{
    51 	iKeys.Close();
    51 	iKeys.Close();
    52 	iKeysToFind.Close();
    52 	iKeysToFind.Close();
       
    53 	delete iListStatus;
    53 	}
    54 	}
    54 
    55 
    55 CListKeys::CListKeys(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
    56 CListKeys::CListKeys(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
    56 	:	CKeyStoreTestAction(aFs, aConsole, aOut), iResultCount(-1)
    57 	:	CKeyStoreTestAction(aFs, aConsole, aOut), iResultCount(-1)
    57 	{
    58 	{
    75 		SetKeySize(buf);
    76 		SetKeySize(buf);
    76 
    77 
    77 	buf.Set(Input::ParseElement(aTestActionSpec.iActionBody, KListCountStart, KListCountEnd, pos, err));
    78 	buf.Set(Input::ParseElement(aTestActionSpec.iActionBody, KListCountStart, KListCountEnd, pos, err));
    78 	if (err == KErrNone)
    79 	if (err == KErrNone)
    79 		SetListCount(buf);
    80 		SetListCount(buf);
    80 
    81 	
    81 	do
    82 	do
    82 		{
    83 		{
    83 		buf.Set(Input::ParseElement(aTestActionSpec.iActionBody, 
    84 		buf.Set(Input::ParseElement(aTestActionSpec.iActionBody, 
    84 									KFoundKeyStart, KFoundKeyEnd,pos,err));
    85 									KFoundKeyStart, KFoundKeyEnd,pos,err));
    85 		if (err == KErrNone)
    86 		if (err == KErrNone)
    86 			AddFoundKeyL(buf);
    87 			AddFoundKeyL(buf);
    87 		} 
    88 		} 
    88 	while (err == KErrNone);
    89 	while (err == KErrNone);
       
    90 	
       
    91 	// set default outcome as success for listing keys
       
    92 	SetListStatus(KErrListingSuccess);
       
    93 	buf.Set(Input::ParseElement(aTestActionSpec.iActionBody, KListingStatusStart, KListingStatusEnd, pos, err ));
       
    94 		if (err == KErrNone)
       
    95 			SetListStatus(buf);
       
    96 
    89 }
    97 }
    90 
    98 
    91 
    99 
    92 
   100 
    93 void CListKeys::SetKeySize(const TDesC8& aKeySize)
   101 void CListKeys::SetKeySize(const TDesC8& aKeySize)
    99 
   107 
   100 void CListKeys::SetListCount(const TDesC8& aListCount)
   108 void CListKeys::SetListCount(const TDesC8& aListCount)
   101 	{
   109 	{
   102 	TLex8 lexer(aListCount);
   110 	TLex8 lexer(aListCount);
   103 	lexer.Val(iResultCount);
   111 	lexer.Val(iResultCount);
       
   112 	}
       
   113 
       
   114 void CListKeys::SetListStatus(const TDesC8& aListStatus)
       
   115 	{
       
   116 	if(iListStatus != NULL)
       
   117 		{
       
   118 		delete iListStatus;
       
   119 		iListStatus = NULL;
       
   120 		}
       
   121 	iListStatus = aListStatus.AllocL();
   104 	}
   122 	}
   105 
   123 
   106 void CListKeys::AddFoundKeyL(const TDesC8& aFoundKey)
   124 void CListKeys::AddFoundKeyL(const TDesC8& aFoundKey)
   107 	{
   125 	{
   108 	HBufC* buf = HBufC::NewLC(aFoundKey.Length());
   126 	HBufC* buf = HBufC::NewLC(aFoundKey.Length());
   126 			
   144 			
   127 		case EFinished:
   145 		case EFinished:
   128 			{
   146 			{
   129 			TRequestStatus* status = &aStatus;
   147 			TRequestStatus* status = &aStatus;
   130 			User::RequestComplete(status, aStatus.Int());
   148 			User::RequestComplete(status, aStatus.Int());
   131 			if (aStatus == iExpectedResult && (iResultCount < 0 ||
   149 			if( iListStatus->Compare(KErrListingFailure) == 0 )
   132 											   iResultCount == iKeys.Count()))
       
   133 				{
   150 				{
   134 				iResult = ETrue;
   151 				iResult = ETrue;
   135 				}
   152 				}
   136 			else
   153 			else
   137 				{
   154 				{
   138 				iResult = EFalse;
   155 				if (aStatus == iExpectedResult && (iResultCount < 0 ||
   139 				}
   156 												   iResultCount == iKeys.Count()))
   140 			
   157 					{
       
   158 					iResult = ETrue;
       
   159 					}
       
   160 				else
       
   161 					{
       
   162 					iResult = EFalse;
       
   163 					}
       
   164 				}
   141 			iActionState = EPostrequisite;				
   165 			iActionState = EPostrequisite;				
   142 			}
   166 			}
   143 		}
   167 		}
   144 	}
   168 	}
   145 
   169 
   203 				buf.Format(KKeyNum, i);
   227 				buf.Format(KKeyNum, i);
   204 				iOut.writeString(buf);
   228 				iOut.writeString(buf);
   205 				iOut.writeNewLine();
   229 				iOut.writeNewLine();
   206 
   230 
   207 				TRAPD(err,PrintKeyInfoL(*iKeys[i])); 
   231 				TRAPD(err,PrintKeyInfoL(*iKeys[i])); 
   208 				_LIT(KFailed, "!!!Key listing failure!!!\n");
   232 				_LIT(KFailed, "!!!Key listing success!!!\n");
   209 				iConsole.Write(KFailed);
   233 				iConsole.Write(KFailed);
   210 				iOut.writeString(KFailed);
   234 				iOut.writeString(KFailed);
   211 				iOut.writeNum(err);
   235 				iOut.writeNum(err);
   212 				iOut.writeNewLine();
   236 				iOut.writeNewLine();
   213 				return;			
   237 				return;