|
1 | 1 | package org.msgpack.value |
2 | 2 |
|
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._ |
7 | 3 | import java.io.ByteArrayOutputStream |
8 | 4 |
|
| 5 | +import org.msgpack.core.{MessagePack, MessagePackSpec} |
| 6 | +import org.msgpack.value.holder.ValueHolder |
| 7 | +import org.msgpack.value.impl.RawValueImpl |
| 8 | + |
9 | 9 |
|
10 | 10 | class RawValueImplTest extends MessagePackSpec { |
11 | 11 |
|
@@ -34,5 +34,30 @@ class RawValueImplTest extends MessagePackSpec { |
34 | 34 | rawStr.asString().toString shouldBe str |
35 | 35 | } |
36 | 36 | } |
| 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 | + } |
37 | 62 | } |
38 | 63 | } |
0 commit comments