/*******************************************************************************
- * Copyright (c) 2014, 2015 Ericsson
+ * Copyright (c) 2014, 2016 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
+import java.text.ParseException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.Logger;
import org.eclipse.swtbot.swt.finder.waits.Conditions;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+import org.eclipse.tracecompass.common.core.format.DataSizeWithUnitFormat;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
// private static final int PACKAGE_SIZE = 213732;
private static final String EXPORT_LOCATION = TmfTraceManager.getTemporaryDirPath() + File.separator + "test.zip";
+ private static final String TRACE_LOCATION = TmfTraceManager.getTemporaryDirPath() + File.separator + "test.xml";
private static final String IMPORT_TRACE_PACKAGE = "Import Trace Package...";
private static final String IMPORT_TRACE_PACKAGE_TITLE = "Import trace package";
private static final String EXPORT_TRACE_PACKAGE = "Export Trace Package...";
private static final String PROJECT_NAME = "Test";
private static final String XMLSTUB_ID = "org.eclipse.linuxtools.tmf.core.tests.xmlstub";
+ private static final Pattern PATTERN = Pattern.compile("Approximate uncompressed size: (.*)B");
+
private static final String TRACE_CONTENT = "<trace>" +
"<event timestamp=\"100\" name=\"event\"><field name=\"field\" value=\"1\" type=\"int\" /></event>" +
"<event timestamp=\"200\" name=\"event1\"><field name=\"field\" value=\"2\" type=\"int\" /></event>" +
*
* @throws IOException
* won't happen
+ * @throws ParseException
+ * won't happen
*/
@Test
- public void test() throws IOException {
- File f = File.createTempFile("temp", ".xml").getCanonicalFile();
- try (FileWriter fw = new FileWriter(f)) {
+ public void test() throws IOException, ParseException {
+ File traceFile = new File(TRACE_LOCATION);
+ if (traceFile.exists()) {
+ traceFile.delete();
+ }
+ traceFile.deleteOnExit();
+ try (FileWriter fw = new FileWriter(traceFile)) {
fw.write(TRACE_CONTENT);
}
File exportPackage = new File(EXPORT_LOCATION);
exportPackage.delete();
}
assertFalse("File: " + EXPORT_LOCATION + " already present, aborting test", exportPackage.exists());
- assertTrue("Trace :" + f.getAbsolutePath() + " does not exist, aborting test", f.exists());
+ assertTrue("Trace :" + traceFile.getAbsolutePath() + " does not exist, aborting test", traceFile.exists());
SWTBotUtils.createProject(PROJECT_NAME);
- SWTBotUtils.openTrace(PROJECT_NAME, f.getAbsolutePath(), XMLSTUB_ID);
- WaitUtils.waitForJobs();
+ SWTBotUtils.openTrace(PROJECT_NAME, TRACE_LOCATION, XMLSTUB_ID);
ITmfTrace trace = TmfTraceManager.getInstance().getActiveTrace();
assertNotNull(trace);
- assertEquals("Incorrect opened trace!", f.getAbsolutePath(), (new File(trace.getPath())).getAbsolutePath());
+ assertEquals("Incorrect opened trace!", traceFile.getAbsolutePath(), (new File(trace.getPath())).getAbsolutePath());
SWTBotView projectExplorerBot = fBot.viewByTitle(PROJECT_EXPLORER);
assertNotNull("Cannot find " + PROJECT_EXPLORER, projectExplorerBot);
projectExplorerBot.show();
for (SWTBotTreeItem item : items) {
assertEquals(item.isChecked(), false);
}
+ String labelText = fBot.label(1).getText();
+ Matcher matcher = PATTERN.matcher(labelText);
+
+ assertTrue(labelText + " matches", matcher.matches());
+ String sizeText = matcher.group(1);
+ assertEquals(labelText + " value", "0", sizeText.trim());
+
shellBot.button(SELECT_ALL).click();
+
for (SWTBotTreeItem item : items) {
assertEquals(item.isChecked(), true);
}
+
+ labelText = fBot.label(1).getText();
+ matcher = PATTERN.matcher(labelText);
+
+ assertTrue(labelText + " matches", matcher.matches());
+ // should be 138 k
+ sizeText = matcher.group(1);
+ int size = ((Number) DataSizeWithUnitFormat.getInstance().parseObject(sizeText)).intValue();
+ assertTrue(labelText + " value", 0 < size);
+
shellBot.radio(SAVE_IN_TAR_FORMAT).click();
shellBot.radio(SAVE_IN_ZIP_FORMAT).click();
fBot = new SWTWorkbenchBot();
exportPackage = new File(EXPORT_LOCATION);
assertTrue("Exported package", exportPackage.exists());
- // Fixme: determine why exportPackageSize is different on different machines
- // assertEquals("Exported package size check", PACKAGE_SIZE, exportPackage.length());
+ /*
+ * Fixme: determine why exportPackageSize is different on different
+ * machines
+ */
+ /*
+ * assertEquals("Exported package size check", PACKAGE_SIZE,
+ * exportPackage.length());
+ */
// import
treeItem = SWTBotUtils.selectTracesFolder(fBot, PROJECT_NAME);
fBot.button("Yes To All").click();
fBot.waitUntil(Conditions.shellCloses(shell));
fBot = new SWTWorkbenchBot();
- SWTBotUtils.openEditor(fBot, PROJECT_NAME, new Path(f.getName()));
+ SWTBotUtils.openEditor(fBot, PROJECT_NAME, new Path(traceFile.getName()));
trace = TmfTraceManager.getInstance().getActiveTrace();
assertNotNull(trace);
- assertEquals("Test if import matches", f.getName(), trace.getName());
- assertFalse("Test if import files don't match", f.getAbsolutePath().equals(trace.getPath()));
+ assertEquals("Test if import matches", traceFile.getName(), trace.getName());
+ assertFalse("Test if import files don't match", traceFile.getAbsolutePath().equals(trace.getPath()));
SWTBotUtils.deleteProject(PROJECT_NAME, fBot);
WaitUtils.waitForJobs();
+ traceFile.delete();
+ exportPackage.delete();
+
}
}