@@ -452,17 +452,22 @@ func TestGetCellImages(t *testing.T) {
452
452
assert .EqualError (t , err , "XML syntax error on line 1: invalid UTF-8" )
453
453
assert .NoError (t , f .Close ())
454
454
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 ()
466
471
pics , err := f .GetPictures ("Sheet1" , "A1" )
467
472
assert .NoError (t , err )
468
473
assert .Equal (t , 1 , len (pics ))
@@ -471,41 +476,64 @@ func TestGetCellImages(t *testing.T) {
471
476
assert .NoError (t , err )
472
477
assert .Equal (t , []string {"A1" }, cells )
473
478
474
- // Test get the Microsoft 365 cell images without image relationships parts
479
+ // Test get the cell images without image relationships parts
475
480
f .Relationships .Delete (defaultXMLRichDataRichValueRelRels )
476
481
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 )))
477
482
pics , err = f .GetPictures ("Sheet1" , "A1" )
478
483
assert .NoError (t , err )
479
484
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
481
486
f .Relationships .Delete (defaultXMLRichDataRichValueRelRels )
482
487
f .Pkg .Store (defaultXMLRichDataRichValueRelRels , MacintoshCyrillicCharset )
483
488
pics , err = f .GetPictures ("Sheet1" , "A1" )
484
489
assert .NoError (t , err )
485
490
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
487
492
f .Pkg .Store (defaultXMLRichDataRichValueRel , MacintoshCyrillicCharset )
488
493
_ , err = f .GetPictures ("Sheet1" , "A1" )
489
494
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
491
496
cells , err = f .GetPictureCells ("Sheet1" )
492
497
assert .EqualError (t , err , "XML syntax error on line 1: invalid UTF-8" )
493
498
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
495
500
f .Pkg .Store (defaultXMLMetadata , []byte (`<metadata><valueMetadata count="1"><bk><rc t="1" v="0"/></bk></valueMetadata></metadata>` ))
496
501
f .Pkg .Store (defaultXMLRichDataRichValueRel , []byte (`<richValueRels/>` ))
497
502
pics , err = f .GetPictures ("Sheet1" , "A1" )
498
503
assert .NoError (t , err )
499
504
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
501
506
f .Pkg .Store (defaultXMLMetadata , MacintoshCyrillicCharset )
502
507
_ , err = f .GetPictures ("Sheet1" , "A1" )
503
508
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
505
510
f .Pkg .Store (defaultXMLMetadata , []byte (`<metadata><valueMetadata/></metadata>` ))
506
511
pics , err = f .GetPictures ("Sheet1" , "A1" )
507
512
assert .NoError (t , err )
508
513
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 )
509
537
}
510
538
511
539
func TestGetImageCells (t * testing.T ) {
0 commit comments