1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-06-09 17:30:43 +00:00
OpenDiablo2/d2common/d2fileformats/d2cof/cof_test.go
gravestench 248eaf9d79 Minor refactor of d2cof
* Changed `Load` to `Unmarshal`
* made `Marshal` and `Unmarshal` into methods of `COF`
* added `New` function which creates a new, empty COF instance
* added helper functions `Marshal` and `Unmarshal`
* Changed `StreamReader.ReadBytes` to account for edge case of reading 0
bytes (this was returning an error when it should not have)
* added really simple unit tests for COF
2021-02-05 14:43:42 -08:00

36 lines
522 B
Go

package d2cof
import "testing"
func TestCOF_New(t *testing.T) {
c := New()
if c == nil {
t.Error("method New created nil instance")
}
}
func TestCOF_Marshal_Unmarshal(t *testing.T) {
cof1 := New()
cof2 := New()
var err error
err = cof1.Unmarshal(make([]byte, 1000))
if err != nil {
t.Error(err)
}
cof1.Speed = 255
data1 := cof1.Marshal()
err = cof2.Unmarshal(data1)
if err != nil {
t.Error(err)
}
if cof2.Speed != cof1.Speed {
t.Error("marshaled data does not match unmarshaled data")
}
}