package promauto.jroboplc.roboplant;
import static org.junit.Assert.*;
import org.junit.Test;
import promauto.jroboplc.JRoboUtils;
import promauto.jroboplc.Module;
import promauto.jroboplc.Tag;
import promauto.jroboplc.roboplant.RoboplantAddressConvertor;
import promauto.jroboplc.roboplant.RoboplantChannel;
public class RoboplantChannelTest {
@Test
public void testCheckChannel() {
System.out.println("\n\n\n===== RoboplantChannelTest");
RoboplantAddressConvertor.add(1, "mod1", "Input%02d", true);
RoboplantAddressConvertor.add(1, "mod2", "Output%02d", false);
RoboplantAddressConvertor.add(2, "mod3", "Input%02d", true);
Module m1 = new Module();
m1.moduleName = "mod1";
Module m2 = new Module();
m2.moduleName = "mod2";
Module m3 = new Module();
m3.moduleName = "mod3";
Module m4 = new Module();
m4.moduleName = "mod4";
try {
JRoboUtils.clearModules();
JRoboUtils.addModules(m1);
JRoboUtils.addModules(m2);
JRoboUtils.addModules(m3);
JRoboUtils.addModules(m4);
} catch (Exception e) {
}
Tag t1 = m1.tagTable.createTag("mytag1", 11);
Tag t2 = m1.tagTable.createTag("mytag2", 22);
Tag t3 = m2.tagTable.createTag("Output00", 33);
Tag t4 = m2.tagTable.createTag("Output01", 44);
Tag t5 = m3.tagTable.createTag("Input10", 55);
Tag t6 = m3.tagTable.createTag("Input11", 66);
Tag t7 = m4.tagTable.createTag("Input20", 77);
Tag t8 = m4.tagTable.createTag("Input21", 88);
RoboplantChannel channel1 = new RoboplantChannel();
channel1.createTags(m1, "mychannel");
// link to t3
channel1.tagChannel.set(0x0100);
assertTrue( channel1.checkChannel(false) );
assertTrue( channel1.changed );
assertEquals( channel1.tagName.getString(), "mod2@Output00" );
assertEquals( channel1.get(), t3.getInteger() );
t3.set( 133 );
assertEquals( channel1.get(), t3.getInteger() );
channel1.set( 233 );
assertEquals( channel1.get(), t3.getInteger() );
assertTrue( channel1.checkChannel(false) );
assertFalse( channel1.changed );
assertEquals( channel1.tagName.getString(), "mod2@Output00" );
assertEquals( channel1.get(), t3.getInteger() );
// link to t5
channel1.setName("mod3@Input10");
assertTrue( channel1.checkChannel(true) );
assertTrue( channel1.changed );
assertEquals(channel1.tagChannel.getInteger(), new Integer(0x020A));
assertEquals( channel1.tagName.getString(), "mod3@Input10" );
assertEquals( channel1.get(), t5.getInteger() );
assertTrue( channel1.checkChannel(true) );
assertFalse( channel1.changed );
// link to unknown
channel1.setName("mod777@Input10");
assertFalse( channel1.checkChannel(true) );
assertTrue( channel1.changed );
assertFalse( channel1.checkChannel(true) );
assertFalse( channel1.changed );
assertFalse( channel1.checkChannel(true) );
assertFalse( channel1.changed );
// link to t8 (none roboplant tag)
channel1.setName("mod4@Input21");
assertTrue( channel1.checkChannel(true) );
assertTrue( channel1.changed );
assertTrue( channel1.checkChannel(true) );
assertFalse( channel1.changed );
assertTrue( channel1.checkChannel(true) );
assertFalse( channel1.changed );
t8.set( 1884 );
assertEquals( channel1.get(), t8.getInteger() );
channel1.set( 2997 );
assertEquals( channel1.get(), t8.getInteger() );
}
}