Skip to content

Commit 64cc860

Browse files
committed
appended test programs for MessagePack class
1 parent c716c4c commit 64cc860

1 file changed

Lines changed: 197 additions & 7 deletions

File tree

src/test/java/org/msgpack/TestMessagePack01.java

Lines changed: 197 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
import java.util.List;
1313
import java.util.Map;
1414

15-
import org.junit.Ignore;
1615
import org.junit.Test;
16+
import org.msgpack.template.Template;
17+
import static org.msgpack.template.Templates.tList;
18+
import static org.msgpack.template.Templates.tMap;
1719
import org.msgpack.type.Value;
1820

1921

@@ -109,12 +111,41 @@ public void testByteArrayUnconvertConvert() throws Exception {
109111
new TestByteArrayUnconvertConvert().testByteArray();
110112
}
111113

112-
@Ignore @Test // FIXME #MN *MUST* fix it in this version
114+
@Test
115+
public void testListBufferPackBufferUnpack() throws Exception {
116+
new TestListBufferPackBufferUnpack().testList();
117+
}
118+
119+
@Test
120+
public void testListBufferPackUnpack() throws Exception {
121+
new TestListBufferPackUnpack().testList();
122+
}
123+
124+
@Test
125+
public void testListPackBufferUnpack() throws Exception {
126+
new TestListPackBufferUnpack().testList();
127+
}
128+
129+
@Test
113130
public void testListPackUnpack() throws Exception {
114131
new TestListPackUnpack().testList();
115132
}
116133

117-
@Ignore @Test // FIXME #MN *MUST* fix it in this version
134+
@Test
135+
public void testMapBufferPackBufferUnpack() throws Exception {
136+
new TestMapBufferPackBufferUnpack().testMap();
137+
}
138+
139+
@Test
140+
public void testMapBufferPackUnpack() throws Exception {
141+
new TestMapBufferPackUnpack().testMap();
142+
}
143+
144+
@Test
145+
public void testMapPackBufferUnpack() throws Exception {
146+
new TestMapPackBufferUnpack().testMap();
147+
}
148+
@Test
118149
public void testMapPackUnpack() throws Exception {
119150
new TestMapPackUnpack().testMap();
120151
}
@@ -461,6 +492,84 @@ public void testByteArray(byte[] v) throws Exception {
461492
}
462493
}
463494

