Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuergen Haug2018-07-18 15:34:51 +0000
committerJuergen Haug2018-07-18 16:39:32 +0000
commitc33073c10865923d47f00981b04169929f32bcd9 (patch)
tree672a5a5d32df975bb385a78d558b992a13fb76c5
parent5dfd44073e44459aef3c3c1edc7bc1b6e1f9957e (diff)
downloadorg.eclipse.etrice-c33073c10865923d47f00981b04169929f32bcd9.tar.gz
org.eclipse.etrice-c33073c10865923d47f00981b04169929f32bcd9.tar.xz
org.eclipse.etrice-c33073c10865923d47f00981b04169929f32bcd9.zip
[etunit] added support for in-memory conversion + fixed tests
-rw-r--r--plugins/org.eclipse.etrice.etunit.converter/src/org/eclipse/etrice/etunit/converter/EtUnitReportConverter.java297
-rw-r--r--tests/org.eclipse.etrice.etunit.converter.tests/.gitignore1
-rw-r--r--tests/org.eclipse.etrice.etunit.converter.tests/META-INF/MANIFEST.MF4
-rw-r--r--tests/org.eclipse.etrice.etunit.converter.tests/expects/report1.xml24
-rw-r--r--tests/org.eclipse.etrice.etunit.converter.tests/reports/combined.xml27
-rw-r--r--tests/org.eclipse.etrice.etunit.converter.tests/reports/only_combined.xml27
-rw-r--r--tests/org.eclipse.etrice.etunit.converter.tests/reports/report1.xml24
-rw-r--r--tests/org.eclipse.etrice.etunit.converter.tests/reports/report2.xml6
-rw-r--r--tests/org.eclipse.etrice.etunit.converter.tests/reports/report3.xml24
-rw-r--r--tests/org.eclipse.etrice.etunit.converter.tests/reports/report4.xml6
-rw-r--r--tests/org.eclipse.etrice.etunit.converter.tests/reports/report5.xml6
-rw-r--r--tests/org.eclipse.etrice.etunit.converter.tests/src/org/eclipse/etrice/etunit/converter/ConverterTest.java45
12 files changed, 250 insertions, 241 deletions
diff --git a/plugins/org.eclipse.etrice.etunit.converter/src/org/eclipse/etrice/etunit/converter/EtUnitReportConverter.java b/plugins/org.eclipse.etrice.etunit.converter/src/org/eclipse/etrice/etunit/converter/EtUnitReportConverter.java
index 34d2cb765..cd0c35c22 100644
--- a/plugins/org.eclipse.etrice.etunit.converter/src/org/eclipse/etrice/etunit/converter/EtUnitReportConverter.java
+++ b/plugins/org.eclipse.etrice.etunit.converter/src/org/eclipse/etrice/etunit/converter/EtUnitReportConverter.java
@@ -7,20 +7,26 @@
*
* CONTRIBUTORS:
* Henrik Rentz-Reichert (initial contribution)
+ * Juergen Haug - added support for in-memory conversion
*
*******************************************************************************/
package org.eclipse.etrice.etunit.converter;
import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
import java.io.File;
-import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
import java.math.BigDecimal;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
+import java.util.List;
+import java.util.UUID;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EPackage;
@@ -42,8 +48,8 @@ import org.eclipse.etrice.etunit.converter.Etunit.util.EtunitResourceFactoryImpl
*
*/
public class EtUnitReportConverter {
-
- protected static class Options {
+
+ public static class BaseOptions {
private boolean combinedResults = false;
private boolean replaceSuiteName = false;
private boolean prefixSuiteName = false;
@@ -51,7 +57,9 @@ public class EtUnitReportConverter {
private String combinedFile = null;
private String suiteName = null;
private String suiteNamePrefix = null;
- private ArrayList<String> files = new ArrayList<String>();
+
+ /** check that etUnit header line is present */
+ private boolean checkEtUnitHeader = true;
public boolean isCombinedResults() {
return combinedResults;
@@ -108,7 +116,23 @@ public class EtUnitReportConverter {
public void setSuiteNamePrefix(String suiteNamePrefix) {
this.suiteNamePrefix = suiteNamePrefix;
}
-
+
+ public boolean needCombined() {
+ return combinedResults;
+ }
+
+ public boolean checkEtUnitHeader() {
+ return checkEtUnitHeader;
+ }
+
+ public void setCheckEtUnitHeader(boolean checkEtUnitHeader) {
+ this.checkEtUnitHeader = checkEtUnitHeader;
+ }
+ }
+
+ protected static class Options extends BaseOptions {
+ private ArrayList<String> files = new ArrayList<String>();
+
public ArrayList<String> getFiles() {
return files;
}
@@ -117,10 +141,6 @@ public class EtUnitReportConverter {
this.files = files;
}
- public boolean needCombined() {
- return combinedResults;
- }
-
public boolean parseOptions(String[] args) {
for (int i=0; i<args.length; ++i) {
if (args[i].equals(OPTION_COMBINED)) {
@@ -218,14 +238,14 @@ public class EtUnitReportConverter {
);
}
- /**
- * @param args
- */
public static void main(String[] args) {
int result = new EtUnitReportConverter().run(args);
System.exit(result);
}
+ /**
+ * Can be used for testing.
+ */
public int run(String[] args) {
// check options and create file list
Options options = parseOptions(args);
@@ -238,13 +258,46 @@ public class EtUnitReportConverter {
rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xml", new EtunitResourceFactoryImpl());
boolean success = saveReports(options, rs);
- if (!saveCombinedReport(options, rs))
- success = false;
+ if (options.needCombined()) {
+ success &= saveCombined(createCombinedReport(rs), options, rs);
+ }
+
+ return (success) ? 0 : 2;
+ }
+
+ /**
+ * In-memory conversion. Returns a list of all successful converted reports.
+ * TODO don't report errors on stderr.
+ */
+ public List<String> convert(BaseOptions options, Iterable<InputStream> etUnitStreams) {
+ ResourceSet rs = new ResourceSetImpl();
+ rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xml", new EtunitResourceFactoryImpl());
+
+ boolean success = saveReports(options, etUnitStreams, rs);
+ final List<Resource> resources = new ArrayList<Resource>();
+ if (options.needCombined()) {
+ DocumentRoot root = createCombinedReport(rs);
+ Resource res = rs.createResource(URI.createURI("dummy:/" + UUID.randomUUID() + ".xml"));
+ res.getContents().add(root);
+ resources.add(res);
+ } else {
+ resources.addAll(rs.getResources());
+ }
- if (!success)
- return 2;
+ List<String> result = new ArrayList<String>();
+ for(Resource res : resources) {
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ try {
+ res.save(output, null);
+ result.add(output.toString(StandardCharsets.UTF_8.name()));
+ } catch (IOException e) {
+ System.err.println("Error: could not serialize report");
+ e.printStackTrace();
+ success = false;
+ }
+ }
- return 0;
+ return (success) ? result : Collections.emptyList();
}
/**
@@ -261,22 +314,19 @@ public class EtUnitReportConverter {
return options;
}
- protected boolean saveCombinedReport(Options options, ResourceSet rs) {
- if (options.needCombined()) {
- DocumentRoot root = EtunitFactory.eINSTANCE.createDocumentRoot();
- TestsuitesType testsuites = EtunitFactory.eINSTANCE.createTestsuitesType();
- root.setTestsuites(testsuites);
+ private DocumentRoot createCombinedReport(ResourceSet rs) {
+ DocumentRoot root = EtunitFactory.eINSTANCE.createDocumentRoot();
+ TestsuitesType testsuites = EtunitFactory.eINSTANCE.createTestsuitesType();
+ root.setTestsuites(testsuites);
- for (Resource res : rs.getResources()) {
- DocumentRoot r = (DocumentRoot) res.getContents().get(0);
- testsuites.getTestsuite().addAll(r.getTestsuites().getTestsuite());
- }
-
- computeAndSetInfo(testsuites);
-
- return saveCombined(root, options, rs);
+ for (Resource res : rs.getResources()) {
+ DocumentRoot r = (DocumentRoot) res.getContents().get(0);
+ testsuites.getTestsuite().addAll(r.getTestsuites().getTestsuite());
}
- return true;
+
+ computeAndSetInfo(testsuites);
+
+ return root;
}
protected boolean saveCombined(DocumentRoot root, Options options, ResourceSet rs) {
@@ -286,38 +336,26 @@ public class EtUnitReportConverter {
}
return true;
}
-
+
+ protected boolean saveReports(BaseOptions options, Iterable<InputStream> etUnitStreams, ResourceSet rs) {
+ boolean success = true;
+ for (InputStream stream : etUnitStreams) {
+ DocumentRoot root = applyOptions(options, createParseTree(stream, options));
+ if((success &= root != null)) {
+ Resource resource = rs.createResource(URI.createURI("dummy:/" + UUID.randomUUID() + ".xml"));
+ resource.getContents().add(root);
+ }
+ }
+ return success;
+ }
+
protected boolean saveReports(Options options, ResourceSet rs) {
boolean success = true;
for (String file : options.getFiles()) {
File report = new File(file);
if (report.exists()) {
- DocumentRoot root = createParseTree(report);
- if (root!=null && options.isReplaceSuiteName()) {
- if (root.getTestsuites()!=null) {
- if (root.getTestsuites().getTestsuite().size()==1) {
- root.getTestsuites().getTestsuite().get(0).setName(options.getSuiteName());
- }
- else {
- int i=0;
- for (TestsuiteType suite : root.getTestsuites().getTestsuite()) {
- suite.setName(options.getSuiteName()+i);
- ++i;
- }
- }
- }
- }
- if(root != null && options.isPrefixSuiteName()) {
- if(root.getTestsuites() != null) {
- for(TestsuiteType suite : root.getTestsuites().getTestsuite()) {
- suite.setName(options.getSuiteNamePrefix() + suite.getName());
- }
- }
- }
- if (root!=null) {
- if (!saveJUnitReport(root, report, rs, !options.isCombinedResults()))
- success = false;
- }
+ DocumentRoot root = applyOptions(options, createParseTree(report, options));
+ success &= root != null && saveJUnitReport(root, report, rs, !options.isCombinedResults());
}
else {
System.err.println("Error: report "+file+" does not exist");
@@ -326,21 +364,31 @@ public class EtUnitReportConverter {
}
return success;
}
-
- private void computeAndSetInfo(TestsuitesType testsuites) {
- for (TestsuiteType ts : testsuites.getTestsuite()) {
- int failures = 0;
- BigDecimal time = new BigDecimal(0);
- for (TestcaseType tc : ts.getTestcase()) {
- if (tc.getTime()!=null)
- time = time.add(tc.getTime());
- if (tc.getFailure()!=null)
- ++failures;
+
+ protected DocumentRoot applyOptions(BaseOptions options, DocumentRoot root) {
+ if (root!=null && options.isReplaceSuiteName()) {
+ if (root.getTestsuites()!=null) {
+ if (root.getTestsuites().getTestsuite().size()==1) {
+ root.getTestsuites().getTestsuite().get(0).setName(options.getSuiteName());
+ }
+ else {
+ int i=0;
+ for (TestsuiteType suite : root.getTestsuites().getTestsuite()) {
+ suite.setName(options.getSuiteName()+i);
+ ++i;
+ }
+ }
}
- ts.setTests(ts.getTestcase().size());
- ts.setFailures(failures);
- ts.setTime(time);
}
+ if(root != null && options.isPrefixSuiteName()) {
+ if(root.getTestsuites() != null) {
+ for(TestsuiteType suite : root.getTestsuites().getTestsuite()) {
+ suite.setName(options.getSuiteNamePrefix() + suite.getName());
+ }
+ }
+ }
+
+ return root;
}
private boolean saveJUnitReport(DocumentRoot root, File report, ResourceSet rs, boolean save) {
@@ -362,40 +410,60 @@ public class EtUnitReportConverter {
return true;
}
- /**
- * @param string
- * @return
- */
- private DocumentRoot createParseTree(File report) {
+ private DocumentRoot createParseTree(File report, BaseOptions options) {
- int count = 0;
+ FileReader input = null;
try {
- FileReader input = new FileReader(report.toString());
+ input = new FileReader(report.toString());
BufferedReader bufRead = new BufferedReader(input);
+ return createParseTree(bufRead, options);
+ } catch (IOException e) {
+ System.err.println("Error: file "+report+" could not be read ("+e.getMessage()+")");
+ e.printStackTrace();
+ }
+ finally {
+ try {
+ if(input != null)
+ input.close();
+ } catch (IOException e) {}
+ }
+ return null;
+ }
+
+ private DocumentRoot createParseTree(InputStream etUnitStream, BaseOptions options) {
+ try {
+ return createParseTree(new BufferedReader(new InputStreamReader(etUnitStream)), options);
+ } catch (IOException e) {
+ return null;
+ }
+ }
+
+ private DocumentRoot createParseTree(BufferedReader bufRead, BaseOptions options) throws IOException {
+ int count = 0;
+
+ try {
+ if(options.checkEtUnitHeader) {
+ String line = bufRead.readLine();
+ ++count;
+ if (line==null) {
+ System.err.println("Error: etUnit report is empty - no etunit file");
+ return null;
+ }
+ if (!line.equals("etUnit report")) {
+ System.err.println("Error: in etUnt report line "+line+" is missing header line - no etunit file");
+ return null;
+ }
+ }
+
HashMap<Integer, TestcaseType> id2case = new HashMap<Integer, TestcaseType>();
TestsuiteType currentSuite = null;
- String line = bufRead.readLine();
- ++count;
- if (line==null) {
- System.err.println("Error: file "+report+", is empty - no etunit file");
- bufRead.close();
- input.close();
- return null;
- }
- if (!line.equals("etUnit report")) {
- System.err.println("Error: file "+report+", line "+line+" is missing header line - no etunit file");
- bufRead.close();
- input.close();
- return null;
- }
-
DocumentRoot root = EtunitFactory.eINSTANCE.createDocumentRoot();
TestsuitesType testsuites = EtunitFactory.eINSTANCE.createTestsuitesType();
root.setTestsuites(testsuites);
- line = bufRead.readLine();
- ++count;
+ String line = bufRead.readLine();
+ ++count;
while (line!=null) {
if (line.startsWith(TS_START)) {
currentSuite = EtunitFactory.eINSTANCE.createTestsuiteType();
@@ -415,9 +483,7 @@ public class EtUnitReportConverter {
int id = Integer.parseInt(line.substring(8, pos));
TestcaseType tc = id2case.get(id);
if (tc==null) {
- System.err.println("Error: in file "+report+", line "+count+" - unknown test case id");
- bufRead.close();
- input.close();
+ System.err.println("Error: in etUnit report line "+count+" - unknown test case id");
return null;
}
FailureType fail = EtunitFactory.eINSTANCE.createFailureType();
@@ -445,9 +511,7 @@ public class EtUnitReportConverter {
int time = Integer.parseInt(line.substring(pos+2));
TestcaseType tc = id2case.get(id);
if (tc==null) {
- System.err.println("Error: in file "+report+", line "+count+" - unknown test case id");
- bufRead.close();
- input.close();
+ System.err.println("Error: in etUnit report line "+count+" - unknown test case id");
return null;
}
// time was measured in ms. Convert to s
@@ -457,22 +521,29 @@ public class EtUnitReportConverter {
++count;
}
- bufRead.close();
-
computeAndSetInfo(testsuites);
return root;
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- System.err.println("Error: file "+report+" could not be read ("+e.getMessage()+")");
- } catch (IOException e) {
- System.err.println("Error: file "+report+" could not be read ("+e.getMessage()+")");
- e.printStackTrace();
} catch (NumberFormatException e) {
- System.err.println("Error: in file "+report+", line "+count+" - could not read number");
+ System.err.println("Error: in etUnit report line "+count+" - could not read number");
+ return null;
+ }
+ }
+
+ private void computeAndSetInfo(TestsuitesType testsuites) {
+ for (TestsuiteType ts : testsuites.getTestsuite()) {
+ int failures = 0;
+ BigDecimal time = new BigDecimal(0);
+ for (TestcaseType tc : ts.getTestcase()) {
+ if (tc.getTime()!=null)
+ time = time.add(tc.getTime());
+ if (tc.getFailure()!=null)
+ ++failures;
+ }
+ ts.setTests(ts.getTestcase().size());
+ ts.setFailures(failures);
+ ts.setTime(time);
}
-
- return null;
}
private void doEMFRegistration() {
@@ -480,4 +551,4 @@ public class EtUnitReportConverter {
EPackage.Registry.INSTANCE.put("platform:/resource/org.eclipse.etrice.etunit.converter/model/etunit.xsd", EtunitPackage.eINSTANCE);
}
}
-}
+} \ No newline at end of file
diff --git a/tests/org.eclipse.etrice.etunit.converter.tests/.gitignore b/tests/org.eclipse.etrice.etunit.converter.tests/.gitignore
index fe99505dc..c5188a7a8 100644
--- a/tests/org.eclipse.etrice.etunit.converter.tests/.gitignore
+++ b/tests/org.eclipse.etrice.etunit.converter.tests/.gitignore
@@ -1,2 +1,3 @@
bin
+reports/*.xml
diff --git a/tests/org.eclipse.etrice.etunit.converter.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.etrice.etunit.converter.tests/META-INF/MANIFEST.MF
index 90506c039..8b854973c 100644
--- a/tests/org.eclipse.etrice.etunit.converter.tests/META-INF/MANIFEST.MF
+++ b/tests/org.eclipse.etrice.etunit.converter.tests/META-INF/MANIFEST.MF
@@ -7,6 +7,8 @@ Bundle-Activator: org.eclipse.etrice.etunit.converter.tests.Activator
Bundle-Vendor: Eclipse eTrice
Require-Bundle: org.eclipse.etrice.etunit.converter;bundle-version="2.0.0",
org.eclipse.core.runtime,
- org.junit;bundle-version="4.8.2"
+ org.junit;bundle-version="4.8.2",
+ com.google.guava
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
+Import-Package: com.google.common.io
diff --git a/tests/org.eclipse.etrice.etunit.converter.tests/expects/report1.xml b/tests/org.eclipse.etrice.etunit.converter.tests/expects/report1.xml
new file mode 100644
index 000000000..6aa431430
--- /dev/null
+++ b/tests/org.eclipse.etrice.etunit.converter.tests/expects/report1.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="ASCII"?>
+<testsuites>
+ <testsuite failures="0" name="TestMessage" tests="1" time="0.0">
+ <testcase name="TestEtMessage_testBasicMessage" time="0.0"/>
+ </testsuite>
+ <testsuite failures="1" name="TestEtMessageQueue" tests="2" time="0.187">
+ <testcase name="TestEtMessageQueue_testPushPop" time="0.0">
+ <failure><expected>334</expected><actual>333</actual>rcvMsg2->evtID: expected=334, actual=333
+ at ..\src\runtime\TestEtMessageQueue.c:42</failure>
+ </testcase>
+ <testcase name="TestEtMessageQueue_testMassiveMessaging" time="0.187"/>
+ </testsuite>
+ <testsuite failures="0" name="TestEtMessageService" tests="5" time="0.016">
+ <testcase name="TestEtMessageService_init" time="0.0"/>
+ <testcase name="TestEtMessageService_GetPushPopReturn" time="0.0"/>
+ <testcase name="TestEtMessageService_GetReturn" time="0.016"/>
+ <testcase name="TestEtMessageService_execute" time="0.0"/>
+ <testcase name="TestEtMessageService_getMessagePoolLowWaterMark" time="0.0"/>
+ </testsuite>
+ <testsuite failures="0" name="TestEtUnit" tests="2" time="0.0">
+ <testcase name="TestEtUnit_Expect_Order" time="0.0"/>
+ <testcase name="TestEtUnit_Expect" time="0.0"/>
+ </testsuite>
+</testsuites> \ No newline at end of file
diff --git a/tests/org.eclipse.etrice.etunit.converter.tests/reports/combined.xml b/tests/org.eclipse.etrice.etunit.converter.tests/reports/combined.xml
deleted file mode 100644
index 1a21e9248..000000000
--- a/tests/org.eclipse.etrice.etunit.converter.tests/reports/combined.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="ASCII"?>
-<testsuites>
- <testsuite failures="0" name="TestMessage" tests="1" time="0">
- <testcase name="TestEtMessage_testBasicMessage" time="0"/>
- </testsuite>
- <testsuite failures="1" name="TestEtMessageQueue" tests="2" time="187">
- <testcase name="TestEtMessageQueue_testPushPop" time="0">
- <failure><expected>334</expected><actual>333</actual>rcvMsg2->evtID: expected=334, actual=333
- at ..\src\runtime\TestEtMessageQueue.c:42</failure>
- </testcase>
- <testcase name="TestEtMessageQueue_testMassiveMessaging" time="187"/>
- </testsuite>
- <testsuite failures="0" name="TestEtMessageService" tests="5" time="16">
- <testcase name="TestEtMessageService_init" time="0"/>
- <testcase name="TestEtMessageService_GetPushPopReturn" time="0"/>
- <testcase name="TestEtMessageService_GetReturn" time="16"/>
- <testcase name="TestEtMessageService_execute" time="0"/>
- <testcase name="TestEtMessageService_getMessagePoolLowWaterMark" time="0"/>
- </testsuite>
- <testsuite failures="0" name="TestEtUnit" tests="2" time="0">
- <testcase name="TestEtUnit_Expect_Order" time="0"/>
- <testcase name="TestEtUnit_Expect" time="0"/>
- </testsuite>
- <testsuite failures="0" name="etUnit" tests="1" time="0">
- <testcase name="openAll and closeAll" time="0"/>
- </testsuite>
-</testsuites> \ No newline at end of file
diff --git a/tests/org.eclipse.etrice.etunit.converter.tests/reports/only_combined.xml b/tests/org.eclipse.etrice.etunit.converter.tests/reports/only_combined.xml
deleted file mode 100644
index 1a21e9248..000000000
--- a/tests/org.eclipse.etrice.etunit.converter.tests/reports/only_combined.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="ASCII"?>
-<testsuites>
- <testsuite failures="0" name="TestMessage" tests="1" time="0">
- <testcase name="TestEtMessage_testBasicMessage" time="0"/>
- </testsuite>
- <testsuite failures="1" name="TestEtMessageQueue" tests="2" time="187">
- <testcase name="TestEtMessageQueue_testPushPop" time="0">
- <failure><expected>334</expected><actual>333</actual>rcvMsg2->evtID: expected=334, actual=333
- at ..\src\runtime\TestEtMessageQueue.c:42</failure>
- </testcase>
- <testcase name="TestEtMessageQueue_testMassiveMessaging" time="187"/>
- </testsuite>
- <testsuite failures="0" name="TestEtMessageService" tests="5" time="16">
- <testcase name="TestEtMessageService_init" time="0"/>
- <testcase name="TestEtMessageService_GetPushPopReturn" time="0"/>
- <testcase name="TestEtMessageService_GetReturn" time="16"/>
- <testcase name="TestEtMessageService_execute" time="0"/>
- <testcase name="TestEtMessageService_getMessagePoolLowWaterMark" time="0"/>
- </testsuite>
- <testsuite failures="0" name="TestEtUnit" tests="2" time="0">
- <testcase name="TestEtUnit_Expect_Order" time="0"/>
- <testcase name="TestEtUnit_Expect" time="0"/>
- </testsuite>
- <testsuite failures="0" name="etUnit" tests="1" time="0">
- <testcase name="openAll and closeAll" time="0"/>
- </testsuite>
-</testsuites> \ No newline at end of file
diff --git a/tests/org.eclipse.etrice.etunit.converter.tests/reports/report1.xml b/tests/org.eclipse.etrice.etunit.converter.tests/reports/report1.xml
deleted file mode 100644
index c99b92aa1..000000000
--- a/tests/org.eclipse.etrice.etunit.converter.tests/reports/report1.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="ASCII"?>
-<testsuites>
- <testsuite failures="0" name="TestMessage" tests="1" time="0">
- <testcase name="TestEtMessage_testBasicMessage" time="0"/>
- </testsuite>
- <testsuite failures="1" name="TestEtMessageQueue" tests="2" time="187">
- <testcase name="TestEtMessageQueue_testPushPop" time="0">
- <failure><expected>334</expected><actual>333</actual>rcvMsg2->evtID: expected=334, actual=333
- at ..\src\runtime\TestEtMessageQueue.c:42</failure>
- </testcase>
- <testcase name="TestEtMessageQueue_testMassiveMessaging" time="187"/>
- </testsuite>
- <testsuite failures="0" name="TestEtMessageService" tests="5" time="16">
- <testcase name="TestEtMessageService_init" time="0"/>
- <testcase name="TestEtMessageService_GetPushPopReturn" time="0"/>
- <testcase name="TestEtMessageService_GetReturn" time="16"/>
- <testcase name="TestEtMessageService_execute" time="0"/>
- <testcase name="TestEtMessageService_getMessagePoolLowWaterMark" time="0"/>
- </testsuite>
- <testsuite failures="0" name="TestEtUnit" tests="2" time="0">
- <testcase name="TestEtUnit_Expect_Order" time="0"/>
- <testcase name="TestEtUnit_Expect" time="0"/>
- </testsuite>
-</testsuites> \ No newline at end of file
diff --git a/tests/org.eclipse.etrice.etunit.converter.tests/reports/report2.xml b/tests/org.eclipse.etrice.etunit.converter.tests/reports/report2.xml
deleted file mode 100644
index 87d8c645c..000000000
--- a/tests/org.eclipse.etrice.etunit.converter.tests/reports/report2.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="ASCII"?>
-<testsuites>
- <testsuite failures="0" name="etUnit" tests="1" time="0">
- <testcase name="openAll and closeAll" time="0"/>
- </testsuite>
-</testsuites> \ No newline at end of file
diff --git a/tests/org.eclipse.etrice.etunit.converter.tests/reports/report3.xml b/tests/org.eclipse.etrice.etunit.converter.tests/reports/report3.xml
deleted file mode 100644
index c99b92aa1..000000000
--- a/tests/org.eclipse.etrice.etunit.converter.tests/reports/report3.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="ASCII"?>
-<testsuites>
- <testsuite failures="0" name="TestMessage" tests="1" time="0">
- <testcase name="TestEtMessage_testBasicMessage" time="0"/>
- </testsuite>
- <testsuite failures="1" name="TestEtMessageQueue" tests="2" time="187">
- <testcase name="TestEtMessageQueue_testPushPop" time="0">
- <failure><expected>334</expected><actual>333</actual>rcvMsg2->evtID: expected=334, actual=333
- at ..\src\runtime\TestEtMessageQueue.c:42</failure>
- </testcase>
- <testcase name="TestEtMessageQueue_testMassiveMessaging" time="187"/>
- </testsuite>
- <testsuite failures="0" name="TestEtMessageService" tests="5" time="16">
- <testcase name="TestEtMessageService_init" time="0"/>
- <testcase name="TestEtMessageService_GetPushPopReturn" time="0"/>
- <testcase name="TestEtMessageService_GetReturn" time="16"/>
- <testcase name="TestEtMessageService_execute" time="0"/>
- <testcase name="TestEtMessageService_getMessagePoolLowWaterMark" time="0"/>
- </testsuite>
- <testsuite failures="0" name="TestEtUnit" tests="2" time="0">
- <testcase name="TestEtUnit_Expect_Order" time="0"/>
- <testcase name="TestEtUnit_Expect" time="0"/>
- </testsuite>
-</testsuites> \ No newline at end of file
diff --git a/tests/org.eclipse.etrice.etunit.converter.tests/reports/report4.xml b/tests/org.eclipse.etrice.etunit.converter.tests/reports/report4.xml
deleted file mode 100644
index 87d8c645c..000000000
--- a/tests/org.eclipse.etrice.etunit.converter.tests/reports/report4.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="ASCII"?>
-<testsuites>
- <testsuite failures="0" name="etUnit" tests="1" time="0">
- <testcase name="openAll and closeAll" time="0"/>
- </testsuite>
-</testsuites> \ No newline at end of file
diff --git a/tests/org.eclipse.etrice.etunit.converter.tests/reports/report5.xml b/tests/org.eclipse.etrice.etunit.converter.tests/reports/report5.xml
deleted file mode 100644
index cf37f05ad..000000000
--- a/tests/org.eclipse.etrice.etunit.converter.tests/reports/report5.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="ASCII"?>
-<testsuites>
- <testsuite failures="0" name="new.suite.name" tests="1" time="0">
- <testcase name="openAll and closeAll" time="0"/>
- </testsuite>
-</testsuites> \ No newline at end of file
diff --git a/tests/org.eclipse.etrice.etunit.converter.tests/src/org/eclipse/etrice/etunit/converter/ConverterTest.java b/tests/org.eclipse.etrice.etunit.converter.tests/src/org/eclipse/etrice/etunit/converter/ConverterTest.java
index 48aa82a7c..2c0a5e4b4 100644
--- a/tests/org.eclipse.etrice.etunit.converter.tests/src/org/eclipse/etrice/etunit/converter/ConverterTest.java
+++ b/tests/org.eclipse.etrice.etunit.converter.tests/src/org/eclipse/etrice/etunit/converter/ConverterTest.java
@@ -12,15 +12,25 @@
package org.eclipse.etrice.etunit.converter;
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
+import java.util.List;
import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.etrice.etunit.converter.EtUnitReportConverter.BaseOptions;
import org.eclipse.etrice.etunit.converter.tests.Activator;
import org.junit.Before;
import org.junit.Test;
+import com.google.common.base.Charsets;
+import com.google.common.io.Files;
+
/**
* @author Henrik Rentz-Reichert
*
@@ -28,6 +38,7 @@ import org.junit.Test;
public class ConverterTest {
private String basePath;
+ private String expectsPath;
@Before
public void prepare() {
@@ -38,16 +49,26 @@ public class ConverterTest {
} catch (IOException e) {
e.printStackTrace();
}
+ try {
+ URL modelsDir = Activator.getInstance().getBundle().getEntry("expects");
+ URL fileURL = FileLocator.toFileURL(modelsDir);
+ expectsPath = fileURL.getFile();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
}
@Test
- public void testConversion() {
+ public void testConversion() throws IOException {
ArrayList<String> args = new ArrayList<String>();
args.add(basePath+"report1.etu");
String[] arguments = new String[args.size()];
- EtUnitReportConverter.main(args.toArray(arguments));
+ new EtUnitReportConverter().run(args.toArray(arguments));
+
+ assertEquals(Files.toString(new File(expectsPath+"report1.xml"), Charsets.UTF_8), Files.toString(new File(basePath+"report1.xml"), Charsets.UTF_8));
}
+
@Test
public void testDoubleConversion() {
@@ -56,7 +77,7 @@ public class ConverterTest {
args.add(basePath+"report2.etu");
String[] arguments = new String[args.size()];
- EtUnitReportConverter.main(args.toArray(arguments));
+ new EtUnitReportConverter().run(args.toArray(arguments));
}
@Test
@@ -68,7 +89,7 @@ public class ConverterTest {
args.add(basePath+"combined.xml");
String[] arguments = new String[args.size()];
- EtUnitReportConverter.main(args.toArray(arguments));
+ new EtUnitReportConverter().run(args.toArray(arguments));
}
@Test
@@ -80,7 +101,7 @@ public class ConverterTest {
args.add(basePath+"only_combined.xml");
String[] arguments = new String[args.size()];
- EtUnitReportConverter.main(args.toArray(arguments));
+ new EtUnitReportConverter().run(args.toArray(arguments));
}
@Test
@@ -91,7 +112,7 @@ public class ConverterTest {
args.add("new.suite.name");
String[] arguments = new String[args.size()];
- EtUnitReportConverter.main(args.toArray(arguments));
+ new EtUnitReportConverter().run(args.toArray(arguments));
}
@Test
@@ -100,6 +121,16 @@ public class ConverterTest {
args.add(basePath+"report6.etu");
String[] arguments = new String[args.size()];
- EtUnitReportConverter.main(args.toArray(arguments));
+ new EtUnitReportConverter().run(args.toArray(arguments));
+ }
+
+ @Test
+ public void testInMemory() throws IOException {
+ List<InputStream> streams = new ArrayList<InputStream>();
+ streams.add(new FileInputStream(new File(basePath+"report1.etu")));
+
+ List<String> results = new EtUnitReportConverter().convert(new BaseOptions(), streams);
+ assertEquals(1, results.size());
+ assertEquals(Files.toString(new File(expectsPath+"report1.xml"), Charsets.UTF_8), results.get(0));
}
}

Back to the top