Skip to content

Commit 438a470

Browse files
committed
Add test for absolute write
1 parent 9c3aae3 commit 438a470

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

bson/src/test/unit/org/bson/io/BasicOutputBufferSpecification.groovy

+40
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,46 @@ class BasicOutputBufferSpecification extends Specification {
320320
bsonOutput.size == 8
321321
}
322322

323+
def 'absolute write should throw with invalid position'() {
324+
given:
325+
def bsonOutput = new BasicOutputBuffer()
326+
bsonOutput.writeBytes([1, 2, 3, 4] as byte[])
327+
328+
when:
329+
bsonOutput.write(-1, 0x1020304)
330+
331+
then:
332+
thrown(IllegalArgumentException)
333+
334+
when:
335+
bsonOutput.write(4, 0x1020304)
336+
337+
then:
338+
thrown(IllegalArgumentException)
339+
}
340+
341+
def 'absolute write should write Int32 at position'() {
342+
given:
343+
def bsonOutput = new BasicOutputBuffer()
344+
bsonOutput.writeBytes([0, 0, 0, 0, 1, 2, 3, 4] as byte[])
345+
346+
when:
347+
bsonOutput.write(0, 0x1020304)
348+
349+
then:
350+
getBytes(bsonOutput) == [4, 0, 0, 0, 1, 2, 3, 4] as byte[]
351+
bsonOutput.position == 8
352+
bsonOutput.size == 8
353+
354+
when:
355+
bsonOutput.write(7, 0x1020304)
356+
357+
then:
358+
getBytes(bsonOutput) == [4, 0, 0, 0, 1, 2, 3, 4] as byte[]
359+
bsonOutput.position == 8
360+
bsonOutput.size == 8
361+
}
362+
323363
def 'truncate should throw with invalid position'() {
324364
given:
325365
def bsonOutput = new BasicOutputBuffer()

0 commit comments

Comments
 (0)