diff --git a/Framework Project/POSIXSerialPortTests/POSIXSerialPortTests.m b/Framework Project/POSIXSerialPortTests/POSIXSerialPortTests.m index 87ec3bd..9f0d1fc 100644 --- a/Framework Project/POSIXSerialPortTests/POSIXSerialPortTests.m +++ b/Framework Project/POSIXSerialPortTests/POSIXSerialPortTests.m @@ -30,6 +30,7 @@ - (void)serialPortWasClosed:(POSIXSerialPort *)serialPort; @property (nullable,weak) XCTestExpectation *portOpen; @property (nullable,weak) XCTestExpectation *firstWrite; +@property (nullable,weak) XCTestExpectation *nextPacket; @property (nullable,weak) XCTestExpectation *readWriteTestComplete; @end @@ -40,6 +41,7 @@ - (void)serialPort:(POSIXSerialPort *)serialPort didReceiveData:(NSData *)data; , data ); if(self.readWriteTestComplete !=nil ) [self.readWriteTestComplete fulfill]; if(self.firstWrite !=nil ) [self.firstWrite fulfill]; + if(self.nextPacket !=nil ) [self.nextPacket fulfill]; } - (DataSegment)serialPort:(POSIXSerialPort *)serialPort nextDataSegmentValidIn:(NSData *)data; { @@ -110,20 +112,24 @@ - (void)test_writeRead { self.pDelegate.portOpen = [self expectationWithDescription:@"Port open"]; self.pDelegate.firstWrite = [self expectationWithDescription:@"Read incomplete packet"]; self.pDelegate.firstWrite.expectedFulfillmentCount = 1; + self.pDelegate.nextPacket = [self expectationWithDescription:@"Next complete packet"]; + self.pDelegate.nextPacket.expectedFulfillmentCount = 2; self.pDelegate.readWriteTestComplete = [self expectationWithDescription:@"Read complete"]; - self.pDelegate.readWriteTestComplete.expectedFulfillmentCount = 2; + self.pDelegate.readWriteTestComplete.expectedFulfillmentCount = 3; - NSData *sendData = [@"FEED BEEF" dataUsingEncoding:NSUTF8StringEncoding]; - [self.port open]; [self waitForExpectations:@[self.pDelegate.portOpen] timeout:5]; + NSData *sendData = [@"FEED BEEF" dataUsingEncoding:NSUTF8StringEncoding]; [self.port sendData:sendData]; [self waitForExpectations:@[self.pDelegate.firstWrite] timeout:10]; sendData = [@" " dataUsingEncoding:NSUTF8StringEncoding]; [self.port sendData:sendData]; - + [self waitForExpectations:@[self.pDelegate.nextPacket] timeout:15]; + + sendData = [@"EAAD " dataUsingEncoding:NSUTF8StringEncoding]; + [self.port sendData:sendData]; [self waitForExpectations:@[self.pDelegate.readWriteTestComplete] timeout:20]; [self.port close]; diff --git a/Source/POSIXSerialPort.m b/Source/POSIXSerialPort.m index de7fbdb..27a4432 100644 --- a/Source/POSIXSerialPort.m +++ b/Source/POSIXSerialPort.m @@ -414,6 +414,8 @@ - (void)processDataReceived; if(ds.offset != offset || ds.size != size) { self._data = dispatch_data_create_map(dispatch_data_create_subrange(region, offset+ds.size+(ds.offset-offset) , size - (ds.size + (ds.offset-offset))),nil,nil); + } else { + self._data = nil; // Release the data } }); });