1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
/*******************************************************************************
* Copyright (c) 2010, 2011 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems - initial API and implementation
*******************************************************************************/
package org.eclipse.tcf.internal.debug.tests;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import org.eclipse.tcf.core.Command;
import org.eclipse.tcf.core.ErrorReport;
import org.eclipse.tcf.protocol.IChannel;
import org.eclipse.tcf.protocol.IErrorReport;
import org.eclipse.tcf.protocol.IToken;
import org.eclipse.tcf.services.IDiagnostics;
class TestEchoERR implements ITCFTest, IDiagnostics.DoneEchoERR {
private final TCFTestSuite test_suite;
private final IDiagnostics diag;
private final Number[] numbers = {
1,
4,
new BigDecimal("0.5")
};
private final String[] strings = {
"",
"abc",
"a\u1134c",
"a\u0003c",
};
private final String[] formats = {
"",
"{0}",
"{0,number}",
"{0,number,integer}",
"{0,number,percent}",
"{1}",
"{0} abcde {1}",
"{1} '' {0}",
"{1} 'abcde{}' {1}",
};
private final LinkedList<ErrorReport> list = new LinkedList<ErrorReport>();
TestEchoERR(TCFTestSuite test_suite, IChannel channel) {
this.test_suite = test_suite;
diag = channel.getRemoteService(IDiagnostics.class);
}
public void start() {
for (Number n : numbers) {
for (String s : strings) {
for (String f : formats) {
ArrayList<Object> params = new ArrayList<Object>();
params.add(n);
params.add(s);
Map<String,Object> map = new HashMap<String,Object>();
map.put(IErrorReport.ERROR_TIME, new Long(System.currentTimeMillis()));
map.put(IErrorReport.ERROR_CODE, new Integer(IErrorReport.TCF_ERROR_OTHER));
map.put(IErrorReport.ERROR_FORMAT, f);
map.put(IErrorReport.ERROR_PARAMS, params);
map.put(s, s); // non-standard attribute
ErrorReport e = new ErrorReport("TCF error", map);
list.add(e);
diag.echoERR(e, this);
}
}
}
}
public void doneEchoERR(IToken token, Throwable error, Throwable error_obj, String error_msg) {
ErrorReport e = list.removeFirst();
if (!test_suite.isActive(this)) return;
Map<String,Object> map0 = e.getAttributes();
Map<String,Object> map1 = null;
if (error_obj instanceof IErrorReport) {
map1 = ((IErrorReport)error_obj).getAttributes();
}
String msg = Command.toErrorString(map0);
if (error instanceof IErrorReport && ((IErrorReport)error).getErrorCode() == IErrorReport.TCF_ERROR_INV_COMMAND) {
// Older agent: the command is not available. Just exit the test.
test_suite.done(this, null);
}
else if (error != null) {
test_suite.done(this, error);
}
else if (!map0.equals(map1)) {
test_suite.done(this, new Exception("Invalid error report attributes"));
}
else if (!msg.equals(error_msg)) {
test_suite.done(this, new Exception("Invalid error report text"));
}
else if (list.size() == 0) {
test_suite.done(this, null);
}
}
public boolean canResume(String id) {
return true;
}
}
|