common: add core properties tests

This commit is contained in:
Todd 2017-09-02 14:05:16 -05:00
parent cb06f7b80a
commit a54e7275e4
6 changed files with 71 additions and 2 deletions

View File

@ -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)
}

View File

@ -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

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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"