2019-01-05 23:35:20 +03:00
|
|
|
package mapblockparser
|
|
|
|
|
|
|
|
import (
|
2019-01-07 21:53:05 +03:00
|
|
|
"fmt"
|
2019-01-05 23:35:20 +03:00
|
|
|
"io/ioutil"
|
2019-01-21 15:45:35 +03:00
|
|
|
"mapserver/coords"
|
2019-01-23 10:02:59 +03:00
|
|
|
"encoding/json"
|
2019-01-05 23:35:20 +03:00
|
|
|
"strconv"
|
2019-01-07 21:38:53 +03:00
|
|
|
"testing"
|
2019-01-05 23:35:20 +03:00
|
|
|
)
|
|
|
|
|
2019-01-07 21:38:53 +03:00
|
|
|
func TestReadU16(t *testing.T) {
|
2019-01-07 18:06:03 +03:00
|
|
|
v := readU16([]byte{0x00, 0x00}, 0)
|
|
|
|
if v != 0 {
|
|
|
|
t.Error(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
v = readU16([]byte{0x00, 0x01}, 0)
|
|
|
|
if v != 1 {
|
|
|
|
t.Error(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
v = readU16([]byte{0x01, 0x00}, 0)
|
|
|
|
if v != 256 {
|
|
|
|
t.Error(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-01-07 21:38:53 +03:00
|
|
|
func TestReadU32(t *testing.T) {
|
2019-01-07 18:06:03 +03:00
|
|
|
v := readU32([]byte{0x00, 0x00, 0x00, 0x00}, 0)
|
|
|
|
if v != 0 {
|
|
|
|
t.Error(v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-07 21:38:53 +03:00
|
|
|
func TestParse(t *testing.T) {
|
2019-01-06 23:00:24 +03:00
|
|
|
|
2019-01-05 23:35:20 +03:00
|
|
|
data, err := ioutil.ReadFile("testdata/0.0.0")
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
2019-01-21 15:45:35 +03:00
|
|
|
mapblock, err := Parse(data, 0, coords.NewMapBlockCoords(0, 0, 0))
|
2019-01-05 23:35:20 +03:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if mapblock.Version != 28 {
|
|
|
|
t.Error("wrong mapblock version: " + strconv.Itoa(int(mapblock.Version)))
|
|
|
|
}
|
|
|
|
|
|
|
|
if !mapblock.Underground {
|
|
|
|
t.Error("Underground flag")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(mapblock.Mapdata) != 16384 {
|
|
|
|
t.Error("Mapdata length wrong")
|
|
|
|
}
|
2019-01-07 18:35:26 +03:00
|
|
|
|
|
|
|
pairs := mapblock.Metadata.GetPairsMap(0)
|
|
|
|
if pairs["owner"] != "pipo" {
|
|
|
|
t.Error(pairs["owner"])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-07 21:38:53 +03:00
|
|
|
func TestParse2(t *testing.T) {
|
|
|
|
|
|
|
|
data, err := ioutil.ReadFile("testdata/11.0.2")
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
2019-01-21 15:45:35 +03:00
|
|
|
mapblock, err := Parse(data, 0, coords.NewMapBlockCoords(0, 0, 0))
|
2019-01-07 21:38:53 +03:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2019-01-07 21:53:05 +03:00
|
|
|
|
|
|
|
for k, v := range mapblock.BlockMapping {
|
|
|
|
fmt.Println("Key", k, "Value", v)
|
|
|
|
}
|
2019-01-07 21:38:53 +03:00
|
|
|
}
|
2019-01-07 18:35:26 +03:00
|
|
|
|
2019-01-07 21:38:53 +03:00
|
|
|
func TestParse3(t *testing.T) {
|
2019-01-07 18:35:26 +03:00
|
|
|
|
2019-01-07 21:38:53 +03:00
|
|
|
data, err := ioutil.ReadFile("testdata/0.1.0")
|
2019-01-07 18:35:26 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
2019-01-21 15:45:35 +03:00
|
|
|
_, err = Parse(data, 0, coords.NewMapBlockCoords(0, 0, 0))
|
2019-01-07 18:35:26 +03:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
2019-01-23 10:02:59 +03:00
|
|
|
|
|
|
|
func TestParseMetadata(t *testing.T) {
|
|
|
|
|
|
|
|
data, err := ioutil.ReadFile("testdata/mb-with-metadata.bin")
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
mb, err := Parse(data, 0, coords.NewMapBlockCoords(0, 0, 0))
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
str, err := json.MarshalIndent(mb, "", " ")
|
|
|
|
fmt.Println(string(str))
|
|
|
|
}
|