(t *testing.T)
| 3377 | } |
| 3378 | |
| 3379 | func 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…