|
| 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 | +} |
0 commit comments