diff --git a/src/main/kotlin/de/gmuth/ipp/core/IppInputStream.kt b/src/main/kotlin/de/gmuth/ipp/core/IppInputStream.kt index f9932e2d..031ea2c5 100644 --- a/src/main/kotlin/de/gmuth/ipp/core/IppInputStream.kt +++ b/src/main/kotlin/de/gmuth/ipp/core/IppInputStream.kt @@ -55,14 +55,14 @@ class IppInputStream(inputStream: BufferedInputStream) : DataInputStream(inputSt } } } while (tag != End) - } catch (exception: Exception) { - readBytes().apply { + } catch (throwable: Throwable) { + if (throwable !is EOFException) readBytes().apply { if (isNotEmpty()) { log.warning { "skipped $size unparsed bytes" } hexdump { log.warning { it } } } } - throw exception + throw throwable } } @@ -75,9 +75,8 @@ class IppInputStream(inputStream: BufferedInputStream) : DataInputStream(inputSt val name = readString() val value = try { readAttributeValue(tag) - } catch (exception: Exception) { - if (exception !is EOFException) readBytes().hexdump { log.info { it } } - throw IppException("failed to read attribute value of '$name' ($tag)", exception) + } catch (throwable: Throwable) { + throw IppException("failed to read attribute value of '$name' ($tag)", throwable) } // remember attributes-charset for name and text value decoding if (name == "attributes-charset") attributesCharset = value as Charset diff --git a/src/main/kotlin/de/gmuth/ipp/core/IppMessage.kt b/src/main/kotlin/de/gmuth/ipp/core/IppMessage.kt index 02af9d37..4963983b 100644 --- a/src/main/kotlin/de/gmuth/ipp/core/IppMessage.kt +++ b/src/main/kotlin/de/gmuth/ipp/core/IppMessage.kt @@ -88,9 +88,6 @@ abstract class IppMessage() { toByteArray() } - fun encodeAsInputStream() = - ByteArrayInputStream(encode()) - // -------- // DECODING // -------- diff --git a/src/main/kotlin/de/gmuth/ipp/core/IppTag.kt b/src/main/kotlin/de/gmuth/ipp/core/IppTag.kt index 148da212..5a44eaf5 100644 --- a/src/main/kotlin/de/gmuth/ipp/core/IppTag.kt +++ b/src/main/kotlin/de/gmuth/ipp/core/IppTag.kt @@ -4,7 +4,7 @@ package de.gmuth.ipp.core * Copyright (c) 2020 Gerhard Muth */ -// [RFC 8010] and [RFC 3380] +// [RFC 8010] and [RFC 3380] enum class IppTag( val code: Byte, val registeredName: String, diff --git a/src/test/kotlin/de/gmuth/ipp/core/IppAttributesGroupTests.kt b/src/test/kotlin/de/gmuth/ipp/core/IppAttributesGroupTests.kt index ca74eda1..813aa0e7 100644 --- a/src/test/kotlin/de/gmuth/ipp/core/IppAttributesGroupTests.kt +++ b/src/test/kotlin/de/gmuth/ipp/core/IppAttributesGroupTests.kt @@ -72,6 +72,12 @@ class IppAttributesGroupTests { assertEquals("bar", group.getValue("foo") as String) } + @Test + fun getTextValue() { + group.attribute("foo", TextWithoutLanguage, "bar".toIppString()) + assertEquals("bar", group.getTextValue("foo")) + } + @Test fun getValueOrNull() { group.attribute("foo0", Keyword, "bar0") diff --git a/src/test/kotlin/de/gmuth/ipp/core/IppInputStreamTests.kt b/src/test/kotlin/de/gmuth/ipp/core/IppInputStreamTests.kt index 0a9c1314..d43334d5 100644 --- a/src/test/kotlin/de/gmuth/ipp/core/IppInputStreamTests.kt +++ b/src/test/kotlin/de/gmuth/ipp/core/IppInputStreamTests.kt @@ -5,6 +5,7 @@ package de.gmuth.ipp.core */ import de.gmuth.ipp.core.IppResolution.Unit.DPI +import de.gmuth.log.Logging import java.io.ByteArrayInputStream import java.net.URI import java.util.logging.Logger @@ -15,6 +16,10 @@ import kotlin.test.assertTrue class IppInputStreamTest { + init { + Logging.configure() + } + private val message = object : IppMessage() { override val codeDescription: String get() = "codeDescription" @@ -181,6 +186,14 @@ class IppInputStreamTest { } } + @Test + fun readMessageFails() { + val encoded = "01 01 00 0B 00 00 00 08 01 47 00 01 61 00 01 66 0A 0B 0C 0D" + assertFailsWith { + encoded.toIppInputStream().readMessage(message) + } + } + @Test fun readMessageReadAttributeFails() { val encoded = "00 03 66 6F 6F 00 03 62 61 72" diff --git a/src/test/kotlin/de/gmuth/ipp/core/IppRequestTests.kt b/src/test/kotlin/de/gmuth/ipp/core/IppRequestTests.kt index d442597c..cbefb69f 100644 --- a/src/test/kotlin/de/gmuth/ipp/core/IppRequestTests.kt +++ b/src/test/kotlin/de/gmuth/ipp/core/IppRequestTests.kt @@ -4,7 +4,9 @@ package de.gmuth.ipp.core * Copyright (c) 2020-2023 Gerhard Muth */ +import de.gmuth.ipp.core.IppOperation.CreateJobSubscriptions import java.net.URI +import java.time.Duration import java.util.logging.Logger.getLogger import kotlin.test.Test import kotlin.test.assertEquals @@ -65,9 +67,27 @@ class IppRequestTests { assertEquals(URI.create("ipp://printer"), getValue("printer-uri")) assertEquals(0, getValue("job-id")) assertEquals(listOf("one", "two"), getValues("requested-attributes")) - assertEquals("user".toIppString(), getValue("requesting-user-name")) + //assertEquals("user".toIppString(), getValue("requesting-user-name")) } + assertEquals("user", requestDecoded.requestingUserName) assertEquals("pdl-content", String(requestDecoded.documentInputStream!!.readBytes())) } + @Test + fun createSubscriptionAttributesGroup() { + IppRequest(CreateJobSubscriptions, URI.create("ipp://foo")) + .createSubscriptionAttributesGroup( + listOf("all"), + Duration.ofHours(1), + Duration.ofMinutes(1), + 999 + ) + } + + @Test + fun createSubscriptionAttributesGroupWithNullDefaults() { + IppRequest(CreateJobSubscriptions, URI.create("ipp://null")) + .createSubscriptionAttributesGroup() + } + } \ No newline at end of file diff --git a/src/test/kotlin/de/gmuth/ipp/core/IppResponseTests.kt b/src/test/kotlin/de/gmuth/ipp/core/IppResponseTests.kt index 6b09b666..ea0e79e4 100644 --- a/src/test/kotlin/de/gmuth/ipp/core/IppResponseTests.kt +++ b/src/test/kotlin/de/gmuth/ipp/core/IppResponseTests.kt @@ -63,4 +63,11 @@ class IppResponseTests { } } + @Test + fun createReponse() { + IppResponse(IppStatus.SuccessfulOk).run { + assertTrue(isSuccessful()) + } + } + } \ No newline at end of file