|
1 /* |
|
2 * Copyright (c) 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 "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 #ifndef TESTFAILEDEXCEPTION_H |
|
20 #define TESTFAILEDEXCEPTION_H |
|
21 |
|
22 #include <string> |
|
23 #include <exception> |
|
24 |
|
25 class TestFailedException : public std::exception |
|
26 { |
|
27 public: |
|
28 |
|
29 TestFailedException(const std::string& message, const std::string& file, |
|
30 const std::string& method, int line); |
|
31 |
|
32 virtual ~TestFailedException() throw() {} |
|
33 |
|
34 std::string toString() const; |
|
35 |
|
36 TestFailedException(const TestFailedException& x) |
|
37 { |
|
38 mErrCode = x.mErrCode; |
|
39 mMessage = x.mMessage; |
|
40 mFile = x.mFile; |
|
41 mMethod = x.mMethod; |
|
42 mLine = x.mLine; |
|
43 } |
|
44 |
|
45 int mErrCode; |
|
46 std::string mMessage; |
|
47 std::string mFile; |
|
48 std::string mMethod; |
|
49 int mLine; |
|
50 |
|
51 private: |
|
52 TestFailedException& operator= (const TestFailedException&); |
|
53 }; |
|
54 |
|
55 inline TestFailedException::TestFailedException(const std::string& message, const std::string& file, |
|
56 const std::string& method, int line) |
|
57 : mErrCode(0),mMessage(message), mFile(file), mMethod(method),mLine(line) {} |
|
58 |
|
59 inline std::string TestFailedException::toString() const |
|
60 { |
|
61 std::string str; |
|
62 if (0 != mErrCode) |
|
63 { |
|
64 char errCode[7]; |
|
65 sprintf(errCode, "%d, ", mErrCode); |
|
66 str.append(errCode); |
|
67 } |
|
68 str.append(mMessage); |
|
69 |
|
70 str.append(" (file: "); |
|
71 str.append(mFile); |
|
72 |
|
73 str.append(", method: "); |
|
74 str.append(mMethod); |
|
75 |
|
76 str.append(", line: "); |
|
77 char line[7]; |
|
78 sprintf(line, "%d", mLine); |
|
79 str.append(line); |
|
80 str.append(")."); |
|
81 return str; |
|
82 } |
|
83 |
|
84 #endif // TESTFAILEDEXCEPTION_H |
|
85 |