This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package haus.nightmare.lib3270j.printer;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class PD3270Test {
|
||||
|
||||
private PD3270 pd;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
pd = new PD3270();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMemoryCaptureAndPageCount() {
|
||||
assertTrue(pd.openPrinter(null));
|
||||
assertTrue(pd.isOpen());
|
||||
|
||||
pd.writePrintLine("Line 1");
|
||||
pd.writePrintLine("Line 2");
|
||||
pd.formFeed();
|
||||
|
||||
assertEquals(1, pd.getPageCount());
|
||||
assertTrue(pd.getByteCount() > 0);
|
||||
|
||||
String text = pd.getCapturedText();
|
||||
assertTrue(text.contains("Line 1"));
|
||||
assertTrue(text.contains("Line 2"));
|
||||
assertTrue(text.contains("\f"));
|
||||
|
||||
pd.closePrinter();
|
||||
assertFalse(pd.isOpen());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileOutput() throws IOException {
|
||||
File tempFile = File.createTempFile("printer_test_", ".txt");
|
||||
tempFile.deleteOnExit();
|
||||
|
||||
PrinterConfig config = new PrinterConfig();
|
||||
config.setDestinationType(PrinterConfig.DestinationType.FILE);
|
||||
config.setDestinationTarget(tempFile.getAbsolutePath());
|
||||
|
||||
PD3270 filePd = new PD3270(config);
|
||||
assertTrue(filePd.openPrinter(tempFile.getAbsolutePath()));
|
||||
|
||||
filePd.writePrintLine("Test Output Line");
|
||||
filePd.closePrinter();
|
||||
|
||||
String fileContent = new String(Files.readAllBytes(tempFile.toPath()));
|
||||
assertTrue(fileContent.contains("Test Output Line"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package haus.nightmare.lib3270j.printer;
|
||||
|
||||
import haus.nightmare.lib3270j.charset.EbcdicTranslator;
|
||||
import haus.nightmare.lib3270j.protocol.DS3270Constants;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class PrintPS3270Test {
|
||||
|
||||
private PrinterConfig config;
|
||||
private PD3270 pd;
|
||||
private EbcdicTranslator translator;
|
||||
private PrintPS3270 printPs;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
config = new PrinterConfig("localhost", 23);
|
||||
pd = new PD3270(config);
|
||||
translator = new EbcdicTranslator("037");
|
||||
printPs = new PrintPS3270(config, pd, translator);
|
||||
pd.openPrinter(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEraseWriteAndStartPrint() {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
out.write(DS3270Constants.CMD_ERASE_WRITE);
|
||||
out.write(PrinterConstants.WCC_START_PRINT_BIT); // WCC with Start Print bit
|
||||
|
||||
// SBA 0, 0
|
||||
out.write(PrinterConstants.ORDER_SBA);
|
||||
out.write(0x40); out.write(0x40); // 0, 0 address
|
||||
|
||||
// Write EBCDIC "REPORT"
|
||||
byte[] rep = translator.stringToEbcdic("REPORT");
|
||||
out.write(rep, 0, rep.length);
|
||||
|
||||
byte[] payload = out.toByteArray();
|
||||
printPs.process3270PrintDS(payload, 0, payload.length);
|
||||
|
||||
String captured = pd.getCapturedText();
|
||||
assertTrue(captured.contains("REPORT"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRepeatToAddressOrder() {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
out.write(DS3270Constants.CMD_WRITE);
|
||||
out.write(0x00); // WCC
|
||||
|
||||
out.write(PrinterConstants.ORDER_SBA);
|
||||
out.write(0x40); out.write(0x40); // 0
|
||||
|
||||
// Repeat '*' to address 10
|
||||
out.write(PrinterConstants.ORDER_RA);
|
||||
out.write(0x40); out.write(0x4A); // Address 10
|
||||
out.write(translator.unicodeToEbcdic('*'));
|
||||
|
||||
byte[] payload = out.toByteArray();
|
||||
printPs.process3270PrintDS(payload, 0, payload.length);
|
||||
printPs.flushPrintBuffer();
|
||||
|
||||
String captured = pd.getCapturedText();
|
||||
assertTrue(captured.contains("**********"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldAttributesAndColorCalculations() {
|
||||
assertEquals(1, printPs.calculateColor(0xF1)); // Blue
|
||||
assertEquals(2, printPs.calculateColor(0xF2)); // Red
|
||||
assertEquals(4, printPs.calculateColor(0xF4)); // Green
|
||||
assertEquals(0, printPs.calculateColor(0x00)); // Neutral
|
||||
|
||||
assertEquals(1, printPs.calculateHighlight(PrinterConstants.SEAC_BLINK));
|
||||
assertEquals(2, printPs.calculateHighlight(PrinterConstants.SEAC_REVERSE));
|
||||
assertEquals(4, printPs.calculateHighlight(PrinterConstants.SEAC_UNDERLINE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package haus.nightmare.lib3270j.printer;
|
||||
|
||||
import haus.nightmare.lib3270j.charset.EbcdicTranslator;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class PrintSCS3270Test {
|
||||
|
||||
private PrinterConfig config;
|
||||
private PD3270 pd;
|
||||
private EbcdicTranslator translator;
|
||||
private PrintSCS3270 scs;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
config = new PrinterConfig("localhost", 23);
|
||||
pd = new PD3270(config);
|
||||
translator = new EbcdicTranslator("037");
|
||||
scs = new PrintSCS3270(config, pd, translator);
|
||||
pd.openPrinter(null); // In-memory capture
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicPrintAndNewLines() {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
// EBCDIC "HELLO" + NL + "WORLD" + FF
|
||||
byte[] helloEbc = translator.stringToEbcdic("HELLO");
|
||||
byte[] worldEbc = translator.stringToEbcdic("WORLD");
|
||||
|
||||
stream.write(helloEbc, 0, helloEbc.length);
|
||||
stream.write(PrinterConstants.SCS_NL);
|
||||
stream.write(worldEbc, 0, worldEbc.length);
|
||||
stream.write(PrinterConstants.SCS_FF);
|
||||
|
||||
byte[] payload = stream.toByteArray();
|
||||
scs.processHostData(payload, 0, payload.length);
|
||||
|
||||
String text = pd.getCapturedText();
|
||||
assertTrue(text.contains("HELLO"));
|
||||
assertTrue(text.contains("WORLD"));
|
||||
assertEquals(1, pd.getPageCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetHorizontalFormatAndTabs() {
|
||||
// SHF order: 0x2B 0xD1 <len> <mpp> <lm> <rm> <tab1> <tab2>
|
||||
byte[] shfOrder = new byte[]{
|
||||
(byte) PrinterConstants.SCS_PREFIX_2B,
|
||||
(byte) PrinterConstants.SCS_SHF,
|
||||
0x08, // Length
|
||||
(byte) 132, // MPP = 132
|
||||
0x05, // Left margin = 5
|
||||
(byte) 120, // Right margin = 120
|
||||
0x10, // Tab 1 = 16
|
||||
0x20 // Tab 2 = 32
|
||||
};
|
||||
|
||||
scs.processHostData(shfOrder, 0, shfOrder.length);
|
||||
assertEquals(132, scs.getLineLength());
|
||||
assertEquals(5, scs.getLeftMargin());
|
||||
assertEquals(120, scs.getRightMargin());
|
||||
|
||||
int nextTab = scs.calculateHorizontalTab(10);
|
||||
assertEquals(16, nextTab);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetVerticalFormatAndTabs() {
|
||||
// SVF order: 0x2B 0xD2 <len> <mpl> <tm> <bm> <tab1> <tab2>
|
||||
byte[] svfOrder = new byte[]{
|
||||
(byte) PrinterConstants.SCS_PREFIX_2B,
|
||||
(byte) PrinterConstants.SCS_SVF,
|
||||
0x08, // Length
|
||||
(byte) 88, // MPL = 88
|
||||
0x03, // Top margin = 3
|
||||
(byte) 80, // Bottom margin = 80
|
||||
0x0A, // Tab 1 = 10
|
||||
0x14 // Tab 2 = 20
|
||||
};
|
||||
|
||||
scs.processHostData(svfOrder, 0, svfOrder.length);
|
||||
assertEquals(88, scs.getPageLength());
|
||||
assertEquals(3, scs.getTopMargin());
|
||||
assertEquals(80, scs.getBottomMargin());
|
||||
|
||||
int nextVTab = scs.calculateVerticalTab(5);
|
||||
assertEquals(10, nextVTab);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleWidthAndHighlighting() {
|
||||
scs.startDoubleWidthCharacters();
|
||||
assertTrue(scs.isDoubleWidth());
|
||||
|
||||
scs.setEnhancedHighlight(PrinterConstants.SEAC_UNDERLINE);
|
||||
assertEquals(PrinterConstants.SEAC_UNDERLINE, scs.getActiveHighlight());
|
||||
|
||||
scs.endDoubleWidthCharacters();
|
||||
assertFalse(scs.isDoubleWidth());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPPAandPPVPositioning() {
|
||||
// PPA absolute to column 25: 0x2B 0xC6 0x02 0x01 0x19
|
||||
byte[] ppa = new byte[]{
|
||||
(byte) PrinterConstants.SCS_PREFIX_2B,
|
||||
(byte) PrinterConstants.SCS_PPA,
|
||||
0x02,
|
||||
PrinterConstants.POS_ABSOLUTE,
|
||||
0x19 // col 25
|
||||
};
|
||||
scs.processHostData(ppa, 0, ppa.length);
|
||||
assertEquals(25, scs.getCurrentColumn());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransparentStream() {
|
||||
// TRS: 0x35 <len> <raw data>
|
||||
byte[] trs = new byte[]{
|
||||
PrinterConstants.SCS_TRS,
|
||||
0x04,
|
||||
'T', 'E', 'S', 'T'
|
||||
};
|
||||
scs.processHostData(trs, 0, trs.length);
|
||||
assertTrue(pd.getByteCount() >= 4);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package haus.nightmare.lib3270j.printer;
|
||||
|
||||
import haus.nightmare.lib3270j.ConnectionConfig;
|
||||
import haus.nightmare.lib3270j.charset.EbcdicTranslator;
|
||||
import haus.nightmare.lib3270j.datastream.DataStreamProcessor;
|
||||
import haus.nightmare.lib3270j.screen.ScreenBuffer;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class PrinterPhase6Test {
|
||||
|
||||
private PrinterConfig printerConfig;
|
||||
private Telnet3270EP printer;
|
||||
private PD3270 pd;
|
||||
private EbcdicTranslator translator;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
printerConfig = new PrinterConfig("localhost", 23, "PRT_LU1");
|
||||
printerConfig.setAssociatedDisplayLuName("DSP_LU1");
|
||||
pd = new PD3270(printerConfig);
|
||||
translator = new EbcdicTranslator("037");
|
||||
printer = new Telnet3270EP(printerConfig, pd, translator);
|
||||
pd.openPrinter(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConnectionConfigToPrinterConfigMapping() {
|
||||
ConnectionConfig ccfg = new ConnectionConfig("10.0.0.1", 992, true);
|
||||
ccfg.setLuName("DSP01");
|
||||
ccfg.setAssociatedPrinterLu("PRT01");
|
||||
ccfg.setCodePage("1047");
|
||||
|
||||
PrinterConfig pcfg = ccfg.toPrinterConfig();
|
||||
assertEquals("10.0.0.1", pcfg.getHost());
|
||||
assertEquals(992, pcfg.getPort());
|
||||
assertTrue(pcfg.isUseTls());
|
||||
assertEquals("PRT01", pcfg.getPrinterLuName());
|
||||
assertEquals("DSP01", pcfg.getAssociatedDisplayLuName());
|
||||
assertEquals("1047", pcfg.getCodePage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDataStreamProcessorEmbeddedScsRouting() {
|
||||
ScreenBuffer screen = new ScreenBuffer(haus.nightmare.lib3270j.TerminalModel.IBM_3279_4, translator);
|
||||
DataStreamProcessor dsp = new DataStreamProcessor(screen, translator);
|
||||
PrintSCS3270 scs = new PrintSCS3270(printerConfig, pd, translator);
|
||||
|
||||
dsp.setEmbeddedScsProcessor(scs);
|
||||
assertSame(scs, dsp.getEmbeddedScsProcessor());
|
||||
|
||||
byte[] helloEbc = translator.stringToEbcdic("EMBEDDED SCS");
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
stream.write(helloEbc, 0, helloEbc.length);
|
||||
stream.write(PrinterConstants.SCS_NL);
|
||||
|
||||
byte[] payload = stream.toByteArray();
|
||||
dsp.processSCSData(payload, 0, payload.length);
|
||||
|
||||
String text = pd.getCapturedText();
|
||||
assertTrue(text.contains("EMBEDDED SCS"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryReplyBuilderAuxDevice() {
|
||||
ScreenBuffer screen = new ScreenBuffer(haus.nightmare.lib3270j.TerminalModel.IBM_3279_4, translator);
|
||||
haus.nightmare.lib3270j.datastream.QueryReplyBuilder qrb = new haus.nightmare.lib3270j.datastream.QueryReplyBuilder(screen);
|
||||
|
||||
byte[] auxDev = qrb.buildAuxDevice();
|
||||
assertNotNull(auxDev);
|
||||
assertTrue(auxDev.length >= 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTelnet3270EPClientFacade() {
|
||||
Telnet3270EPClient client = new Telnet3270EPClient(printerConfig);
|
||||
assertNotNull(client.getPD());
|
||||
assertNotNull(client.getSCS());
|
||||
assertNotNull(client.getPrintPS());
|
||||
assertNotNull(client.getConfig());
|
||||
|
||||
// Test direct print through client
|
||||
byte[] testText = translator.stringToEbcdic("CLIENT PRINT");
|
||||
client.printDirectBytes(testText, 0, testText.length);
|
||||
client.getSCS().flushLineBuffer();
|
||||
|
||||
String captured = client.getPD().getCapturedText();
|
||||
assertTrue(captured.contains("CLIENT PRINT"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package haus.nightmare.lib3270j.printer;
|
||||
|
||||
import haus.nightmare.lib3270j.protocol.TN3270EConstants;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class Telnet3270EPTest {
|
||||
|
||||
private PrinterConfig config;
|
||||
private PD3270 pd;
|
||||
private Telnet3270EP printer;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
config = new PrinterConfig("localhost", 23, "PRT01");
|
||||
config.setAssociatedDisplayLuName("DSP01");
|
||||
pd = new PD3270(config);
|
||||
printer = new Telnet3270EP(config, pd, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrinterConfigAndDefaults() {
|
||||
assertNotNull(config);
|
||||
assertEquals("PRT01", config.getPrinterLuName());
|
||||
assertEquals("DSP01", config.getAssociatedDisplayLuName());
|
||||
assertEquals(PrinterConstants.DEV_IBM_3287_1, config.getDeviceType());
|
||||
assertEquals(80, config.getMpp());
|
||||
assertEquals(66, config.getMpl());
|
||||
assertTrue(config.isFormFeedAtEoj());
|
||||
assertTrue(config.isAutoFlushOnEoj());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindProcessingLU1andLU3() {
|
||||
// Test LU-1 SCS bind
|
||||
printer.process_bind(PrinterConstants.LU_TYPE_1_SCS);
|
||||
assertEquals(PrinterConstants.LU_TYPE_1_SCS, printer.getActiveLuType());
|
||||
assertEquals(PrinterConstants.STATUS_PRINTER_READY, printer.getStatusCode());
|
||||
|
||||
// Test LU-3 3270 DS bind
|
||||
printer.process_bind(PrinterConstants.LU_TYPE_3_DS);
|
||||
assertEquals(PrinterConstants.LU_TYPE_3_DS, printer.getActiveLuType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindImagePayloadParsing() {
|
||||
byte[] bindImage = new byte[30];
|
||||
bindImage[14] = 0x01; // LU1 profile
|
||||
printer.processBindImage(bindImage, 0, bindImage.length);
|
||||
assertEquals(PrinterConstants.LU_TYPE_1_SCS, printer.getActiveLuType());
|
||||
|
||||
bindImage[14] = 0x03; // LU3 profile
|
||||
printer.processBindImage(bindImage, 0, bindImage.length);
|
||||
assertEquals(PrinterConstants.LU_TYPE_3_DS, printer.getActiveLuType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEOJAndListeners() {
|
||||
List<PrintSessionEvent> events = new ArrayList<>();
|
||||
printer.addPrintListener(new PrintSessionListener() {
|
||||
@Override public void onPrintJobStarted(PrintSessionEvent event) { events.add(event); }
|
||||
@Override public void onPrintJobData(PrintSessionEvent event) { events.add(event); }
|
||||
@Override public void onPrintJobPageComplete(PrintSessionEvent event) { events.add(event); }
|
||||
@Override public void onPrintJobComplete(PrintSessionEvent event) { events.add(event); }
|
||||
@Override public void onPrinterStatusChanged(PrintSessionEvent event) { events.add(event); }
|
||||
@Override public void onPrinterError(PrintSessionEvent event) { events.add(event); }
|
||||
});
|
||||
|
||||
printer.firePrintJobStarted("JOB001");
|
||||
printer.sendEOJ(true);
|
||||
|
||||
assertEquals(PrinterConstants.STATUS_JOB_COMPLETE, printer.getStatusCode());
|
||||
assertTrue(events.size() >= 2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user