-
Notifications
You must be signed in to change notification settings - Fork 2
/
filePreview_test.go
62 lines (56 loc) · 1.79 KB
/
filePreview_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package ff9Save
import (
"bytes"
"encoding/json"
"io/ioutil"
"testing"
)
func TestFilePreviewBinaryMarshaler(t *testing.T) {
var filePreview FilePreview
filePreviewJsonBytes, err := ioutil.ReadFile("testdata/filePreview.json")
if err != nil {
t.FailNow()
}
if err := json.Unmarshal(filePreviewJsonBytes, &filePreview); err != nil{
t.FailNow()
}
filePreviewBinBytes, err := filePreview.BinaryMarshaler()
if err != nil{
t.FailNow()
}
if len(filePreviewBinBytes) != FilePreviewSize {
t.Error("Binary generated from Json is too small")
}
/*if !bytes.Equal(fileBinBytes, fileOrigBinBytes) {
t.Error("Binary generated from JSON does not match the original Binary")
}*/
}
func TestFilePreviewEmptyBinaryMarshaler(t *testing.T) {
var filePreview FilePreview
filePreviewBinBytes, err := filePreview.BinaryMarshaler()
if err != nil{
t.FailNow()
}
if len(filePreviewBinBytes) != FilePreviewSize {
t.Error("Binary generated from Json is too small")
}
if !bytes.Equal(filePreviewBinBytes[:4], NoneHeader[:]) {
t.Error("File Preview does not start with NONE invalid empty save preview")
}
}
func TestFilePreviewFixCharacterInfoFromBinary(t *testing.T) {
var filePreview FilePreview
filePreview.CharacterInfoList[0].SerialID = -1
filePreview.CharacterInfoList[0].Level = -1
filePreview.FixCharacterInfoFromBinary()
if filePreview.CharacterInfoList[0].SerialID != 0 || filePreview.CharacterInfoList[0].Level != 0 {
t.Error("Empty character info incorrect converted from binary")
}
}
func TestFilePreview_FixCharacterInfoForBinary(t *testing.T) {
var filePreview FilePreview
filePreview.FixCharacterInfoForBinary()
if filePreview.CharacterInfoList[0].SerialID != -1 || filePreview.CharacterInfoList[0].Level != -1 {
t.Error("Empty character info incorrect converted from binary")
}
}