Files
Erupe/server/channelserver/handlers_cast_binary_test.go
Houmgaor 2d8f1d3b41 test: expand channelserver coverage from 16% to 20%
Add comprehensive tests for handler functions and utilities:
- Achievement system (GetAchData, curves, mappings)
- Language system (getLangStrings)
- Core handlers (empty handlers, simple responses)
- Cafe/boost handlers
- Diva defense handlers
- Reward, caravan, tactics handlers
- Festa/ranking handlers
- Cast binary constants
2026-02-02 15:15:47 +01:00

81 lines
1.9 KiB
Go

package channelserver
import (
"testing"
)
func TestBinaryMessageTypeConstants(t *testing.T) {
tests := []struct {
name string
constant int
expected int
}{
{"BinaryMessageTypeState", BinaryMessageTypeState, 0},
{"BinaryMessageTypeChat", BinaryMessageTypeChat, 1},
{"BinaryMessageTypeQuest", BinaryMessageTypeQuest, 2},
{"BinaryMessageTypeData", BinaryMessageTypeData, 3},
{"BinaryMessageTypeMailNotify", BinaryMessageTypeMailNotify, 4},
{"BinaryMessageTypeEmote", BinaryMessageTypeEmote, 6},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.constant != tt.expected {
t.Errorf("%s = %d, want %d", tt.name, tt.constant, tt.expected)
}
})
}
}
func TestBroadcastTypeConstants(t *testing.T) {
tests := []struct {
name string
constant int
expected int
}{
{"BroadcastTypeTargeted", BroadcastTypeTargeted, 0x01},
{"BroadcastTypeStage", BroadcastTypeStage, 0x03},
{"BroadcastTypeServer", BroadcastTypeServer, 0x06},
{"BroadcastTypeWorld", BroadcastTypeWorld, 0x0a},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.constant != tt.expected {
t.Errorf("%s = %d, want %d", tt.name, tt.constant, tt.expected)
}
})
}
}
func TestCommandsMapInitialized(t *testing.T) {
// commands map should be initialized by init()
if commands == nil {
t.Error("commands map should be initialized")
}
}
func TestSendServerChatMessage(t *testing.T) {
server := createMockServer()
session := createMockSession(1, server)
// Should not panic
defer func() {
if r := recover(); r != nil {
t.Errorf("sendServerChatMessage panicked: %v", r)
}
}()
sendServerChatMessage(session, "Test message")
// Should queue a packet
select {
case p := <-session.sendPackets:
if len(p.data) == 0 {
t.Error("Response packet should have data")
}
default:
t.Error("No packet queued")
}
}