Skip to content

Commit 6cbc674

Browse files
committed
RawStringValueImpl#equals failure example
1 parent 92b2e42 commit 6cbc674

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

msgpack-core/src/test/scala/org/msgpack/value/RawValueImplTest.scala

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package org.msgpack.value
22

3-
import scala.util.Random
4-
import org.msgpack.core.MessagePack.Code
5-
import org.msgpack.core.{MessagePack, MessageFormat, MessageFormatException, MessagePackSpec}
6-
import org.msgpack.core.MessagePack.Code._
73
import java.io.ByteArrayOutputStream
84

5+
import org.msgpack.core.{MessagePack, MessagePackSpec}
6+
import org.msgpack.value.holder.ValueHolder
7+
import org.msgpack.value.impl.RawValueImpl
8+
99

1010
class RawValueImplTest extends MessagePackSpec {
1111

@@ -34,5 +34,30 @@ class RawValueImplTest extends MessagePackSpec {
3434
rawStr.asString().toString shouldBe str
3535
}
3636
}
37+
38+
"RawStringValueImpl#equals" in {
39+
def printRawValueImplInternal(v: Value): Unit = {
40+
val field = classOf[RawValueImpl].getDeclaredField("byteBuffer")
41+
field.setAccessible(true)
42+
println(field.get(v).asInstanceOf[java.nio.ByteBuffer])
43+
}
44+
45+
val str = ValueFactory.newRawString("aaa".getBytes("UTF-8"))
46+
val bytes = createMessagePackData(_.packValue(str))
47+
val unpacker = MessagePack.newDefaultUnpacker(bytes)
48+
val holder = new ValueHolder
49+
unpacker.unpackValue(holder)
50+
val unpackedValue = holder.get
51+
52+
unpackedValue.toString shouldBe str.toString
53+
54+
// java.nio.HeapByteBuffer[pos=0 lim=3 cap=3]
55+
printRawValueImplInternal(unpackedValue)
56+
57+
// java.nio.HeapByteBuffer[pos=3 lim=3 cap=3]
58+
printRawValueImplInternal(str)
59+
60+
unpackedValue shouldBe str // failure
61+
}
3762
}
3863
}

0 commit comments

Comments
 (0)