Skip to content

Commit e41e1d0

Browse files
committed
updates
1 parent 22805da commit e41e1d0

File tree

1 file changed

+41
-40
lines changed

1 file changed

+41
-40
lines changed

read_test.go

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ func TestReadNativeFrames(t *testing.T) {
211211
cases := []struct {
212212
Name string
213213
existingData Dataset
214-
data []int16
215-
dataBytes []byte
214+
int16Data []int16
215+
uint8Data []byte
216216
expectedPixelData *PixelDataInfo
217217
expectedError error
218218
pixelVLOverride uint32
@@ -228,7 +228,7 @@ func TestReadNativeFrames(t *testing.T) {
228228
mustNewElement(tag.SamplesPerPixel, []int{1}),
229229
mustNewElement(tag.PixelRepresentation, []int{0}),
230230
}},
231-
data: []int16{1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
231+
int16Data: []int16{1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
232232
expectedPixelData: &PixelDataInfo{
233233
IsEncapsulated: false,
234234
Frames: []*frame.Frame{
@@ -255,7 +255,7 @@ func TestReadNativeFrames(t *testing.T) {
255255
mustNewElement(tag.SamplesPerPixel, []int{1}),
256256
mustNewElement(tag.PixelRepresentation, []int{0}),
257257
}},
258-
data: []int16{1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 0},
258+
int16Data: []int16{1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 0},
259259
expectedPixelData: &PixelDataInfo{
260260
IsEncapsulated: false,
261261
Frames: []*frame.Frame{
@@ -300,7 +300,7 @@ func TestReadNativeFrames(t *testing.T) {
300300
mustNewElement(tag.SamplesPerPixel, []int{2}),
301301
mustNewElement(tag.PixelRepresentation, []int{0}),
302302
}},
303-
data: []int16{1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 5},
303+
int16Data: []int16{1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 5},
304304
expectedPixelData: &PixelDataInfo{
305305
IsEncapsulated: false,
306306
Frames: []*frame.Frame{
@@ -336,7 +336,7 @@ func TestReadNativeFrames(t *testing.T) {
336336
mustNewElement(tag.SamplesPerPixel, []int{2}),
337337
mustNewElement(tag.PixelRepresentation, []int{0}),
338338
}},
339-
data: []int16{1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3},
339+
int16Data: []int16{1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3},
340340
expectedPixelData: nil,
341341
expectedError: ErrorMismatchPixelDataLength,
342342
},
@@ -350,7 +350,7 @@ func TestReadNativeFrames(t *testing.T) {
350350
mustNewElement(tag.SamplesPerPixel, []int{2}),
351351
mustNewElement(tag.PixelRepresentation, []int{0}),
352352
}},
353-
data: []int16{1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 2},
353+
int16Data: []int16{1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 2},
354354
expectedPixelData: nil,
355355
expectedError: ErrorMismatchPixelDataLength,
356356
},
@@ -364,7 +364,7 @@ func TestReadNativeFrames(t *testing.T) {
364364
mustNewElement(tag.SamplesPerPixel, []int{2}),
365365
mustNewElement(tag.PixelRepresentation, []int{0}),
366366
}},
367-
data: []int16{1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 2},
367+
int16Data: []int16{1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 2},
368368
expectedPixelData: &PixelDataInfo{
369369
ParseErr: ErrorMismatchPixelDataLength,
370370
Frames: []*frame.Frame{
@@ -387,7 +387,7 @@ func TestReadNativeFrames(t *testing.T) {
387387
mustNewElement(tag.SamplesPerPixel, []int{1}),
388388
mustNewElement(tag.PixelRepresentation, []int{0}),
389389
}},
390-
data: []int16{1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
390+
int16Data: []int16{1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
391391
expectedPixelData: nil,
392392
expectedError: ErrorElementNotFound,
393393
},
@@ -401,12 +401,12 @@ func TestReadNativeFrames(t *testing.T) {
401401
mustNewElement(tag.SamplesPerPixel, []int{1}),
402402
mustNewElement(tag.PixelRepresentation, []int{0}),
403403
}},
404-
data: []int16{1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
404+
int16Data: []int16{1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
405405
expectedPixelData: nil,
406406
expectedError: ErrorUnsupportedBitsAllocated,
407407
},
408408
{
409-
Name: "3x3, 3 frames, 1 samples/pixel, data bytes with padded 0",
409+
Name: "3x3, 3 frames, 1 samples/pixel, int16Data bytes with padded 0",
410410
existingData: Dataset{Elements: []*Element{
411411
mustNewElement(tag.Rows, []int{3}),
412412
mustNewElement(tag.Columns, []int{3}),
@@ -415,7 +415,7 @@ func TestReadNativeFrames(t *testing.T) {
415415
mustNewElement(tag.SamplesPerPixel, []int{1}),
416416
mustNewElement(tag.PixelRepresentation, []int{0}),
417417
}},
418-
dataBytes: []byte{11, 12, 13, 21, 22, 23, 31, 32, 33, 11, 12, 13, 21, 22, 23, 31, 32, 33, 11, 12, 13, 21, 22, 23, 31, 32, 33, 0}, // there is a 28th byte to make total value length even, as required by DICOM spec
418+
uint8Data: []byte{11, 12, 13, 21, 22, 23, 31, 32, 33, 11, 12, 13, 21, 22, 23, 31, 32, 33, 11, 12, 13, 21, 22, 23, 31, 32, 33, 0}, // there is a 28th byte to make total value length even, as required by DICOM spec
419419
expectedPixelData: &PixelDataInfo{
420420
IsEncapsulated: false,
421421
Frames: []*frame.Frame{
@@ -452,7 +452,7 @@ func TestReadNativeFrames(t *testing.T) {
452452
expectedError: nil,
453453
},
454454
{
455-
Name: "1x1, 3 frames, 3 samples/pixel, data bytes with padded 0",
455+
Name: "1x1, 3 frames, 3 samples/pixel, int16Data bytes with padded 0",
456456
existingData: Dataset{Elements: []*Element{
457457
mustNewElement(tag.Rows, []int{1}),
458458
mustNewElement(tag.Columns, []int{1}),
@@ -461,7 +461,7 @@ func TestReadNativeFrames(t *testing.T) {
461461
mustNewElement(tag.SamplesPerPixel, []int{3}),
462462
mustNewElement(tag.PixelRepresentation, []int{0}),
463463
}},
464-
dataBytes: []byte{1, 2, 3, 1, 2, 3, 1, 2, 3, 0}, // 10th byte to make total value length even
464+
uint8Data: []byte{1, 2, 3, 1, 2, 3, 1, 2, 3, 0}, // 10th byte to make total value length even
465465
expectedPixelData: &PixelDataInfo{
466466
IsEncapsulated: false,
467467
Frames: []*frame.Frame{
@@ -506,7 +506,7 @@ func TestReadNativeFrames(t *testing.T) {
506506
mustNewElement(tag.SamplesPerPixel, []int{3}),
507507
mustNewElement(tag.PixelRepresentation, []int{0}),
508508
}},
509-
dataBytes: []byte{1, 2, 3, 1, 2, 3},
509+
uint8Data: []byte{1, 2, 3, 1, 2, 3},
510510
expectedPixelData: nil,
511511
pixelVLOverride: 7,
512512
expectedError: ErrorExpectedEvenLength,
@@ -521,7 +521,7 @@ func TestReadNativeFrames(t *testing.T) {
521521
mustNewElement(tag.SamplesPerPixel, []int{1}),
522522
mustNewElement(tag.PixelRepresentation, []int{1}),
523523
}},
524-
dataBytes: []byte{1, 2, 3, 0},
524+
uint8Data: []byte{1, 2, 3, 0},
525525
expectedPixelData: &PixelDataInfo{
526526
IsEncapsulated: false,
527527
Frames: []*frame.Frame{
@@ -547,31 +547,31 @@ func TestReadNativeFrames(t *testing.T) {
547547
mustNewElement(tag.SamplesPerPixel, []int{1}),
548548
mustNewElement(tag.PixelRepresentation, []int{1}),
549549
}},
550-
dataBytes: []byte{0b10000001, 2, 3, 0},
550+
uint8Data: []byte{0b10000001, 2, 3, 0},
551551
expectedPixelData: nil,
552552
expectedError: ErrorSignedNativePixelDataUnsupported,
553553
},
554554
{
555555
Name: "Signed Pixel Representation with No Negative Values, uint16: No Error",
556556
existingData: Dataset{Elements: []*Element{
557-
mustNewElement(tag.Rows, []int{5}),
558-
mustNewElement(tag.Columns, []int{5}),
557+
mustNewElement(tag.Rows, []int{2}),
558+
mustNewElement(tag.Columns, []int{2}),
559559
mustNewElement(tag.NumberOfFrames, []string{"1"}),
560560
mustNewElement(tag.BitsAllocated, []int{16}),
561561
mustNewElement(tag.SamplesPerPixel, []int{1}),
562562
mustNewElement(tag.PixelRepresentation, []int{1}),
563563
}},
564-
data: []int16{1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
564+
int16Data: []int16{1, 2, 3, 4},
565565
expectedPixelData: &PixelDataInfo{
566566
IsEncapsulated: false,
567567
Frames: []*frame.Frame{
568568
{
569569
Encapsulated: false,
570570
NativeData: frame.NativeFrame{
571571
BitsPerSample: 16,
572-
Rows: 5,
573-
Cols: 5,
574-
Data: [][]int{{1}, {2}, {3}, {4}, {5}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}},
572+
Rows: 2,
573+
Cols: 2,
574+
Data: [][]int{{1}, {2}, {3}, {4}},
575575
},
576576
},
577577
},
@@ -580,14 +580,14 @@ func TestReadNativeFrames(t *testing.T) {
580580
{
581581
Name: "Signed Pixel Representation with Negative Values, uint16: Returns Error",
582582
existingData: Dataset{Elements: []*Element{
583-
mustNewElement(tag.Rows, []int{5}),
584-
mustNewElement(tag.Columns, []int{5}),
583+
mustNewElement(tag.Rows, []int{2}),
584+
mustNewElement(tag.Columns, []int{2}),
585585
mustNewElement(tag.NumberOfFrames, []string{"1"}),
586586
mustNewElement(tag.BitsAllocated, []int{16}),
587587
mustNewElement(tag.SamplesPerPixel, []int{1}),
588588
mustNewElement(tag.PixelRepresentation, []int{1}),
589589
}},
590-
data: []int16{-1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
590+
int16Data: []int16{-1, 2, 3, 4},
591591
expectedPixelData: nil,
592592
expectedError: ErrorSignedNativePixelDataUnsupported,
593593
},
@@ -599,14 +599,15 @@ func TestReadNativeFrames(t *testing.T) {
599599
var dcmdata *bytes.Buffer
600600
var expectedBytes int
601601

602-
if len(tc.data) == 0 {
602+
if len(tc.uint8Data) > 0 {
603603
// writing byte-by-byte
604-
expectedBytes = len(tc.dataBytes)
605-
dcmdata = writeIntsToBuffer(t, tc.dataBytes)
606-
} else {
604+
expectedBytes = len(tc.uint8Data)
605+
dcmdata = writeIntsToBuffer(t, tc.uint8Data)
606+
}
607+
if len(tc.int16Data) > 0 {
607608
// writing 2 bytes (uint16) at a time
608-
expectedBytes = len(tc.data) * 2
609-
dcmdata = writeIntsToBuffer(t, tc.data)
609+
expectedBytes = len(tc.int16Data) * 2
610+
dcmdata = writeIntsToBuffer(t, tc.int16Data)
610611
}
611612

612613
var vl uint32
@@ -623,14 +624,14 @@ func TestReadNativeFrames(t *testing.T) {
623624

624625
pixelData, bytesRead, err := r.readNativeFrames(&tc.existingData, nil, vl)
625626
if !errors.Is(err, tc.expectedError) {
626-
t.Errorf("TestReadNativeFrames(%v): did not get expected error. got: %v, want: %v", tc.data, err, tc.expectedError)
627+
t.Errorf("TestReadNativeFrames(%v): did not get expected error. got: %v, want: %v", tc.int16Data, err, tc.expectedError)
627628
}
628629
if err == nil && bytesRead != expectedBytes {
629-
t.Errorf("TestReadNativeFrames(%v): did not read expected number of bytes. got: %d, want: %d", tc.data, bytesRead, expectedBytes)
630+
t.Errorf("TestReadNativeFrames(%v): did not read expected number of bytes. got: %d, want: %d", tc.int16Data, bytesRead, expectedBytes)
630631
}
631632

632633
if diff := cmp.Diff(tc.expectedPixelData, pixelData, cmpopts.EquateErrors()); diff != "" {
633-
t.Errorf("TestReadNativeFrames(%v): unexpected diff: %v", tc.data, diff)
634+
t.Errorf("TestReadNativeFrames(%v): unexpected diff: %v", tc.int16Data, diff)
634635
}
635636
})
636637
}
@@ -795,9 +796,9 @@ func TestReadPixelData_SkipPixelData(t *testing.T) {
795796
}
796797
}
797798

798-
// Used to encode the data from the generated headers.
799+
// Used to encode the int16Data from the generated headers.
799800
type headerData struct {
800-
// The byte encoded header data.
801+
// The byte encoded header int16Data.
801802
HeaderBytes *bytes.Buffer
802803
// The decoded elements conforming the header.
803804
Elements []*Element
@@ -890,7 +891,7 @@ func TestReadHeader_TryAllowErrorMetaElementGroupLength(t *testing.T) {
890891
t.Run("NoFileMetaInformationGroupLength", func(t *testing.T) {
891892
dcmheaderNoInfoGrpLen, err := headerWithNoFileMetaInformationGroupLength()
892893
if err != nil {
893-
t.Fatalf("unsuccesful generation of fake header data")
894+
t.Fatalf("unsuccesful generation of fake header int16Data")
894895
} else {
895896
r := &reader{
896897
rawReader: dicomio.NewReader(bufio.NewReader(dcmheaderNoInfoGrpLen.HeaderBytes), binary.LittleEndian, int64(dcmheaderNoInfoGrpLen.HeaderBytes.Len())),
@@ -911,7 +912,7 @@ func TestReadHeader_TryAllowErrorMetaElementGroupLength(t *testing.T) {
911912
t.Run("WithFileMetaInformationGroupLength", func(t *testing.T) {
912913
dcmHeaderInfoGrpLen, err := headerWithFileMetaInformationGroupLength()
913914
if err != nil {
914-
t.Fatalf("unsuccesful generation of fake header data with FileMetaInformationGroupLength")
915+
t.Fatalf("unsuccesful generation of fake header int16Data with FileMetaInformationGroupLength")
915916
} else {
916917
r := &reader{
917918
rawReader: dicomio.NewReader(bufio.NewReader(dcmHeaderInfoGrpLen.HeaderBytes), binary.LittleEndian, int64(dcmHeaderInfoGrpLen.HeaderBytes.Len())),
@@ -1062,7 +1063,7 @@ func TestReadNativeFrames_OneBitAllocated(t *testing.T) {
10621063
}
10631064

10641065
if diff := cmp.Diff(tc.expectedPixelData, pixelData); diff != "" {
1065-
t.Errorf("TestReadNativeFrames(%v): unexpected diff: %v\ndata:%v", tc.data, diff, pixelData)
1066+
t.Errorf("TestReadNativeFrames(%v): unexpected diff: %v\nint16Data:%v", tc.data, diff, pixelData)
10661067
}
10671068
})
10681069
}

0 commit comments

Comments
 (0)