Skip to content

Commit 48c779c

Browse files
author
jantje
committed
#1268 added unit test for single config from sloeber V4.3.3
off course the test fails now I need to get the test to be successfull I also remloved some exception handling from a shared method which makes there are 2 more tests added to this commit
1 parent 6c02541 commit 48c779c

File tree

5 files changed

+153
-13
lines changed

5 files changed

+153
-13
lines changed

io.sloeber.tests/src/io/sloeber/core/CompileAndUpload.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
import org.junit.runners.Parameterized;
3030
import org.junit.runners.Parameterized.Parameters;
3131

32-
import io.sloeber.core.api.SloeberProject;
3332
import io.sloeber.core.api.CodeDescription;
3433
import io.sloeber.core.api.CompileDescription;
3534
import io.sloeber.core.api.PackageManager;
3635
import io.sloeber.core.api.Preferences;
3736
import io.sloeber.core.api.Sketch;
37+
import io.sloeber.core.api.SloeberProject;
3838
import io.sloeber.core.common.ConfigurationPreferences;
3939
import io.sloeber.providers.MCUBoard;
4040
import io.sloeber.ui.monitor.SerialConnection;
@@ -129,7 +129,7 @@ public static void installAdditionalBoards() {
129129
}
130130

131131
@Test
132-
public void testExamples() {
132+
public void testExamples() throws Exception {
133133
IPath templateFolder = Shared.getTemplateFolder("fastBlink");
134134
CompileDescription compileOptions = new CompileDescription();
135135
DateTimeFormatter df = DateTimeFormatter

io.sloeber.tests/src/io/sloeber/core/CreateAndCompileDefaultInoOnAllBoardsTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ public static void installAdditionalBoards() {
340340
}
341341

342342
@Test
343-
public void testBoard() {
343+
public void testBoard() throws Exception {
344344
myBuildCounter++;
345345
Assume.assumeTrue("Skipping first " + mySkipTestsAtStart + " tests", myBuildCounter >= mySkipTestsAtStart);
346346
Assume.assumeTrue("To many fails. Stopping test", myTotalFails < maxFails);

io.sloeber.tests/src/io/sloeber/core/Shared.java

+81-10
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22

33
import static org.junit.Assert.fail;
44

5+
import java.io.BufferedOutputStream;
56
import java.io.File;
7+
import java.io.FileInputStream;
8+
import java.io.FileOutputStream;
69
import java.io.IOException;
7-
import java.net.URISyntaxException;
810
import java.net.URL;
911
import java.nio.file.Files;
1012
import java.nio.file.Paths;
13+
import java.util.zip.ZipEntry;
14+
import java.util.zip.ZipInputStream;
1115

1216
import org.apache.commons.lang.SystemUtils;
1317
import org.eclipse.cdt.core.model.ICModelMarker;
@@ -90,20 +94,20 @@ public static void waitForAllJobsToFinish() {
9094
}
9195
}
9296

93-
public static IPath getTemplateFolder(String templateName) {
94-
try {
97+
public static IPath getTemplateFolder(String templateName) throws Exception {
9598
Bundle bundle = Platform.getBundle("io.sloeber.tests");
9699
Path path = new Path("src/templates/" + templateName);
97100
URL fileURL = FileLocator.find(bundle, path, null);
98101
URL resolvedFileURL = FileLocator.toFileURL(fileURL);
99102
return new Path(resolvedFileURL.toURI().getPath());
100-
} catch (URISyntaxException e) {
101-
e.printStackTrace();
102-
} catch (IOException e) {
103-
e.printStackTrace();
104-
}
105-
System.err.println("Failed to find templates in io.sloeber.tests plugin.");
106-
return new Path(new String());
103+
}
104+
105+
public static IPath getprojectZip(String zipFileName) throws Exception {
106+
Bundle bundle = Platform.getBundle("io.sloeber.tests");
107+
Path path = new Path("src/projects/" + zipFileName);
108+
URL fileURL = FileLocator.find(bundle, path, null);
109+
URL resolvedFileURL = FileLocator.toFileURL(fileURL);
110+
return new Path(resolvedFileURL.toURI().getPath());
107111
}
108112

109113
/**
@@ -261,4 +265,71 @@ public static String getLastFailMessage() {
261265
// TODO Auto-generated method stub
262266
return myLastFailMessage;
263267
}
268+
269+
// copied from
270+
// https://www.codejava.net/java-se/file-io/programmatically-extract-a-zip-file-using-java
271+
272+
// /**
273+
// * This utility extracts files and directories of a standard zip file to
274+
// * a destination directory.
275+
// * @author www.codejava.net
276+
// *
277+
// */
278+
// public class UnzipUtility {
279+
/**
280+
* Size of the buffer to read/write data
281+
*/
282+
private static final int BUFFER_SIZE = 4096;
283+
284+
/**
285+
* Extracts a zip file specified by the zipFilePath to a directory specified by
286+
* destDirectory (will be created if does not exists)
287+
*
288+
* @param zipFilePath
289+
* @param destDirectory
290+
* @throws IOException
291+
*/
292+
public static void unzip(String zipFilePath, String destDirectory) throws IOException {
293+
File destDir = new File(destDirectory);
294+
if (!destDir.exists()) {
295+
destDir.mkdir();
296+
}
297+
ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFilePath));
298+
ZipEntry entry = zipIn.getNextEntry();
299+
// iterates over entries in the zip file
300+
while (entry != null) {
301+
String filePath = destDirectory + File.separator + entry.getName();
302+
if (!entry.isDirectory()) {
303+
// if the entry is a file, extracts it
304+
extractFile(zipIn, filePath);
305+
} else {
306+
// if the entry is a directory, make the directory
307+
File dir = new File(filePath);
308+
dir.mkdirs();
309+
}
310+
zipIn.closeEntry();
311+
entry = zipIn.getNextEntry();
312+
}
313+
zipIn.close();
314+
}
315+
316+
/**
317+
* Extracts a zip entry (file entry)
318+
*
319+
* @param zipIn
320+
* @param filePath
321+
* @throws IOException
322+
*/
323+
private static void extractFile(ZipInputStream zipIn, String filePath) throws IOException {
324+
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath));
325+
byte[] bytesIn = new byte[BUFFER_SIZE];
326+
int read = 0;
327+
while ((read = zipIn.read(bytesIn)) != -1) {
328+
bos.write(bytesIn, 0, read);
329+
}
330+
bos.close();
331+
}
332+
// }
333+
// end copy from
334+
// https://www.codejava.net/java-se/file-io/programmatically-extract-a-zip-file-using-java
264335
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package io.sloeber.core;
2+
3+
import static org.junit.Assert.fail;
4+
5+
import org.eclipse.core.resources.IProject;
6+
import org.eclipse.core.resources.IWorkspace;
7+
import org.eclipse.core.resources.IWorkspaceRoot;
8+
import org.eclipse.core.resources.IncrementalProjectBuilder;
9+
import org.eclipse.core.resources.ResourcesPlugin;
10+
import org.junit.Test;
11+
12+
/**
13+
* this test assumes it is stared in a clean workspace and not in the UI thread
14+
*
15+
* this test copies previous versions sloeber projects into the new workspace
16+
* opens them and builds them if the build is successful the test is considered
17+
* successful
18+
*
19+
* @author jan
20+
*
21+
*/
22+
@SuppressWarnings({ "nls", "static-method" })
23+
public class UpgradeTest {
24+
/**
25+
* Upgrade a single config project
26+
*
27+
* @throws Exception
28+
*/
29+
30+
@Test
31+
public void upgradeSingleConfigProjectFromVersion4_3_3() throws Exception {
32+
33+
String projectName = "upgradeSingleConfigProject";
34+
String inputZipFile = Shared.getprojectZip("upgradeSingleConfigProject4_3_3.zip").toOSString();
35+
// /io.sloeber.tests/src/projects/upgradeSingleConfigProject4_3_3.zip
36+
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
37+
IWorkspaceRoot root = workspace.getRoot();
38+
IProject theTestProject = root.getProject(projectName);
39+
Shared.unzip(inputZipFile, root.getLocation().toOSString());
40+
theTestProject.create(null);
41+
theTestProject.open(null);
42+
Shared.waitForAllJobsToFinish(); // for the indexer
43+
theTestProject.build(IncrementalProjectBuilder.FULL_BUILD, null);
44+
if (Shared.hasBuildErrors(theTestProject)) {
45+
fail("Failed to compile the project:" + projectName);
46+
}
47+
}
48+
49+
/**
50+
* Upgrade a triple dual project
51+
*
52+
* @throws Exception
53+
*/
54+
@Test
55+
public void upgradeDualConfigProject() throws Exception {
56+
57+
}
58+
59+
/**
60+
* Upgrade a triple config project
61+
*
62+
* @throws Exception
63+
*/
64+
@Test
65+
public void upgradeTripleConfigProject() throws Exception {
66+
67+
}
68+
69+
}
Binary file not shown.

0 commit comments

Comments
 (0)