Skip to content

Commit

Permalink
some updates
Browse files Browse the repository at this point in the history
  • Loading branch information
suyashkumar committed Nov 6, 2023
1 parent f9d6b5f commit 5263e25
Showing 1 changed file with 26 additions and 62 deletions.
88 changes: 26 additions & 62 deletions read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,25 +556,17 @@ func TestReadNativeFrames(t *testing.T) {
for _, tc := range cases {
tc := tc
t.Run(tc.Name, func(t *testing.T) {
dcmdata := bytes.Buffer{}
var dcmdata *bytes.Buffer
var expectedBytes int

if len(tc.data) == 0 {
// writing byte-by-byte
expectedBytes = len(tc.dataBytes)
for _, item := range tc.dataBytes {
if err := binary.Write(&dcmdata, binary.LittleEndian, item); err != nil {
t.Errorf("TestReadNativeFrames: Unable to setup test buffer")
}
}
dcmdata = writeIntsToBuffer(t, tc.dataBytes)
} else {
// writing 2 bytes (uint16) at a time
expectedBytes = len(tc.data) * 2
for _, item := range tc.data {
if err := binary.Write(&dcmdata, binary.LittleEndian, item); err != nil {
t.Errorf("TestReadNativeFrames: Unable to setup test buffer")
}
}
dcmdata = writeIntsToBuffer(t, tc.data)
}

var vl uint32
Expand All @@ -585,7 +577,7 @@ func TestReadNativeFrames(t *testing.T) {
}

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

Expand Down Expand Up @@ -631,25 +623,8 @@ func TestReadNativeFrames_MaxUInt8PixelValue(t *testing.T) {
},
}

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)
}
dcmdata := writeIntsToBuffer(t, pixelData)
testReadNativeFramesBody(t, dcmdata, &existingDS, want)
}

func TestReadNativeFrames_MaxUInt16PixelValue(t *testing.T) {
Expand Down Expand Up @@ -678,26 +653,8 @@ func TestReadNativeFrames_MaxUInt16PixelValue(t *testing.T) {
},
},
}

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)
}
dcmdata := writeIntsToBuffer(t, pixelData)
testReadNativeFramesBody(t, dcmdata, &existingDS, want)
}

func TestReadNativeFrames_MaxUInt32PixelValue(t *testing.T) {
Expand Down Expand Up @@ -727,27 +684,34 @@ func TestReadNativeFrames_MaxUInt32PixelValue(t *testing.T) {
},
}

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")
}
}
dcmdata := writeIntsToBuffer(t, pixelData)
testReadNativeFramesBody(t, dcmdata, &existingDS, want)
}

r := &reader{
rawReader: dicomio.NewReader(bufio.NewReader(&dcmdata), binary.LittleEndian, int64(dcmdata.Len())),
}
func testReadNativeFramesBody(t *testing.T, dcmdata *bytes.Buffer, existingDS *Dataset, wantPixelData *PixelDataInfo) {
r := &reader{rawReader: dicomio.NewReader(bufio.NewReader(dcmdata), binary.LittleEndian, int64(dcmdata.Len()))}

parsedPixelData, _, err := r.readNativeFrames(&existingDS, nil, uint32(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 != "" {
if diff := cmp.Diff(wantPixelData, parsedPixelData, cmpopts.EquateErrors()); diff != "" {
t.Errorf("TestReadNativeFrames(): unexpected diff: %v", diff)
}
}

func writeIntsToBuffer[T any](t *testing.T, ints []T) *bytes.Buffer {
t.Helper()
dcmdata := &bytes.Buffer{}
for _, item := range ints {
if err := binary.Write(dcmdata, binary.LittleEndian, item); err != nil {
t.Errorf("unable to setup test buffer")
}
}
return dcmdata
}

func TestReadPixelData_SkipPixelData(t *testing.T) {
cases := []struct {
name string
Expand Down

0 comments on commit 5263e25

Please sign in to comment.