Skip to content

Commit

Permalink
added an icmp test
Browse files Browse the repository at this point in the history
  • Loading branch information
compscidr committed Sep 9, 2024
1 parent dc2158e commit af12d06
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions knet/src/test/kotlin/com/jasonernst/knet/icmp/ICMPTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.jasonernst.knet.icmp

import com.jasonernst.icmp_common.ICMPHeader
import com.jasonernst.icmp_common.v4.ICMPv4EchoPacket
import com.jasonernst.icmp_common.v6.ICMPv6EchoPacket
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import java.nio.ByteBuffer

class ICMPTest {
@Test
fun icmpv4() {
val icmp = ICMPv4EchoPacket(id = 1u, sequence = 2u, data = "hello".toByteArray())
val stream = ByteBuffer.wrap(icmp.toByteArray())
val parsed = ICMPHeader.fromStream(stream)
assertEquals(icmp, parsed)
}

@Test fun icmpv6() {
val icmp = ICMPv6EchoPacket(id = 1u, sequence = 2u, data = "hello".toByteArray())
val stream = ByteBuffer.wrap(icmp.toByteArray())
val parsed = ICMPHeader.fromStream(stream, isIcmpV4 = false)
assertEquals(icmp, parsed)
}
}

0 comments on commit af12d06

Please sign in to comment.