From ac564afa56a691e378ab9bb04cb14bb283886a16 Mon Sep 17 00:00:00 2001 From: xuri Date: Sun, 13 Nov 2022 00:40:04 +0800 Subject: Remove internal error log print, throw XML deserialize error --- picture_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'picture_test.go') diff --git a/picture_test.go b/picture_test.go index 65abf9e..11196c6 100644 --- a/picture_test.go +++ b/picture_test.go @@ -67,6 +67,12 @@ func TestAddPicture(t *testing.T) { // Test write file to given path. assert.NoError(t, f.SaveAs(filepath.Join("test", "TestAddPicture1.xlsx"))) assert.NoError(t, f.Close()) + + // Test add picture with unsupported charset content types. + f = NewFile() + f.ContentTypes = nil + f.Pkg.Store(defaultXMLPathContentTypes, MacintoshCyrillicCharset) + assert.EqualError(t, f.AddPictureFromBytes("Sheet1", "Q1", "", "Excel Logo", ".png", file), "XML syntax error on line 1: invalid UTF-8") } func TestAddPictureErrors(t *testing.T) { @@ -236,3 +242,27 @@ func TestDrawingResize(t *testing.T) { ws.(*xlsxWorksheet).MergeCells = &xlsxMergeCells{Cells: []*xlsxMergeCell{{Ref: "A:A"}}} assert.EqualError(t, f.AddPicture("Sheet1", "A1", filepath.Join("test", "images", "excel.jpg"), `{"autofit": true}`), newCellNameToCoordinatesError("A", newInvalidCellNameError("A")).Error()) } + +func TestSetContentTypePartImageExtensions(t *testing.T) { + f := NewFile() + // Test set content type part image extensions with unsupported charset content types. + f.ContentTypes = nil + f.Pkg.Store(defaultXMLPathContentTypes, MacintoshCyrillicCharset) + assert.EqualError(t, f.setContentTypePartImageExtensions(), "XML syntax error on line 1: invalid UTF-8") +} + +func TestSetContentTypePartVMLExtensions(t *testing.T) { + f := NewFile() + // Test set content type part VML extensions with unsupported charset content types. + f.ContentTypes = nil + f.Pkg.Store(defaultXMLPathContentTypes, MacintoshCyrillicCharset) + assert.EqualError(t, f.setContentTypePartVMLExtensions(), "XML syntax error on line 1: invalid UTF-8") +} + +func TestAddContentTypePart(t *testing.T) { + f := NewFile() + // Test add content type part with unsupported charset content types. + f.ContentTypes = nil + f.Pkg.Store(defaultXMLPathContentTypes, MacintoshCyrillicCharset) + assert.EqualError(t, f.addContentTypePart(0, "unknown"), "XML syntax error on line 1: invalid UTF-8") +} -- cgit v1.2.1