[zb4osgi-changeset] [scm] ZigBee 4 OSGi repository change: r1088 - in /projects/zb4osgi/trunk/zigbee.basedriver/src: main/java/it/cnr/isti/zigbee/basedriver/api/impl/ZigBeeNodeImpl.java test/java/it/cnr/isti/zigbee/basedriver/api/impl/ZigBeeNodeImplTest.java

scm-notify at zb4osgi.aaloa.org scm-notify at zb4osgi.aaloa.org
Wed Nov 5 18:55:37 CET 2014


Author: stefano.lenzi
Date: Wed Nov  5 18:55:37 2014
New Revision: 1088

Log:
Added JUnit for testing the issue ( refs #271 )
Fixed the behavior on some constructor ( refs #271 )


Added:
    projects/zb4osgi/trunk/zigbee.basedriver/src/test/java/it/cnr/isti/zigbee/basedriver/api/impl/ZigBeeNodeImplTest.java   (with props)
Modified:
    projects/zb4osgi/trunk/zigbee.basedriver/src/main/java/it/cnr/isti/zigbee/basedriver/api/impl/ZigBeeNodeImpl.java

Modified: projects/zb4osgi/trunk/zigbee.basedriver/src/main/java/it/cnr/isti/zigbee/basedriver/api/impl/ZigBeeNodeImpl.java
==============================================================================
--- projects/zb4osgi/trunk/zigbee.basedriver/src/main/java/it/cnr/isti/zigbee/basedriver/api/impl/ZigBeeNodeImpl.java	(original)
+++ projects/zb4osgi/trunk/zigbee.basedriver/src/main/java/it/cnr/isti/zigbee/basedriver/api/impl/ZigBeeNodeImpl.java	Wed Nov  5 18:55:37 2014
@@ -59,14 +59,13 @@
      * @since 0.6.0 - Revision 67
      */
     public ZigBeeNodeImpl(int nwk, String ieee, short pan) {
-        this.nwkAddress = nwk;
+        description = new Properties();
+        setNetworkAddress(nwk);
         this.ieeeAddress = ieee;
         IEEEAddress.fromColonNotation(ieee); // Only for checking the IEEE
                                                 // format
 
-        description = new Properties();
         description.put(ZigBeeNode.IEEE_ADDRESS, ieee);
-        description.put(ZigBeeNode.NWK_ADDRESS, nwk);
         description.put(ZigBeeNode.PAN_ID, pan & 0xFFFF);
     }
 
@@ -90,7 +89,7 @@
         if ( nwk < 0 ) {
         	logger.debug("Recieved a negative Network Address, but we are normalizing it as positive value");
         }
-        setNetworkAddress(nwk & 0xFFFF);
+        setNetworkAddress(nwk);
     }
 
     public Dictionary getDescription() {
@@ -109,7 +108,7 @@
      * @since 0.6.0 - Revision 74
      */
     public void setNetworkAddress(int nwk) {
-        nwkAddress = nwk;
+        nwkAddress = nwk & 0xFFFF;
         description.put(ZigBeeNode.NWK_ADDRESS, nwk);
     }
 

Added: projects/zb4osgi/trunk/zigbee.basedriver/src/test/java/it/cnr/isti/zigbee/basedriver/api/impl/ZigBeeNodeImplTest.java
==============================================================================
--- projects/zb4osgi/trunk/zigbee.basedriver/src/test/java/it/cnr/isti/zigbee/basedriver/api/impl/ZigBeeNodeImplTest.java	(added)
+++ projects/zb4osgi/trunk/zigbee.basedriver/src/test/java/it/cnr/isti/zigbee/basedriver/api/impl/ZigBeeNodeImplTest.java	Wed Nov  5 18:55:37 2014
@@ -0,0 +1,71 @@
+package it.cnr.isti.zigbee.basedriver.api.impl;
+
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.junit.Assert.*;
+import it.cnr.isti.zigbee.basedriver.Activator;
+import it.cnr.isti.zigbee.basedriver.configuration.ConfigurationService;
+import it.cnr.isti.zigbee.dongle.api.DuplicateMacPolicy;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+
+import com.itaca.ztool.api.ZToolAddress64;
+
+public class ZigBeeNodeImplTest {
+
+    private ConfigurationService cs = null;
+    private BundleContext bc = null;
+
+    private BundleContext stub;
+
+    @Before
+    public void createActivatorStub() {
+        cs = createConfigurationServiceStub();
+        bc = createBundleContextStub();
+        Activator.setStubObjectes(cs, bc);
+    }
+
+    public BundleContext createBundleContextStub() {
+        stub = createMock(BundleContext.class);
+        return stub;
+    }
+
+    public ConfigurationService createConfigurationServiceStub() {
+        ConfigurationService stub = createMock(ConfigurationService.class);
+        expect(stub.getPanId()).andReturn(new Short((short) 13531)).anyTimes();
+
+        replay(stub);
+
+        return stub;
+    }
+    
+    /**
+     * This test verify that any negative value assigned as network address is translated 
+     * to complement-to-2 positive value, so that we avoid signing issues due to implicit
+     * casts of Java. For example: -25 is translated to 65511
+     * 
+     * @see redmine issue #271
+     */
+	@Test
+	public void testZigBeeNodeImplIntStringShort() {
+		ZigBeeNodeImpl node =  null;
+		final int NEGATIVE_NWK_ADDR = -25;
+		final int NORMALIZED_NWK_ADDR = NEGATIVE_NWK_ADDR & 0xFFFF;
+		final int EXPECTED_NWK_ADDR = 65511;
+		assertEquals("Normalized value matches", NORMALIZED_NWK_ADDR, EXPECTED_NWK_ADDR);
+		node = new ZigBeeNodeImpl(NEGATIVE_NWK_ADDR, "01:02:03:04:05:06", (short) 40);
+		assertEquals("Checking negative network address", EXPECTED_NWK_ADDR, node.getNetworkAddress() );
+		node = new ZigBeeNodeImpl(NEGATIVE_NWK_ADDR, "01:02:03:04:05:06");
+		assertEquals("Checking negative network address", EXPECTED_NWK_ADDR, node.getNetworkAddress() );
+		node = new ZigBeeNodeImpl(NEGATIVE_NWK_ADDR, new ZToolAddress64(0x010203040506L) );
+		assertEquals("Checking negative network address", EXPECTED_NWK_ADDR, node.getNetworkAddress() );
+		node.setNetworkAddress(NEGATIVE_NWK_ADDR);
+		assertEquals("Checking negative network address", EXPECTED_NWK_ADDR, node.getNetworkAddress() );
+	}
+
+}

Propchange: projects/zb4osgi/trunk/zigbee.basedriver/src/test/java/it/cnr/isti/zigbee/basedriver/api/impl/ZigBeeNodeImplTest.java
------------------------------------------------------------------------------
    svn:executable = *




More information about the Commit mailing list