Skip to content

Commit ce9f200

Browse files
committed
Merge pull request #449 from PaulaRudy/issue316
Issue316: make a test for ALL the steps to ensure backwards compatibility.
2 parents 9e495b0 + 6836421 commit ce9f200

4 files changed

Lines changed: 932 additions & 0 deletions

File tree

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package edu.wpi.grip.core.serialization;
2+
3+
import com.google.common.eventbus.EventBus;
4+
import com.google.inject.Guice;
5+
import com.google.inject.Injector;
6+
import edu.wpi.grip.core.GRIPCoreModule;
7+
import edu.wpi.grip.core.Pipeline;
8+
import edu.wpi.grip.core.operations.Operations;
9+
import edu.wpi.grip.core.settings.ProjectSettings;
10+
import edu.wpi.grip.generated.CVOperations;
11+
import edu.wpi.grip.util.Files;
12+
import org.junit.Before;
13+
import org.junit.Test;
14+
15+
import java.io.*;
16+
import java.net.URI;
17+
18+
import static junit.framework.TestCase.assertEquals;
19+
20+
/**
21+
* This tests for backwards compatibility by opening a project file containing ALL the steps of GRIP
22+
* at the time of this file's creation. Please note that this test requires a webcam at position 0.
23+
*/
24+
public class CompatibilityTest {
25+
26+
private static final URI testphotoURI = Files.testphotoURI; //The location of the photo source for the test
27+
private static final URI testprojectURI = Files.testprojectURI; //The location of the save file for the test
28+
29+
private Pipeline pipeline;
30+
private Project project;
31+
private ProjectSettings settings;
32+
33+
private EventBus eventBus;
34+
35+
@Before
36+
public void setUp() throws Exception {
37+
38+
//Set up the stuff we need for the core functionality for GRIP
39+
final Injector injector = Guice.createInjector(new GRIPCoreModule());
40+
41+
eventBus = injector.getInstance(EventBus.class);
42+
pipeline = injector.getInstance(Pipeline.class);
43+
project = injector.getInstance(Project.class);
44+
settings = injector.getInstance(ProjectSettings.class);
45+
46+
//Add the operations so that GRIP will recognize them
47+
Operations.addOperations(eventBus);
48+
CVOperations.addOperations(eventBus);
49+
50+
//Set up the test project file to work with this machine
51+
String fileName = testprojectURI.toString().substring(5);
52+
String photoFileName = testphotoURI.toString().substring(5);
53+
54+
//Open the project save file and read it into a string so that we can alter it
55+
File file = new File(fileName);
56+
57+
Reader temp = new FileReader(file);
58+
BufferedReader reader = new BufferedReader(temp);
59+
String line = "", oldtext = "";
60+
while ((line = reader.readLine()) != null) {
61+
oldtext += line + "\r\n";
62+
}
63+
reader.close();
64+
String newtext = oldtext.replaceAll("REPLACEME", photoFileName);//This gives the correct location of the test photo needed to the project file
65+
66+
//Write the altered project file text
67+
FileWriter writer2 = new FileWriter(file);
68+
writer2.write(newtext);
69+
70+
writer2.close();
71+
72+
//Open the test file as a project
73+
project.open(file);
74+
}
75+
76+
@Test
77+
public void testFoo() throws Exception {
78+
assertEquals("The expected number of steps were not found", 50, pipeline.getSteps().size());
79+
assertEquals("The expected number of sources were not found", 2, pipeline.getSources().size());
80+
}
81+
}

core/src/test/java/edu/wpi/grip/util/Files.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package edu.wpi.grip.util;
22

33
import java.io.File;
4+
import java.net.URI;
45
import java.net.URISyntaxException;
56

67
/**
@@ -9,6 +10,8 @@
910
public class Files {
1011
public static final ImageWithData imageFile, gompeiJpegFile;
1112
public static final File textFile;
13+
public static final URI testphotoURI, testprojectURI;
14+
1215

1316
static {
1417
try {
@@ -17,6 +20,9 @@ public class Files {
1720
Files.class.getResource("/edu/wpi/grip/images/GRIP_Logo.png").toURI()), 183, 480);
1821
gompeiJpegFile = new ImageWithData(new File(
1922
Files.class.getResource("/edu/wpi/grip/images/gompei.jpeg").toURI()), 220, 225);
23+
testphotoURI = Files.class.getResource("/edu/wpi/grip/images/testphoto.png").toURI();
24+
testprojectURI = Files.class.getResource("/edu/wpi/grip/projects/testALL.grip").toURI();
25+
2026
} catch (URISyntaxException e) {
2127
throw new IllegalStateException("Could not load file from system", e);
2228
}
122 KB
Loading

0 commit comments

Comments
 (0)