MCPcopy Index your code
hub / github.com/RoaringBitmap/roaring / TestBitMapValidationFromDeserialization

Function TestBitMapValidationFromDeserialization

roaring_test.go:3379–3476  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3377}
3378
3379func TestBitMapValidationFromDeserialization(t *testing.T) {
3380 // To understand what is going on here, read https://github.com/RoaringBitmap/RoaringFormatSpec
3381 // Maintainers: The loader and corruptor are dependent on one another
3382 // The tests expect a certain size, with values at certain location.
3383 // The tests are geared toward single byte corruption.
3384
3385 // There is no way to test Bitmap container corruption once the bitmap is deserialzied
3386
3387 deserializationTests := []struct {
3388 name string
3389 loader func(bm *Bitmap)
3390 corruptor func(s []byte)
3391 err error
3392 }{
3393 {
3394 name: "Corrupts Run Length vs Num Runs",
3395 loader: func(bm *Bitmap) {
3396 bm.AddRange(0, 2)
3397 bm.AddRange(4, 6)
3398 bm.AddRange(8, 100)
3399 },
3400 corruptor: func(s []byte) {
3401 // 21 is the length of the run of the last run/range
3402 // Shortening causes interval sum to be to short
3403 s[21] = 1
3404 },
3405 err: ErrRunIntervalSize,
3406 },
3407 {
3408 name: "Corrupts Run Length",
3409 loader: func(bm *Bitmap) {
3410 bm.AddRange(100, 110)
3411 },
3412 corruptor: func(s []byte) {
3413 s[13] = 0
3414 },
3415 err: ErrRunIntervalSize,
3416 },
3417 {
3418 name: "Creates Interval Overlap",
3419 loader: func(bm *Bitmap) {
3420 bm.AddRange(100, 110)
3421 bm.AddRange(115, 125)
3422 },
3423 corruptor: func(s []byte) {
3424 // sets the start of the second run
3425 // Creates overlapping intervals
3426 s[15] = 108
3427 },
3428 err: ErrRunIntervalOverlap,
3429 },
3430 {
3431 name: "Break Array Sort Order",
3432 loader: func(bm *Bitmap) {
3433 arrayEntries := make([]uint32, 0, 10)
3434 for i := 0; i < 10; i++ {
3435 arrayEntries = append(arrayEntries, uint32(i))
3436 }

Callers

nothing calls this directly

Calls 7

AddRangeMethod · 0.95
AddManyMethod · 0.95
ValidateMethod · 0.95
ToBytesMethod · 0.95
ReadFromMethod · 0.95
MustReadFromMethod · 0.95
NewBitmapFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…