Skip to content

Commit

Permalink
additional quick updates
Browse files Browse the repository at this point in the history
  • Loading branch information
suyashkumar committed Nov 6, 2023
1 parent 75727e4 commit f9d6b5f
Showing 1 changed file with 102 additions and 6 deletions.
108 changes: 102 additions & 6 deletions read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,28 +604,124 @@ func TestReadNativeFrames(t *testing.T) {
}
}

func TestReadNativeFrames_MaxUInt8PixelValue(t *testing.T) {
// This tests that reading the maximum uint8 pixel value still works, when
// PixelRepresentation is 0, mostly as a regression test.
existingDS := Dataset{Elements: []*Element{
mustNewElement(tag.Rows, []int{1}),
mustNewElement(tag.Columns, []int{1}),
mustNewElement(tag.NumberOfFrames, []string{"1"}),
mustNewElement(tag.BitsAllocated, []int{8}),
mustNewElement(tag.SamplesPerPixel, []int{1}),
mustNewElement(tag.PixelRepresentation, []int{0}),
}}
pixelData := []uint8{math.MaxUint8}
want := &PixelDataInfo{
IsEncapsulated: false,
Frames: []*frame.Frame{
{
Encapsulated: false,
NativeData: frame.NativeFrame{
BitsPerSample: 8,
Rows: 1,
Cols: 1,
Data: [][]int{{math.MaxUint8}},
},
},
},
}

dcmdata := bytes.Buffer{}
for _, item := range pixelData {
if err := binary.Write(&dcmdata, binary.LittleEndian, item); err != nil {
t.Errorf("TestReadNativeFrames: Unable to setup test buffer")
}
}

r := &reader{
rawReader: dicomio.NewReader(bufio.NewReader(&dcmdata), binary.LittleEndian, int64(dcmdata.Len())),
}

parsedPixelData, _, err := r.readNativeFrames(&existingDS, nil, uint32(dcmdata.Len()))
if err != nil {
t.Errorf("TestReadNativeFrames(): did not get expected error. got: %v, want: %v", err, nil)
}

if diff := cmp.Diff(want, parsedPixelData, cmpopts.EquateErrors()); diff != "" {
t.Errorf("TestReadNativeFrames(): unexpected diff: %v", diff)
}
}

func TestReadNativeFrames_MaxUInt16PixelValue(t *testing.T) {
// This tests that reading the maximum uint16 pixel value still works, when
// PixelRepresentation is 0, mostly as a regression test.
existingDS := Dataset{Elements: []*Element{
mustNewElement(tag.Rows, []int{5}),
mustNewElement(tag.Columns, []int{5}),
mustNewElement(tag.Rows, []int{1}),
mustNewElement(tag.Columns, []int{1}),
mustNewElement(tag.NumberOfFrames, []string{"1"}),
mustNewElement(tag.BitsAllocated, []int{16}),
mustNewElement(tag.SamplesPerPixel, []int{1}),
mustNewElement(tag.PixelRepresentation, []int{0}),
}}
pixelData := []uint16{math.MaxUint16, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
pixelData := []uint16{math.MaxUint16}
want := &PixelDataInfo{
IsEncapsulated: false,
Frames: []*frame.Frame{
{
Encapsulated: false,
NativeData: frame.NativeFrame{
BitsPerSample: 16,
Rows: 5,
Cols: 5,
Data: [][]int{{math.MaxUint16}, {2}, {3}, {4}, {5}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}},
Rows: 1,
Cols: 1,
Data: [][]int{{math.MaxUint16}},
},
},
},
}

dcmdata := bytes.Buffer{}
for _, item := range pixelData {
if err := binary.Write(&dcmdata, binary.LittleEndian, item); err != nil {
t.Errorf("TestReadNativeFrames: Unable to setup test buffer")
}
}

r := &reader{
rawReader: dicomio.NewReader(bufio.NewReader(&dcmdata), binary.LittleEndian, int64(dcmdata.Len())),
}

parsedPixelData, _, err := r.readNativeFrames(&existingDS, nil, uint32(dcmdata.Len()))
if err != nil {
t.Errorf("TestReadNativeFrames(): did not get expected error. got: %v, want: %v", err, nil)
}

if diff := cmp.Diff(want, parsedPixelData, cmpopts.EquateErrors()); diff != "" {
t.Errorf("TestReadNativeFrames(): unexpected diff: %v", diff)
}
}

func TestReadNativeFrames_MaxUInt32PixelValue(t *testing.T) {
// This tests that reading the maximum uint32 pixel value still works, when
// PixelRepresentation is 0, mostly as a regression test.
existingDS := Dataset{Elements: []*Element{
mustNewElement(tag.Rows, []int{1}),
mustNewElement(tag.Columns, []int{1}),
mustNewElement(tag.NumberOfFrames, []string{"1"}),
mustNewElement(tag.BitsAllocated, []int{32}),
mustNewElement(tag.SamplesPerPixel, []int{1}),
mustNewElement(tag.PixelRepresentation, []int{0}),
}}
pixelData := []uint32{math.MaxUint32}
want := &PixelDataInfo{
IsEncapsulated: false,
Frames: []*frame.Frame{
{
Encapsulated: false,
NativeData: frame.NativeFrame{
BitsPerSample: 32,
Rows: 1,
Cols: 1,
Data: [][]int{{math.MaxUint32}},
},
},
},
Expand Down

0 comments on commit f9d6b5f

Please sign in to comment.