Skip to content

Commit

Permalink
additional updates
Browse files Browse the repository at this point in the history
  • Loading branch information
suyashkumar committed Nov 6, 2023
1 parent 8161503 commit 75727e4
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"bytes"
"encoding/binary"
"errors"
"math"
"math/rand"
"strconv"
"testing"
Expand Down Expand Up @@ -603,6 +604,54 @@ func TestReadNativeFrames(t *testing.T) {
}
}

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.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}
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}},
},
},
},
}

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 TestReadPixelData_SkipPixelData(t *testing.T) {
cases := []struct {
name string
Expand Down

0 comments on commit 75727e4

Please sign in to comment.