diff options
author | Kevin Chabowski <kevin@kch42.de> | 2013-08-07 14:29:58 +0200 |
---|---|---|
committer | Kevin Chabowski <kevin@kch42.de> | 2013-08-07 14:29:58 +0200 |
commit | b990c3d2db0280f0c4b3dccc2520caf5f2b6b6e6 (patch) | |
tree | 721c052cabe115edeb45f7ad02962c12cdb21df6 /nbt/bigtest_test.go | |
parent | 5a12f9e05c7cc608ba9685e50eabab21f7fc1f51 (diff) | |
download | gonbt-b990c3d2db0280f0c4b3dccc2520caf5f2b6b6e6.tar.gz gonbt-b990c3d2db0280f0c4b3dccc2520caf5f2b6b6e6.tar.bz2 gonbt-b990c3d2db0280f0c4b3dccc2520caf5f2b6b6e6.zip |
Added functions to create NBT data + tests.
Diffstat (limited to 'nbt/bigtest_test.go')
-rw-r--r-- | nbt/bigtest_test.go | 64 |
1 files changed, 62 insertions, 2 deletions
diff --git a/nbt/bigtest_test.go b/nbt/bigtest_test.go index 079141e..af6c573 100644 --- a/nbt/bigtest_test.go +++ b/nbt/bigtest_test.go @@ -3,6 +3,7 @@ package nbt import ( "bytes" "fmt" + "io" "testing" ) @@ -55,6 +56,8 @@ func bigtest() []byte { } } +func byteArrayTestSeries(n int) byte { return byte((n*n*255 + n*7) % 100) } + func getKey(t *testing.T, comp TagCompound, key string, tt TagType) (tag Tag, ok bool) { tag, ok = comp[key] if !ok { @@ -131,7 +134,10 @@ func nestedCompoundHelper(t *testing.T, comp TagCompound, id, name string, value } func TestBigtest(t *testing.T) { - r := bytes.NewReader(bigtest()) + testBigtest(bytes.NewReader(bigtest()), t) +} + +func testBigtest(r io.Reader, t *testing.T) { root, name, err := ReadGzipdNamedTag(r) if err != nil { t.Fatalf("Could not read NBT data: %s", err) @@ -214,7 +220,7 @@ func TestBigtest(t *testing.T) { t.Errorf("byteArrayTest data has length %d, expected 1000", len(data)) } else { for n := 0; n < 1000; n++ { - want := byte((n*n*255 + n*7) % 100) + want := byteArrayTestSeries(n) if data[n] != want { t.Errorf("Wrong byteArrayTest data at index %d: 0x%02x", n, data[n]) break @@ -223,3 +229,57 @@ func TestBigtest(t *testing.T) { } } } + +func makeNested(name string, value float32) Tag { + comp := make(TagCompound) + comp["name"] = NewStringTag(name) + comp["value"] = NewFloatTag(value) + return Tag{TAG_Compound, comp} +} + +func TestCreateBigtest(t *testing.T) { + rootcomp := make(TagCompound) + + rootcomp["shortTest"] = NewShortTag(32767) + rootcomp["longTest"] = NewLongTag(9223372036854775807) + rootcomp["floatTest"] = NewFloatTag(0.49823147) + rootcomp["stringTest"] = NewStringTag("HELLO WORLD THIS IS A TEST STRING ÅÄÖ!") + rootcomp["intTest"] = NewIntTag(2147483647) + rootcomp["byteTest"] = NewByteTag(127) + rootcomp["doubleTest"] = NewDoubleTag(0.4931287132182315) + + comp := make(TagCompound) + comp["ham"] = makeNested("Hampus", 0.75) + comp["egg"] = makeNested("Eggbert", 0.5) + rootcomp["nested compound test"] = Tag{TAG_Compound, comp} + + listlong := make([]interface{}, 5) + for i := 0; i < 5; i++ { + listlong[i] = int64(i + 11) + } + rootcomp["listTest (long)"] = Tag{TAG_List, TagList{TAG_Long, listlong}} + + listcomp := make([]interface{}, 2) + for i := 0; i < 2; i++ { + comp := make(TagCompound) + comp["name"] = NewStringTag(fmt.Sprintf("Compound tag #%d", i)) + comp["created-on"] = NewLongTag(1264099775885) + listcomp[i] = comp + } + rootcomp["listTest (compound)"] = Tag{TAG_List, TagList{TAG_Compound, listcomp}} + + data := make([]byte, 1000) + for n := 0; n < 1000; n++ { + data[n] = byteArrayTestSeries(n) + } + rootcomp["byteArrayTest (the first 1000 values of (n*n*255+n*7)%100, starting with n=0 (0, 62, 34, 16, 8, ...))"] = NewByteArrayTag(data) + + tag := Tag{TAG_Compound, rootcomp} + buf := new(bytes.Buffer) + + if err := WriteGzipdNamedTag(buf, "Level", tag); err != nil { + t.Fatalf("Could not write NBT data: %s", err) + } + + testBigtest(buf, t) +} |