495+
public static class TestListBufferPackBufferUnpack extends org.msgpack.TestSet {
496+
@Test @Override
497+
public void testList() throws Exception {
498+
super.testList();
499+
}
500+
501+
@Override
502+
public <E> void testList(List<E> v, Class<E> elementClass) throws Exception {
503+
MessagePack msgpack = new MessagePack();
504+
Template<E> tElm = msgpack.lookup(elementClass);
505+
byte[] bytes = msgpack.write(v, tList(tElm));
506+
List<E> ret = msgpack.read(bytes, new ArrayList<E>(), tList(tElm));
507+
if (v == null) {
508+
assertEquals(null, ret);
509+
return;
510+
}
511+
assertEquals(v.size(), ret.size());
512+
Iterator<E> v_iter = v.iterator();
513+
Iterator<E> ret_iter = ret.iterator();
514+
while (v_iter.hasNext()) {
515+
assertEquals(v_iter.next(), ret_iter.next());
516+
}
517+
}
518+
}
519+
520+
public static class TestListBufferPackUnpack extends org.msgpack.TestSet {
521+
@Test @Override
522+
public void testList() throws Exception {
523+
super.testList();
524+
}
525+
526+
@Override
527+
public <E> void testList(List<E> v, Class<E> elementClass) throws Exception {
528+
MessagePack msgpack = new MessagePack();
529+
Template<E> tElm = msgpack.lookup(elementClass);
530+
byte[] bytes = msgpack.write(v, tList(tElm));
531+
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
532+
List<E> ret = msgpack.read(in, new ArrayList<E>(), tList(tElm));
533+
if (v == null) {
534+
assertEquals(null, ret);
535+
return;
536+
}
537+
assertEquals(v.size(), ret.size());
538+
Iterator<E> v_iter = v.iterator();
539+
Iterator<E> ret_iter = ret.iterator();
540+
while (v_iter.hasNext()) {
541+
assertEquals(v_iter.next(), ret_iter.next());
542+
}
543+
}
544+
}
545+
546+
public static class TestListPackBufferUnpack extends org.msgpack.TestSet {
547+
@Test @Override
548+
public void testList() throws Exception {
549+
super.testList();
550+
}
551+
552+
@Override
553+
public <E> void testList(List<E> v, Class<E> elementClass) throws Exception {
554+
MessagePack msgpack = new MessagePack();
555+
ByteArrayOutputStream out = new ByteArrayOutputStream();
556+
Template<E> tElm = msgpack.lookup(elementClass);
557+
msgpack.write(out, v, tList(tElm));
558+
byte[] bytes = out.toByteArray();
559+
List<E> ret = msgpack.read(bytes, tList(tElm));
560+
if (v == null) {
561+
assertEquals(null, ret);
562+
return;
563+
}
564+
assertEquals(v.size(), ret.size());
565+
Iterator<E> v_iter = v.iterator();
566+
Iterator<E> ret_iter = ret.iterator();
567+
while (v_iter.hasNext()) {
568+
assertEquals(v_iter.next(), ret_iter.next());
569+
}
570+
}
571+
}
572+
464573
public static class TestListPackUnpack extends org.msgpack.TestSet {
465574
@Test @Override
466575
public void testList() throws Exception {
@@ -471,9 +580,10 @@ public void testList() throws Exception {
471580
public <E> void testList(List<E> v, Class<E> elementClass) throws Exception {
472581
MessagePack msgpack = new MessagePack();
473582
ByteArrayOutputStream out = new ByteArrayOutputStream();
474-
msgpack.write(out, v);
583+
Template<E> tElm = msgpack.lookup(elementClass);
584+
msgpack.write(out, v, tList(tElm));
475585
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
476-
List<E> ret = msgpack.read(in, new ArrayList<E>());
586+
List<E> ret = msgpack.read(in, new ArrayList<E>(), tList(tElm));
477587
if (v == null) {
478588
assertEquals(null, ret);
479589
return;
@@ -487,6 +597,84 @@ public <E> void testList(List<E> v, Class<E> elementClass) throws Exception {
487597
}
488598
}
489599

600+
public static class TestMapBufferPackBufferUnpack extends org.msgpack.TestSet {
601+
@Test @Override
602+
public void testMap() throws Exception {
603+
super.testMap();
604+
}
605+
606+
@Override
607+
public <K, V> void testMap(Map<K, V> v, Class<K> keyElementClass, Class<V> valueElementClass) throws Exception {
608+
MessagePack msgpack = new MessagePack();
609+
Template<K> tKey = msgpack.lookup(keyElementClass);
610+
Template<V> tValue = msgpack.lookup(valueElementClass);
611+
byte[] bytes = msgpack.write(v, tMap(tKey, tValue));
612+
Map<K, V> ret = msgpack.read(bytes, new HashMap<K, V>(), tMap(tKey, tValue));
613+
if (v == null) {
614+
assertEquals(null, ret);
615+
return;
616+
}
617+
assertEquals(v.size(), ret.size());
618+
for (Map.Entry<K, V> e : ((Map<K, V>) v).entrySet()) {
619+
Object value = ret.get(e.getKey());
620+
assertEquals(e.getValue(), value);
621+
}
622+
}
623+
}
624+
625+
public static class TestMapBufferPackUnpack extends org.msgpack.TestSet {
626+
@Test @Override
627+
public void testMap() throws Exception {
628+
super.testMap();
629+
}
630+
631+
@Override
632+
public <K, V> void testMap(Map<K, V> v, Class<K> keyElementClass, Class<V> valueElementClass) throws Exception {
633+
MessagePack msgpack = new MessagePack();
634+
Template<K> tKey = msgpack.lookup(keyElementClass);
635+
Template<V> tValue = msgpack.lookup(valueElementClass);
636+
byte[] bytes = msgpack.write(v, tMap(tKey, tValue));
637+
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
638+
Map<K, V> ret = msgpack.read(in, new HashMap<K, V>(), tMap(tKey, tValue));
639+
if (v == null) {
640+
assertEquals(null, ret);
641+
return;
642+
}
643+
assertEquals(v.size(), ret.size());
644+
for (Map.Entry<K, V> e : ((Map<K, V>) v).entrySet()) {
645+
Object value = ret.get(e.getKey());
646+
assertEquals(e.getValue(), value);
647+
}
648+
}
649+
}
650+
651+
public static class TestMapPackBufferUnpack extends org.msgpack.TestSet {
652+
@Test @Override
653+
public void testMap() throws Exception {
654+
super.testMap();
655+
}
656+
657+
@Override
658+
public <K, V> void testMap(Map<K, V> v, Class<K> keyElementClass, Class<V> valueElementClass) throws Exception {
659+
MessagePack msgpack = new MessagePack();
660+
ByteArrayOutputStream out = new ByteArrayOutputStream();
661+
Template<K> tKey = msgpack.lookup(keyElementClass);
662+
Template<V> tValue = msgpack.lookup(valueElementClass);
663+
msgpack.write(out, v, tMap(tKey, tValue));
664+
byte[] bytes = out.toByteArray();
665+
Map<K, V> ret = msgpack.read(bytes, new HashMap<K, V>(), tMap(tKey, tValue));
666+
if (v == null) {
667+
assertEquals(null, ret);
668+
return;
669+
}
670+
assertEquals(v.size(), ret.size());
671+
for (Map.Entry<K, V> e : ((Map<K, V>) v).entrySet()) {
672+
Object value = ret.get(e.getKey());
673+
assertEquals(e.getValue(), value);
674+
}
675+
}
676+
}
677+
490678
public static class TestMapPackUnpack extends org.msgpack.TestSet {
491679
@Test @Override
492680
public void testMap() throws Exception {
@@ -497,9 +685,11 @@ public void testMap() throws Exception {
497685
public <K, V> void testMap(Map<K, V> v, Class<K> keyElementClass, Class<V> valueElementClass) throws Exception {
498686
MessagePack msgpack = new MessagePack();
499687
ByteArrayOutputStream out = new ByteArrayOutputStream();
500-
msgpack.write(out, v);
688+
Template<K> tKey = msgpack.lookup(keyElementClass);
689+
Template<V> tValue = msgpack.lookup(valueElementClass);
690+
msgpack.write(out, v, tMap(tKey, tValue));
501691
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
502-
Map<K, V> ret = msgpack.read(in, new HashMap<K, V>());
692+
Map<K, V> ret = msgpack.read(in, new HashMap<K, V>(), tMap(tKey, tValue));
503693
if (v == null) {
504694
assertEquals(null, ret);
505695
return;

0 commit comments

Comments
 (0)