Skip to content

Commit 9da2c06

Browse files
fix bugs in the test compilation
1 parent f873611 commit 9da2c06

File tree

3 files changed

+83
-7
lines changed

3 files changed

+83
-7
lines changed

build.gradle

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ dependencies {
8080
'junit:junit:4.11',
8181
'org.mockito:mockito-all:1.9.5',
8282
'com.google.code.gson:gson:2.3.1'
83+
84+
testCompile files('build/classes/generated')
8385
}
8486

8587
compileJava {
@@ -101,7 +103,11 @@ compileExamplesJava.dependsOn 'compileGeneratedJava'
101103
compileGeneratedJava.classpath += sourceSets.main.runtimeClasspath
102104
compileExamplesJava.classpath += sourceSets.generated.runtimeClasspath + sourceSets.main.runtimeClasspath
103105

104-
task (generateExampleCodecs, dependsOn: 'test', type: JavaExec) {
106+
test {
107+
classpath += files('build/classes/generated')
108+
}
109+
110+
task (generateExampleCodecs, type: JavaExec) {
105111
main = 'uk.co.real_logic.sbe.SbeTool'
106112
classpath = sourceSets.main.runtimeClasspath
107113
systemProperties('sbe.output.dir': generatedDir,

main/java/uk/co/real_logic/sbe/json/JsonPrinter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
/**
2828
* Pretty Print Json based upon the given Ir.
2929
*/
30-
public class JsonPrinter {
30+
public class JsonPrinter
31+
{
3132

3233
private final OtfHeaderDecoder headerDecoder;
3334
private final Ir ir;
@@ -74,7 +75,7 @@ private void validateId(int schemaId)
7475
if (schemaId != ir.id())
7576
{
7677
throw new IllegalArgumentException(
77-
String.format("Required schema id %d but was actually %d", ir.id(), schemaId));
78+
String.format("Required schema id %d but was actually %d", ir.id(), schemaId));
7879
}
7980
}
8081

test/java/uk/co/real_logic/sbe/json/JsonPrinterTest.java

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@
1515
*/
1616
package uk.co.real_logic.sbe.json;
1717

18-
import baseline.Car;
19-
import baseline.MessageHeader;
18+
import baseline.*;
19+
import org.junit.BeforeClass;
2020
import org.junit.Test;
2121
import uk.co.real_logic.agrona.concurrent.UnsafeBuffer;
22-
import uk.co.real_logic.sbe.examples.ExampleUsingGeneratedStub;
2322
import uk.co.real_logic.sbe.ir.Ir;
2423
import uk.co.real_logic.sbe.ir.IrDecoder;
2524
import uk.co.real_logic.sbe.ir.IrEncoder;
@@ -31,6 +30,7 @@
3130
import java.io.FileInputStream;
3231
import java.io.IOException;
3332
import java.io.InputStream;
33+
import java.io.UnsupportedEncodingException;
3434
import java.nio.ByteBuffer;
3535

3636
import static junit.framework.TestCase.assertEquals;
@@ -42,6 +42,28 @@ public class JsonPrinterTest
4242
private static final int ACTING_VERSION = 0;
4343
private static final int MSG_BUFFER_CAPACITY = 4 * 1024;
4444
private static final int SCHEMA_BUFFER_CAPACITY = 16 * 1024;
45+
private static final String ENCODING_FILENAME = "sbe.encoding.filename";
46+
47+
private static byte[] vehicleCode;
48+
private static byte[] manufacturerCode;
49+
private static byte[] make;
50+
private static byte[] model;
51+
52+
@BeforeClass
53+
public static void setupExampleData()
54+
{
55+
try
56+
{
57+
vehicleCode = "abcdef".getBytes(Car.vehicleCodeCharacterEncoding());
58+
manufacturerCode = "123".getBytes(Engine.manufacturerCodeCharacterEncoding());
59+
make = "Honda".getBytes(Car.makeCharacterEncoding());
60+
model = "Civic VTi".getBytes(Car.modelCharacterEncoding());
61+
}
62+
catch (final UnsupportedEncodingException ex)
63+
{
64+
throw new RuntimeException(ex);
65+
}
66+
}
4567

4668
@Test
4769
public void exampleMessagePrintedAsJson() throws Exception
@@ -147,7 +169,54 @@ private static void encodeTestMessage(final ByteBuffer buffer)
147169

148170
bufferOffset += MESSAGE_HEADER.size();
149171

150-
bufferOffset += ExampleUsingGeneratedStub.encode(CAR, directBuffer, bufferOffset);
172+
final int srcOffset = 0;
173+
174+
CAR.wrapForEncode(directBuffer, bufferOffset)
175+
.serialNumber(1234)
176+
.modelYear(2013)
177+
.available(BooleanType.TRUE)
178+
.code(Model.A)
179+
.putVehicleCode(vehicleCode, srcOffset);
180+
181+
for (int i = 0, size = Car.someNumbersLength(); i < size; i++)
182+
{
183+
CAR.someNumbers(i, i);
184+
}
185+
186+
CAR.extras()
187+
.clear()
188+
.cruiseControl(true)
189+
.sportsPack(true)
190+
.sunRoof(false);
191+
192+
CAR.engine()
193+
.capacity(2000)
194+
.numCylinders((short)4)
195+
.putManufacturerCode(manufacturerCode, srcOffset);
196+
197+
CAR.fuelFiguresCount(3)
198+
.next().speed(30).mpg(35.9f)
199+
.next().speed(55).mpg(49.0f)
200+
.next().speed(75).mpg(40.0f);
201+
202+
final Car.PerformanceFigures perfFigures = CAR.performanceFiguresCount(2);
203+
perfFigures.next()
204+
.octaneRating((short)95)
205+
.accelerationCount(3)
206+
.next().mph(30).seconds(4.0f)
207+
.next().mph(60).seconds(7.5f)
208+
.next().mph(100).seconds(12.2f);
209+
perfFigures.next()
210+
.octaneRating((short)99)
211+
.accelerationCount(3)
212+
.next().mph(30).seconds(3.8f)
213+
.next().mph(60).seconds(7.1f)
214+
.next().mph(100).seconds(11.8f);
215+
216+
CAR.make(new String(make));
217+
CAR.putModel(model, srcOffset, model.length);
218+
219+
bufferOffset += CAR.size();
151220

152221
buffer.position(bufferOffset);
153222
}

0 commit comments

Comments
 (0)