Esempio n. 1
0
func TestEntityIdChange(t *testing.T) {
	oldId := message.EntityId(24)
	newId := message.EntityId(87)

	testMessage(t, message.Types["entity_id_change"], func(w io.Writer) error {
		return builder.SendEntityIdChange(w, oldId, newId)
	}, func(conn *message.Conn, t *testing.T) {
		roldId, rnewId := handler.ReadEntityIdChange(conn)
		if roldId != oldId {
			t.Fatal("Sent old id", oldId, "but received", roldId)
		}
		if rnewId != newId {
			t.Fatal("Sent new id", newId, "but received", rnewId)
		}
	})
}
Esempio n. 2
0
func TestEntityDestroy(t *testing.T) {
	tick := message.Tick(42)
	entityId := message.EntityId(93)

	testMessage(t, message.Types["entity_destroy"], func(w io.Writer) error {
		return builder.SendEntityDestroy(w, tick, entityId)
	}, func(conn *message.Conn, t *testing.T) {
		rt, id := handler.ReadEntityDestroy(conn)
		if rt != tick {
			t.Fatal("Sent tick", tick, "but received", rt)
		}
		if entityId != id {
			t.Fatal("Sent entity id", entityId, "but received", id)
		}
	})
}
Esempio n. 3
0
func TestMetaAction_PlayerLeft(t *testing.T) {
	code := message.MetaActionCodes["player_left"]
	tick := message.Tick(42)
	entityId := message.EntityId(69)

	testMessage(t, message.Types["meta_action"], func(w io.Writer) error {
		return builder.SendPlayerLeft(w, tick, entityId)
	}, func(conn *message.Conn, t *testing.T) {
		rt, id, c, _ := handler.ReadMetaAction(conn)
		if rt != tick {
			t.Fatal("Sent tick", tick, "but received", rt)
		}
		if id != entityId {
			t.Fatal("Sent entity id", entityId, "but received", id)
		}
		if c != code {
			t.Fatal("Sent code", code, "but received", c)
		}
	})
}
Esempio n. 4
0
func TestMetaAction_PlayerJoined(t *testing.T) {
	code := message.MetaActionCodes["player_joined"]
	tick := message.Tick(42)
	entityId := message.EntityId(69)
	username := "******"

	testMessage(t, message.Types["meta_action"], func(w io.Writer) error {
		return builder.SendPlayerJoined(w, tick, entityId, username)
	}, func(conn *message.Conn, t *testing.T) {
		rt, id, c, u := handler.ReadMetaAction(conn)
		if rt != tick {
			t.Fatal("Sent tick", tick, "but received", rt)
		}
		if id != entityId {
			t.Fatal("Sent entity id", entityId, "but received", id)
		}
		if c != code {
			t.Fatal("Sent code", code, "but received", c)
		}
		if u != username {
			t.Fatal("Sent username", username, "but received", u)
		}
	})
}