unipdf/internal/testutils/testutils.go

12 lines
8.8 KiB
Go
Raw Normal View History

2020-08-27 21:45:09 +00:00
//
// Copyright 2020 FoxyUtils ehf. All rights reserved.
//
// This is a commercial product and requires a license to operate.
// A trial license can be obtained at https://unidoc.io
//
// DO NOT EDIT: generated by unitwist Go source code obfuscator.
//
// Use of this source code is governed by the UniDoc End User License Agreement
// terms that can be accessed at https://unidoc.io/eula/
2021-01-26 01:31:56 +00:00
package testutils ;import (_aa "crypto/md5";_ef "encoding/hex";_bfc "errors";_bf "fmt";_bd "github.com/unidoc/unipdf/v3/common";_g "github.com/unidoc/unipdf/v3/core";_d "image";_fa "image/png";_ag "io";_ae "os";_e "os/exec";_b "path/filepath";_f "strings";_c "testing";);func CompareDictionariesDeep (d1 ,d2 *_g .PdfObjectDictionary )bool {if len (d1 .Keys ())!=len (d2 .Keys ()){_bd .Log .Debug ("\u0044\u0069\u0063\u0074\u0020\u0065\u006e\u0074\u0072\u0069\u0065\u0073\u0020\u006d\u0069s\u006da\u0074\u0063\u0068\u0020\u0028\u0025\u0064\u0020\u0021\u003d\u0020\u0025\u0064\u0029",len (d1 .Keys ()),len (d2 .Keys ()));_bd .Log .Debug ("\u0057\u0061s\u0020\u0027\u0025s\u0027\u0020\u0076\u0073\u0020\u0027\u0025\u0073\u0027",d1 .WriteString (),d2 .WriteString ());return false ;};for _ ,_dgg :=range d1 .Keys (){if _dgg =="\u0050\u0061\u0072\u0065\u006e\u0074"{continue ;};_fda :=_g .TraceToDirectObject (d1 .Get (_dgg ));_acb :=_g .TraceToDirectObject (d2 .Get (_dgg ));if _fda ==nil {_bd .Log .Debug ("\u00761\u0020\u0069\u0073\u0020\u006e\u0069l");return false ;};if _acb ==nil {_bd .Log .Debug ("\u00762\u0020\u0069\u0073\u0020\u006e\u0069l");return false ;};switch _daa :=_fda .(type ){case *_g .PdfObjectDictionary :_cba ,_edge :=_acb .(*_g .PdfObjectDictionary );if !_edge {_bd .Log .Debug ("\u0054\u0079\u0070\u0065 m\u0069\u0073\u006d\u0061\u0074\u0063\u0068\u0020\u0025\u0054\u0020\u0076\u0073\u0020%\u0054",_fda ,_acb );return false ;};if !CompareDictionariesDeep (_daa ,_cba ){return false ;};continue ;case *_g .PdfObjectArray :_dbf ,_bae :=_acb .(*_g .PdfObjectArray );if !_bae {_bd .Log .Debug ("\u00762\u0020n\u006f\u0074\u0020\u0061\u006e\u0020\u0061\u0072\u0072\u0061\u0079");return false ;};if _daa .Len ()!=_dbf .Len (){_bd .Log .Debug ("\u0061\u0072\u0072\u0061\u0079\u0020\u006c\u0065\u006e\u0067\u0074\u0068\u0020\u006d\u0069s\u006da\u0074\u0063\u0068\u0020\u0028\u0025\u0064\u0020\u0021\u003d\u0020\u0025\u0064\u0029",_daa .Len (),_dbf .Len ());return false ;};for _dca :=0;_dca < _daa .Len ();_dca ++{_bgc :=_g .TraceToDirectObject (_daa .Get (_dca ));_aba :=_g .TraceToDirectObject (_dbf .Get (_dca ));if _aed ,_ebc :=_bgc .(*_g .PdfObjectDictionary );_ebc {_dced ,_eed :=_aba .(*_g .PdfObjectDictionary );if !_eed {return false ;};if !CompareDictionariesDeep (_aed ,_dced ){return false ;};}else {if _bgc .WriteString ()!=_aba .WriteString (){_bd .Log .Debug ("M\u0069\u0073\u006d\u0061tc\u0068 \u0027\u0025\u0073\u0027\u0020!\u003d\u0020\u0027\u0025\u0073\u0027",_bgc .WriteString (),_aba .WriteString ());return false ;};};};continue ;};if _fda .String ()!=_acb .String (){_bd .Log .Debug ("\u006b\u0065y\u003d\u0025\u0073\u0020\u004d\u0069\u0073\u006d\u0061\u0074\u0063\u0068\u0021\u0020\u0027\u0025\u0073\u0027\u0020\u0021\u003d\u0020'%\u0073\u0027",_dgg ,_fda .String (),_acb .String ());_bd .Log .Debug ("\u0046o\u0072 \u0027\u0025\u0054\u0027\u0020\u002d\u0020\u0027\u0025\u0054\u0027",_fda ,_acb );_bd .Log .Debug ("\u0046\u006f\u0072\u0020\u0027\u0025\u002b\u0076\u0027\u0020\u002d\u0020'\u0025\u002b\u0076\u0027",_fda ,_acb );return false ;};};return true ;};func RunRenderTest (t *_c .T ,pdfPath ,outputDir ,baselineRenderPath string ,saveBaseline bool ){_eg :=_f .TrimSuffix (_b .Base (pdfPath ),_b .Ext (pdfPath ));t .Run ("\u0072\u0065\u006e\u0064\u0065\u0072",func (_adf *_c .T ){_fcd :=_b .Join (outputDir ,_eg );_gcd :=_fcd +"\u002d%\u0064\u002e\u0070\u006e\u0067";if _cac :=RenderPDFToPNGs (pdfPath ,0,_gcd );_cac !=nil {_adf .Skip (_cac );};for _ga :=1;true ;_ga ++{_gef :=_bf .Sprintf ("\u0025s\u002d\u0025\u0064\u002e\u0070\u006eg",_fcd ,_ga );_egf :=_b .Join (baselineRenderPath ,_bf .Sprintf ("\u0025\u0073\u002d\u0025\u0064\u005f\u0065\u0078\u0070\u002e\u0070\u006e\u0067",_eg ,_ga ));if _ ,_bc :=_ae .Stat (_gef );_bc !=nil {break ;};_adf .Logf ("\u0025\u0073",_egf );if saveBaseline {_adf .Logf ("\u0043\u006fp\u0079\u0069\u006eg\u0020\u0025\u0073\u0020\u002d\u003e\u0020\u0025\u0073",_gef ,_egf );_eac :=CopyFile (_gef ,_egf );if _eac !=nil {_adf .Fatalf ("\u0045\u0052\u0052OR\u0020\u0063\u006f\u0070\u0079\u0069\u006e\u0067\u0020\u0074\u00