xref: /AOO42X/test/testcommon/source/org/openoffice/test/common/CSVReporter.java (revision b0efeae40e43e6d4ccd561d22ec612d42773857b)
1*180e3c91SLiu Zhe /**************************************************************
2*180e3c91SLiu Zhe  *
3*180e3c91SLiu Zhe  * Licensed to the Apache Software Foundation (ASF) under one
4*180e3c91SLiu Zhe  * or more contributor license agreements.  See the NOTICE file
5*180e3c91SLiu Zhe  * distributed with this work for additional information
6*180e3c91SLiu Zhe  * regarding copyright ownership.  The ASF licenses this file
7*180e3c91SLiu Zhe  * to you under the Apache License, Version 2.0 (the
8*180e3c91SLiu Zhe  * "License"); you may not use this file except in compliance
9*180e3c91SLiu Zhe  * with the License.  You may obtain a copy of the License at
10*180e3c91SLiu Zhe  *
11*180e3c91SLiu Zhe  *   http://www.apache.org/licenses/LICENSE-2.0
12*180e3c91SLiu Zhe  *
13*180e3c91SLiu Zhe  * Unless required by applicable law or agreed to in writing,
14*180e3c91SLiu Zhe  * software distributed under the License is distributed on an
15*180e3c91SLiu Zhe  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*180e3c91SLiu Zhe  * KIND, either express or implied.  See the License for the
17*180e3c91SLiu Zhe  * specific language governing permissions and limitations
18*180e3c91SLiu Zhe  * under the License.
19*180e3c91SLiu Zhe  *
20*180e3c91SLiu Zhe  *************************************************************/
219e9f0f63SLiu Zhe package org.openoffice.test.common;
229e9f0f63SLiu Zhe 
23a7a6f583SLiu Zhe import java.io.File;
24a7a6f583SLiu Zhe import java.util.Map.Entry;
25a7a6f583SLiu Zhe import java.util.Set;
26a7a6f583SLiu Zhe 
27a7a6f583SLiu Zhe import org.junit.Ignore;
289e9f0f63SLiu Zhe import org.junit.runner.Description;
299e9f0f63SLiu Zhe import org.junit.runner.Result;
309e9f0f63SLiu Zhe import org.junit.runner.notification.Failure;
319e9f0f63SLiu Zhe import org.junit.runner.notification.RunListener;
329e9f0f63SLiu Zhe 
339e9f0f63SLiu Zhe public class CSVReporter extends RunListener {
349e9f0f63SLiu Zhe 
35a7a6f583SLiu Zhe     private File reportDir = Testspace.getFile("output/result");
36a7a6f583SLiu Zhe 
37a7a6f583SLiu Zhe     private File file = null;
38a7a6f583SLiu Zhe 
39a7a6f583SLiu Zhe     private String testClassName = null;
40a7a6f583SLiu Zhe 
41a7a6f583SLiu Zhe     private long suiteStart = 0;
42a7a6f583SLiu Zhe 
43a7a6f583SLiu Zhe     private long failures = 0;
44a7a6f583SLiu Zhe 
45a7a6f583SLiu Zhe     private long errors = 0;
46a7a6f583SLiu Zhe 
47a7a6f583SLiu Zhe     private long tests = 0;
48a7a6f583SLiu Zhe 
49a7a6f583SLiu Zhe     private long ignored = 0;
50a7a6f583SLiu Zhe 
51a7a6f583SLiu Zhe     private long testStart = 0;
52a7a6f583SLiu Zhe 
53a7a6f583SLiu Zhe     @Override
testStarted(Description description)54a7a6f583SLiu Zhe     public void testStarted(Description description) throws Exception {
55a7a6f583SLiu Zhe         System.out.println("testStarted");
56a7a6f583SLiu Zhe         if (!description.getClassName().equals(testClassName)) {
57a7a6f583SLiu Zhe             finishSuite();
58a7a6f583SLiu Zhe             startSuite(description);
59a7a6f583SLiu Zhe         }
60a7a6f583SLiu Zhe 
61a7a6f583SLiu Zhe 
62a7a6f583SLiu Zhe     }
63a7a6f583SLiu Zhe 
649e9f0f63SLiu Zhe     @Override
testAssumptionFailure(Failure failure)659e9f0f63SLiu Zhe     public void testAssumptionFailure(Failure failure) {
66a7a6f583SLiu Zhe 
679e9f0f63SLiu Zhe     }
689e9f0f63SLiu Zhe 
699e9f0f63SLiu Zhe     @Override
testFailure(Failure failure)709e9f0f63SLiu Zhe     public void testFailure(Failure failure) throws Exception {
71a7a6f583SLiu Zhe         System.out.println("testFailure");
72a7a6f583SLiu Zhe         if (failure.getException() instanceof AssertionError) {
73a7a6f583SLiu Zhe             failures++;
74a7a6f583SLiu Zhe         } else {
75a7a6f583SLiu Zhe             errors++;
76a7a6f583SLiu Zhe         }
779e9f0f63SLiu Zhe     }
789e9f0f63SLiu Zhe 
799e9f0f63SLiu Zhe     @Override
testFinished(Description description)809e9f0f63SLiu Zhe     public void testFinished(Description description) throws Exception {
81a7a6f583SLiu Zhe         System.out.println("testFinished");
82a7a6f583SLiu Zhe         tests++;
839e9f0f63SLiu Zhe     }
849e9f0f63SLiu Zhe 
859e9f0f63SLiu Zhe     @Override
testIgnored(Description description)869e9f0f63SLiu Zhe     public void testIgnored(Description description) throws Exception {
87a7a6f583SLiu Zhe         testStarted(description);
88a7a6f583SLiu Zhe         System.out.println("testIgnored");
89a7a6f583SLiu Zhe         ignored++;
90a7a6f583SLiu Zhe         Ignore ignore = description.getAnnotation(Ignore.class);
91a7a6f583SLiu Zhe         testFinished(description);
929e9f0f63SLiu Zhe     }
939e9f0f63SLiu Zhe 
949e9f0f63SLiu Zhe     @Override
testRunFinished(Result result)959e9f0f63SLiu Zhe     public void testRunFinished(Result result) throws Exception {
96a7a6f583SLiu Zhe         System.out.println("testRunFinished");
97a7a6f583SLiu Zhe         finishSuite();
989e9f0f63SLiu Zhe     }
999e9f0f63SLiu Zhe 
1009e9f0f63SLiu Zhe     @Override
testRunStarted(Description description)1019e9f0f63SLiu Zhe     public void testRunStarted(Description description) throws Exception {
102a7a6f583SLiu Zhe         System.out.println("testRunStarted");
1039e9f0f63SLiu Zhe     }
1049e9f0f63SLiu Zhe 
startSuite(Description description)105a7a6f583SLiu Zhe     private void startSuite(Description description) {
106a7a6f583SLiu Zhe         testClassName = description.getClassName();
107a7a6f583SLiu Zhe         suiteStart = System.currentTimeMillis();
108a7a6f583SLiu Zhe         failures = 0;
109a7a6f583SLiu Zhe         errors = 0;
110a7a6f583SLiu Zhe         tests = 0;
111a7a6f583SLiu Zhe         ignored = 0;
112a7a6f583SLiu Zhe 
113a7a6f583SLiu Zhe         file = new File(reportDir, testClassName + ".csv");
114a7a6f583SLiu Zhe     }
115a7a6f583SLiu Zhe 
finishSuite()116a7a6f583SLiu Zhe     private void finishSuite() {
117a7a6f583SLiu Zhe         if (testClassName == null)
118a7a6f583SLiu Zhe             return;
119a7a6f583SLiu Zhe 
120a7a6f583SLiu Zhe 
121a7a6f583SLiu Zhe         Set<Entry<Object, Object>> entries = System.getProperties().entrySet();
122a7a6f583SLiu Zhe         for (Entry<Object, Object> e : entries) {
123a7a6f583SLiu Zhe //          Element prop = doc.createElement("property");
124a7a6f583SLiu Zhe //          prop.setAttribute("name", "" + e.getKey());
125a7a6f583SLiu Zhe //          prop.setAttribute("value", "" + e.getValue());
126a7a6f583SLiu Zhe //          props.appendChild(prop);
127a7a6f583SLiu Zhe         }
128a7a6f583SLiu Zhe 
129a7a6f583SLiu Zhe         store();
130a7a6f583SLiu Zhe     }
131a7a6f583SLiu Zhe 
store()132a7a6f583SLiu Zhe     private void store() {
133a7a6f583SLiu Zhe 
1349e9f0f63SLiu Zhe     }
1359e9f0f63SLiu Zhe 
1369e9f0f63SLiu Zhe }
137