Phase 1
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
package haus.nightmare.lib3270j.ecl;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import haus.nightmare.lib3270j.TerminalModel;
|
||||
import haus.nightmare.lib3270j.charset.EbcdicTranslator;
|
||||
import haus.nightmare.lib3270j.input.InputProcessor;
|
||||
import haus.nightmare.lib3270j.screen.ScreenBuffer;
|
||||
import static haus.nightmare.lib3270j.protocol.DS3270Constants.*;
|
||||
|
||||
public class ECLFieldListTest {
|
||||
|
||||
private ScreenBuffer screen;
|
||||
private EbcdicTranslator translator;
|
||||
private InputProcessor input;
|
||||
private ECLPS ps;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
translator = new EbcdicTranslator();
|
||||
screen = new ScreenBuffer(TerminalModel.IBM_3278_2, translator);
|
||||
input = new InputProcessor(screen, translator, null);
|
||||
ps = new ECLPS(screen, input, translator);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldListDetection() {
|
||||
// Create 2 fields: pos 0 (unprotected, 9 chars), pos 10 (protected, 19 chars), pos 30 (high intensity)
|
||||
screen.setFieldAttribute(0, (byte) FA_PRINTABLE);
|
||||
screen.setFieldAttribute(10, (byte) (FA_PRINTABLE | FA_PROTECT));
|
||||
screen.setFieldAttribute(30, (byte) (FA_PRINTABLE | FA_INT_HIGH_SEL));
|
||||
|
||||
ECLFieldList list = ps.getFieldList();
|
||||
assertEquals(3, list.getFieldCount());
|
||||
|
||||
ECLField f1 = list.getFirstField();
|
||||
assertNotNull(f1);
|
||||
assertEquals(0, f1.getStart());
|
||||
assertEquals(1, f1.getDataStart());
|
||||
assertEquals(9, f1.getEnd());
|
||||
assertEquals(9, f1.getLength());
|
||||
assertFalse(f1.isProtected());
|
||||
|
||||
ECLField f2 = list.getNextField(f1);
|
||||
assertNotNull(f2);
|
||||
assertEquals(10, f2.getStart());
|
||||
assertEquals(11, f2.getDataStart());
|
||||
assertEquals(29, f2.getEnd());
|
||||
assertEquals(19, f2.getLength());
|
||||
assertTrue(f2.isProtected());
|
||||
|
||||
ECLField f3 = list.getNextField(f2);
|
||||
assertNotNull(f3);
|
||||
assertEquals(30, f3.getStart());
|
||||
assertTrue(f3.isHighIntensity());
|
||||
assertTrue(f3.isPenSelectable());
|
||||
|
||||
assertNull(list.getNextField(f3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindFieldByPositionAndRowCol() {
|
||||
screen.setFieldAttribute(0, (byte) FA_PRINTABLE);
|
||||
screen.setFieldAttribute(80, (byte) (FA_PRINTABLE | FA_PROTECT));
|
||||
|
||||
ECLFieldList list = ps.getFieldList();
|
||||
ECLField found1 = list.findField(40);
|
||||
assertNotNull(found1);
|
||||
assertEquals(0, found1.getStart());
|
||||
|
||||
ECLField found2 = list.findField(1, 10); // Row 1, Col 10 -> addr 90
|
||||
assertNotNull(found2);
|
||||
assertEquals(80, found2.getStart());
|
||||
assertTrue(found2.isProtected());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLightpenSelectionOnField() {
|
||||
screen.setFieldAttribute(0, (byte) (FA_PRINTABLE | FA_INT_HIGH_SEL));
|
||||
screen.setCell(1, translator.unicodeToEbcdic('?'));
|
||||
screen.setCell(2, translator.unicodeToEbcdic('O'));
|
||||
screen.setCell(3, translator.unicodeToEbcdic('K'));
|
||||
screen.setFieldAttribute(10, (byte) (FA_PRINTABLE | FA_PROTECT));
|
||||
screen.translateToUnicode();
|
||||
|
||||
ECLField field = ps.getFieldList().getFirstField();
|
||||
assertEquals('?', field.getSelectorPenType());
|
||||
|
||||
field.selectField();
|
||||
assertEquals('>', field.getSelectorPenType());
|
||||
|
||||
field.deSelectField();
|
||||
assertEquals('?', field.getSelectorPenType());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package haus.nightmare.lib3270j.ecl;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import haus.nightmare.lib3270j.TerminalModel;
|
||||
import haus.nightmare.lib3270j.charset.EbcdicTranslator;
|
||||
import haus.nightmare.lib3270j.input.InputProcessor;
|
||||
import haus.nightmare.lib3270j.screen.ScreenBuffer;
|
||||
import static haus.nightmare.lib3270j.ecl.ECLConstants.*;
|
||||
|
||||
public class ECLOIATest {
|
||||
|
||||
private ScreenBuffer screen;
|
||||
private EbcdicTranslator translator;
|
||||
private InputProcessor input;
|
||||
private ECLOIA oia;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
translator = new EbcdicTranslator();
|
||||
screen = new ScreenBuffer(TerminalModel.IBM_3278_2, translator);
|
||||
input = new InputProcessor(screen, translator, null);
|
||||
oia = new ECLOIA(screen, input, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInhibitStateTransitions() {
|
||||
assertEquals(INHIBIT_NOT_INHIBITED, oia.getInputInhibited());
|
||||
assertTrue(oia.waitForInput(100));
|
||||
|
||||
input.setKeyboardLocked(true);
|
||||
assertEquals(INHIBIT_SYSTEM_LOCK, oia.getInputInhibited());
|
||||
assertFalse(oia.waitForInput(50));
|
||||
|
||||
input.setKeyboardLocked(false);
|
||||
assertEquals(INHIBIT_NOT_INHIBITED, oia.getInputInhibited());
|
||||
assertTrue(oia.waitForInput(100));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOIAEventListener() {
|
||||
AtomicBoolean triggered = new AtomicBoolean(false);
|
||||
oia.registerOIAEvent(changedOia -> triggered.set(true));
|
||||
|
||||
input.setKeyboardLocked(true);
|
||||
assertTrue(triggered.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInsertModeState() {
|
||||
assertFalse(oia.isInsertMode());
|
||||
input.setInsertMode(true);
|
||||
assertTrue(oia.isInsertMode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package haus.nightmare.lib3270j.ecl;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import haus.nightmare.lib3270j.TerminalModel;
|
||||
import haus.nightmare.lib3270j.charset.EbcdicTranslator;
|
||||
import haus.nightmare.lib3270j.input.InputProcessor;
|
||||
import haus.nightmare.lib3270j.screen.ScreenBuffer;
|
||||
import haus.nightmare.lib3270j.telnet.TelnetFSM;
|
||||
import static haus.nightmare.lib3270j.protocol.DS3270Constants.*;
|
||||
|
||||
public class ECLPSTest implements ECLConstants {
|
||||
|
||||
private ScreenBuffer screen;
|
||||
private EbcdicTranslator translator;
|
||||
private InputProcessor input;
|
||||
private ECLPS ps;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
translator = new EbcdicTranslator();
|
||||
screen = new ScreenBuffer(TerminalModel.IBM_3278_2, translator);
|
||||
input = new InputProcessor(screen, translator, null);
|
||||
ps = new ECLPS(screen, input, translator);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeometry() {
|
||||
assertEquals(24, ps.getRows());
|
||||
assertEquals(80, ps.getCols());
|
||||
assertEquals(24 * 80, ps.getSize());
|
||||
assertEquals(0, ps.getCursorPos());
|
||||
|
||||
ps.setCursorPos(10, 20);
|
||||
assertEquals(10 * 80 + 20, ps.getCursorPos());
|
||||
assertEquals(10, ps.getCursorRow());
|
||||
assertEquals(20, ps.getCursorCol());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlaneTextExtractionAndSearch() {
|
||||
// Set some text in buffer
|
||||
screen.setCell(0, 0xC8); // 'H'
|
||||
screen.setCell(1, 0xC5); // 'E'
|
||||
screen.setCell(2, 0xD3); // 'L'
|
||||
screen.setCell(3, 0xD3); // 'L'
|
||||
screen.setCell(4, 0xD6); // 'O'
|
||||
screen.translateToUnicode();
|
||||
|
||||
assertEquals("HELLO", ps.getString(0, 5));
|
||||
|
||||
// Search string forward
|
||||
int pos = ps.searchString("ELL", 0, 0, SEARCH_FORWARD, false);
|
||||
assertEquals(1, pos);
|
||||
|
||||
// Search string case-insensitive
|
||||
int posLower = ps.searchString("hello", 0, 0, SEARCH_FORWARD, true);
|
||||
assertEquals(0, posLower);
|
||||
|
||||
// Search not found
|
||||
int notFound = ps.searchString("WORLD", 0, 0, SEARCH_FORWARD, false);
|
||||
assertEquals(-1, notFound);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiPlaneReading() {
|
||||
screen.setFieldAttribute(0, (byte) (FA_PRINTABLE | FA_PROTECT));
|
||||
screen.setCell(1, 0xC1); // 'A'
|
||||
screen.getCell(1).fg = COLOR_RED;
|
||||
screen.getCell(1).gr = (byte) HILITE_BLINK;
|
||||
|
||||
char[] textPlane = new char[2];
|
||||
char[] colorPlane = new char[2];
|
||||
char[] hilitePlane = new char[2];
|
||||
char[] fieldPlane = new char[2];
|
||||
|
||||
ps.getPlane(PLANE_TEXT, textPlane, 0, 2);
|
||||
ps.getPlane(PLANE_COLOR, colorPlane, 0, 2);
|
||||
ps.getPlane(PLANE_HILITE, hilitePlane, 0, 2);
|
||||
ps.getPlane(PLANE_FIELD, fieldPlane, 0, 2);
|
||||
|
||||
assertEquals(' ', textPlane[0]); // FA is space in text plane
|
||||
assertEquals('A', textPlane[1]);
|
||||
|
||||
assertEquals(0, colorPlane[0]);
|
||||
assertEquals(COLOR_RED, colorPlane[1]);
|
||||
|
||||
assertEquals(0, hilitePlane[0]);
|
||||
assertEquals((char) (HILITE_BLINK & 0xFF), hilitePlane[1]);
|
||||
|
||||
assertTrue((fieldPlane[0] & 0xFF) != 0);
|
||||
assertEquals(0, fieldPlane[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSendKeysMnemonics() {
|
||||
// Create an unprotected field at pos 0
|
||||
screen.setFieldAttribute(0, (byte) FA_PRINTABLE);
|
||||
screen.setCursorAddress(1);
|
||||
|
||||
ps.sendKeys("IBM[tab]");
|
||||
assertEquals('I', screen.getCell(1).ucs4);
|
||||
assertEquals('B', screen.getCell(2).ucs4);
|
||||
assertEquals('M', screen.getCell(3).ucs4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPasteLineWrap() {
|
||||
screen.setFieldAttribute(0, (byte) FA_PRINTABLE);
|
||||
screen.setCursorAddress(1);
|
||||
|
||||
int count = ps.pasteLineWrap("ABC\nDEF", 1, 80, false);
|
||||
assertEquals(6, count);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user