Skip to content
Permalink
Browse files
Merge pull request #28 from LinShunKang/master
  • Loading branch information
chickenlj committed Mar 27, 2020
2 parents 2e6e735 + 5a3b564 commit 5d16bbcbc600adfc89b193f467741cf835e6531e
Showing 2 changed files with 39 additions and 10 deletions.
@@ -206,12 +206,13 @@ public void reset() {
@Override
public boolean checkAndReadNull() {
try {
int tmp_offset = _offset;
int tag = read();
if ('N' == tag) {
return true;
}
_offset = tmp_offset;
if (-1 != tag) {
_offset--;
}
} catch (IOException ignored) {
}
return false;
@@ -20,10 +20,12 @@
import com.alibaba.com.caucho.hessian.io.beans.Hessian2StringShortType;
import com.alibaba.com.caucho.hessian.io.beans.PersonType;

import org.junit.Assert;
import org.junit.Test;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.*;

import static junit.framework.TestCase.assertEquals;
@@ -92,8 +94,8 @@ public void serialize_map_then_deserialize() throws Exception {
public void serialize_map_then_deserialize0() throws Exception {

Map<String, Short> stringShortMap = new HashMap<String, Short>();
stringShortMap.put("first", (short)0);
stringShortMap.put("last", (short)60);
stringShortMap.put("first", (short) 0);
stringShortMap.put("last", (short) 60);

ByteArrayOutputStream bout = new ByteArrayOutputStream();
Hessian2Output out = new Hessian2Output(bout);
@@ -112,8 +114,8 @@ public void serialize_map_then_deserialize0() throws Exception {
assertTrue(deserialize != null);
assertTrue(deserialize.size() == 2);
assertTrue(deserialize.get("last") instanceof Short);
assertEquals(Short.valueOf((short)0), deserialize.get("first"));
assertEquals(Short.valueOf((short)60), deserialize.get("last"));
assertEquals(Short.valueOf((short) 0), deserialize.get("first"));
assertEquals(Short.valueOf((short) 60), deserialize.get("last"));
}

@Test
@@ -181,8 +183,8 @@ public void serialize_list_then_deserialize() throws Exception {
public void serialize_list_then_deserialize0() throws Exception {

List<Short> shortList = new ArrayList<Short>();
shortList.add((short)0);
shortList.add((short)60);
shortList.add((short) 0);
shortList.add((short) 60);

ByteArrayOutputStream bout = new ByteArrayOutputStream();
Hessian2Output out = new Hessian2Output(bout);
@@ -200,8 +202,8 @@ public void serialize_list_then_deserialize0() throws Exception {
assertTrue(deserialize != null);
assertTrue(deserialize.size() == 2);
assertTrue(deserialize.get(1) instanceof Short);
assertEquals(Short.valueOf((short)0), deserialize.get(0));
assertEquals(Short.valueOf((short)60), deserialize.get(1));
assertEquals(Short.valueOf((short) 0), deserialize.get(0));
assertEquals(Short.valueOf((short) 60), deserialize.get(1));
}

@Test
@@ -219,4 +221,30 @@ public void serialize_short_set_then_deserialize() throws Exception {
assertTrue(deserialize.shortSet.contains((short) 0));
assertTrue(deserialize.shortSet.contains((short) 60));
}

@Test
public void test_string_short_type() throws IOException {
for (int i = 0; i < 100; i++) {
Hessian2StringShortType obj = new Hessian2StringShortType();
obj.shortSet = new HashSet<>();
obj.stringShortMap = new HashMap<>();
obj.stringByteMap = new HashMap<>();
obj.stringPersonTypeMap = new HashMap<>();

obj.shortSet.add((short) i);
obj.shortSet.add((short) (i * 2));

obj.stringShortMap.put(String.valueOf(i), (short) i);
obj.stringShortMap.put(String.valueOf(i * 100), (short) (i * 100));
obj.stringByteMap.put(String.valueOf(i), (byte) 1);

List<Short> shorts = Arrays.asList((short) 12, (short) 4);
PersonType abc = new PersonType("ABC", 12, 128D, (short) 1, (byte) 2, shorts);
obj.stringPersonTypeMap.put("P_" + i, abc);

Hessian2StringShortType newObj = baseHessian2Serialize(obj);
Assert.assertEquals(obj, newObj);
System.out.println("ShortTypeTest.testHessian2StringShortType(): i=" + i + " passed!");
}
}
}

0 comments on commit 5d16bbc

Please sign in to comment.