miqt/cmd/miqt-uic/uic_test.go

48 lines
1.1 KiB
Go
Raw Normal View History

2024-09-20 06:39:12 +00:00
package main
import (
"bytes"
"encoding/xml"
"io/ioutil"
"testing"
)
func TestFixtureMarshalRoundtrip(t *testing.T) {
testFixture := func(fixtureFile string) {
in, err := ioutil.ReadFile(fixtureFile)
if err != nil {
t.Fatalf("ReadFile: %v", err)
}
in = bytes.Replace(in, []byte("\r"), []byte{}, -1) // Replace CRLF to LF
var parsed UiFile
err = xml.Unmarshal(in, &parsed)
if err != nil {
t.Fatalf("Unmarshal: %v", err)
}
ret, err := xml.MarshalIndent(parsed, "", " ")
if err != nil {
t.Fatalf("Marshal: %v", err)
}
// Make some minor changes to our generated file to more closely match
// Qt Designer's generated ui file
// - Prepend XML header
// - Convert to self-closing tags
ret = []byte(xml.Header + xmlConvertToSelfClosing(string(ret)) + "\n")
// Verify that the marshalled result matches the original identically,
// i.e. we did not miss any properties in our XML type definitions
if string(in) != string(ret) {
t.Errorf("Mismatch")
t.Log(lineDiff(string(in), string(ret)))
}
}
testFixture("../../examples/uidesigner/design.ui")
2024-09-20 06:39:12 +00:00
}