Add tests

This commit is contained in:
Milan Nikolic
2023-09-02 12:11:09 +02:00
parent 6c293adc1f
commit aa65bfa4f4
9 changed files with 117 additions and 0 deletions

117
cbconvert_test.go Normal file
View File

@@ -0,0 +1,117 @@
package cbconvert
import (
"fmt"
"os"
"path/filepath"
"testing"
)
func TestConvert(t *testing.T) {
tmpDir, err := os.MkdirTemp(os.TempDir(), "cbc")
if err != nil {
t.Error(err)
}
opts := Options{}
opts.OutDir = tmpDir
opts.Archive = "zip"
opts.Quality = 75
opts.Filter = 2
conv := New(opts)
conv.Initialize()
defer conv.Terminate()
files, err := conv.Files([]string{"testdata/test", "testdata"})
if err != nil {
t.Error(err)
}
for _, format := range []string{"jpeg", "png", "tiff", "bmp", "webp", "avif"} {
conv.Opts.Format = format
for _, file := range files {
conv.Opts.Suffix = fmt.Sprintf("_%s%s", format, filepath.Ext(file.Path))
err = conv.Convert(file.Path, file.Stat)
if err != nil {
t.Errorf("format %s: file %s: %v", format, file.Name, err)
}
}
}
err = os.RemoveAll(tmpDir)
if err != nil {
t.Error(err)
}
}
func TestCover(t *testing.T) {
tmpDir, err := os.MkdirTemp(os.TempDir(), "cbc")
if err != nil {
t.Error(err)
}
opts := Options{}
opts.OutDir = tmpDir
opts.Quality = 75
opts.Filter = 2
opts.Format = "jpeg"
conv := New(opts)
conv.Initialize()
defer conv.Terminate()
files, err := conv.Files([]string{"testdata/test.cbt"})
if err != nil {
t.Error(err)
}
for _, file := range files {
err = conv.Cover(file.Path, file.Stat)
if err != nil {
t.Error(err)
}
}
err = os.RemoveAll(tmpDir)
if err != nil {
t.Error(err)
}
}
func TestThumbnail(t *testing.T) {
tmpDir, err := os.MkdirTemp(os.TempDir(), "cbc")
if err != nil {
t.Error(err)
}
opts := Options{}
opts.OutDir = tmpDir
opts.Filter = 2
conv := New(opts)
conv.Initialize()
defer conv.Terminate()
files, err := conv.Files([]string{"testdata/test.pdf"})
if err != nil {
t.Error(err)
}
for _, file := range files {
err = conv.Thumbnail(file.Path, file.Stat)
if err != nil {
t.Error(err)
}
}
err = os.RemoveAll(tmpDir)
if err != nil {
t.Error(err)
}
}

BIN
testdata/test.cb7 vendored Normal file

Binary file not shown.

BIN
testdata/test.cbr vendored Normal file

Binary file not shown.

BIN
testdata/test.cbt vendored Normal file

Binary file not shown.

BIN
testdata/test.cbz vendored Normal file

Binary file not shown.

BIN
testdata/test.epub vendored Normal file

Binary file not shown.

BIN
testdata/test.pdf vendored Normal file

Binary file not shown.

BIN
testdata/test/00.jpg vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 229 KiB

BIN
testdata/test/01.jpg vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 387 KiB