@@ -8,12 +8,14 @@ import (
88 "encoding/xml"
99 "errors"
1010 "image/color"
11+ "path/filepath"
1112 "reflect"
1213 "strconv"
1314 "testing"
1415
1516 "github.com/go-test/deep"
1617 "github.com/hpinc/go3mf/spec"
18+ "github.com/hpinc/go3mf/utils"
1719 "github.com/stretchr/testify/mock"
1820)
1921
@@ -309,3 +311,62 @@ func TestEncoder_Encode_Roundtrip(t *testing.T) {
309311 })
310312 }
311313}
314+
315+ func TestEncoder_Relationship (t * testing.T ) {
316+ type request struct {
317+ fileName string
318+ }
319+ type response struct {
320+ relationships []Relationship
321+ }
322+
323+ tests := []struct {
324+ name string
325+ request request
326+ response response
327+ }{ /*Verfy if a file rels is not update in case of relationship exists*/
328+ {"file_with_texture_rel_but_no_texture" ,
329+ request {fileName : "super_boogoku_tiny.3mf" },
330+ response {relationships : []Relationship {
331+ {ID : "rel2" , Type : "http://schemas.microsoft.com/3dmanufacturing/2013/01/3dtexture" , Path : "/Thumbnails/super_boo.png" },
332+ {ID : "rel3" , Type : "http://schemas.microsoft.com/3dmanufacturing/2013/01/3dtexture" , Path : "/Thumbnails/goku_ss.png" },
333+ }},
334+ },
335+ }
336+ for _ , tt := range tests {
337+ t .Run (tt .name , func (t * testing.T ) {
338+ utils .WithProjectDirAndTestTempDirRemoveAtEnd (
339+ filepath .Join ("testdata" ), func (testFileDir string , testTempDir string ) {
340+ testFile := filepath .Join (testFileDir , tt .request .fileName )
341+ outputFile := filepath .Join (testTempDir , "SW3DBUG-2700_changed.3mf" )
342+ var model Model
343+ r , err := OpenReader (testFile )
344+ if err != nil {
345+ t .Errorf ("TestEncoder_Relationship() error = %v" , err )
346+ }
347+ r .Decode (& model )
348+ defer r .Close ()
349+ w , err := CreateWriter (outputFile )
350+ if err != nil {
351+ t .Errorf ("TestEncoder_Relationship() error = %v" , err )
352+ }
353+ w .Encode (& model )
354+ defer w .Close ()
355+
356+ var modelUpdated Model
357+ r , err = OpenReader (outputFile )
358+ if err != nil {
359+ t .Errorf ("TestEncoder_Relationship() error = %v" , err )
360+ }
361+ r .Decode (& modelUpdated )
362+ defer r .Close ()
363+
364+ if diff := deep .Equal (modelUpdated .Relationships , tt .response .relationships ); diff != nil {
365+ t .Errorf ("TestEncoder_Relationship() = %v" , diff )
366+ }
367+ })
368+
369+ })
370+ }
371+
372+ }
0 commit comments