Update contrib.
2 * Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * T_CErrorConverter.CPP
21 #include "t_errorconverter.h"
22 #include <securityerr.h>
25 class CErrorItem : public CBase
28 static CErrorItem *NewLC(const TDesC &aErrorName, const TInt aError);
29 static CErrorItem *NewL(const TDesC &aErrorName, const TInt aError);
30 virtual ~CErrorItem(void) { delete iErrorName;};
37 void ConstructL(const TDesC &aErrorName);
38 CErrorItem(const TInt aError) : iError(aError){}
41 CErrorItem *CErrorItem::NewLC(const TDesC &aErrorName, const TInt aError)
43 CErrorItem *errorItem = new (ELeave) CErrorItem(aError);
44 CleanupStack::PushL(errorItem);
45 errorItem->ConstructL(aErrorName);
49 CErrorItem *CErrorItem::NewL(const TDesC &aErrorName, const TInt aError)
51 CErrorItem *errorItem = CErrorItem::NewLC(aErrorName, aError);
52 CleanupStack::Pop(errorItem);
56 void CErrorItem::ConstructL(const TDesC &aErrorName)
58 iErrorName = HBufC8::NewL(aErrorName.Length());
59 iErrorName->Des().Copy(aErrorName);
62 EXPORT_C CErrorConverter* CErrorConverter::NewLC(void)
64 CErrorConverter *errorConverter = new (ELeave) CErrorConverter();
65 CleanupStack::PushL(errorConverter);
66 errorConverter->ConstructL();
67 return(errorConverter);
69 EXPORT_C CErrorConverter* CErrorConverter::NewL(void)
71 CErrorConverter *errorConverter = CErrorConverter::NewLC();
72 CleanupStack::Pop(errorConverter);
73 return(errorConverter);
76 EXPORT_C CErrorConverter::~CErrorConverter()
78 iErrorMap.ResetAndDestroy();
81 void CErrorConverter::ConstructL(void)
86 EXPORT_C void CErrorConverter::AddErrorItem(const TDesC& aErrorName, const TInt &aErrorCode)
88 CErrorItem *errorItem = CErrorItem::NewLC(aErrorName, aErrorCode);
90 User::LeaveIfError(iErrorMap.Append(errorItem));
91 CleanupStack::Pop(errorItem);
94 void CErrorConverter::CreateErrorMapL()
96 AddErrorItem(_L("KErrNone"), KErrNone);
97 AddErrorItem(_L("KErrNotFound"), KErrNotFound);
98 AddErrorItem(_L("KErrGeneral"), KErrGeneral);
99 AddErrorItem(_L("KErrCancel"), KErrCancel);
100 AddErrorItem(_L("KErrNoMemory"), KErrNoMemory);
101 AddErrorItem(_L("KErrNotSupported"), KErrNotSupported);
102 AddErrorItem(_L("KErrArgument"), KErrArgument);
103 AddErrorItem(_L("KErrTotalLossOfPrecision"), KErrTotalLossOfPrecision);
104 AddErrorItem(_L("KErrBadHandle"), KErrBadHandle);
105 AddErrorItem(_L("KErrOverflow"), KErrOverflow);
106 AddErrorItem(_L("KErrUnderflow"), KErrUnderflow);
107 AddErrorItem(_L("KErrAlreadyExists"), KErrAlreadyExists);
108 AddErrorItem(_L("KErrPathNotFound"), KErrPathNotFound);
109 AddErrorItem(_L("KErrDied"), KErrDied);
110 AddErrorItem(_L("KErrInUse"), KErrInUse);
111 AddErrorItem(_L("KErrServerTerminated"), KErrServerTerminated);
112 AddErrorItem(_L("KErrServerBusy"), KErrServerBusy);
113 AddErrorItem(_L("KErrCompletion"), KErrCompletion);
114 AddErrorItem(_L("KErrNotReady"), KErrNotReady);
115 AddErrorItem(_L("KErrUnknown"), KErrUnknown);
116 AddErrorItem(_L("KErrCorrupt"), KErrCorrupt);
117 AddErrorItem(_L("KErrAccessDenied"), KErrAccessDenied);
118 AddErrorItem(_L("KErrLocked"), KErrLocked);
119 AddErrorItem(_L("KErrWrite"), KErrWrite);
120 AddErrorItem(_L("KErrDisMounted"), KErrDisMounted);
121 AddErrorItem(_L("KErrEof"), KErrEof);
122 AddErrorItem(_L("KErrDiskFull"), KErrDiskFull);
123 AddErrorItem(_L("KErrBadDriver"), KErrBadDriver);
124 AddErrorItem(_L("KErrBadName"), KErrBadName);
125 AddErrorItem(_L("KErrCommsLineFail"), KErrCommsLineFail);
126 AddErrorItem(_L("KErrCommsFrame"), KErrCommsFrame);
127 AddErrorItem(_L("KErrCommsOverrun"), KErrCommsOverrun);
128 AddErrorItem(_L("KErrCommsParity"), KErrCommsParity);
129 AddErrorItem(_L("KErrTimedOut"), KErrTimedOut);
130 AddErrorItem(_L("KErrCouldNotConnect"), KErrCouldNotConnect);
131 AddErrorItem(_L("KErrCouldNotDisconnect"), KErrCouldNotDisconnect);
132 AddErrorItem(_L("KErrDisconnected"), KErrDisconnected);
133 AddErrorItem(_L("KErrBadLibraryEntryPoint"), KErrBadLibraryEntryPoint);
134 AddErrorItem(_L("KErrBadDescriptor"), KErrBadDescriptor);
135 AddErrorItem(_L("KErrAbort"), KErrAbort);
136 AddErrorItem(_L("KErrTooBig"), KErrTooBig);
137 AddErrorItem(_L("KErrDivideByZero"), KErrDivideByZero);
138 AddErrorItem(_L("KErrBadPower"), KErrBadPower);
139 AddErrorItem(_L("KErrDirFull"), KErrDirFull);
140 AddErrorItem(_L("KErrHardwareNotAvailable"), KErrHardwareNotAvailable);
141 AddErrorItem(_L("KErrPrivateKeyNotFound"), KErrPrivateKeyNotFound);
142 AddErrorItem(_L("KErrPermissionDenied"), KErrPermissionDenied);
145 EXPORT_C TBool CErrorConverter::GetExpectedResultL(const TDesC& aResult /* in */, TInt &aError /* out */)
147 HBufC8 *resultBuf = HBufC8::NewLC(aResult.Length());
148 resultBuf->Des().Copy(aResult);
149 TBool result = EFalse;
153 aError = KErrUnknown;
155 for(errorPos = 0; errorPos < iErrorMap.Count() && !result; errorPos++)
157 pError = iErrorMap[errorPos];
158 if(pError->iErrorName->CompareF(*resultBuf)==0)
160 aError = pError->iError;
164 CleanupStack::PopAndDestroy(resultBuf);
170 EXPORT_C TBool CErrorConverter::GetExpectedResultL(const TInt &aError /* in */, HBufC*& aResult /* out */)
172 TBool result = EFalse;
176 __ASSERT_DEBUG(!result, User::Panic(_L("CErrorConverter::GetExpectedResultL"), 1));
177 for(errorPos = 0; errorPos < iErrorMap.Count() && !result; errorPos++)
179 pError = iErrorMap[errorPos];
180 if(pError->iError == aError)
182 aResult = HBufC::NewLC(pError->iErrorName->Length());
183 aResult->Des().Copy(*pError->iErrorName);
187 // just so it always has something to pop even if it didnt find error
190 aResult = HBufC::NewLC(0);