mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-11-05 09:47:18 -05:00
248eaf9d79
* 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
36 lines
522 B
Go
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")
|
|
}
|
|
}
|