2019-01-05 21:35:20 +01:00
|
|
|
package mapblockparser
|
|
|
|
|
|
|
|
import (
|
2019-01-07 16:35:26 +01:00
|
|
|
"fmt"
|
2019-01-05 21:35:20 +01:00
|
|
|
"testing"
|
|
|
|
"io/ioutil"
|
|
|
|
"strconv"
|
2019-01-06 21:00:24 +01:00
|
|
|
log "github.com/sirupsen/logrus"
|
2019-01-05 21:35:20 +01:00
|
|
|
)
|
|
|
|
|
2019-01-07 16:06:03 +01:00
|
|
|
func TestReadU16(t *testing.T){
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
func TestReadU32(t *testing.T){
|
|
|
|
v := readU32([]byte{0x00, 0x00, 0x00, 0x00}, 0)
|
|
|
|
if v != 0 {
|
|
|
|
t.Error(v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-05 21:35:20 +01:00
|
|
|
func TestParse(t *testing.T){
|
2019-01-06 21:00:24 +01:00
|
|
|
log.SetLevel(log.DebugLevel)
|
|
|
|
|
2019-01-05 21:35:20 +01:00
|
|
|
data, err := ioutil.ReadFile("testdata/0.0.0")
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
2019-01-07 08:59:06 +01:00
|
|
|
mapblock, err := Parse(data)
|
2019-01-07 16:35:26 +01:00
|
|
|
fmt.Println("mapblock.Metadata", mapblock.Metadata)
|
2019-01-05 21:35:20 +01: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 16:35:26 +01:00
|
|
|
|
|
|
|
pairs := mapblock.Metadata.GetPairsMap(0)
|
|
|
|
if pairs["owner"] != "pipo" {
|
|
|
|
t.Error(pairs["owner"])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestParse2(t *testing.T){
|
|
|
|
log.SetLevel(log.DebugLevel)
|
|
|
|
|
|
|
|
data, err := ioutil.ReadFile("testdata/0.9.0")
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = Parse(data)
|
|
|
|
//fmt.Println("mapblock.Metadata", mapblock.Metadata)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|