Skip to content

Commit 8693d41

Browse files
committed
added unit test
1 parent 1214fef commit 8693d41

12 files changed

+939
-1
lines changed

ShimmerDriver/src/main/java/com/shimmerresearch/comms/wiredProtocol/ShimmerCrc.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class ShimmerCrc {
99
* @param b the byte to calculate the CRC on
1010
* @return the new CRC value
1111
*/
12-
protected static int shimmerUartCrcByte(int crc, byte b) {
12+
public static int shimmerUartCrcByte(int crc, byte b) {
1313
crc &= 0xFFFF;
1414
crc = ((crc & 0xFFFF) >>> 8) | ((crc & 0xFFFF) << 8);
1515
crc ^= (b&0xFF);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package com.shimmerresearch.shimmer3.communication;
2+
import org.junit.Before;
3+
import org.junit.BeforeClass;
4+
import org.junit.FixMethodOrder;
5+
import org.junit.Test;
6+
import org.junit.runners.MethodSorters;
7+
8+
import com.shimmerresearch.bluetooth.ShimmerBluetooth.BT_STATE;
9+
import com.shimmerresearch.driver.BasicProcessWithCallBack;
10+
import com.shimmerresearch.driver.CallbackObject;
11+
import com.shimmerresearch.driver.ObjectCluster;
12+
import com.shimmerresearch.driver.ShimmerMsg;
13+
import com.shimmerresearch.driver.Configuration.COMMUNICATION_TYPE;
14+
import com.shimmerresearch.driverUtilities.ChannelDetails;
15+
import com.shimmerresearch.driverUtilities.SensorDetails;
16+
import com.shimmerresearch.driverUtilities.ShimmerVerDetails.HW_ID;
17+
import com.shimmerresearch.exceptions.ShimmerException;
18+
import com.shimmerresearch.pcDriver.ShimmerPC;
19+
import com.shimmerresearch.sensors.AbstractSensor;
20+
import com.shimmerresearch.sensors.AbstractSensor.SENSORS;
21+
22+
import bolts.TaskCompletionSource;
23+
24+
import static org.junit.Assert.assertEquals;
25+
26+
import java.util.ArrayList;
27+
import java.util.LinkedHashMap;
28+
import java.util.concurrent.TimeUnit;
29+
@FixMethodOrder(MethodSorters.NAME_ASCENDING) // Test methods will be run in alphabetical order
30+
public class API_0000X_ByteCommunicationShimmer3_Streaming_Contiguous_Check extends BasicProcessWithCallBack{
31+
ShimmerPC mDevice;
32+
TaskCompletionSource<Boolean> mCalibrationTask;
33+
TaskCompletionSource<Boolean> mStreamingTask;
34+
ByteCommunicationSimulatorS3 mByteCommunicationSimulatorS3;
35+
36+
@Before
37+
public void setUp() {
38+
mByteCommunicationSimulatorS3 = new ByteCommunicationSimulatorS3_streaming_timestamp_contiguous_check("COM99");
39+
mDevice = new ShimmerPC("COM99");
40+
mDevice.setTestRadio(mByteCommunicationSimulatorS3);
41+
setWaitForData(mDevice);
42+
}
43+
44+
ArrayList<ObjectCluster> mListOJC;
45+
@Test
46+
public void test001_testStreaming() {
47+
mListOJC = new ArrayList<ObjectCluster>();
48+
mByteCommunicationSimulatorS3.setIsNewBMPSupported(false);
49+
mCalibrationTask = new TaskCompletionSource<Boolean>();
50+
mDevice.connect("","");
51+
52+
mCalibrationTask = new TaskCompletionSource<>();
53+
mStreamingTask = new TaskCompletionSource<Boolean>();
54+
try {
55+
boolean result = mCalibrationTask.getTask().waitForCompletion(5, TimeUnit.SECONDS);
56+
} catch (InterruptedException e) {
57+
// TODO Auto-generated catch block
58+
e.printStackTrace();
59+
}
60+
61+
try {
62+
mDevice.startStreaming();
63+
} catch (ShimmerException e) {
64+
// TODO Auto-generated catch block
65+
e.printStackTrace();
66+
}
67+
try {
68+
mStreamingTask.getTask().waitForCompletion(2, TimeUnit.SECONDS);
69+
if(mListOJC.size()!=2) {//only one is expected because only the first packet is followed which meets ShimmerBluetooth.processPacket requirements
70+
assert(false);
71+
}
72+
} catch (InterruptedException e) {
73+
// TODO Auto-generated catch block
74+
e.printStackTrace();
75+
}
76+
77+
78+
79+
}
80+
81+
82+
@Override
83+
protected void processMsgFromCallback(ShimmerMsg shimmerMSG) {
84+
// TODO Auto-generated method stub
85+
int ind = shimmerMSG.mIdentifier;
86+
87+
Object object = (Object) shimmerMSG.mB;
88+
89+
if (ind == ShimmerPC.MSG_IDENTIFIER_STATE_CHANGE) {
90+
if (ind == ShimmerPC.MSG_IDENTIFIER_STATE_CHANGE) {
91+
CallbackObject callbackObject = (CallbackObject)object;
92+
93+
if (callbackObject.mState == BT_STATE.CONNECTED) {
94+
if (mDevice.isInitialised()) {
95+
try {
96+
Thread.sleep(200);
97+
} catch (InterruptedException e) {
98+
// TODO Auto-generated catch block
99+
e.printStackTrace();
100+
}
101+
102+
}
103+
104+
}
105+
}
106+
} else if (ind == ShimmerPC.MSG_IDENTIFIER_DATA_PACKET) {
107+
System.out.println("Shimmer MSG_IDENTIFIER_DATA_PACKET");
108+
ObjectCluster objc = (ObjectCluster) shimmerMSG.mB;
109+
mListOJC.add(objc);
110+
}
111+
112+
}
113+
114+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
package com.shimmerresearch.shimmer3.communication;
2+
import org.junit.Before;
3+
import org.junit.BeforeClass;
4+
import org.junit.FixMethodOrder;
5+
import org.junit.Test;
6+
import org.junit.runners.MethodSorters;
7+
8+
import com.shimmerresearch.bluetooth.ShimmerBluetooth.BT_STATE;
9+
import com.shimmerresearch.driver.BasicProcessWithCallBack;
10+
import com.shimmerresearch.driver.CallbackObject;
11+
import com.shimmerresearch.driver.ObjectCluster;
12+
import com.shimmerresearch.driver.ShimmerMsg;
13+
import com.shimmerresearch.driver.ShimmerObject;
14+
import com.shimmerresearch.driver.Configuration.COMMUNICATION_TYPE;
15+
import com.shimmerresearch.driverUtilities.ChannelDetails;
16+
import com.shimmerresearch.driverUtilities.SensorDetails;
17+
import com.shimmerresearch.driverUtilities.ShimmerVerDetails.HW_ID;
18+
import com.shimmerresearch.exceptions.ShimmerException;
19+
import com.shimmerresearch.pcDriver.ShimmerPC;
20+
import com.shimmerresearch.sensors.AbstractSensor;
21+
import com.shimmerresearch.sensors.AbstractSensor.SENSORS;
22+
23+
import bolts.TaskCompletionSource;
24+
25+
import static org.junit.Assert.assertEquals;
26+
27+
import java.util.ArrayList;
28+
import java.util.LinkedHashMap;
29+
import java.util.concurrent.TimeUnit;
30+
@FixMethodOrder(MethodSorters.NAME_ASCENDING) // Test methods will be run in alphabetical order
31+
public class API_0000X_ByteCommunicationShimmer3_Streaming_Contiguous_Check_Fail extends BasicProcessWithCallBack{
32+
ShimmerPC mDevice;
33+
TaskCompletionSource<Boolean> mCalibrationTask;
34+
TaskCompletionSource<Boolean> mStreamingTask;
35+
ByteCommunicationSimulatorS3 mByteCommunicationSimulatorS3;
36+
public static int CONTIGUOUS_TIMESTAMP_TICKS_LIMIT = (10*32768);
37+
@Before
38+
public void setUp() {
39+
mByteCommunicationSimulatorS3 = new ByteCommunicationSimulatorS3_streaming_timestamp_contiguous_check_fail("COM99");
40+
mDevice = new ShimmerPC("COM99");
41+
mDevice.setTestRadio(mByteCommunicationSimulatorS3);
42+
setWaitForData(mDevice);
43+
}
44+
45+
ArrayList<ObjectCluster> mListOJC;
46+
@Test
47+
public void test001_testStreaming() {
48+
mListOJC = new ArrayList<ObjectCluster>();
49+
mByteCommunicationSimulatorS3.setIsNewBMPSupported(false);
50+
mCalibrationTask = new TaskCompletionSource<Boolean>();
51+
mDevice.connect("","");
52+
53+
mCalibrationTask = new TaskCompletionSource<>();
54+
mStreamingTask = new TaskCompletionSource<Boolean>();
55+
try {
56+
boolean result = mCalibrationTask.getTask().waitForCompletion(5, TimeUnit.SECONDS);
57+
} catch (InterruptedException e) {
58+
// TODO Auto-generated catch block
59+
e.printStackTrace();
60+
}
61+
62+
try {
63+
mDevice.startStreaming();
64+
System.out.println("Limit = " + CONTIGUOUS_TIMESTAMP_TICKS_LIMIT);
65+
} catch (ShimmerException e) {
66+
// TODO Auto-generated catch block
67+
e.printStackTrace();
68+
}
69+
try {
70+
mStreamingTask.getTask().waitForCompletion(2, TimeUnit.SECONDS);
71+
if(mListOJC.size()!=2) {//only one is expected because only the first packet is followed which meets ShimmerBluetooth.processPacket requirements
72+
assert(false);
73+
}
74+
} catch (InterruptedException e) {
75+
// TODO Auto-generated catch block
76+
e.printStackTrace();
77+
}
78+
79+
80+
81+
}
82+
83+
84+
@Override
85+
protected void processMsgFromCallback(ShimmerMsg shimmerMSG) {
86+
// TODO Auto-generated method stub
87+
int ind = shimmerMSG.mIdentifier;
88+
89+
Object object = (Object) shimmerMSG.mB;
90+
91+
if (ind == ShimmerPC.MSG_IDENTIFIER_STATE_CHANGE) {
92+
if (ind == ShimmerPC.MSG_IDENTIFIER_STATE_CHANGE) {
93+
CallbackObject callbackObject = (CallbackObject)object;
94+
95+
if (callbackObject.mState == BT_STATE.CONNECTED) {
96+
if (mDevice.isInitialised()) {
97+
try {
98+
Thread.sleep(200);
99+
} catch (InterruptedException e) {
100+
// TODO Auto-generated catch block
101+
e.printStackTrace();
102+
}
103+
104+
}
105+
106+
}
107+
}
108+
} else if (ind == ShimmerPC.MSG_IDENTIFIER_DATA_PACKET) {
109+
System.out.println("Shimmer MSG_IDENTIFIER_DATA_PACKET");
110+
ObjectCluster objc = (ObjectCluster) shimmerMSG.mB;
111+
mListOJC.add(objc);
112+
}
113+
114+
}
115+
116+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package com.shimmerresearch.shimmer3.communication;
2+
import org.junit.Before;
3+
import org.junit.BeforeClass;
4+
import org.junit.FixMethodOrder;
5+
import org.junit.Test;
6+
import org.junit.runners.MethodSorters;
7+
8+
import com.shimmerresearch.bluetooth.ShimmerBluetooth.BT_STATE;
9+
import com.shimmerresearch.driver.BasicProcessWithCallBack;
10+
import com.shimmerresearch.driver.CallbackObject;
11+
import com.shimmerresearch.driver.ObjectCluster;
12+
import com.shimmerresearch.driver.ShimmerMsg;
13+
import com.shimmerresearch.driver.Configuration.COMMUNICATION_TYPE;
14+
import com.shimmerresearch.driverUtilities.ChannelDetails;
15+
import com.shimmerresearch.driverUtilities.SensorDetails;
16+
import com.shimmerresearch.driverUtilities.ShimmerVerDetails.HW_ID;
17+
import com.shimmerresearch.exceptions.ShimmerException;
18+
import com.shimmerresearch.pcDriver.ShimmerPC;
19+
import com.shimmerresearch.sensors.AbstractSensor;
20+
import com.shimmerresearch.sensors.AbstractSensor.SENSORS;
21+
22+
import bolts.TaskCompletionSource;
23+
24+
import static org.junit.Assert.assertEquals;
25+
26+
import java.util.ArrayList;
27+
import java.util.LinkedHashMap;
28+
import java.util.concurrent.TimeUnit;
29+
@FixMethodOrder(MethodSorters.NAME_ASCENDING) // Test methods will be run in alphabetical order
30+
public class API_0000X_ByteCommunicationShimmer3_Streaming_Contiguous_Check_Overflow extends BasicProcessWithCallBack{
31+
ShimmerPC mDevice;
32+
TaskCompletionSource<Boolean> mCalibrationTask;
33+
TaskCompletionSource<Boolean> mStreamingTask;
34+
ByteCommunicationSimulatorS3 mByteCommunicationSimulatorS3;
35+
36+
@Before
37+
public void setUp() {
38+
mByteCommunicationSimulatorS3 = new ByteCommunicationSimulatorS3_streaming_timestamp_contiguous_check_overflow("COM99");
39+
mDevice = new ShimmerPC("COM99");
40+
mDevice.setTestRadio(mByteCommunicationSimulatorS3);
41+
setWaitForData(mDevice);
42+
}
43+
44+
ArrayList<ObjectCluster> mListOJC;
45+
@Test
46+
public void test001_testStreaming() {
47+
mListOJC = new ArrayList<ObjectCluster>();
48+
mByteCommunicationSimulatorS3.setIsNewBMPSupported(false);
49+
mCalibrationTask = new TaskCompletionSource<Boolean>();
50+
mDevice.connect("","");
51+
52+
mCalibrationTask = new TaskCompletionSource<>();
53+
mStreamingTask = new TaskCompletionSource<Boolean>();
54+
try {
55+
boolean result = mCalibrationTask.getTask().waitForCompletion(5, TimeUnit.SECONDS);
56+
} catch (InterruptedException e) {
57+
// TODO Auto-generated catch block
58+
e.printStackTrace();
59+
}
60+
61+
try {
62+
mDevice.startStreaming();
63+
} catch (ShimmerException e) {
64+
// TODO Auto-generated catch block
65+
e.printStackTrace();
66+
}
67+
try {
68+
mStreamingTask.getTask().waitForCompletion(2, TimeUnit.SECONDS);
69+
if(mListOJC.size()!=2) {//only one is expected because only the first packet is followed which meets ShimmerBluetooth.processPacket requirements
70+
assert(false);
71+
}
72+
} catch (InterruptedException e) {
73+
// TODO Auto-generated catch block
74+
e.printStackTrace();
75+
}
76+
77+
78+
79+
}
80+
81+
82+
@Override
83+
protected void processMsgFromCallback(ShimmerMsg shimmerMSG) {
84+
// TODO Auto-generated method stub
85+
int ind = shimmerMSG.mIdentifier;
86+
87+
Object object = (Object) shimmerMSG.mB;
88+
89+
if (ind == ShimmerPC.MSG_IDENTIFIER_STATE_CHANGE) {
90+
if (ind == ShimmerPC.MSG_IDENTIFIER_STATE_CHANGE) {
91+
CallbackObject callbackObject = (CallbackObject)object;
92+
93+
if (callbackObject.mState == BT_STATE.CONNECTED) {
94+
if (mDevice.isInitialised()) {
95+
try {
96+
Thread.sleep(200);
97+
} catch (InterruptedException e) {
98+
// TODO Auto-generated catch block
99+
e.printStackTrace();
100+
}
101+
102+
}
103+
104+
}
105+
}
106+
} else if (ind == ShimmerPC.MSG_IDENTIFIER_DATA_PACKET) {
107+
System.out.println("Shimmer MSG_IDENTIFIER_DATA_PACKET");
108+
ObjectCluster objc = (ObjectCluster) shimmerMSG.mB;
109+
mListOJC.add(objc);
110+
}
111+
112+
}
113+
114+
}

0 commit comments

Comments
 (0)