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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
package gui
import (
"io/ioutil"
"os"
"github.com/twstrike/gotk3adapter/gtk_mock"
"github.com/twstrike/gotk3adapter/gtki"
. "gopkg.in/check.v1"
)
type UIReaderSuite struct{}
var _ = Suite(&UIReaderSuite{})
const testFile string = `
<interface>
<object class="GtkWindow" id="conversation">
<property name="default-height">600</property>
<property name="default-width">500</property>
<child>
<object class="GtkVBox" id="vbox"></object>
</child>
</object>
</interface>
`
func writeTestFile(name, content string) {
ioutil.WriteFile(name, []byte(content), 0700)
}
func removeFile(name string) {
os.Remove(name)
}
type mockBuilder struct {
gtk_mock.MockBuilder
stringGiven string
}
func (v *mockBuilder) AddFromString(v1 string) error {
v.stringGiven = v1
return nil
}
type mockWithBuilder struct {
gtk_mock.Mock
}
func (*mockWithBuilder) BuilderNew() (gtki.Builder, error) {
return &mockBuilder{}, nil
}
func (s *UIReaderSuite) Test_builderForDefinition_useXMLIfExists(c *C) {
g = Graphics{gtk: &mockWithBuilder{}}
removeFile(getActualDefsFolder() + "/Test.xml")
writeTestFile(getActualDefsFolder()+"/Test.xml", testFile)
ui := "Test"
builder := builderForDefinition(ui)
str := builder.(*mockBuilder).stringGiven
c.Assert(str, Equals, testFile)
}
func (s *UIReaderSuite) Test_builderForDefinition_useGoFileIfXMLDoesntExists(c *C) {
g = Graphics{gtk: &mockWithBuilder{}}
removeFile(getActualDefsFolder() + "/Test.xml")
ui := "Test"
builder := builderForDefinition(ui)
str := builder.(*mockBuilder).stringGiven
c.Assert(str, Equals, testFile)
}
func (s *UIReaderSuite) Test_builderForDefinition_shouldReturnErrorWhenDefinitionDoesntExist(c *C) {
ui := "nonexistent"
c.Assert(func() {
builderForDefinition(ui)
}, Panics, "No definition found for nonexistent")
}
|