Skip to content

Commit 0a870e1

Browse files
committed
Add a failing test for #94
1 parent 01645bf commit 0a870e1

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

protobuf/src/test/java/com/fasterxml/jackson/dataformat/protobuf/failing/GenerateSchema68Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ static class ShortBean
1717
{
1818
public short version;
1919
}
20-
20+
2121
/*
2222
/**********************************************************
2323
/* Test methods
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.fasterxml.jackson.dataformat.protobuf.failing;
2+
3+
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
4+
5+
import com.fasterxml.jackson.dataformat.protobuf.*;
6+
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchema;
7+
8+
public class WriteLongString94Test extends ProtobufTestBase
9+
{
10+
@JsonPropertyOrder({ "a", "b" })
11+
public static class TwoStrings {
12+
public String a;
13+
public String b;
14+
}
15+
16+
/*
17+
/**********************************************************
18+
/* Test methods
19+
/**********************************************************
20+
*/
21+
22+
final ProtobufMapper MAPPER = new ProtobufMapper();
23+
24+
// [dataformats-binary#94]
25+
public void testLongerStrings() throws Exception {
26+
TwoStrings p = new TwoStrings();
27+
// near 8000, so index out of bounds at 8000
28+
p.a = makeString(7995);
29+
p.b = makeString(7995);
30+
31+
ProtobufSchema schema = MAPPER.generateSchemaFor(p.getClass());
32+
byte[] proto = MAPPER.writer(schema)
33+
.writeValueAsBytes(p);
34+
assertEquals(13, proto.length);
35+
36+
TwoStrings result = MAPPER.readerFor(p.getClass())
37+
.with(schema)
38+
.readValue(proto);
39+
assertEquals(p.a, result.a);
40+
assertEquals(p.b, result.b);
41+
}
42+
43+
private String makeString(int len) {
44+
StringBuilder sb = new StringBuilder(len);
45+
for (int i = 0; i < len; i++) {
46+
sb.append((char) ('a' + (i & 15)));
47+
}
48+
return sb.toString();
49+
}
50+
}

0 commit comments

Comments
 (0)