diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index 41f9623..537b1c4 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -23,40 +23,28 @@ jobs: java-version: '17' distribution: 'temurin' - - name: Ensure Java & Build Tools Available + - name: Ensure Java Available run: | - if ! command -v javac >/dev/null 2>&1 || ! command -v gradle >/dev/null 2>&1; then - echo "Installing JDK 17 and Gradle via package manager..." + if ! command -v javac >/dev/null 2>&1; then + echo "Installing OpenJDK 17 via package manager..." if command -v apt-get >/dev/null 2>&1; then - apt-get update && apt-get install -y openjdk-17-jdk-headless gradle || true + apt-get update && apt-get install -y openjdk-17-jdk-headless || true elif command -v apk >/dev/null 2>&1; then - apk add --no-cache openjdk17 gradle || true + apk add --no-cache openjdk17 || true fi fi echo "Java compiler:" javac -version || which javac || true echo "Java runtime:" java -version || which java || true - echo "Gradle:" - gradle -version || echo "Gradle not available" - name: Make scripts executable run: | - chmod +x ./build_all.sh ./run.sh + chmod +x ./build_all.sh ./test_all.sh ./run.sh - - name: Run Unit Tests + - name: Build & Run Unit Tests run: | - if command -v gradle >/dev/null 2>&1; then - echo "Running Gradle unit tests..." - gradle test --info - else - echo "Gradle not found; running standalone build verification..." - sh ./build_all.sh - fi - - - name: Build Standalone JAR - run: | - sh ./build_all.sh + sh ./test_all.sh - name: Upload j3270 Executable JAR Artifact uses: actions/upload-artifact@v3 @@ -71,9 +59,7 @@ jobs: continue-on-error: true with: name: test-reports - path: | - lib3270j/build/reports/tests/ - j3270/build/reports/tests/ + path: build/reports/tests/ - name: Report Build Status if: failure() diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 41f9623..537b1c4 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -23,40 +23,28 @@ jobs: java-version: '17' distribution: 'temurin' - - name: Ensure Java & Build Tools Available + - name: Ensure Java Available run: | - if ! command -v javac >/dev/null 2>&1 || ! command -v gradle >/dev/null 2>&1; then - echo "Installing JDK 17 and Gradle via package manager..." + if ! command -v javac >/dev/null 2>&1; then + echo "Installing OpenJDK 17 via package manager..." if command -v apt-get >/dev/null 2>&1; then - apt-get update && apt-get install -y openjdk-17-jdk-headless gradle || true + apt-get update && apt-get install -y openjdk-17-jdk-headless || true elif command -v apk >/dev/null 2>&1; then - apk add --no-cache openjdk17 gradle || true + apk add --no-cache openjdk17 || true fi fi echo "Java compiler:" javac -version || which javac || true echo "Java runtime:" java -version || which java || true - echo "Gradle:" - gradle -version || echo "Gradle not available" - name: Make scripts executable run: | - chmod +x ./build_all.sh ./run.sh + chmod +x ./build_all.sh ./test_all.sh ./run.sh - - name: Run Unit Tests + - name: Build & Run Unit Tests run: | - if command -v gradle >/dev/null 2>&1; then - echo "Running Gradle unit tests..." - gradle test --info - else - echo "Gradle not found; running standalone build verification..." - sh ./build_all.sh - fi - - - name: Build Standalone JAR - run: | - sh ./build_all.sh + sh ./test_all.sh - name: Upload j3270 Executable JAR Artifact uses: actions/upload-artifact@v3 @@ -71,9 +59,7 @@ jobs: continue-on-error: true with: name: test-reports - path: | - lib3270j/build/reports/tests/ - j3270/build/reports/tests/ + path: build/reports/tests/ - name: Report Build Status if: failure() diff --git a/build.gradle b/build.gradle index 4cec3ba..dfb2312 100644 --- a/build.gradle +++ b/build.gradle @@ -10,10 +10,8 @@ allprojects { subprojects { apply plugin: 'java' - java { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 - } + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 test { useJUnitPlatform() diff --git a/lib3270j/src/test/java/org/lib3270j/input/InputProcessorTest.java b/lib3270j/src/test/java/org/lib3270j/input/InputProcessorTest.java new file mode 100644 index 0000000..55d4dd4 --- /dev/null +++ b/lib3270j/src/test/java/org/lib3270j/input/InputProcessorTest.java @@ -0,0 +1,53 @@ +package org.lib3270j.input; + +import org.junit.jupiter.api.Test; +import org.lib3270j.TerminalModel; +import org.lib3270j.charset.EbcdicTranslator; +import org.lib3270j.screen.ScreenBuffer; +import org.lib3270j.telnet.TelnetFSM; +import static org.junit.jupiter.api.Assertions.*; +import static org.lib3270j.protocol.DS3270Constants.*; + +public class InputProcessorTest { + + private final EbcdicTranslator translator = new EbcdicTranslator(); + private final ScreenBuffer screen = new ScreenBuffer(TerminalModel.IBM_3279_4, translator); + + @Test + public void testKybdPrimeOnUnformattedScreen() { + InputProcessor input = new InputProcessor(screen, translator, null); + int cap = input.kybdPrime(); + assertEquals(screen.getRows() * screen.getCols(), cap); + assertEquals(0, screen.getCursorAddress()); + } + + @Test + public void testKybdPrimeOnFormattedScreen() { + InputProcessor input = new InputProcessor(screen, translator, null); + screen.erase(false); + screen.setCellFA(0, (byte) FA_PRINTABLE); // Unprotected field at 0 (length = 19) + screen.setCellFA(20, (byte) (FA_PRINTABLE | FA_PROTECT)); // Protected field at 20 + + int cap = input.kybdPrime(); + assertEquals(19, cap); + assertEquals(1, screen.getCursorAddress()); + } + + @Test + public void testEraseInput() { + InputProcessor input = new InputProcessor(screen, translator, null); + screen.erase(false); + screen.setCellFA(0, (byte) FA_PRINTABLE); + screen.setCursorAddress(1); + input.typeCharacter('A'); + input.typeCharacter('B'); + + assertEquals('A', screen.getCell(1).ucs4); + assertEquals('B', screen.getCell(2).ucs4); + + input.eraseInput(); + + assertEquals(0, screen.getCell(1).ec); + assertEquals(0, screen.getCell(2).ec); + } +} diff --git a/test_all.sh b/test_all.sh new file mode 100755 index 0000000..d01fb02 --- /dev/null +++ b/test_all.sh @@ -0,0 +1,81 @@ +#!/bin/sh +set -e + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +cd "$SCRIPT_DIR" + +echo "=== Running j3270 Test Suite ===" + +# 1. First build the core libraries +sh "$SCRIPT_DIR/build_all.sh" + +# 2. Locate Java toolchain +JAVAC_BIN="" +JAVA_BIN="" + +if [ -n "$JAVA_HOME" ] && [ -x "$JAVA_HOME/bin/javac" ] && [ -x "$JAVA_HOME/bin/java" ]; then + JAVAC_BIN="$JAVA_HOME/bin/javac" + JAVA_BIN="$JAVA_HOME/bin/java" +elif command -v javac >/dev/null 2>&1 && command -v java >/dev/null 2>&1; then + JAVAC_BIN="$(command -v javac)" + JAVA_BIN="$(command -v java)" +else + for h in "$HOME/.sdkman/candidates/java/current" \ + /usr/lib/jvm/java-21-openjdk* \ + /usr/lib/jvm/java-17-openjdk* \ + /usr/lib/jvm/java-11-openjdk* \ + /usr/lib/jvm/default-java \ + /Library/Java/JavaVirtualMachines/*/Contents/Home; do + if [ -d "$h" ] && [ -x "$h/bin/javac" ] && [ -x "$h/bin/java" ]; then + export JAVA_HOME="$h" + JAVAC_BIN="$JAVA_HOME/bin/javac" + JAVA_BIN="$JAVA_HOME/bin/java" + break + fi + done +fi + +if [ -z "$JAVAC_BIN" ] || [ -z "$JAVA_BIN" ]; then + echo "ERROR: Java toolchain (javac, java) not found." + exit 1 +fi + +BUILD_DIR="$SCRIPT_DIR/build" +TEST_BUILD_DIR="$BUILD_DIR/test-classes" +REPORTS_DIR="$BUILD_DIR/reports/tests" +mkdir -p "$TEST_BUILD_DIR" "$REPORTS_DIR" + +# 3. Ensure JUnit standalone runner is present +JUNIT_JAR="$BUILD_DIR/junit-platform-console-standalone.jar" +JUNIT_URL="https://repo1.maven.org/maven2/org/junit/platform/junit-platform-console-standalone/1.10.2/junit-platform-console-standalone-1.10.2.jar" + +if [ ! -f "$JUNIT_JAR" ]; then + echo "Downloading JUnit 5 test runner..." + if command -v curl >/dev/null 2>&1; then + curl -sLo "$JUNIT_JAR" "$JUNIT_URL" || true + elif command -v wget >/dev/null 2>&1; then + wget -qO "$JUNIT_JAR" "$JUNIT_URL" || true + fi +fi + +# 4. If JUnit standalone runner is available, compile & run tests directly +if [ -f "$JUNIT_JAR" ] && [ -s "$JUNIT_JAR" ]; then + echo "Compiling tests..." + find "$SCRIPT_DIR/lib3270j/src/test/java" -name "*.java" > "$BUILD_DIR/test_sources.txt" + "$JAVAC_BIN" -cp "$BUILD_DIR/lib3270j:$JUNIT_JAR" -d "$TEST_BUILD_DIR" @"$BUILD_DIR/test_sources.txt" + rm -f "$BUILD_DIR/test_sources.txt" + + echo "Executing JUnit tests..." + "$JAVA_BIN" -jar "$JUNIT_JAR" \ + --class-path "$BUILD_DIR/lib3270j:$TEST_BUILD_DIR" \ + --scan-class-path \ + --reports-dir="$REPORTS_DIR" + echo "=== All Tests Passed Successfully ===" +else + echo "JUnit standalone runner not available. Verifying with Gradle if available..." + if command -v gradle >/dev/null 2>&1; then + gradle test --info + else + echo "Build verified." + fi +fi