Skip to content

Commit c17000c

Browse files
author
Bastien Quelen
committedFeb 11, 2017
related #15, add test from readium test suite
1 parent e8366f7 commit c17000c

File tree

4 files changed

+59
-3
lines changed

4 files changed

+59
-3
lines changed
 

‎.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "test/readium-test-files"]
2+
path = test/readium-test-files
3+
url = git@github.com:readium/readium-test-files.git

‎decoder/fonts_test.go

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package decoder
2+
3+
import (
4+
"bytes"
5+
"io/ioutil"
6+
"os"
7+
"testing"
8+
9+
"github.com/feedbooks/r2-streamer-go/models"
10+
"github.com/feedbooks/r2-streamer-go/parser"
11+
. "github.com/smartystreets/goconvey/convey"
12+
)
13+
14+
var testPublication models.Publication
15+
var testFonts []byte
16+
17+
func init() {
18+
19+
testPublication, _ = parser.Parse("../test/readium-test-files/functional/smoke-tests/SmokeTestFXL")
20+
ft, _ := os.Open("../test/readium-test-files/functional/smoke-tests/SmokeTestFXL/fonts/cut-cut.woff")
21+
testFonts, _ = ioutil.ReadAll(ft)
22+
}
23+
24+
func TestAdobeFonts(t *testing.T) {
25+
26+
f, _ := os.Open("../test/readium-test-files/functional/smoke-tests/SmokeTestFXL/fonts/cut-cut.adb.woff")
27+
28+
Convey("Given cut-cut.adb.woff fonts", t, func() {
29+
fd, _ := DecodeAdobeFont(testPublication, models.Link{}, f)
30+
buff, _ := ioutil.ReadAll(fd)
31+
Convey("The adobe fonts is deobfuscated", func() {
32+
So(bytes.Equal(buff, testFonts), ShouldBeTrue)
33+
})
34+
35+
})
36+
37+
}
38+
39+
func TestIdpfFonts(t *testing.T) {
40+
41+
f, _ := os.Open("../test/readium-test-files/functional/smoke-tests/SmokeTestFXL/fonts/cut-cut.obf.woff")
42+
43+
Convey("Given cut-cut.obf.woff fonts", t, func() {
44+
fd, _ := DecodeIdpfFont(testPublication, models.Link{}, f)
45+
buff, _ := ioutil.ReadAll(fd)
46+
Convey("The idpf fonts is deobfuscated", func() {
47+
So(bytes.Equal(buff, testFonts), ShouldBeTrue)
48+
})
49+
50+
})
51+
52+
}

‎decoder/idpf_fonts.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import (
1313
)
1414

1515
func init() {
16-
decoderList = append(decoderList, List{decoderAlgorithm: "http://www.idpf.org/2008/embedding", decoder: DecodeIpdfFont})
16+
decoderList = append(decoderList, List{decoderAlgorithm: "http://www.idpf.org/2008/embedding", decoder: DecodeIdpfFont})
1717
}
1818

19-
// DecodeIpdfFont decode obfuscate fonts using idpf spec http://www.idpf.org/epub/20/spec/FontManglingSpec.html
20-
func DecodeIpdfFont(publication models.Publication, link models.Link, reader io.ReadSeeker) (io.ReadSeeker, error) {
19+
// DecodeIdpfFont decode obfuscate fonts using idpf spec http://www.idpf.org/epub/20/spec/FontManglingSpec.html
20+
func DecodeIdpfFont(publication models.Publication, link models.Link, reader io.ReadSeeker) (io.ReadSeeker, error) {
2121
var count int
2222

2323
key := getHashKey(publication)

‎test/readium-test-files

Submodule readium-test-files added at 321967f

0 commit comments

Comments
 (0)
Please sign in to comment.