@@ -452,17 +452,22 @@ func TestGetCellImages(t *testing.T) {
452452 assert .EqualError (t , err , "XML syntax error on line 1: invalid UTF-8" )
453453 assert .NoError (t , f .Close ())
454454
455- // Test get the Microsoft 365 cell images
456- f = NewFile ()
457- assert .NoError (t , f .AddPicture ("Sheet1" , "A1" , filepath .Join ("test" , "images" , "excel.png" ), nil ))
458- f .Pkg .Store (defaultXMLMetadata , []byte (`<metadata><valueMetadata count="1"><bk><rc t="1" v="0"/></bk></valueMetadata></metadata>` ))
459- f .Pkg .Store (defaultXMLRichDataRichValueRel , []byte (`<richValueRels><rel r:id="rId1"/></richValueRels>` ))
460- f .Pkg .Store (defaultXMLRichDataRichValueRelRels , []byte (fmt .Sprintf (`<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="%s" Target="../media/image1.png"/></Relationships>` , SourceRelationshipImage )))
461- f .Sheet .Store ("xl/worksheets/sheet1.xml" , & xlsxWorksheet {
462- SheetData : xlsxSheetData {Row : []xlsxRow {
463- {R : 1 , C : []xlsxC {{R : "A1" , T : "e" , V : formulaErrorVALUE , Vm : uintPtr (1 )}}},
464- }},
465- })
455+ // Test get the cell images
456+ prepareWorkbook := func () * File {
457+ f := NewFile ()
458+ assert .NoError (t , f .AddPicture ("Sheet1" , "A1" , filepath .Join ("test" , "images" , "excel.png" ), nil ))
459+ f .Pkg .Store (defaultXMLMetadata , []byte (`<metadata><valueMetadata count="1"><bk><rc t="1" v="0"/></bk></valueMetadata></metadata>` ))
460+ f .Pkg .Store (defaultXMLRichDataRichValue , []byte (`<rvData count="1"><rv s="0"><v>0</v><v>5</v></rv></rvData>` ))
461+ f .Pkg .Store (defaultXMLRichDataRichValueRel , []byte (`<richValueRels><rel r:id="rId1"/></richValueRels>` ))
462+ f .Pkg .Store (defaultXMLRichDataRichValueRelRels , []byte (fmt .Sprintf (`<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="%s" Target="../media/image1.png"/></Relationships>` , SourceRelationshipImage )))
463+ f .Sheet .Store ("xl/worksheets/sheet1.xml" , & xlsxWorksheet {
464+ SheetData : xlsxSheetData {Row : []xlsxRow {
465+ {R : 1 , C : []xlsxC {{R : "A1" , T : "e" , V : formulaErrorVALUE , Vm : uintPtr (1 )}}},
466+ }},
467+ })
468+ return f
469+ }
470+ f = prepareWorkbook ()
466471 pics , err := f .GetPictures ("Sheet1" , "A1" )
467472 assert .NoError (t , err )
468473 assert .Equal (t , 1 , len (pics ))
@@ -471,41 +476,64 @@ func TestGetCellImages(t *testing.T) {
471476 assert .NoError (t , err )
472477 assert .Equal (t , []string {"A1" }, cells )
473478
474- // Test get the Microsoft 365 cell images without image relationships parts
479+ // Test get the cell images without image relationships parts
475480 f .Relationships .Delete (defaultXMLRichDataRichValueRelRels )
476481 f .Pkg .Store (defaultXMLRichDataRichValueRelRels , []byte (fmt .Sprintf (`<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="%s" Target="../media/image1.png"/></Relationships>` , SourceRelationshipHyperLink )))
477482 pics , err = f .GetPictures ("Sheet1" , "A1" )
478483 assert .NoError (t , err )
479484 assert .Empty (t , pics )
480- // Test get the Microsoft 365 cell images with unsupported charset rich data rich value relationships
485+ // Test get the cell images with unsupported charset rich data rich value relationships
481486 f .Relationships .Delete (defaultXMLRichDataRichValueRelRels )
482487 f .Pkg .Store (defaultXMLRichDataRichValueRelRels , MacintoshCyrillicCharset )
483488 pics , err = f .GetPictures ("Sheet1" , "A1" )
484489 assert .NoError (t , err )
485490 assert .Empty (t , pics )
486- // Test get the Microsoft 365 cell images with unsupported charset rich data rich value
491+ // Test get the cell images with unsupported charset rich data rich value
487492 f .Pkg .Store (defaultXMLRichDataRichValueRel , MacintoshCyrillicCharset )
488493 _ , err = f .GetPictures ("Sheet1" , "A1" )
489494 assert .EqualError (t , err , "XML syntax error on line 1: invalid UTF-8" )
490- // Test get the Microsoft 365 image cells without block of metadata records
495+ // Test get the image cells without block of metadata records
491496 cells , err = f .GetPictureCells ("Sheet1" )
492497 assert .EqualError (t , err , "XML syntax error on line 1: invalid UTF-8" )
493498 assert .Empty (t , cells )
494- // Test get the Microsoft 365 cell images with rich data rich value relationships
499+ // Test get the cell images with rich data rich value relationships
495500 f .Pkg .Store (defaultXMLMetadata , []byte (`<metadata><valueMetadata count="1"><bk><rc t="1" v="0"/></bk></valueMetadata></metadata>` ))
496501 f .Pkg .Store (defaultXMLRichDataRichValueRel , []byte (`<richValueRels/>` ))
497502 pics , err = f .GetPictures ("Sheet1" , "A1" )
498503 assert .NoError (t , err )
499504 assert .Empty (t , pics )
500- // Test get the Microsoft 365 cell images with unsupported charset meta data
505+ // Test get the cell images with unsupported charset meta data
501506 f .Pkg .Store (defaultXMLMetadata , MacintoshCyrillicCharset )
502507 _ , err = f .GetPictures ("Sheet1" , "A1" )
503508 assert .EqualError (t , err , "XML syntax error on line 1: invalid UTF-8" )
504- // Test get the Microsoft 365 cell images without block of metadata records
509+ // Test get the cell images without block of metadata records
505510 f .Pkg .Store (defaultXMLMetadata , []byte (`<metadata><valueMetadata/></metadata>` ))
506511 pics , err = f .GetPictures ("Sheet1" , "A1" )
507512 assert .NoError (t , err )
508513 assert .Empty (t , pics )
514+
515+ f = prepareWorkbook ()
516+ // Test get the cell images with empty image cell rich value
517+ f .Pkg .Store (defaultXMLRichDataRichValue , []byte (`<rvData count="1"><rv s="0"><v></v><v>5</v></rv></rvData>` ))
518+ pics , err = f .GetPictures ("Sheet1" , "A1" )
519+ assert .EqualError (t , err , "strconv.Atoi: parsing \" \" : invalid syntax" )
520+ assert .Empty (t , pics )
521+ // Test get the cell images without image cell rich value
522+ f .Pkg .Store (defaultXMLRichDataRichValue , []byte (`<rvData count="1"><rv s="0"><v>0</v><v>1</v></rv></rvData>` ))
523+ pics , err = f .GetPictures ("Sheet1" , "A1" )
524+ assert .NoError (t , err )
525+ assert .Empty (t , pics )
526+ // Test get the cell images with unsupported charset rich value
527+ f .Pkg .Store (defaultXMLRichDataRichValue , MacintoshCyrillicCharset )
528+ _ , err = f .GetPictures ("Sheet1" , "A1" )
529+ assert .EqualError (t , err , "XML syntax error on line 1: invalid UTF-8" )
530+
531+ f = prepareWorkbook ()
532+ // Test get the cell images with invalid rich value index
533+ f .Pkg .Store (defaultXMLMetadata , []byte (`<metadata><valueMetadata count="1"><bk><rc t="1" v="1"/></bk></valueMetadata></metadata>` ))
534+ pics , err = f .GetPictures ("Sheet1" , "A1" )
535+ assert .NoError (t , err )
536+ assert .Empty (t , pics )
509537}
510538
511539func TestGetImageCells (t * testing.T ) {
0 commit comments