Files
Erupe/server/channelserver/handlers_coverage5_test.go
Houmgaor 645c4ddd38 test: increase code coverage from 45.1% to 48.3%
Add unit tests across multiple packages:
- byteframe: SetBE/SetLE byte order switching
- config: Mode.String() for all safe version ranges
- mhfpacket: 28 Parse methods, 5 Build methods, empty packet builds,
  variable-length packets, NOT IMPLEMENTED error paths, UpdateWarehouse
- network: PacketID.String() for known IDs, out-of-range, and all valid
- channelserver: handleMsgMhfGetPaperData (6 switch cases), grpToGR
  (11 input values), gacha handlers, TimeGameAbsolute, equipSkinHistSize
  (4 config branches), guild mission handlers, dumpSaveData disabled path
- entranceserver: makeHeader with various inputs
2026-02-17 17:32:54 +01:00

203 lines
5.2 KiB
Go

package channelserver
import (
"testing"
_config "erupe-ce/config"
"erupe-ce/network/mhfpacket"
)
// =============================================================================
// equipSkinHistSize: pure function, tests all 3 config branches
// =============================================================================
func TestEquipSkinHistSize_Default(t *testing.T) {
orig := _config.ErupeConfig.RealClientMode
defer func() { _config.ErupeConfig.RealClientMode = orig }()
_config.ErupeConfig.RealClientMode = _config.ZZ
got := equipSkinHistSize()
if got != 3200 {
t.Errorf("equipSkinHistSize() with ZZ = %d, want 3200", got)
}
}
func TestEquipSkinHistSize_Z2(t *testing.T) {
orig := _config.ErupeConfig.RealClientMode
defer func() { _config.ErupeConfig.RealClientMode = orig }()
_config.ErupeConfig.RealClientMode = _config.Z2
got := equipSkinHistSize()
if got != 2560 {
t.Errorf("equipSkinHistSize() with Z2 = %d, want 2560", got)
}
}
func TestEquipSkinHistSize_Z1(t *testing.T) {
orig := _config.ErupeConfig.RealClientMode
defer func() { _config.ErupeConfig.RealClientMode = orig }()
_config.ErupeConfig.RealClientMode = _config.Z1
got := equipSkinHistSize()
if got != 1280 {
t.Errorf("equipSkinHistSize() with Z1 = %d, want 1280", got)
}
}
func TestEquipSkinHistSize_OlderMode(t *testing.T) {
orig := _config.ErupeConfig.RealClientMode
defer func() { _config.ErupeConfig.RealClientMode = orig }()
_config.ErupeConfig.RealClientMode = _config.G1
got := equipSkinHistSize()
if got != 1280 {
t.Errorf("equipSkinHistSize() with G1 = %d, want 1280", got)
}
}
// =============================================================================
// DB-free guild handlers: simple ack stubs
// =============================================================================
func TestHandleMsgMhfAddGuildMissionCount(t *testing.T) {
server := createMockServer()
session := createMockSession(1, server)
handleMsgMhfAddGuildMissionCount(session, &mhfpacket.MsgMhfAddGuildMissionCount{
AckHandle: 1,
})
select {
case p := <-session.sendPackets:
if len(p.data) == 0 {
t.Error("response should have data")
}
default:
t.Error("no response queued")
}
}
func TestHandleMsgMhfSetGuildMissionTarget(t *testing.T) {
server := createMockServer()
session := createMockSession(1, server)
handleMsgMhfSetGuildMissionTarget(session, &mhfpacket.MsgMhfSetGuildMissionTarget{
AckHandle: 1,
})
select {
case p := <-session.sendPackets:
if len(p.data) == 0 {
t.Error("response should have data")
}
default:
t.Error("no response queued")
}
}
func TestHandleMsgMhfCancelGuildMissionTarget(t *testing.T) {
server := createMockServer()
session := createMockSession(1, server)
handleMsgMhfCancelGuildMissionTarget(session, &mhfpacket.MsgMhfCancelGuildMissionTarget{
AckHandle: 1,
})
select {
case p := <-session.sendPackets:
if len(p.data) == 0 {
t.Error("response should have data")
}
default:
t.Error("no response queued")
}
}
func TestHandleMsgMhfGetGuildMissionRecord(t *testing.T) {
server := createMockServer()
session := createMockSession(1, server)
handleMsgMhfGetGuildMissionRecord(session, &mhfpacket.MsgMhfGetGuildMissionRecord{
AckHandle: 1,
})
select {
case p := <-session.sendPackets:
if len(p.data) == 0 {
t.Error("response should have data")
}
default:
t.Error("no response queued")
}
}
func TestHandleMsgMhfAcquireGuildTresureSouvenir(t *testing.T) {
server := createMockServer()
session := createMockSession(1, server)
handleMsgMhfAcquireGuildTresureSouvenir(session, &mhfpacket.MsgMhfAcquireGuildTresureSouvenir{
AckHandle: 1,
})
select {
case p := <-session.sendPackets:
if len(p.data) == 0 {
t.Error("response should have data")
}
default:
t.Error("no response queued")
}
}
func TestHandleMsgMhfGetUdGuildMapInfo(t *testing.T) {
server := createMockServer()
session := createMockSession(1, server)
handleMsgMhfGetUdGuildMapInfo(session, &mhfpacket.MsgMhfGetUdGuildMapInfo{
AckHandle: 1,
})
select {
case p := <-session.sendPackets:
if len(p.data) == 0 {
t.Error("response should have data")
}
default:
t.Error("no response queued")
}
}
// =============================================================================
// DB-free guild mission list handler (large static data)
// =============================================================================
func TestHandleMsgMhfGetGuildMissionList(t *testing.T) {
server := createMockServer()
session := createMockSession(1, server)
handleMsgMhfGetGuildMissionList(session, &mhfpacket.MsgMhfGetGuildMissionList{
AckHandle: 1,
})
select {
case p := <-session.sendPackets:
if len(p.data) == 0 {
t.Error("response should have data")
}
default:
t.Error("no response queued")
}
}
// handleMsgMhfEnumerateUnionItem requires DB (calls userGetItems)
// handleMsgMhfRegistSpabiTime, handleMsgMhfKickExportForce, handleMsgMhfUseUdShopCoin
// are tested in handlers_misc_test.go
// handleMsgMhfGetUdShopCoin and handleMsgMhfGetLobbyCrowd are tested in handlers_misc_test.go
// handleMsgMhfEnumerateGuacot requires DB (calls getGoocooData)
// handleMsgMhfPostRyoudama is tested in handlers_caravan_test.go
// handleMsgMhfResetTitle is tested in handlers_coverage2_test.go