mirror of
https://github.com/unidoc/unioffice.git
synced 2025-04-27 13:48:54 +08:00
common: add core properties tests
This commit is contained in:
parent
cb06f7b80a
commit
a54e7275e4
@ -163,5 +163,5 @@ func (c CoreProperties) SetDescription(s string) {
|
||||
if c.x.Description == nil {
|
||||
c.x.Description = &gooxml.XSDAny{XMLName: xml.Name{Local: "dc:description"}}
|
||||
}
|
||||
c.x.Title.Data = []byte(s)
|
||||
c.x.Description.Data = []byte(s)
|
||||
}
|
||||
|
@ -34,6 +34,75 @@ func TestMarshalCoreProperties(t *testing.T) {
|
||||
testhelper.CompareGoldenXML(t, "core.xml", got.Bytes())
|
||||
}
|
||||
|
||||
func TestCorePropertiesSettersStrings(t *testing.T) {
|
||||
cp := common.NewCoreProperties()
|
||||
exp := "Foo"
|
||||
|
||||
if got := cp.Author(); got != "" {
|
||||
t.Errorf("expected empty author, got %s", got)
|
||||
}
|
||||
if got := cp.Title(); got != "" {
|
||||
t.Errorf("expected empty title, got %s", got)
|
||||
}
|
||||
if got := cp.Description(); got != "" {
|
||||
t.Errorf("expected empty description, got %s", got)
|
||||
}
|
||||
if got := cp.Category(); got != "" {
|
||||
t.Errorf("expected empty category, got %s", got)
|
||||
}
|
||||
if got := cp.ContentStatus(); got != "" {
|
||||
t.Errorf("expected empty contentStatus, got %s", got)
|
||||
}
|
||||
if got := cp.LastModifiedBy(); got != "" {
|
||||
t.Errorf("expected empty lastModifiedBy, got %s", got)
|
||||
}
|
||||
cp.SetAuthor(exp)
|
||||
if got := cp.Author(); got != exp {
|
||||
t.Errorf("expected author=%s, got %s", exp, got)
|
||||
}
|
||||
cp.SetTitle(exp)
|
||||
if got := cp.Title(); got != exp {
|
||||
t.Errorf("expected title=%s, got %s", exp, got)
|
||||
}
|
||||
cp.SetDescription(exp)
|
||||
if got := cp.Description(); got != exp {
|
||||
t.Errorf("expected description=%s, got %s", exp, got)
|
||||
}
|
||||
cp.SetCategory(exp)
|
||||
if got := cp.Category(); got != exp {
|
||||
t.Errorf("expected category=%s, got %s", exp, got)
|
||||
}
|
||||
cp.SetContentStatus(exp)
|
||||
if got := cp.ContentStatus(); got != exp {
|
||||
t.Errorf("expected contentStatus=%s, got %s", exp, got)
|
||||
}
|
||||
cp.SetLastModifiedBy(exp)
|
||||
if got := cp.LastModifiedBy(); got != exp {
|
||||
t.Errorf("expected lastModifiedBy=%s, got %s", exp, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCorePropertiesSettersDates(t *testing.T) {
|
||||
cp := common.NewCoreProperties()
|
||||
exp := time.Date(2017, 1, 2, 3, 4, 5, 0, time.UTC)
|
||||
if !cp.Created().IsZero() {
|
||||
t.Errorf("expected zero created time, got %v", exp)
|
||||
}
|
||||
if !cp.Modified().IsZero() {
|
||||
t.Errorf("expected zero Modified time, got %v", exp)
|
||||
}
|
||||
|
||||
cp.SetCreated(exp)
|
||||
if got := cp.Created(); got != exp {
|
||||
t.Errorf("expected created =%v, got %v", exp, got)
|
||||
}
|
||||
|
||||
cp.SetModified(exp)
|
||||
if got := cp.Modified(); got != exp {
|
||||
t.Errorf("expected modified =%v, got %v", exp, got)
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleCoreProperties() {
|
||||
doc, _ := document.Open("document.docx")
|
||||
cp := doc.CoreProperties
|
||||
|
BIN
document/testdata/header-footer-multiple.docx
vendored
BIN
document/testdata/header-footer-multiple.docx
vendored
Binary file not shown.
BIN
document/testdata/simple-1.docx
vendored
BIN
document/testdata/simple-1.docx
vendored
Binary file not shown.
BIN
spreadsheet/testdata/simple-1.xlsx
vendored
BIN
spreadsheet/testdata/simple-1.xlsx
vendored
Binary file not shown.
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
PKG=baliance.com/gooxml
|
||||
ALLPKGS=`go list $PKG/...`
|
||||
ALLPKGS=`go list $PKG/... | grep -iv schema`
|
||||
|
||||
cd $GOPATH/src/$PKG
|
||||
echo "Prebuilding"
|
||||
|
Loading…
x
Reference in New Issue
Block a user