From 990b9e345cb9e04e742f5b679d2ecc139d029e6e Mon Sep 17 00:00:00 2001 From: Graham Jones Date: Sun, 23 Jan 2022 06:29:43 +0000 Subject: [PATCH] Setting up test framework for logmanager - does not do anything useful yet! --- .../openseizuredetector/LogManagerTest.java | 101 +++++++++++++ .../openseizuredetector/MainActivityTest.java | 46 ------ .../openseizuredetector/SdAnalyserTest.java | 143 ------------------ .../SdDataSourceNetworkTest.java | 36 ----- .../SdDataSourcePebbleTest.java | 51 ------- .../org/openseizuredetector/SdDataTest.java | 45 ++++++ .../org/openseizuredetector/SdServerTest.java | 141 ----------------- .../SdServiceConnectionTest.java | 41 ----- 8 files changed, 146 insertions(+), 458 deletions(-) create mode 100644 app/src/test/java/uk/org/openseizuredetector/LogManagerTest.java delete mode 100644 app/src/test/java/uk/org/openseizuredetector/MainActivityTest.java delete mode 100644 app/src/test/java/uk/org/openseizuredetector/SdAnalyserTest.java delete mode 100644 app/src/test/java/uk/org/openseizuredetector/SdDataSourceNetworkTest.java delete mode 100644 app/src/test/java/uk/org/openseizuredetector/SdDataSourcePebbleTest.java create mode 100644 app/src/test/java/uk/org/openseizuredetector/SdDataTest.java delete mode 100644 app/src/test/java/uk/org/openseizuredetector/SdServerTest.java delete mode 100644 app/src/test/java/uk/org/openseizuredetector/SdServiceConnectionTest.java diff --git a/app/src/test/java/uk/org/openseizuredetector/LogManagerTest.java b/app/src/test/java/uk/org/openseizuredetector/LogManagerTest.java new file mode 100644 index 0000000..764585a --- /dev/null +++ b/app/src/test/java/uk/org/openseizuredetector/LogManagerTest.java @@ -0,0 +1,101 @@ +package uk.org.openseizuredetector; + +import android.os.Build; + +import junit.framework.TestCase; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.RuntimeEnvironment; +import org.robolectric.annotation.Config; + +import java.util.TimeZone; + +@RunWith(RobolectricTestRunner.class) +@Config(sdk = {Build.VERSION_CODES.O_MR1}, packageName = "uk.org.openseizuredetector") +public class LogManagerTest extends TestCase { + LogManager mLm; + public void setUp() throws Exception { + super.setUp(); + TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles")); + mLm = new LogManager(RuntimeEnvironment.systemContext); + } + + public void tearDown() throws Exception { + mLm.close(); + } + + SdData getFakeSdData() { + SdData sdData = new SdData(); + return sdData; + } + + + @Test + public void testWriteToLocalDb() { + SdData sd1 = getFakeSdData(); + mLm.writeToLocalDb(sd1); + assertTrue(true); + } + + public void testGetDatapointById() { + } + + public void testSetDatapointToUploaded() { + } + + public void testSetDatapointStatus() { + } + + public void testGetDatapointsByDate() { + } + + public void testGetEventsList() { + } + + public void testPruneLocalDb() { + } + + public void testGetNextEventToUpload() { + } + + public void testGetNearestDatapointToDate() { + } + + public void testGetLocalEventsCount() { + } + + public void testGetLocalDatapointsCount() { + } + + public void testWriteToRemoteServer() { + } + + public void testUploadSdData() { + } + + public void testAuthCallback() { + } + + public void testFinishUpload() { + } + + public void testEventCallback() { + } + + public void testUploadNextDatapoint() { + } + + public void testDatapointCallback() { + } + + public void testClose() { + } + + public void testStopRemoteLogTimer() { + } + + public void testStopAutoPruneTimer() { + } +} \ No newline at end of file diff --git a/app/src/test/java/uk/org/openseizuredetector/MainActivityTest.java b/app/src/test/java/uk/org/openseizuredetector/MainActivityTest.java deleted file mode 100644 index 6d0c854..0000000 --- a/app/src/test/java/uk/org/openseizuredetector/MainActivityTest.java +++ /dev/null @@ -1,46 +0,0 @@ -package uk.org.openseizuredetector; - -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Created by graham on 01/01/16. - */ -public class MainActivityTest { - - @Test - public void testOnCreate() throws Exception { - - } - - @Test - public void testOnCreateOptionsMenu() throws Exception { - - } - - @Test - public void testOnOptionsItemSelected() throws Exception { - - } - - @Test - public void testOnStart() throws Exception { - - } - - @Test - public void testOnStop() throws Exception { - - } - - @Test - public void testOnPause() throws Exception { - - } - - @Test - public void testOnResume() throws Exception { - - } -} \ No newline at end of file diff --git a/app/src/test/java/uk/org/openseizuredetector/SdAnalyserTest.java b/app/src/test/java/uk/org/openseizuredetector/SdAnalyserTest.java deleted file mode 100644 index a6cfb8c..0000000 --- a/app/src/test/java/uk/org/openseizuredetector/SdAnalyserTest.java +++ /dev/null @@ -1,143 +0,0 @@ -package uk.org.openseizuredetector; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.robolectric.RobolectricTestRunner; - -import static org.junit.Assert.*; - -@RunWith(RobolectricTestRunner.class) -public class SdAnalyserTest { - public SdAnalyser sda; - - public String alarmJSON = "{ 'dataType': 'raw', " + - "'data': [" + - "1644, 1316, 1144, 1332, 1716, 1716, 1392, 1148, 1276, 1660, " + - "1716, 1496, 1196, 1232, 1572, 1684, 1552, 1236, 1228, 1528, " + - "1648, 1572, 1268, 1208, 1492, 1680, 1596, 1272, 1192, 1424, " + - "1668, 1636, 1300, 1200, 1356, 1652, 1684, 1420, 1208, 1304, " + - "1620, 1672, 1448, 1232, 1248, 1536, 1676, 1540, 1256, 1244, " + - "1544, 1644, 1512, 1252, 1236, 1504, 1684, 1540, 1252, 1200, " + - "1436, 1664, 1624, 1344, 1204, 1396, 1616, 1596, 1344, 1216, " + - "1368, 1648, 1660, 1388, 1220, 1316, 1588, 1672, 1460, 1232, " + - "1256, 1580, 1672, 1500, 1256, 1288, 1540, 1688, 1516, 1252, " + - "1212, 1464, 1684, 1584, 1288, 1224, 1468, 1692, 1616, 1316, " + - "1188, 1360, 1680, 1724, 1424, 1192, 1224, 1556, 1744, 1588, " + - "1260, 1220, 1472, 1692, 1608, 1328, 1192, 1412, 1668, 1656, " + - "1356, 1216, 1304, 1636, 1712], " + - "'HR':54, " + - "'Mute':0 " + - "}"; - - private String okJSON = "{ " + - "\"dataType\": \"raw\", " + - "\"data\": [" + - "1140, 1188, 1144, 1172, 1228, 1212, 1236, 1236, 1256, 1320, " + - "1316, 1280, 1240, 1280, 1324, 1284, 1292, 1268, 1284, 1276, " + - "1296, 1324, 1308, 1288, 1304, 1276, 1304, 1304, 1276, 1296, " + - "1280, 1284, 1296, 1300, 1284, 1288, 1296, 1284, 1300, 1280, " + - "1300, 1292, 1276, 1304, 1276, 1316, 1280, 1288, 1296, 1280, " + - "1284, 1272, 1300, 1284, 1288, 1292, 1276, 1296, 1276, 1292, " + - "1280, 1284, 1284, 1284, 1284, 1284, 1288, 1284, 1304, 1284, " + - "1288, 1280, 1296, 1284, 1292, 1296, 1280, 1276, 1288, 1296, " + - "1276, 1292, 1288, 1276, 1288, 1276, 1272, 1272, 1292, 1284, " + - "1292, 1288, 1280, 1284, 1284, 1268, 1288, 1268, 1276, 1300, " + - "1268, 1292, 1292, 1304, 1288, 1284, 1280, 1276, 1288, 1280, " + - "1300, 1288, 1320, 1268, 1288, 1280, 1304, 1280, 1280, 1288, " + - "1292, 1308, 1268, 1292, 1280], " + - "\"HR\":57, " + - "\"Mute\":0 " + - "}"; - - @Before - public void setUp() throws Exception { - sda = new SdAnalyser(25.0, - 3.0, - 8.0, - 5.0, - 5.0, - 100.0, - 54.0 - ); - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testFreq2fftBin() { - int n; - n = sda.freq2fftBin(0.0); - assertEquals(0,n); - n = sda.freq2fftBin(5.0); - assertEquals(25,n); - } - - @Test - public void testGetMagnitude() { - double[] fft = {1, 1, - 2, 1, - 2, 2}; - double m; - m = sda.getMagnitude(fft,0); - assertEquals(2.0, m, m * 1e-4); - m = sda.getMagnitude(fft,1); - assertEquals(5.0, m, m * 1e-4); - m = sda.getMagnitude(fft,2); - assertEquals(8.0, m, m * 1e-4); - } - - @Test - public void testGetAccelDataFromJson() { - double[] retVal; - - retVal = sda.getAccelDataFromJSON(okJSON); - assertNotNull(retVal); - assertEquals(125,retVal.length); - assertEquals(1140,retVal[0],0.001); - assertEquals(1280,retVal[124],0.001); - } - - - @Test - public void testGetSpectrumRatio() { - double[] okRawVals; - double[] alarmRawVals; - okRawVals = sda.getAccelDataFromJSON(okJSON); - alarmRawVals = sda.getAccelDataFromJSON(alarmJSON); - - double okRatio; - double alarmRatio; - - okRatio = sda.getSpectrumRatio(okRawVals); - alarmRatio = sda.getSpectrumRatio(alarmRawVals); - - assertTrue("Check Spectrum Ratio for OK data "+okRatio+" is <="+sda.mAlarmRatioThresh, - okRatio <= sda.mAlarmRatioThresh); - assertTrue("Check Spectrum Ratio for ALARM data "+alarmRatio+" is >"+sda.mAlarmRatioThresh, - alarmRatio > sda.mAlarmRatioThresh); - - } - - - @Test - public void testgetAlarmState() { - double[] okRawVals; - double[] alarmRawVals; - okRawVals = sda.getAccelDataFromJSON(okJSON); - alarmRawVals = sda.getAccelDataFromJSON(alarmJSON); - - int okAlarmState; - int alarmAlarmState; - - okAlarmState = sda.getAlarmState(okRawVals); - alarmAlarmState = sda.getAlarmState(alarmRawVals); - - assertEquals("check OK start detected from raw data",0, okAlarmState); - assertEquals("check alarm state detected from raw data",1, alarmAlarmState); - } - -} \ No newline at end of file diff --git a/app/src/test/java/uk/org/openseizuredetector/SdDataSourceNetworkTest.java b/app/src/test/java/uk/org/openseizuredetector/SdDataSourceNetworkTest.java deleted file mode 100644 index ab7c8b6..0000000 --- a/app/src/test/java/uk/org/openseizuredetector/SdDataSourceNetworkTest.java +++ /dev/null @@ -1,36 +0,0 @@ -package uk.org.openseizuredetector; - -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Created by graham on 01/01/16. - */ -public class SdDataSourceNetworkTest { - - @Test - public void testStart() throws Exception { - - } - - @Test - public void testStop() throws Exception { - - } - - @Test - public void testUpdatePrefs() throws Exception { - - } - - @Test - public void testDownloadSdData() throws Exception { - - } - - @Test - public void testReadInputStream() throws Exception { - - } -} \ No newline at end of file diff --git a/app/src/test/java/uk/org/openseizuredetector/SdDataSourcePebbleTest.java b/app/src/test/java/uk/org/openseizuredetector/SdDataSourcePebbleTest.java deleted file mode 100644 index e7e5f7f..0000000 --- a/app/src/test/java/uk/org/openseizuredetector/SdDataSourcePebbleTest.java +++ /dev/null @@ -1,51 +0,0 @@ -package uk.org.openseizuredetector; - -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Created by graham on 01/01/16. - */ -public class SdDataSourcePebbleTest { - - @Test - public void testStart() throws Exception { - - } - - @Test - public void testStop() throws Exception { - - } - - @Test - public void testUpdatePrefs() throws Exception { - - } - - @Test - public void testStopPebbleServer() throws Exception { - - } - - @Test - public void testStartWatchApp() throws Exception { - - } - - @Test - public void testStopWatchApp() throws Exception { - - } - - @Test - public void testGetPebbleSdSettings() throws Exception { - - } - - @Test - public void testGetPebbleStatus() throws Exception { - - } -} \ No newline at end of file diff --git a/app/src/test/java/uk/org/openseizuredetector/SdDataTest.java b/app/src/test/java/uk/org/openseizuredetector/SdDataTest.java new file mode 100644 index 0000000..1eb5521 --- /dev/null +++ b/app/src/test/java/uk/org/openseizuredetector/SdDataTest.java @@ -0,0 +1,45 @@ +package uk.org.openseizuredetector; + +import android.os.Build; + +import junit.framework.TestCase; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; + +import java.util.TimeZone; + +@RunWith(RobolectricTestRunner.class) +@Config(sdk = {Build.VERSION_CODES.O_MR1}, packageName = "uk.org.openseizuredetector") +public class SdDataTest extends TestCase { + public void setUp() throws Exception { + super.setUp(); + } + + public void tearDown() throws Exception { + } + + @Test + public void testConstructor() { + SdData sd = new SdData(); + assertTrue(true); + + } + + public void testFromJSON() { + } + + public void testTestToString() { + } + + public void testToJSON() { + } + + public void testToDataString() { + } + + public void testToCSVString() { + } +} \ No newline at end of file diff --git a/app/src/test/java/uk/org/openseizuredetector/SdServerTest.java b/app/src/test/java/uk/org/openseizuredetector/SdServerTest.java deleted file mode 100644 index 890f286..0000000 --- a/app/src/test/java/uk/org/openseizuredetector/SdServerTest.java +++ /dev/null @@ -1,141 +0,0 @@ -package uk.org.openseizuredetector; - -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Created by graham on 01/01/16. - */ -public class SdServerTest { - - @Test - public void testOnBind() throws Exception { - - } - - @Test - public void testOnCreate() throws Exception { - - } - - @Test - public void testOnStartCommand() throws Exception { - - } - - @Test - public void testOnDestroy() throws Exception { - - } - - @Test - public void testOnSdDataReceived() throws Exception { - - } - - @Test - public void testOnSdDataFault() throws Exception { - - } - - @Test - public void testFaultWarningBeep() throws Exception { - - } - - @Test - public void testAlarmBeep() throws Exception { - - } - - @Test - public void testWarningBeep() throws Exception { - - } - - @Test - public void testSendSMSAlarm() throws Exception { - - } - - @Test - public void testAcceptAlarm() throws Exception { - - } - - @Test - public void testCancelAudible() throws Exception { - - } - - @Test - public void testIsAudibleCancelled() throws Exception { - - } - - @Test - public void testCancelAudibleTimeRemaining() throws Exception { - - } - - @Test - public void testIsLatchAlarms() throws Exception { - - } - - @Test - public void testStartWebServer() throws Exception { - - } - - @Test - public void testStopWebServer() throws Exception { - - } - - @Test - public void testLogData() throws Exception { - - } - - @Test - public void testUpdatePrefs() throws Exception { - - } - - @Test - public void testIsExternalStorageWritable() throws Exception { - - } - - @Test - public void testGetDataStorageDir() throws Exception { - - } - - @Test - public void testWriteAlarmToSD() throws Exception { - - } - - @Test - public void testWriteToSD() throws Exception { - - } - - @Test - public void testWriteToSD1() throws Exception { - - } - - @Test - public void testStartFaultTimer() throws Exception { - - } - - @Test - public void testStopFaultTimer() throws Exception { - - } -} \ No newline at end of file diff --git a/app/src/test/java/uk/org/openseizuredetector/SdServiceConnectionTest.java b/app/src/test/java/uk/org/openseizuredetector/SdServiceConnectionTest.java deleted file mode 100644 index 0e50e3b..0000000 --- a/app/src/test/java/uk/org/openseizuredetector/SdServiceConnectionTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package uk.org.openseizuredetector; - -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Created by graham on 01/01/16. - */ -public class SdServiceConnectionTest { - - @Test - public void testOnServiceConnected() throws Exception { - - } - - @Test - public void testOnServiceDisconnected() throws Exception { - - } - - @Test - public void testHasSdData() throws Exception { - - } - - @Test - public void testHasSdSettings() throws Exception { - - } - - @Test - public void testPebbleConnected() throws Exception { - - } - - @Test - public void testPebbleAppRunning() throws Exception { - - } -} \ No newline at end of file