mirror of
https://github.com/gen2brain/cbconvert
synced 2025-10-13 18:18:52 +02:00
Add tests
This commit is contained in:
117
cbconvert_test.go
Normal file
117
cbconvert_test.go
Normal 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
BIN
testdata/test.cb7
vendored
Normal file
Binary file not shown.
BIN
testdata/test.cbr
vendored
Normal file
BIN
testdata/test.cbr
vendored
Normal file
Binary file not shown.
BIN
testdata/test.cbt
vendored
Normal file
BIN
testdata/test.cbt
vendored
Normal file
Binary file not shown.
BIN
testdata/test.cbz
vendored
Normal file
BIN
testdata/test.cbz
vendored
Normal file
Binary file not shown.
BIN
testdata/test.epub
vendored
Normal file
BIN
testdata/test.epub
vendored
Normal file
Binary file not shown.
BIN
testdata/test.pdf
vendored
Normal file
BIN
testdata/test.pdf
vendored
Normal file
Binary file not shown.
BIN
testdata/test/00.jpg
vendored
Normal file
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
BIN
testdata/test/01.jpg
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 387 KiB |
Reference in New Issue
Block a user