--- /dev/null
+package org.simantics.sysdyn.tests.fmi;\r
+\r
+import java.util.Arrays;\r
+import java.util.List;\r
+\r
+import junit.framework.Assert;\r
+\r
+import org.junit.Test;\r
+import org.simantics.modelica.fmi.FMUControlJNI;\r
+import org.simantics.modelica.fmi.FMUJNIException;\r
+\r
+\r
+/**\r
+ * Tests result filtering\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class FMUResultFilterTest {\r
+ \r
+ /*\r
+ Below is the model used for testing. \r
+ Model is located in Models\FMUTests\FMURealTest \r
+ \r
+ model FMURealTestModel\r
+ parameter Real r1 = 1.0;\r
+ parameter Real r2 = 1.0;\r
+ Real valve;\r
+ Real stock(start=0.0,fixed=true);\r
+ parameter Real time = 0; // Time parameter is set at each time step by simulator\r
+ equation\r
+ if initial() or r1 < 0 or r1 >= 0 then (r1 + r2) else pre(valve);\r
+ der(stock) = valve;\r
+ end FMURealTestModel;\r
+ \r
+ \r
+ The condition for valve is automatically generated in sysdyn. It is a hack for getting \r
+ valve to notice a change in i1 and i2. \r
+ \r
+ Results always contain "time" for each modelica class, hence result size is +1\r
+ */\r
+\r
+ @Test\r
+ public void testReturn3() {\r
+\r
+ FMUControlJNI control = new FMUControlJNI();\r
+\r
+ String path = ".\\Models\\FMUTests\\FMURealTest\\FMURealTestModel.fmu";\r
+\r
+\r
+ try {\r
+ \r
+ \r
+\r
+ control.loadFMUFile(path);\r
+\r
+ String[] bothRealParameters = control.filterVariables("r(.*)");\r
+ Assert.assertEquals("Filter \"r(.*)\" returned " + bothRealParameters.length + " results. Should have returned 3", bothRealParameters.length, 3);\r
+ List<String> result = Arrays.asList(bothRealParameters);\r
+ Assert.assertTrue("Result did not contain r1", result.contains("r1"));\r
+ Assert.assertTrue("Result did not contain r2", result.contains("r2"));\r
+ Assert.assertTrue("Result did not contain time", result.contains("time"));\r
+\r
+ control.unloadFMU();\r
+ } catch (FMUJNIException e) {\r
+ Assert.fail("Exception in native fmu code: " + e.getMessage());\r
+ }\r
+ }\r
+ \r
+ @Test\r
+ public void testReturn2() {\r
+\r
+ FMUControlJNI control = new FMUControlJNI();\r
+\r
+ String path = ".\\Models\\FMUTests\\FMURealTest\\FMURealTestModel.fmu";\r
+\r
+\r
+ try {\r
+\r
+ control.loadFMUFile(path);\r
+\r
+ String[] stock = control.filterVariables("stock");\r
+ Assert.assertEquals("Filter \"stock\" returned " + stock.length + " results. Should have returned 2", stock.length, 2);\r
+ List<String> result = Arrays.asList(stock);\r
+ Assert.assertTrue("Result did not contain stock", result.contains("stock"));\r
+ Assert.assertTrue("Result did not contain time", result.contains("time"));\r
+ \r
+ control.unloadFMU();\r
+ } catch (FMUJNIException e) {\r
+ Assert.fail("Exception in native fmu code: " + e.getMessage());\r
+ }\r
+ }\r
+ \r
+ @Test\r
+ public void testReturn1() {\r
+\r
+ FMUControlJNI control = new FMUControlJNI();\r
+\r
+ String path = ".\\Models\\FMUTests\\FMURealTest\\FMURealTestModel.fmu";\r
+\r
+\r
+ try {\r
+ control.loadFMUFile(path);\r
+ \r
+ String[] empty = control.filterVariables("empty");\r
+ Assert.assertEquals("Filter \"empty\" returned " + empty.length + " results. Should have returned 1", empty.length, 1);\r
+ \r
+ List<String> result = Arrays.asList(empty);\r
+ Assert.assertTrue("Result did not contain time", result.contains("time"));\r
+ \r
+ control.unloadFMU();\r
+ } catch (FMUJNIException e) {\r
+ Assert.fail("Exception in native fmu code: " + e.getMessage());\r
+ }\r
+ }\r
+ \r
+ @Test\r
+ public void testReturn1WhenNullFilter() {\r
+\r
+ FMUControlJNI control = new FMUControlJNI();\r
+\r
+ String path = ".\\Models\\FMUTests\\FMURealTest\\FMURealTestModel.fmu";\r
+\r
+\r
+ try {\r
+ control.loadFMUFile(path);\r
+ \r
+ String[] NULL = control.filterVariables(null);\r
+ Assert.assertEquals("Filter null returned " + NULL.length + " results. Should have returned 1", NULL.length, 1);\r
+ \r
+ List<String> result = Arrays.asList(NULL);\r
+ Assert.assertTrue("Result did not contain time", result.contains("time"));\r
+ \r
+ control.unloadFMU();\r
+ } catch (FMUJNIException e) {\r
+ Assert.fail("Exception in native fmu code: " + e.getMessage());\r
+ }\r
+ }\r
+ \r
+\r
+ \r
+\r
+}\r