tests fixed

This commit is contained in:
Vyacheslav Zgordan 2020-07-16 08:56:36 +03:00
parent 4fa52f56dc
commit ff0e0fd082
2 changed files with 26 additions and 24 deletions

View File

@ -19,11 +19,13 @@ type CustomProperties struct {
x *custom_properties.Properties
}
// CustomProperty contains document specific property.
// Using of this type is deprecated.
type CustomProperty struct {
x *custom_properties.CT_Property
}
// X returns the inner wrapped XML type of CustomProperty.
func (c CustomProperty) X() *custom_properties.CT_Property {
return c.x
}
@ -48,7 +50,7 @@ func (c CustomProperties) GetPropertyByName(name string) CustomProperty {
propsList := c.x.Property
for _, property := range propsList {
if *property.NameAttr == name {
return CustomProperty{property}
return CustomProperty{x: property}
}
}
return CustomProperty{}

View File

@ -43,7 +43,7 @@ func TestCustomPropertiesNew(t *testing.T) {
t.Errorf("expected empty properties list, got %d elements", len(got))
}
if got := cp.GetPropertyByName(expName); got != nil {
if got := cp.GetPropertyByName(expName); got.X() != nil {
t.Errorf("expected nil Foo property, got %p", got)
}
}
@ -54,57 +54,57 @@ func TestCustomPropertiesSettersStrings(t *testing.T) {
expValue := "Bar"
cp.SetPropertyAsLpstr(expName, expValue)
if got := cp.GetPropertyByName(expName); *got.Lpstr != expValue {
if got := cp.GetPropertyByName(expName).X(); *got.Lpstr != expValue {
t.Errorf("expected value of %s=%s, got %s", expName, expValue, *got.Lpstr)
}
cp.SetPropertyAsLpwstr(expName, expValue)
if got := cp.GetPropertyByName(expName); *got.Lpwstr != expValue {
if got := cp.GetPropertyByName(expName).X(); *got.Lpwstr != expValue {
t.Errorf("expected value of %s=%s, got %s", expName, expValue, *got.Lpwstr)
}
cp.SetPropertyAsBlob(expName, expValue)
if got := cp.GetPropertyByName(expName); *got.Blob != expValue {
if got := cp.GetPropertyByName(expName).X(); *got.Blob != expValue {
t.Errorf("expected value of %s=%s, got %s", expName, expValue, *got.Blob)
}
cp.SetPropertyAsOblob(expName, expValue)
if got := cp.GetPropertyByName(expName); *got.Oblob != expValue {
if got := cp.GetPropertyByName(expName).X(); *got.Oblob != expValue {
t.Errorf("expected value of %s=%s, got %s", expName, expValue, *got.Oblob)
}
cp.SetPropertyAsStream(expName, expValue)
if got := cp.GetPropertyByName(expName); *got.Stream != expValue {
if got := cp.GetPropertyByName(expName).X(); *got.Stream != expValue {
t.Errorf("expected value of %s=%s, got %s", expName, expValue, *got.Stream)
}
cp.SetPropertyAsOstream(expName, expValue)
if got := cp.GetPropertyByName(expName); *got.Ostream != expValue {
if got := cp.GetPropertyByName(expName).X(); *got.Ostream != expValue {
t.Errorf("expected value of %s=%s, got %s", expName, expValue, *got.Ostream)
}
cp.SetPropertyAsStorage(expName, expValue)
if got := cp.GetPropertyByName(expName); *got.Storage != expValue {
if got := cp.GetPropertyByName(expName).X(); *got.Storage != expValue {
t.Errorf("expected value of %s=%s, got %s", expName, expValue, *got.Storage)
}
cp.SetPropertyAsOstorage(expName, expValue)
if got := cp.GetPropertyByName(expName); *got.Ostorage != expValue {
if got := cp.GetPropertyByName(expName).X(); *got.Ostorage != expValue {
t.Errorf("expected value of %s=%s, got %s", expName, expValue, *got.Ostorage)
}
cp.SetPropertyAsClsid(expName, expValue)
if got := cp.GetPropertyByName(expName); *got.Clsid != expValue {
if got := cp.GetPropertyByName(expName).X(); *got.Clsid != expValue {
t.Errorf("expected value of %s=%s, got %s", expName, expValue, *got.Clsid)
}
cp.SetPropertyAsCy(expName, expValue)
if got := cp.GetPropertyByName(expName); *got.Cy != expValue {
if got := cp.GetPropertyByName(expName).X(); *got.Cy != expValue {
t.Errorf("expected value of %s=%s, got %s", expName, expValue, *got.Cy)
}
cp.SetPropertyAsError(expName, expValue)
if got := cp.GetPropertyByName(expName); *got.Error != expValue {
if got := cp.GetPropertyByName(expName).X(); *got.Error != expValue {
t.Errorf("expected value of %s=%s, got %s", expName, expValue, *got.Error)
}
}
@ -118,22 +118,22 @@ func TestCustomPropertiesSettersNumbers(t *testing.T) {
expFloat32 := float32(3.14)
cp.SetPropertyAsInt(expName, expInt)
if got := cp.GetPropertyByName(expName); *got.Int != int32(expInt) {
if got := cp.GetPropertyByName(expName).X(); *got.Int != int32(expInt) {
t.Errorf("expected value of %s=%v, got %v", expName, expInt, *got.Int)
}
cp.SetPropertyAsI8(expName, expInt64)
if got := cp.GetPropertyByName(expName); *got.I8 != expInt64 {
if got := cp.GetPropertyByName(expName).X(); *got.I8 != expInt64 {
t.Errorf("expected value of %s=%v, got %v", expName, expInt64, *got.I8)
}
cp.SetPropertyAsR4(expName, expFloat32)
if got := cp.GetPropertyByName(expName); *got.R4 != expFloat32 {
if got := cp.GetPropertyByName(expName).X(); *got.R4 != expFloat32 {
t.Errorf("expected value of %s=%v, got %v", expName, expFloat32, *got.R4)
}
cp.SetPropertyAsDecimal(expName, expFloat64)
if got := cp.GetPropertyByName(expName); *got.Decimal != expFloat64 {
if got := cp.GetPropertyByName(expName).X(); *got.Decimal != expFloat64 {
t.Errorf("expected value of %s=%v, got %v", expName, expFloat64, *got.Decimal)
}
}
@ -144,12 +144,12 @@ func TestCustomPropertiesSettersDates(t *testing.T) {
expValue := time.Date(2017, 1, 2, 3, 4, 5, 0, time.UTC)
cp.SetPropertyAsDate(expName, expValue)
if got := cp.GetPropertyByName(expName); *got.Date != expValue {
if got := cp.GetPropertyByName(expName).X(); *got.Date != expValue {
t.Errorf("expected created =%v, got %v", expValue, *got.Date)
}
cp.SetPropertyAsFiletime(expName, expValue)
if got := cp.GetPropertyByName(expName); *got.Filetime != expValue {
if got := cp.GetPropertyByName(expName).X(); *got.Filetime != expValue {
t.Errorf("expected created =%v, got %v", expValue, *got.Filetime)
}
}
@ -163,7 +163,7 @@ func TestCustomPropertiesSettersVstream(t *testing.T) {
newVstream.Content = "c1"
cp.SetPropertyAsVstream(expName, newVstream)
if got := cp.GetPropertyByName(expName); *got.Vstream != *newVstream {
if got := cp.GetPropertyByName(expName).X(); *got.Vstream != *newVstream {
t.Errorf("expected created =%v, got %v", *newVstream, *got.Vstream)
}
}
@ -174,10 +174,10 @@ func ExampleCustomProperties() {
cp := doc.CustomProperties
// You can read properties from the document
fmt.Println("AppVersion", *cp.GetPropertyByName("AppVersion").Lpwstr)
fmt.Println("category", *cp.GetPropertyByName("category").Lpwstr)
fmt.Println("contentStatus", *cp.GetPropertyByName("contentStatus").Lpwstr)
fmt.Println("HyperlinksChanged", *cp.GetPropertyByName("HyperlinksChanged").Bool)
fmt.Println("AppVersion", *cp.GetPropertyByName("AppVersion").X().Lpwstr)
fmt.Println("category", *cp.GetPropertyByName("category").X().Lpwstr)
fmt.Println("contentStatus", *cp.GetPropertyByName("contentStatus").X().Lpwstr)
fmt.Println("HyperlinksChanged", *cp.GetPropertyByName("HyperlinksChanged").X().Bool)
fmt.Println("Non-existent", cp.GetPropertyByName("nonexistentproperty"))
// And change them as well