Skip to content

Commit

Permalink
Check return from NCP when setting channel (#1450)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Jackson <chris@cd-jackson.com>
  • Loading branch information
cdjackson authored Nov 24, 2024
1 parent a2129ad commit 5774fca
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1083,11 +1083,12 @@ public ZigBeeStatus setZigBeeChannel(ZigBeeChannel channel) {
}
if (networkStateUp) {
EmberNcp ncp = getEmberNcp();
ncp.setRadioChannel(channel);
return ncp.setRadioChannel(channel) == EmberStatus.EMBER_SUCCESS ? ZigBeeStatus.SUCCESS
: ZigBeeStatus.BAD_RESPONSE;
} else {
networkParameters.setRadioChannel(channel.getChannel());
return ZigBeeStatus.SUCCESS;
}
return ZigBeeStatus.SUCCESS;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,18 @@ public EmberNcp getEmberNcp() {
}

@Test
public void setZigBeeChannel() {
public void setZigBeeChannelOk() {
System.out.println("--- " + Thread.currentThread().getStackTrace()[1].getMethodName());
ZigBeeDongleEzsp dongle = new ZigBeeDongleEzsp(null);

assertEquals(ZigBeeStatus.INVALID_ARGUMENTS, dongle.setZigBeeChannel(ZigBeeChannel.CHANNEL_03));
final EmberNcp ncp = Mockito.mock(EmberNcp.class);
ZigBeeDongleEzsp dongle = new ZigBeeDongleEzsp(null) {
@Override
public EmberNcp getEmberNcp() {
return ncp;
}
};

Mockito.when(ncp.setRadioChannel(ArgumentMatchers.any())).thenReturn(EmberStatus.EMBER_SUCCESS);

assertEquals(ZigBeeStatus.SUCCESS, dongle.setZigBeeChannel(ZigBeeChannel.CHANNEL_11));
assertEquals(ZigBeeChannel.CHANNEL_11, dongle.getZigBeeChannel());
Expand All @@ -428,13 +435,31 @@ public void setZigBeeChannel() {
assertEquals(ZigBeeChannel.CHANNEL_24, dongle.getZigBeeChannel());
}

@Test
public void setZigBeeChannelError() throws Exception {
System.out.println("--- " + Thread.currentThread().getStackTrace()[1].getMethodName());

final EmberNcp ncp = Mockito.mock(EmberNcp.class);
ZigBeeDongleEzsp dongle = new ZigBeeDongleEzsp(null) {
@Override
public EmberNcp getEmberNcp() {
return ncp;
}
};

TestUtilities.setField(ZigBeeDongleEzsp.class, dongle, "networkStateUp", true);

Mockito.when(ncp.setRadioChannel(ArgumentMatchers.any())).thenReturn(EmberStatus.UNKNOWN);

assertEquals(ZigBeeStatus.INVALID_ARGUMENTS, dongle.setZigBeeChannel(ZigBeeChannel.CHANNEL_03));
assertEquals(ZigBeeStatus.BAD_RESPONSE, dongle.setZigBeeChannel(ZigBeeChannel.CHANNEL_24));
}

@Test
public void testEzspMessageSentHandler() throws Exception {
System.out.println("--- " + Thread.currentThread().getStackTrace()[1].getMethodName());
ZigBeeTransportReceive transport = Mockito.mock(ZigBeeTransportReceive.class);

final EmberNcp ncp = Mockito.mock(EmberNcp.class);
Mockito.when(ncp.getNwkAddress()).thenReturn(1243);
ZigBeeDongleEzsp dongle = new ZigBeeDongleEzsp(null);
dongle.setZigBeeTransportReceive(transport);

Expand Down

0 comments on commit 5774fca

Please sign in to comment.