|
| 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