-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscribus_test.go
70 lines (56 loc) · 1.81 KB
/
scribus_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package scribus
import (
"fmt"
"os"
"testing"
)
func TestReadScribusFile(t *testing.T) {
document, err := NewScribusDocumentFromFile("Document-1.sla")
if err != nil {
t.Errorf("error: %v", err)
}
// Check if we got the correct version back
if document.Version != "1.5.1.svn" {
t.Errorf("document.Version was incorrect, got: %v, want: %v.", document.Version, "1.5.1.svn")
}
}
func TestWriteScribusFile(t *testing.T) {
document, err := NewScribusDocumentFromFile("Document-1.sla")
if err != nil {
t.Errorf("error: %v", err)
}
// Make a simple text change
for _, po := range document.DOCUMENT.GetPageObjectsWithText("One") {
po.StoryText.ITEXT[0].CH = "Changed"
fmt.Println(po.StoryText.ITEXT[0].CH)
}
// Change some bullet points
for _, po := range document.DOCUMENT.GetPageObjectsWithText("Three") {
po.StoryText.ChangeBulletPoints([]string{"AAA", "BBB", "CCC"})
}
// Change a picture
for i := range document.DOCUMENT.PAGEOBJECT { // Need to use 'i' so that we can edit the original rather than a copy
if document.DOCUMENT.PAGEOBJECT[i].PTYPE == "2" { // Assuming that 2 means picture
document.DOCUMENT.PAGEOBJECT[i].PFILE = "/usr/share/icons/hicolor/16x16/apps/software-properties.png"
}
}
// Write back Scribus file
testfile := "test.sla"
err = document.WriteScribusFile(testfile)
if err != nil {
t.Errorf("error: %v", err)
}
// Test if the written file exists
if _, err := os.Stat(testfile); os.IsNotExist(err) {
t.Errorf("error: %v does not exist", testfile)
}
// Test if we can read the written file
document, err = NewScribusDocumentFromFile(testfile)
if err != nil {
t.Errorf("error: %v", err)
}
// Check if we got the correct version back
if document.Version != "1.5.1.svn" {
t.Errorf("document.Version was incorrect, got: %v, want: %v.", document.Version, "1.5.1.svn")
}
}