mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-21 23:22:34 +01:00
test: improve test coverage from 11% to 20%
Add comprehensive tests across multiple packages: - mhfpacket: Add tests for 300+ packet opcodes, system packets, MHF packets, and detailed parsing tests (6.4% -> 38.8%) - timeserver: Add tests for all time functions (0% -> 97.4%) - deltacomp: Add edge case tests for compression functions - entranceserver: Add server creation tests - binpacket: Add mail notify panic test - config: Add Mode.String() tests - signserver: Expand server tests
This commit is contained in:
@@ -475,6 +475,37 @@ func TestChannelStruct(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestModeString(t *testing.T) {
|
||||
tests := []struct {
|
||||
mode Mode
|
||||
want string
|
||||
}{
|
||||
{S1, "S1.0"},
|
||||
{S15, "S1.5"},
|
||||
{S2, "S2.0"},
|
||||
{S6, "S6.0"},
|
||||
{F1, "FW.1"},
|
||||
{F5, "FW.5"},
|
||||
{G1, "G1"},
|
||||
{G10, "G10"},
|
||||
{Z1, "Z1"},
|
||||
{Z2, "Z2"},
|
||||
{ZZ, "ZZ"},
|
||||
{Mode(0), "Unknown"},
|
||||
{Mode(-1), "Unknown"},
|
||||
{Mode(100), "Unknown"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.want, func(t *testing.T) {
|
||||
got := tt.mode.String()
|
||||
if got != tt.want {
|
||||
t.Errorf("Mode(%d).String() = %s, want %s", tt.mode, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigCompleteStructure(t *testing.T) {
|
||||
// Test building a complete config structure
|
||||
cfg := &Config{
|
||||
|
||||
@@ -399,3 +399,32 @@ func TestMsgBinChatAllTypes(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMsgBinMailNotifyParsePanics(t *testing.T) {
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
t.Error("Parse() should panic with 'implement me'")
|
||||
}
|
||||
}()
|
||||
|
||||
m := MsgBinMailNotify{}
|
||||
bf := byteframe.NewByteFrame()
|
||||
_ = m.Parse(bf)
|
||||
}
|
||||
|
||||
func TestMsgBinMailNotifyBuildLongName(t *testing.T) {
|
||||
m := MsgBinMailNotify{
|
||||
SenderName: "ThisIsAVeryLongPlayerNameThatExceeds21Characters",
|
||||
}
|
||||
|
||||
bf := byteframe.NewByteFrame()
|
||||
err := m.Build(bf)
|
||||
if err != nil {
|
||||
t.Fatalf("Build() error = %v", err)
|
||||
}
|
||||
|
||||
// Data should still be 22 bytes (1 + 21)
|
||||
if len(bf.Data()) != 22 {
|
||||
t.Errorf("Data len = %d, want 22", len(bf.Data()))
|
||||
}
|
||||
}
|
||||
|
||||
1152
network/mhfpacket/msg_comprehensive_test.go
Normal file
1152
network/mhfpacket/msg_comprehensive_test.go
Normal file
File diff suppressed because it is too large
Load Diff
537
network/mhfpacket/msg_mhf_packets_test.go
Normal file
537
network/mhfpacket/msg_mhf_packets_test.go
Normal file
@@ -0,0 +1,537 @@
|
||||
package mhfpacket
|
||||
|
||||
import (
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"erupe-ce/common/byteframe"
|
||||
"erupe-ce/network"
|
||||
"erupe-ce/network/clientctx"
|
||||
)
|
||||
|
||||
// TestMsgMhfSavedataParse tests parsing MsgMhfSavedata
|
||||
func TestMsgMhfSavedataParse(t *testing.T) {
|
||||
pkt := FromOpcode(network.MSG_MHF_SAVEDATA)
|
||||
if pkt == nil {
|
||||
t.Fatal("FromOpcode(MSG_MHF_SAVEDATA) returned nil")
|
||||
}
|
||||
if pkt.Opcode() != network.MSG_MHF_SAVEDATA {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_SAVEDATA", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfLoaddataParse tests parsing MsgMhfLoaddata
|
||||
func TestMsgMhfLoaddataParse(t *testing.T) {
|
||||
pkt := FromOpcode(network.MSG_MHF_LOADDATA)
|
||||
if pkt == nil {
|
||||
t.Fatal("FromOpcode(MSG_MHF_LOADDATA) returned nil")
|
||||
}
|
||||
if pkt.Opcode() != network.MSG_MHF_LOADDATA {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_LOADDATA", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfListMemberOpcode tests MsgMhfListMember Opcode
|
||||
func TestMsgMhfListMemberOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfListMember{}
|
||||
if pkt.Opcode() != network.MSG_MHF_LIST_MEMBER {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_LIST_MEMBER", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfOprMemberOpcode tests MsgMhfOprMember Opcode
|
||||
func TestMsgMhfOprMemberOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfOprMember{}
|
||||
if pkt.Opcode() != network.MSG_MHF_OPR_MEMBER {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_OPR_MEMBER", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfEnumerateDistItemOpcode tests MsgMhfEnumerateDistItem Opcode
|
||||
func TestMsgMhfEnumerateDistItemOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfEnumerateDistItem{}
|
||||
if pkt.Opcode() != network.MSG_MHF_ENUMERATE_DIST_ITEM {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_ENUMERATE_DIST_ITEM", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfApplyDistItemOpcode tests MsgMhfApplyDistItem Opcode
|
||||
func TestMsgMhfApplyDistItemOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfApplyDistItem{}
|
||||
if pkt.Opcode() != network.MSG_MHF_APPLY_DIST_ITEM {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_APPLY_DIST_ITEM", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfAcquireDistItemOpcode tests MsgMhfAcquireDistItem Opcode
|
||||
func TestMsgMhfAcquireDistItemOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfAcquireDistItem{}
|
||||
if pkt.Opcode() != network.MSG_MHF_ACQUIRE_DIST_ITEM {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_ACQUIRE_DIST_ITEM", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfGetDistDescriptionOpcode tests MsgMhfGetDistDescription Opcode
|
||||
func TestMsgMhfGetDistDescriptionOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfGetDistDescription{}
|
||||
if pkt.Opcode() != network.MSG_MHF_GET_DIST_DESCRIPTION {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_GET_DIST_DESCRIPTION", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfSendMailOpcode tests MsgMhfSendMail Opcode
|
||||
func TestMsgMhfSendMailOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfSendMail{}
|
||||
if pkt.Opcode() != network.MSG_MHF_SEND_MAIL {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_SEND_MAIL", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfReadMailOpcode tests MsgMhfReadMail Opcode
|
||||
func TestMsgMhfReadMailOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfReadMail{}
|
||||
if pkt.Opcode() != network.MSG_MHF_READ_MAIL {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_READ_MAIL", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfListMailOpcode tests MsgMhfListMail Opcode
|
||||
func TestMsgMhfListMailOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfListMail{}
|
||||
if pkt.Opcode() != network.MSG_MHF_LIST_MAIL {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_LIST_MAIL", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfOprtMailOpcode tests MsgMhfOprtMail Opcode
|
||||
func TestMsgMhfOprtMailOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfOprtMail{}
|
||||
if pkt.Opcode() != network.MSG_MHF_OPRT_MAIL {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_OPRT_MAIL", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfLoadFavoriteQuestOpcode tests MsgMhfLoadFavoriteQuest Opcode
|
||||
func TestMsgMhfLoadFavoriteQuestOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfLoadFavoriteQuest{}
|
||||
if pkt.Opcode() != network.MSG_MHF_LOAD_FAVORITE_QUEST {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_LOAD_FAVORITE_QUEST", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfSaveFavoriteQuestOpcode tests MsgMhfSaveFavoriteQuest Opcode
|
||||
func TestMsgMhfSaveFavoriteQuestOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfSaveFavoriteQuest{}
|
||||
if pkt.Opcode() != network.MSG_MHF_SAVE_FAVORITE_QUEST {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_SAVE_FAVORITE_QUEST", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfRegisterEventOpcode tests MsgMhfRegisterEvent Opcode
|
||||
func TestMsgMhfRegisterEventOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfRegisterEvent{}
|
||||
if pkt.Opcode() != network.MSG_MHF_REGISTER_EVENT {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_REGISTER_EVENT", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfReleaseEventOpcode tests MsgMhfReleaseEvent Opcode
|
||||
func TestMsgMhfReleaseEventOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfReleaseEvent{}
|
||||
if pkt.Opcode() != network.MSG_MHF_RELEASE_EVENT {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_RELEASE_EVENT", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfTransitMessageOpcode tests MsgMhfTransitMessage Opcode
|
||||
func TestMsgMhfTransitMessageOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfTransitMessage{}
|
||||
if pkt.Opcode() != network.MSG_MHF_TRANSIT_MESSAGE {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_TRANSIT_MESSAGE", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfPresentBoxOpcode tests MsgMhfPresentBox Opcode
|
||||
func TestMsgMhfPresentBoxOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfPresentBox{}
|
||||
if pkt.Opcode() != network.MSG_MHF_PRESENT_BOX {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_PRESENT_BOX", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfServerCommandOpcode tests MsgMhfServerCommand Opcode
|
||||
func TestMsgMhfServerCommandOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfServerCommand{}
|
||||
if pkt.Opcode() != network.MSG_MHF_SERVER_COMMAND {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_SERVER_COMMAND", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfShutClientOpcode tests MsgMhfShutClient Opcode
|
||||
func TestMsgMhfShutClientOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfShutClient{}
|
||||
if pkt.Opcode() != network.MSG_MHF_SHUT_CLIENT {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_SHUT_CLIENT", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfAnnounceOpcode tests MsgMhfAnnounce Opcode
|
||||
func TestMsgMhfAnnounceOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfAnnounce{}
|
||||
if pkt.Opcode() != network.MSG_MHF_ANNOUNCE {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_ANNOUNCE", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfSetLoginwindowOpcode tests MsgMhfSetLoginwindow Opcode
|
||||
func TestMsgMhfSetLoginwindowOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfSetLoginwindow{}
|
||||
if pkt.Opcode() != network.MSG_MHF_SET_LOGINWINDOW {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_SET_LOGINWINDOW", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfGetCaUniqueIDOpcode tests MsgMhfGetCaUniqueID Opcode
|
||||
func TestMsgMhfGetCaUniqueIDOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfGetCaUniqueID{}
|
||||
if pkt.Opcode() != network.MSG_MHF_GET_CA_UNIQUE_ID {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_GET_CA_UNIQUE_ID", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfSetCaAchievementOpcode tests MsgMhfSetCaAchievement Opcode
|
||||
func TestMsgMhfSetCaAchievementOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfSetCaAchievement{}
|
||||
if pkt.Opcode() != network.MSG_MHF_SET_CA_ACHIEVEMENT {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_SET_CA_ACHIEVEMENT", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfCaravanMyScoreOpcode tests MsgMhfCaravanMyScore Opcode
|
||||
func TestMsgMhfCaravanMyScoreOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfCaravanMyScore{}
|
||||
if pkt.Opcode() != network.MSG_MHF_CARAVAN_MY_SCORE {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_CARAVAN_MY_SCORE", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfCaravanRankingOpcode tests MsgMhfCaravanRanking Opcode
|
||||
func TestMsgMhfCaravanRankingOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfCaravanRanking{}
|
||||
if pkt.Opcode() != network.MSG_MHF_CARAVAN_RANKING {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_CARAVAN_RANKING", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfCaravanMyRankOpcode tests MsgMhfCaravanMyRank Opcode
|
||||
func TestMsgMhfCaravanMyRankOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfCaravanMyRank{}
|
||||
if pkt.Opcode() != network.MSG_MHF_CARAVAN_MY_RANK {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_CARAVAN_MY_RANK", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfEnumerateQuestOpcode tests MsgMhfEnumerateQuest Opcode
|
||||
func TestMsgMhfEnumerateQuestOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfEnumerateQuest{}
|
||||
if pkt.Opcode() != network.MSG_MHF_ENUMERATE_QUEST {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_ENUMERATE_QUEST", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfEnumerateEventOpcode tests MsgMhfEnumerateEvent Opcode
|
||||
func TestMsgMhfEnumerateEventOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfEnumerateEvent{}
|
||||
if pkt.Opcode() != network.MSG_MHF_ENUMERATE_EVENT {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_ENUMERATE_EVENT", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfEnumeratePriceOpcode tests MsgMhfEnumeratePrice Opcode
|
||||
func TestMsgMhfEnumeratePriceOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfEnumeratePrice{}
|
||||
if pkt.Opcode() != network.MSG_MHF_ENUMERATE_PRICE {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_ENUMERATE_PRICE", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfEnumerateRankingOpcode tests MsgMhfEnumerateRanking Opcode
|
||||
func TestMsgMhfEnumerateRankingOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfEnumerateRanking{}
|
||||
if pkt.Opcode() != network.MSG_MHF_ENUMERATE_RANKING {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_ENUMERATE_RANKING", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfEnumerateOrderOpcode tests MsgMhfEnumerateOrder Opcode
|
||||
func TestMsgMhfEnumerateOrderOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfEnumerateOrder{}
|
||||
if pkt.Opcode() != network.MSG_MHF_ENUMERATE_ORDER {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_ENUMERATE_ORDER", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfEnumerateShopOpcode tests MsgMhfEnumerateShop Opcode
|
||||
func TestMsgMhfEnumerateShopOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfEnumerateShop{}
|
||||
if pkt.Opcode() != network.MSG_MHF_ENUMERATE_SHOP {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_ENUMERATE_SHOP", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfGetExtraInfoOpcode tests MsgMhfGetExtraInfo Opcode
|
||||
func TestMsgMhfGetExtraInfoOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfGetExtraInfo{}
|
||||
if pkt.Opcode() != network.MSG_MHF_GET_EXTRA_INFO {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_GET_EXTRA_INFO", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfEnumerateItemOpcode tests MsgMhfEnumerateItem Opcode
|
||||
func TestMsgMhfEnumerateItemOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfEnumerateItem{}
|
||||
if pkt.Opcode() != network.MSG_MHF_ENUMERATE_ITEM {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_ENUMERATE_ITEM", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfAcquireItemOpcode tests MsgMhfAcquireItem Opcode
|
||||
func TestMsgMhfAcquireItemOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfAcquireItem{}
|
||||
if pkt.Opcode() != network.MSG_MHF_ACQUIRE_ITEM {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_ACQUIRE_ITEM", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfTransferItemOpcode tests MsgMhfTransferItem Opcode
|
||||
func TestMsgMhfTransferItemOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfTransferItem{}
|
||||
if pkt.Opcode() != network.MSG_MHF_TRANSFER_ITEM {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_TRANSFER_ITEM", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfEntryRookieGuildOpcode tests MsgMhfEntryRookieGuild Opcode
|
||||
func TestMsgMhfEntryRookieGuildOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfEntryRookieGuild{}
|
||||
if pkt.Opcode() != network.MSG_MHF_ENTRY_ROOKIE_GUILD {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_ENTRY_ROOKIE_GUILD", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgCaExchangeItemOpcode tests MsgCaExchangeItem Opcode
|
||||
func TestMsgCaExchangeItemOpcode(t *testing.T) {
|
||||
pkt := &MsgCaExchangeItem{}
|
||||
if pkt.Opcode() != network.MSG_CA_EXCHANGE_ITEM {
|
||||
t.Errorf("Opcode() = %s, want MSG_CA_EXCHANGE_ITEM", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfEnumerateCampaignOpcode tests MsgMhfEnumerateCampaign Opcode
|
||||
func TestMsgMhfEnumerateCampaignOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfEnumerateCampaign{}
|
||||
if pkt.Opcode() != network.MSG_MHF_ENUMERATE_CAMPAIGN {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_ENUMERATE_CAMPAIGN", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfStateCampaignOpcode tests MsgMhfStateCampaign Opcode
|
||||
func TestMsgMhfStateCampaignOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfStateCampaign{}
|
||||
if pkt.Opcode() != network.MSG_MHF_STATE_CAMPAIGN {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_STATE_CAMPAIGN", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfApplyCampaignOpcode tests MsgMhfApplyCampaign Opcode
|
||||
func TestMsgMhfApplyCampaignOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfApplyCampaign{}
|
||||
if pkt.Opcode() != network.MSG_MHF_APPLY_CAMPAIGN {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_APPLY_CAMPAIGN", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfCreateJointOpcode tests MsgMhfCreateJoint Opcode
|
||||
func TestMsgMhfCreateJointOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfCreateJoint{}
|
||||
if pkt.Opcode() != network.MSG_MHF_CREATE_JOINT {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_CREATE_JOINT", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfOperateJointOpcode tests MsgMhfOperateJoint Opcode
|
||||
func TestMsgMhfOperateJointOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfOperateJoint{}
|
||||
if pkt.Opcode() != network.MSG_MHF_OPERATE_JOINT {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_OPERATE_JOINT", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfInfoJointOpcode tests MsgMhfInfoJoint Opcode
|
||||
func TestMsgMhfInfoJointOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfInfoJoint{}
|
||||
if pkt.Opcode() != network.MSG_MHF_INFO_JOINT {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_INFO_JOINT", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfGetCogInfoOpcode tests MsgMhfGetCogInfo Opcode
|
||||
func TestMsgMhfGetCogInfoOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfGetCogInfo{}
|
||||
if pkt.Opcode() != network.MSG_MHF_GET_COG_INFO {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_GET_COG_INFO", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfCheckMonthlyItemOpcode tests MsgMhfCheckMonthlyItem Opcode
|
||||
func TestMsgMhfCheckMonthlyItemOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfCheckMonthlyItem{}
|
||||
if pkt.Opcode() != network.MSG_MHF_CHECK_MONTHLY_ITEM {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_CHECK_MONTHLY_ITEM", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfAcquireMonthlyItemOpcode tests MsgMhfAcquireMonthlyItem Opcode
|
||||
func TestMsgMhfAcquireMonthlyItemOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfAcquireMonthlyItem{}
|
||||
if pkt.Opcode() != network.MSG_MHF_ACQUIRE_MONTHLY_ITEM {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_ACQUIRE_MONTHLY_ITEM", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfCheckWeeklyStampOpcode tests MsgMhfCheckWeeklyStamp Opcode
|
||||
func TestMsgMhfCheckWeeklyStampOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfCheckWeeklyStamp{}
|
||||
if pkt.Opcode() != network.MSG_MHF_CHECK_WEEKLY_STAMP {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_CHECK_WEEKLY_STAMP", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfExchangeWeeklyStampOpcode tests MsgMhfExchangeWeeklyStamp Opcode
|
||||
func TestMsgMhfExchangeWeeklyStampOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfExchangeWeeklyStamp{}
|
||||
if pkt.Opcode() != network.MSG_MHF_EXCHANGE_WEEKLY_STAMP {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_EXCHANGE_WEEKLY_STAMP", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfCreateMercenaryOpcode tests MsgMhfCreateMercenary Opcode
|
||||
func TestMsgMhfCreateMercenaryOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfCreateMercenary{}
|
||||
if pkt.Opcode() != network.MSG_MHF_CREATE_MERCENARY {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_CREATE_MERCENARY", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfEnumerateMercenaryLogOpcode tests MsgMhfEnumerateMercenaryLog Opcode
|
||||
func TestMsgMhfEnumerateMercenaryLogOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfEnumerateMercenaryLog{}
|
||||
if pkt.Opcode() != network.MSG_MHF_ENUMERATE_MERCENARY_LOG {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_ENUMERATE_MERCENARY_LOG", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfEnumerateGuacotOpcode tests MsgMhfEnumerateGuacot Opcode
|
||||
func TestMsgMhfEnumerateGuacotOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfEnumerateGuacot{}
|
||||
if pkt.Opcode() != network.MSG_MHF_ENUMERATE_GUACOT {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_ENUMERATE_GUACOT", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfUpdateGuacotOpcode tests MsgMhfUpdateGuacot Opcode
|
||||
func TestMsgMhfUpdateGuacotOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfUpdateGuacot{}
|
||||
if pkt.Opcode() != network.MSG_MHF_UPDATE_GUACOT {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_UPDATE_GUACOT", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfEnterTournamentQuestOpcode tests MsgMhfEnterTournamentQuest Opcode
|
||||
func TestMsgMhfEnterTournamentQuestOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfEnterTournamentQuest{}
|
||||
if pkt.Opcode() != network.MSG_MHF_ENTER_TOURNAMENT_QUEST {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_ENTER_TOURNAMENT_QUEST", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfResetAchievementOpcode tests MsgMhfResetAchievement Opcode
|
||||
func TestMsgMhfResetAchievementOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfResetAchievement{}
|
||||
if pkt.Opcode() != network.MSG_MHF_RESET_ACHIEVEMENT {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_RESET_ACHIEVEMENT", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfPaymentAchievementOpcode tests MsgMhfPaymentAchievement Opcode
|
||||
func TestMsgMhfPaymentAchievementOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfPaymentAchievement{}
|
||||
if pkt.Opcode() != network.MSG_MHF_PAYMENT_ACHIEVEMENT {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_PAYMENT_ACHIEVEMENT", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfDisplayedAchievementOpcode tests MsgMhfDisplayedAchievement Opcode
|
||||
func TestMsgMhfDisplayedAchievementOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfDisplayedAchievement{}
|
||||
if pkt.Opcode() != network.MSG_MHF_DISPLAYED_ACHIEVEMENT {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_DISPLAYED_ACHIEVEMENT", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfGetBbsSnsStatusOpcode tests MsgMhfGetBbsSnsStatus Opcode
|
||||
func TestMsgMhfGetBbsSnsStatusOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfGetBbsSnsStatus{}
|
||||
if pkt.Opcode() != network.MSG_MHF_GET_BBS_SNS_STATUS {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_GET_BBS_SNS_STATUS", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfApplyBbsArticleOpcode tests MsgMhfApplyBbsArticle Opcode
|
||||
func TestMsgMhfApplyBbsArticleOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfApplyBbsArticle{}
|
||||
if pkt.Opcode() != network.MSG_MHF_APPLY_BBS_ARTICLE {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_APPLY_BBS_ARTICLE", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfGetEtcPointsOpcode tests MsgMhfGetEtcPoints Opcode
|
||||
func TestMsgMhfGetEtcPointsOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfGetEtcPoints{}
|
||||
if pkt.Opcode() != network.MSG_MHF_GET_ETC_POINTS {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_GET_ETC_POINTS", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfUpdateEtcPointOpcode tests MsgMhfUpdateEtcPoint Opcode
|
||||
func TestMsgMhfUpdateEtcPointOpcode(t *testing.T) {
|
||||
pkt := &MsgMhfUpdateEtcPoint{}
|
||||
if pkt.Opcode() != network.MSG_MHF_UPDATE_ETC_POINT {
|
||||
t.Errorf("Opcode() = %s, want MSG_MHF_UPDATE_ETC_POINT", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestAchievementPacketParse tests simple achievement packet parsing
|
||||
func TestAchievementPacketParse(t *testing.T) {
|
||||
bf := byteframe.NewByteFrame()
|
||||
bf.WriteUint8(5) // AchievementID
|
||||
bf.WriteUint16(100) // Unk1
|
||||
bf.WriteUint16(200) // Unk2
|
||||
bf.Seek(0, io.SeekStart)
|
||||
|
||||
pkt := &MsgMhfAddAchievement{}
|
||||
err := pkt.Parse(bf, &clientctx.ClientContext{})
|
||||
if err != nil {
|
||||
t.Fatalf("Parse() error = %v", err)
|
||||
}
|
||||
|
||||
if pkt.AchievementID != 5 {
|
||||
t.Errorf("AchievementID = %d, want 5", pkt.AchievementID)
|
||||
}
|
||||
if pkt.Unk1 != 100 {
|
||||
t.Errorf("Unk1 = %d, want 100", pkt.Unk1)
|
||||
}
|
||||
if pkt.Unk2 != 200 {
|
||||
t.Errorf("Unk2 = %d, want 200", pkt.Unk2)
|
||||
}
|
||||
}
|
||||
298
network/mhfpacket/msg_parse_test.go
Normal file
298
network/mhfpacket/msg_parse_test.go
Normal file
@@ -0,0 +1,298 @@
|
||||
package mhfpacket
|
||||
|
||||
import (
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"erupe-ce/common/byteframe"
|
||||
"erupe-ce/network/clientctx"
|
||||
)
|
||||
|
||||
// TestMsgMhfGetAchievementParse tests MsgMhfGetAchievement parsing
|
||||
func TestMsgMhfGetAchievementDetailedParse(t *testing.T) {
|
||||
bf := byteframe.NewByteFrame()
|
||||
bf.WriteUint32(0x12345678) // AckHandle
|
||||
bf.WriteUint32(54321) // CharID
|
||||
bf.WriteUint32(99999) // Unk1
|
||||
bf.Seek(0, io.SeekStart)
|
||||
|
||||
pkt := &MsgMhfGetAchievement{}
|
||||
err := pkt.Parse(bf, &clientctx.ClientContext{})
|
||||
if err != nil {
|
||||
t.Fatalf("Parse() error = %v", err)
|
||||
}
|
||||
|
||||
if pkt.AckHandle != 0x12345678 {
|
||||
t.Errorf("AckHandle = 0x%X, want 0x12345678", pkt.AckHandle)
|
||||
}
|
||||
if pkt.CharID != 54321 {
|
||||
t.Errorf("CharID = %d, want 54321", pkt.CharID)
|
||||
}
|
||||
if pkt.Unk1 != 99999 {
|
||||
t.Errorf("Unk1 = %d, want 99999", pkt.Unk1)
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgMhfAddAchievementDetailedParse tests MsgMhfAddAchievement parsing
|
||||
func TestMsgMhfAddAchievementDetailedParse(t *testing.T) {
|
||||
bf := byteframe.NewByteFrame()
|
||||
bf.WriteUint8(42) // AchievementID
|
||||
bf.WriteUint16(12345) // Unk1
|
||||
bf.WriteUint16(0xFFFF) // Unk2 - max value
|
||||
bf.Seek(0, io.SeekStart)
|
||||
|
||||
pkt := &MsgMhfAddAchievement{}
|
||||
err := pkt.Parse(bf, &clientctx.ClientContext{})
|
||||
if err != nil {
|
||||
t.Fatalf("Parse() error = %v", err)
|
||||
}
|
||||
|
||||
if pkt.AchievementID != 42 {
|
||||
t.Errorf("AchievementID = %d, want 42", pkt.AchievementID)
|
||||
}
|
||||
if pkt.Unk1 != 12345 {
|
||||
t.Errorf("Unk1 = %d, want 12345", pkt.Unk1)
|
||||
}
|
||||
if pkt.Unk2 != 0xFFFF {
|
||||
t.Errorf("Unk2 = %d, want 65535", pkt.Unk2)
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysCastBinaryDetailedParse tests MsgSysCastBinary parsing with various payloads
|
||||
func TestMsgSysCastBinaryDetailedParse(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
unk0 uint16
|
||||
unk1 uint16
|
||||
broadcastType uint8
|
||||
messageType uint8
|
||||
payload []byte
|
||||
}{
|
||||
{"empty payload", 0, 0, 1, 2, []byte{}},
|
||||
{"typical payload", 100, 200, 0x10, 0x20, []byte{0x01, 0x02, 0x03}},
|
||||
{"chat message", 0, 0, 0x01, 0x01, []byte("Hello, World!")},
|
||||
{"binary data", 0xFFFF, 0xFFFF, 0xFF, 0xFF, []byte{0xDE, 0xAD, 0xBE, 0xEF}},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
bf := byteframe.NewByteFrame()
|
||||
bf.WriteUint16(tt.unk0)
|
||||
bf.WriteUint16(tt.unk1)
|
||||
bf.WriteUint8(tt.broadcastType)
|
||||
bf.WriteUint8(tt.messageType)
|
||||
bf.WriteUint16(uint16(len(tt.payload)))
|
||||
bf.WriteBytes(tt.payload)
|
||||
bf.Seek(0, io.SeekStart)
|
||||
|
||||
pkt := &MsgSysCastBinary{}
|
||||
err := pkt.Parse(bf, &clientctx.ClientContext{})
|
||||
if err != nil {
|
||||
t.Fatalf("Parse() error = %v", err)
|
||||
}
|
||||
|
||||
if pkt.Unk0 != tt.unk0 {
|
||||
t.Errorf("Unk0 = %d, want %d", pkt.Unk0, tt.unk0)
|
||||
}
|
||||
if pkt.Unk1 != tt.unk1 {
|
||||
t.Errorf("Unk1 = %d, want %d", pkt.Unk1, tt.unk1)
|
||||
}
|
||||
if pkt.BroadcastType != tt.broadcastType {
|
||||
t.Errorf("BroadcastType = %d, want %d", pkt.BroadcastType, tt.broadcastType)
|
||||
}
|
||||
if pkt.MessageType != tt.messageType {
|
||||
t.Errorf("MessageType = %d, want %d", pkt.MessageType, tt.messageType)
|
||||
}
|
||||
if len(pkt.RawDataPayload) != len(tt.payload) {
|
||||
t.Errorf("RawDataPayload len = %d, want %d", len(pkt.RawDataPayload), len(tt.payload))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysCreateSemaphoreDetailedParse tests MsgSysCreateSemaphore parsing
|
||||
func TestMsgSysCreateSemaphoreDetailedParse(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
ackHandle uint32
|
||||
unk0 uint16
|
||||
payload []byte
|
||||
}{
|
||||
{"minimal", 1, 0, []byte{}},
|
||||
{"typical", 0xABCD1234, 100, []byte{0x01, 0x02, 0x03, 0x04}},
|
||||
{"maxed", 0xFFFFFFFF, 0xFFFF, make([]byte, 256)},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
bf := byteframe.NewByteFrame()
|
||||
bf.WriteUint32(tt.ackHandle)
|
||||
bf.WriteUint16(tt.unk0)
|
||||
bf.WriteUint16(uint16(len(tt.payload)))
|
||||
bf.WriteBytes(tt.payload)
|
||||
bf.Seek(0, io.SeekStart)
|
||||
|
||||
pkt := &MsgSysCreateSemaphore{}
|
||||
err := pkt.Parse(bf, &clientctx.ClientContext{})
|
||||
if err != nil {
|
||||
t.Fatalf("Parse() error = %v", err)
|
||||
}
|
||||
|
||||
if pkt.AckHandle != tt.ackHandle {
|
||||
t.Errorf("AckHandle = 0x%X, want 0x%X", pkt.AckHandle, tt.ackHandle)
|
||||
}
|
||||
if pkt.Unk0 != tt.unk0 {
|
||||
t.Errorf("Unk0 = %d, want %d", pkt.Unk0, tt.unk0)
|
||||
}
|
||||
if pkt.DataSize != uint16(len(tt.payload)) {
|
||||
t.Errorf("DataSize = %d, want %d", pkt.DataSize, len(tt.payload))
|
||||
}
|
||||
if len(pkt.RawDataPayload) != len(tt.payload) {
|
||||
t.Errorf("RawDataPayload len = %d, want %d", len(pkt.RawDataPayload), len(tt.payload))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysLogoutParse tests MsgSysLogout parsing
|
||||
func TestMsgSysLogoutDetailedParse(t *testing.T) {
|
||||
tests := []struct {
|
||||
unk0 uint8
|
||||
}{
|
||||
{0},
|
||||
{1},
|
||||
{100},
|
||||
{255},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
bf := byteframe.NewByteFrame()
|
||||
bf.WriteUint8(tt.unk0)
|
||||
bf.Seek(0, io.SeekStart)
|
||||
|
||||
pkt := &MsgSysLogout{}
|
||||
err := pkt.Parse(bf, &clientctx.ClientContext{})
|
||||
if err != nil {
|
||||
t.Fatalf("Parse() error = %v", err)
|
||||
}
|
||||
|
||||
if pkt.Unk0 != tt.unk0 {
|
||||
t.Errorf("Unk0 = %d, want %d", pkt.Unk0, tt.unk0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysBackStageParse tests MsgSysBackStage parsing
|
||||
func TestMsgSysBackStageDetailedParse(t *testing.T) {
|
||||
tests := []struct {
|
||||
ackHandle uint32
|
||||
}{
|
||||
{0},
|
||||
{1},
|
||||
{0x12345678},
|
||||
{0xFFFFFFFF},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
bf := byteframe.NewByteFrame()
|
||||
bf.WriteUint32(tt.ackHandle)
|
||||
bf.Seek(0, io.SeekStart)
|
||||
|
||||
pkt := &MsgSysBackStage{}
|
||||
err := pkt.Parse(bf, &clientctx.ClientContext{})
|
||||
if err != nil {
|
||||
t.Fatalf("Parse() error = %v", err)
|
||||
}
|
||||
|
||||
if pkt.AckHandle != tt.ackHandle {
|
||||
t.Errorf("AckHandle = 0x%X, want 0x%X", pkt.AckHandle, tt.ackHandle)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysUnlockStageParse tests MsgSysUnlockStage parsing
|
||||
func TestMsgSysUnlockStageDetailedParse(t *testing.T) {
|
||||
tests := []struct {
|
||||
unk0 uint16
|
||||
}{
|
||||
{0},
|
||||
{1},
|
||||
{100},
|
||||
{0xFFFF},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
bf := byteframe.NewByteFrame()
|
||||
bf.WriteUint16(tt.unk0)
|
||||
bf.Seek(0, io.SeekStart)
|
||||
|
||||
pkt := &MsgSysUnlockStage{}
|
||||
err := pkt.Parse(bf, &clientctx.ClientContext{})
|
||||
if err != nil {
|
||||
t.Fatalf("Parse() error = %v", err)
|
||||
}
|
||||
|
||||
if pkt.Unk0 != tt.unk0 {
|
||||
t.Errorf("Unk0 = %d, want %d", pkt.Unk0, tt.unk0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysPingParse tests MsgSysPing parsing
|
||||
func TestMsgSysPingDetailedParse(t *testing.T) {
|
||||
tests := []struct {
|
||||
ackHandle uint32
|
||||
}{
|
||||
{0},
|
||||
{0xABCDEF12},
|
||||
{0xFFFFFFFF},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
bf := byteframe.NewByteFrame()
|
||||
bf.WriteUint32(tt.ackHandle)
|
||||
bf.Seek(0, io.SeekStart)
|
||||
|
||||
pkt := &MsgSysPing{}
|
||||
err := pkt.Parse(bf, &clientctx.ClientContext{})
|
||||
if err != nil {
|
||||
t.Fatalf("Parse() error = %v", err)
|
||||
}
|
||||
|
||||
if pkt.AckHandle != tt.ackHandle {
|
||||
t.Errorf("AckHandle = 0x%X, want 0x%X", pkt.AckHandle, tt.ackHandle)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysTimeParse tests MsgSysTime parsing
|
||||
func TestMsgSysTimeDetailedParse(t *testing.T) {
|
||||
tests := []struct {
|
||||
getRemoteTime bool
|
||||
timestamp uint32
|
||||
}{
|
||||
{false, 0},
|
||||
{true, 1577836800}, // 2020-01-01 00:00:00
|
||||
{false, 0xFFFFFFFF},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
bf := byteframe.NewByteFrame()
|
||||
bf.WriteBool(tt.getRemoteTime)
|
||||
bf.WriteUint32(tt.timestamp)
|
||||
bf.Seek(0, io.SeekStart)
|
||||
|
||||
pkt := &MsgSysTime{}
|
||||
err := pkt.Parse(bf, &clientctx.ClientContext{})
|
||||
if err != nil {
|
||||
t.Fatalf("Parse() error = %v", err)
|
||||
}
|
||||
|
||||
if pkt.GetRemoteTime != tt.getRemoteTime {
|
||||
t.Errorf("GetRemoteTime = %v, want %v", pkt.GetRemoteTime, tt.getRemoteTime)
|
||||
}
|
||||
if pkt.Timestamp != tt.timestamp {
|
||||
t.Errorf("Timestamp = %d, want %d", pkt.Timestamp, tt.timestamp)
|
||||
}
|
||||
}
|
||||
}
|
||||
641
network/mhfpacket/msg_sys_packets_test.go
Normal file
641
network/mhfpacket/msg_sys_packets_test.go
Normal file
@@ -0,0 +1,641 @@
|
||||
package mhfpacket
|
||||
|
||||
import (
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"erupe-ce/common/byteframe"
|
||||
"erupe-ce/network"
|
||||
"erupe-ce/network/clientctx"
|
||||
)
|
||||
|
||||
// TestMsgSysCastBinaryParse tests parsing MsgSysCastBinary
|
||||
func TestMsgSysCastBinaryParse(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
unk0 uint16
|
||||
unk1 uint16
|
||||
broadcastType uint8
|
||||
messageType uint8
|
||||
payload []byte
|
||||
}{
|
||||
{"empty payload", 0, 0, 1, 2, []byte{}},
|
||||
{"small payload", 100, 200, 3, 4, []byte{0xAA, 0xBB, 0xCC}},
|
||||
{"large payload", 0xFFFF, 0xFFFF, 0xFF, 0xFF, make([]byte, 100)},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
bf := byteframe.NewByteFrame()
|
||||
bf.WriteUint16(tt.unk0)
|
||||
bf.WriteUint16(tt.unk1)
|
||||
bf.WriteUint8(tt.broadcastType)
|
||||
bf.WriteUint8(tt.messageType)
|
||||
bf.WriteUint16(uint16(len(tt.payload)))
|
||||
bf.WriteBytes(tt.payload)
|
||||
bf.Seek(0, io.SeekStart)
|
||||
|
||||
pkt := &MsgSysCastBinary{}
|
||||
err := pkt.Parse(bf, &clientctx.ClientContext{})
|
||||
if err != nil {
|
||||
t.Fatalf("Parse() error = %v", err)
|
||||
}
|
||||
|
||||
if pkt.Unk0 != tt.unk0 {
|
||||
t.Errorf("Unk0 = %d, want %d", pkt.Unk0, tt.unk0)
|
||||
}
|
||||
if pkt.Unk1 != tt.unk1 {
|
||||
t.Errorf("Unk1 = %d, want %d", pkt.Unk1, tt.unk1)
|
||||
}
|
||||
if pkt.BroadcastType != tt.broadcastType {
|
||||
t.Errorf("BroadcastType = %d, want %d", pkt.BroadcastType, tt.broadcastType)
|
||||
}
|
||||
if pkt.MessageType != tt.messageType {
|
||||
t.Errorf("MessageType = %d, want %d", pkt.MessageType, tt.messageType)
|
||||
}
|
||||
if len(pkt.RawDataPayload) != len(tt.payload) {
|
||||
t.Errorf("RawDataPayload len = %d, want %d", len(pkt.RawDataPayload), len(tt.payload))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysCastBinaryOpcode tests Opcode method
|
||||
func TestMsgSysCastBinaryOpcode(t *testing.T) {
|
||||
pkt := &MsgSysCastBinary{}
|
||||
if pkt.Opcode() != network.MSG_SYS_CAST_BINARY {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_CAST_BINARY", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysCreateSemaphoreParse tests parsing MsgSysCreateSemaphore
|
||||
func TestMsgSysCreateSemaphoreParse(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
ackHandle uint32
|
||||
unk0 uint16
|
||||
payload []byte
|
||||
}{
|
||||
{"empty payload", 1, 0, []byte{}},
|
||||
{"with data", 0x12345678, 100, []byte{0x01, 0x02, 0x03, 0x04}},
|
||||
{"max values", 0xFFFFFFFF, 0xFFFF, make([]byte, 50)},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
bf := byteframe.NewByteFrame()
|
||||
bf.WriteUint32(tt.ackHandle)
|
||||
bf.WriteUint16(tt.unk0)
|
||||
bf.WriteUint16(uint16(len(tt.payload)))
|
||||
bf.WriteBytes(tt.payload)
|
||||
bf.Seek(0, io.SeekStart)
|
||||
|
||||
pkt := &MsgSysCreateSemaphore{}
|
||||
err := pkt.Parse(bf, &clientctx.ClientContext{})
|
||||
if err != nil {
|
||||
t.Fatalf("Parse() error = %v", err)
|
||||
}
|
||||
|
||||
if pkt.AckHandle != tt.ackHandle {
|
||||
t.Errorf("AckHandle = %d, want %d", pkt.AckHandle, tt.ackHandle)
|
||||
}
|
||||
if pkt.Unk0 != tt.unk0 {
|
||||
t.Errorf("Unk0 = %d, want %d", pkt.Unk0, tt.unk0)
|
||||
}
|
||||
if pkt.DataSize != uint16(len(tt.payload)) {
|
||||
t.Errorf("DataSize = %d, want %d", pkt.DataSize, len(tt.payload))
|
||||
}
|
||||
if len(pkt.RawDataPayload) != len(tt.payload) {
|
||||
t.Errorf("RawDataPayload len = %d, want %d", len(pkt.RawDataPayload), len(tt.payload))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysCreateSemaphoreOpcode tests Opcode method
|
||||
func TestMsgSysCreateSemaphoreOpcode(t *testing.T) {
|
||||
pkt := &MsgSysCreateSemaphore{}
|
||||
if pkt.Opcode() != network.MSG_SYS_CREATE_SEMAPHORE {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_CREATE_SEMAPHORE", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysCastedBinaryOpcode tests Opcode method
|
||||
func TestMsgSysCastedBinaryOpcode(t *testing.T) {
|
||||
pkt := &MsgSysCastedBinary{}
|
||||
if pkt.Opcode() != network.MSG_SYS_CASTED_BINARY {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_CASTED_BINARY", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysSetStageBinaryOpcode tests Opcode method
|
||||
func TestMsgSysSetStageBinaryOpcode(t *testing.T) {
|
||||
pkt := &MsgSysSetStageBinary{}
|
||||
if pkt.Opcode() != network.MSG_SYS_SET_STAGE_BINARY {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_SET_STAGE_BINARY", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysGetStageBinaryOpcode tests Opcode method
|
||||
func TestMsgSysGetStageBinaryOpcode(t *testing.T) {
|
||||
pkt := &MsgSysGetStageBinary{}
|
||||
if pkt.Opcode() != network.MSG_SYS_GET_STAGE_BINARY {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_GET_STAGE_BINARY", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysWaitStageBinaryOpcode tests Opcode method
|
||||
func TestMsgSysWaitStageBinaryOpcode(t *testing.T) {
|
||||
pkt := &MsgSysWaitStageBinary{}
|
||||
if pkt.Opcode() != network.MSG_SYS_WAIT_STAGE_BINARY {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_WAIT_STAGE_BINARY", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysEnumerateClientOpcode tests Opcode method
|
||||
func TestMsgSysEnumerateClientOpcode(t *testing.T) {
|
||||
pkt := &MsgSysEnumerateClient{}
|
||||
if pkt.Opcode() != network.MSG_SYS_ENUMERATE_CLIENT {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_ENUMERATE_CLIENT", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysEnumerateStageOpcode tests Opcode method
|
||||
func TestMsgSysEnumerateStageOpcode(t *testing.T) {
|
||||
pkt := &MsgSysEnumerateStage{}
|
||||
if pkt.Opcode() != network.MSG_SYS_ENUMERATE_STAGE {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_ENUMERATE_STAGE", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysCreateMutexOpcode tests Opcode method
|
||||
func TestMsgSysCreateMutexOpcode(t *testing.T) {
|
||||
pkt := &MsgSysCreateMutex{}
|
||||
if pkt.Opcode() != network.MSG_SYS_CREATE_MUTEX {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_CREATE_MUTEX", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysCreateOpenMutexOpcode tests Opcode method
|
||||
func TestMsgSysCreateOpenMutexOpcode(t *testing.T) {
|
||||
pkt := &MsgSysCreateOpenMutex{}
|
||||
if pkt.Opcode() != network.MSG_SYS_CREATE_OPEN_MUTEX {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_CREATE_OPEN_MUTEX", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysDeleteMutexOpcode tests Opcode method
|
||||
func TestMsgSysDeleteMutexOpcode(t *testing.T) {
|
||||
pkt := &MsgSysDeleteMutex{}
|
||||
if pkt.Opcode() != network.MSG_SYS_DELETE_MUTEX {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_DELETE_MUTEX", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysOpenMutexOpcode tests Opcode method
|
||||
func TestMsgSysOpenMutexOpcode(t *testing.T) {
|
||||
pkt := &MsgSysOpenMutex{}
|
||||
if pkt.Opcode() != network.MSG_SYS_OPEN_MUTEX {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_OPEN_MUTEX", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysCloseMutexOpcode tests Opcode method
|
||||
func TestMsgSysCloseMutexOpcode(t *testing.T) {
|
||||
pkt := &MsgSysCloseMutex{}
|
||||
if pkt.Opcode() != network.MSG_SYS_CLOSE_MUTEX {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_CLOSE_MUTEX", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysDeleteSemaphoreOpcode tests Opcode method
|
||||
func TestMsgSysDeleteSemaphoreOpcode(t *testing.T) {
|
||||
pkt := &MsgSysDeleteSemaphore{}
|
||||
if pkt.Opcode() != network.MSG_SYS_DELETE_SEMAPHORE {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_DELETE_SEMAPHORE", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysAcquireSemaphoreOpcode tests Opcode method
|
||||
func TestMsgSysAcquireSemaphoreOpcode(t *testing.T) {
|
||||
pkt := &MsgSysAcquireSemaphore{}
|
||||
if pkt.Opcode() != network.MSG_SYS_ACQUIRE_SEMAPHORE {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_ACQUIRE_SEMAPHORE", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysReleaseSemaphoreOpcode tests Opcode method
|
||||
func TestMsgSysReleaseSemaphoreOpcode(t *testing.T) {
|
||||
pkt := &MsgSysReleaseSemaphore{}
|
||||
if pkt.Opcode() != network.MSG_SYS_RELEASE_SEMAPHORE {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_RELEASE_SEMAPHORE", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysCheckSemaphoreOpcode tests Opcode method
|
||||
func TestMsgSysCheckSemaphoreOpcode(t *testing.T) {
|
||||
pkt := &MsgSysCheckSemaphore{}
|
||||
if pkt.Opcode() != network.MSG_SYS_CHECK_SEMAPHORE {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_CHECK_SEMAPHORE", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysCreateAcquireSemaphoreOpcode tests Opcode method
|
||||
func TestMsgSysCreateAcquireSemaphoreOpcode(t *testing.T) {
|
||||
pkt := &MsgSysCreateAcquireSemaphore{}
|
||||
if pkt.Opcode() != network.MSG_SYS_CREATE_ACQUIRE_SEMAPHORE {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_CREATE_ACQUIRE_SEMAPHORE", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysOperateRegisterOpcode tests Opcode method
|
||||
func TestMsgSysOperateRegisterOpcode(t *testing.T) {
|
||||
pkt := &MsgSysOperateRegister{}
|
||||
if pkt.Opcode() != network.MSG_SYS_OPERATE_REGISTER {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_OPERATE_REGISTER", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysLoadRegisterOpcode tests Opcode method
|
||||
func TestMsgSysLoadRegisterOpcode(t *testing.T) {
|
||||
pkt := &MsgSysLoadRegister{}
|
||||
if pkt.Opcode() != network.MSG_SYS_LOAD_REGISTER {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_LOAD_REGISTER", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysNotifyRegisterOpcode tests Opcode method
|
||||
func TestMsgSysNotifyRegisterOpcode(t *testing.T) {
|
||||
pkt := &MsgSysNotifyRegister{}
|
||||
if pkt.Opcode() != network.MSG_SYS_NOTIFY_REGISTER {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_NOTIFY_REGISTER", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysCreateObjectOpcode tests Opcode method
|
||||
func TestMsgSysCreateObjectOpcode(t *testing.T) {
|
||||
pkt := &MsgSysCreateObject{}
|
||||
if pkt.Opcode() != network.MSG_SYS_CREATE_OBJECT {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_CREATE_OBJECT", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysDeleteObjectOpcode tests Opcode method
|
||||
func TestMsgSysDeleteObjectOpcode(t *testing.T) {
|
||||
pkt := &MsgSysDeleteObject{}
|
||||
if pkt.Opcode() != network.MSG_SYS_DELETE_OBJECT {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_DELETE_OBJECT", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysPositionObjectOpcode tests Opcode method
|
||||
func TestMsgSysPositionObjectOpcode(t *testing.T) {
|
||||
pkt := &MsgSysPositionObject{}
|
||||
if pkt.Opcode() != network.MSG_SYS_POSITION_OBJECT {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_POSITION_OBJECT", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysRotateObjectOpcode tests Opcode method
|
||||
func TestMsgSysRotateObjectOpcode(t *testing.T) {
|
||||
pkt := &MsgSysRotateObject{}
|
||||
if pkt.Opcode() != network.MSG_SYS_ROTATE_OBJECT {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_ROTATE_OBJECT", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysDuplicateObjectOpcode tests Opcode method
|
||||
func TestMsgSysDuplicateObjectOpcode(t *testing.T) {
|
||||
pkt := &MsgSysDuplicateObject{}
|
||||
if pkt.Opcode() != network.MSG_SYS_DUPLICATE_OBJECT {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_DUPLICATE_OBJECT", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysSetObjectBinaryOpcode tests Opcode method
|
||||
func TestMsgSysSetObjectBinaryOpcode(t *testing.T) {
|
||||
pkt := &MsgSysSetObjectBinary{}
|
||||
if pkt.Opcode() != network.MSG_SYS_SET_OBJECT_BINARY {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_SET_OBJECT_BINARY", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysGetObjectBinaryOpcode tests Opcode method
|
||||
func TestMsgSysGetObjectBinaryOpcode(t *testing.T) {
|
||||
pkt := &MsgSysGetObjectBinary{}
|
||||
if pkt.Opcode() != network.MSG_SYS_GET_OBJECT_BINARY {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_GET_OBJECT_BINARY", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysGetObjectOwnerOpcode tests Opcode method
|
||||
func TestMsgSysGetObjectOwnerOpcode(t *testing.T) {
|
||||
pkt := &MsgSysGetObjectOwner{}
|
||||
if pkt.Opcode() != network.MSG_SYS_GET_OBJECT_OWNER {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_GET_OBJECT_OWNER", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysUpdateObjectBinaryOpcode tests Opcode method
|
||||
func TestMsgSysUpdateObjectBinaryOpcode(t *testing.T) {
|
||||
pkt := &MsgSysUpdateObjectBinary{}
|
||||
if pkt.Opcode() != network.MSG_SYS_UPDATE_OBJECT_BINARY {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_UPDATE_OBJECT_BINARY", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysCleanupObjectOpcode tests Opcode method
|
||||
func TestMsgSysCleanupObjectOpcode(t *testing.T) {
|
||||
pkt := &MsgSysCleanupObject{}
|
||||
if pkt.Opcode() != network.MSG_SYS_CLEANUP_OBJECT {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_CLEANUP_OBJECT", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysInsertUserOpcode tests Opcode method
|
||||
func TestMsgSysInsertUserOpcode(t *testing.T) {
|
||||
pkt := &MsgSysInsertUser{}
|
||||
if pkt.Opcode() != network.MSG_SYS_INSERT_USER {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_INSERT_USER", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysDeleteUserOpcode tests Opcode method
|
||||
func TestMsgSysDeleteUserOpcode(t *testing.T) {
|
||||
pkt := &MsgSysDeleteUser{}
|
||||
if pkt.Opcode() != network.MSG_SYS_DELETE_USER {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_DELETE_USER", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysSetUserBinaryOpcode tests Opcode method
|
||||
func TestMsgSysSetUserBinaryOpcode(t *testing.T) {
|
||||
pkt := &MsgSysSetUserBinary{}
|
||||
if pkt.Opcode() != network.MSG_SYS_SET_USER_BINARY {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_SET_USER_BINARY", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysGetUserBinaryOpcode tests Opcode method
|
||||
func TestMsgSysGetUserBinaryOpcode(t *testing.T) {
|
||||
pkt := &MsgSysGetUserBinary{}
|
||||
if pkt.Opcode() != network.MSG_SYS_GET_USER_BINARY {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_GET_USER_BINARY", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysNotifyUserBinaryOpcode tests Opcode method
|
||||
func TestMsgSysNotifyUserBinaryOpcode(t *testing.T) {
|
||||
pkt := &MsgSysNotifyUserBinary{}
|
||||
if pkt.Opcode() != network.MSG_SYS_NOTIFY_USER_BINARY {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_NOTIFY_USER_BINARY", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysUpdateRightOpcode tests Opcode method
|
||||
func TestMsgSysUpdateRightOpcode(t *testing.T) {
|
||||
pkt := &MsgSysUpdateRight{}
|
||||
if pkt.Opcode() != network.MSG_SYS_UPDATE_RIGHT {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_UPDATE_RIGHT", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysAuthQueryOpcode tests Opcode method
|
||||
func TestMsgSysAuthQueryOpcode(t *testing.T) {
|
||||
pkt := &MsgSysAuthQuery{}
|
||||
if pkt.Opcode() != network.MSG_SYS_AUTH_QUERY {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_AUTH_QUERY", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysAuthDataOpcode tests Opcode method
|
||||
func TestMsgSysAuthDataOpcode(t *testing.T) {
|
||||
pkt := &MsgSysAuthData{}
|
||||
if pkt.Opcode() != network.MSG_SYS_AUTH_DATA {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_AUTH_DATA", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysAuthTerminalOpcode tests Opcode method
|
||||
func TestMsgSysAuthTerminalOpcode(t *testing.T) {
|
||||
pkt := &MsgSysAuthTerminal{}
|
||||
if pkt.Opcode() != network.MSG_SYS_AUTH_TERMINAL {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_AUTH_TERMINAL", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysRightsReloadOpcode tests Opcode method
|
||||
func TestMsgSysRightsReloadOpcode(t *testing.T) {
|
||||
pkt := &MsgSysRightsReload{}
|
||||
if pkt.Opcode() != network.MSG_SYS_RIGHTS_RELOAD {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_RIGHTS_RELOAD", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysTerminalLogOpcode tests Opcode method
|
||||
func TestMsgSysTerminalLogOpcode(t *testing.T) {
|
||||
pkt := &MsgSysTerminalLog{}
|
||||
if pkt.Opcode() != network.MSG_SYS_TERMINAL_LOG {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_TERMINAL_LOG", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysIssueLogkeyOpcode tests Opcode method
|
||||
func TestMsgSysIssueLogkeyOpcode(t *testing.T) {
|
||||
pkt := &MsgSysIssueLogkey{}
|
||||
if pkt.Opcode() != network.MSG_SYS_ISSUE_LOGKEY {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_ISSUE_LOGKEY", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysRecordLogOpcode tests Opcode method
|
||||
func TestMsgSysRecordLogOpcode(t *testing.T) {
|
||||
pkt := &MsgSysRecordLog{}
|
||||
if pkt.Opcode() != network.MSG_SYS_RECORD_LOG {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_RECORD_LOG", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysEchoOpcode tests Opcode method
|
||||
func TestMsgSysEchoOpcode(t *testing.T) {
|
||||
pkt := &MsgSysEcho{}
|
||||
if pkt.Opcode() != network.MSG_SYS_ECHO {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_ECHO", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysGetFileOpcode tests Opcode method
|
||||
func TestMsgSysGetFileOpcode(t *testing.T) {
|
||||
pkt := &MsgSysGetFile{}
|
||||
if pkt.Opcode() != network.MSG_SYS_GET_FILE {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_GET_FILE", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysHideClientOpcode tests Opcode method
|
||||
func TestMsgSysHideClientOpcode(t *testing.T) {
|
||||
pkt := &MsgSysHideClient{}
|
||||
if pkt.Opcode() != network.MSG_SYS_HIDE_CLIENT {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_HIDE_CLIENT", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysSetStatusOpcode tests Opcode method
|
||||
func TestMsgSysSetStatusOpcode(t *testing.T) {
|
||||
pkt := &MsgSysSetStatus{}
|
||||
if pkt.Opcode() != network.MSG_SYS_SET_STATUS {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_SET_STATUS", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysStageDestructOpcode tests Opcode method
|
||||
func TestMsgSysStageDestructOpcode(t *testing.T) {
|
||||
pkt := &MsgSysStageDestruct{}
|
||||
if pkt.Opcode() != network.MSG_SYS_STAGE_DESTRUCT {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_STAGE_DESTRUCT", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysLeaveStageOpcode tests Opcode method
|
||||
func TestMsgSysLeaveStageOpcode(t *testing.T) {
|
||||
pkt := &MsgSysLeaveStage{}
|
||||
if pkt.Opcode() != network.MSG_SYS_LEAVE_STAGE {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_LEAVE_STAGE", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysReserveStageOpcode tests Opcode method
|
||||
func TestMsgSysReserveStageOpcode(t *testing.T) {
|
||||
pkt := &MsgSysReserveStage{}
|
||||
if pkt.Opcode() != network.MSG_SYS_RESERVE_STAGE {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_RESERVE_STAGE", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysUnreserveStageOpcode tests Opcode method
|
||||
func TestMsgSysUnreserveStageOpcode(t *testing.T) {
|
||||
pkt := &MsgSysUnreserveStage{}
|
||||
if pkt.Opcode() != network.MSG_SYS_UNRESERVE_STAGE {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_UNRESERVE_STAGE", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysSetStagePassOpcode tests Opcode method
|
||||
func TestMsgSysSetStagePassOpcode(t *testing.T) {
|
||||
pkt := &MsgSysSetStagePass{}
|
||||
if pkt.Opcode() != network.MSG_SYS_SET_STAGE_PASS {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_SET_STAGE_PASS", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysLockGlobalSemaOpcode tests Opcode method
|
||||
func TestMsgSysLockGlobalSemaOpcode(t *testing.T) {
|
||||
pkt := &MsgSysLockGlobalSema{}
|
||||
if pkt.Opcode() != network.MSG_SYS_LOCK_GLOBAL_SEMA {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_LOCK_GLOBAL_SEMA", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysUnlockGlobalSemaOpcode tests Opcode method
|
||||
func TestMsgSysUnlockGlobalSemaOpcode(t *testing.T) {
|
||||
pkt := &MsgSysUnlockGlobalSema{}
|
||||
if pkt.Opcode() != network.MSG_SYS_UNLOCK_GLOBAL_SEMA {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_UNLOCK_GLOBAL_SEMA", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysTransBinaryOpcode tests Opcode method
|
||||
func TestMsgSysTransBinaryOpcode(t *testing.T) {
|
||||
pkt := &MsgSysTransBinary{}
|
||||
if pkt.Opcode() != network.MSG_SYS_TRANS_BINARY {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_TRANS_BINARY", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysCollectBinaryOpcode tests Opcode method
|
||||
func TestMsgSysCollectBinaryOpcode(t *testing.T) {
|
||||
pkt := &MsgSysCollectBinary{}
|
||||
if pkt.Opcode() != network.MSG_SYS_COLLECT_BINARY {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_COLLECT_BINARY", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysGetStateOpcode tests Opcode method
|
||||
func TestMsgSysGetStateOpcode(t *testing.T) {
|
||||
pkt := &MsgSysGetState{}
|
||||
if pkt.Opcode() != network.MSG_SYS_GET_STATE {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_GET_STATE", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysSerializeOpcode tests Opcode method
|
||||
func TestMsgSysSerializeOpcode(t *testing.T) {
|
||||
pkt := &MsgSysSerialize{}
|
||||
if pkt.Opcode() != network.MSG_SYS_SERIALIZE {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_SERIALIZE", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysEnumlobbyOpcode tests Opcode method
|
||||
func TestMsgSysEnumlobbyOpcode(t *testing.T) {
|
||||
pkt := &MsgSysEnumlobby{}
|
||||
if pkt.Opcode() != network.MSG_SYS_ENUMLOBBY {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_ENUMLOBBY", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysEnumuserOpcode tests Opcode method
|
||||
func TestMsgSysEnumuserOpcode(t *testing.T) {
|
||||
pkt := &MsgSysEnumuser{}
|
||||
if pkt.Opcode() != network.MSG_SYS_ENUMUSER {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_ENUMUSER", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysInfokyserverOpcode tests Opcode method
|
||||
func TestMsgSysInfokyserverOpcode(t *testing.T) {
|
||||
pkt := &MsgSysInfokyserver{}
|
||||
if pkt.Opcode() != network.MSG_SYS_INFOKYSERVER {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_INFOKYSERVER", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysExtendThresholdOpcode tests Opcode method
|
||||
func TestMsgSysExtendThresholdOpcode(t *testing.T) {
|
||||
pkt := &MsgSysExtendThreshold{}
|
||||
if pkt.Opcode() != network.MSG_SYS_EXTEND_THRESHOLD {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_EXTEND_THRESHOLD", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysAddObjectOpcode tests Opcode method
|
||||
func TestMsgSysAddObjectOpcode(t *testing.T) {
|
||||
pkt := &MsgSysAddObject{}
|
||||
if pkt.Opcode() != network.MSG_SYS_ADD_OBJECT {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_ADD_OBJECT", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysDelObjectOpcode tests Opcode method
|
||||
func TestMsgSysDelObjectOpcode(t *testing.T) {
|
||||
pkt := &MsgSysDelObject{}
|
||||
if pkt.Opcode() != network.MSG_SYS_DEL_OBJECT {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_DEL_OBJECT", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysDispObjectOpcode tests Opcode method
|
||||
func TestMsgSysDispObjectOpcode(t *testing.T) {
|
||||
pkt := &MsgSysDispObject{}
|
||||
if pkt.Opcode() != network.MSG_SYS_DISP_OBJECT {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_DISP_OBJECT", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsgSysHideObjectOpcode tests Opcode method
|
||||
func TestMsgSysHideObjectOpcode(t *testing.T) {
|
||||
pkt := &MsgSysHideObject{}
|
||||
if pkt.Opcode() != network.MSG_SYS_HIDE_OBJECT {
|
||||
t.Errorf("Opcode() = %s, want MSG_SYS_HIDE_OBJECT", pkt.Opcode())
|
||||
}
|
||||
}
|
||||
@@ -111,3 +111,87 @@ func TestDeltaPatch(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyDataDiffEmptyDiff(t *testing.T) {
|
||||
baseData := []byte{1, 2, 3, 4, 5}
|
||||
diff := []byte{}
|
||||
|
||||
result := ApplyDataDiff(diff, baseData)
|
||||
if !bytes.Equal(result, baseData) {
|
||||
t.Errorf("ApplyDataDiff with empty diff should return base data")
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyDataDiffEmptyBase(t *testing.T) {
|
||||
baseData := []byte{}
|
||||
diff := []byte{}
|
||||
|
||||
result := ApplyDataDiff(diff, baseData)
|
||||
if len(result) != 0 {
|
||||
t.Errorf("ApplyDataDiff with empty base and diff should return empty")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckReadUint8Error(t *testing.T) {
|
||||
r := bytes.NewReader([]byte{})
|
||||
_, err := checkReadUint8(r)
|
||||
if err == nil {
|
||||
t.Error("checkReadUint8 on empty reader should return error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckReadUint16Error(t *testing.T) {
|
||||
r := bytes.NewReader([]byte{0x01}) // Only 1 byte, need 2
|
||||
_, err := checkReadUint16(r)
|
||||
if err == nil {
|
||||
t.Error("checkReadUint16 with insufficient data should return error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckReadUint16Success(t *testing.T) {
|
||||
r := bytes.NewReader([]byte{0x12, 0x34})
|
||||
val, err := checkReadUint16(r)
|
||||
if err != nil {
|
||||
t.Errorf("checkReadUint16 error = %v", err)
|
||||
}
|
||||
if val != 0x1234 {
|
||||
t.Errorf("checkReadUint16 = 0x%04X, want 0x1234", val)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadCountError(t *testing.T) {
|
||||
r := bytes.NewReader([]byte{})
|
||||
_, err := readCount(r)
|
||||
if err == nil {
|
||||
t.Error("readCount on empty reader should return error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadCountExtended(t *testing.T) {
|
||||
// When count8 is 0, read count16
|
||||
r := bytes.NewReader([]byte{0x00, 0x01, 0x00}) // count8=0, count16=256
|
||||
count, err := readCount(r)
|
||||
if err != nil {
|
||||
t.Errorf("readCount error = %v", err)
|
||||
}
|
||||
if count != 256 {
|
||||
t.Errorf("readCount = %d, want 256", count)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadCountExtendedError(t *testing.T) {
|
||||
// count8 is 0 but not enough bytes for count16
|
||||
r := bytes.NewReader([]byte{0x00, 0x01})
|
||||
_, err := readCount(r)
|
||||
if err == nil {
|
||||
t.Error("readCount with insufficient data for count16 should return error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckReadUint16EmptyReader(t *testing.T) {
|
||||
r := bytes.NewReader([]byte{})
|
||||
_, err := checkReadUint16(r)
|
||||
if err == nil {
|
||||
t.Error("checkReadUint16 on empty reader should return error")
|
||||
}
|
||||
}
|
||||
|
||||
150
server/channelserver/timeserver/time_mode_test.go
Normal file
150
server/channelserver/timeserver/time_mode_test.go
Normal file
@@ -0,0 +1,150 @@
|
||||
package timeserver
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestPFaddTime(t *testing.T) {
|
||||
// Save original state
|
||||
originalPnewtime := Pnewtime
|
||||
defer func() { Pnewtime = originalPnewtime }()
|
||||
|
||||
Pnewtime = 0
|
||||
|
||||
// First call should return 24
|
||||
result := PFadd_time()
|
||||
if result != time.Duration(24) {
|
||||
t.Errorf("PFadd_time() = %v, want 24", result)
|
||||
}
|
||||
|
||||
// Second call should return 48
|
||||
result = PFadd_time()
|
||||
if result != time.Duration(48) {
|
||||
t.Errorf("PFadd_time() second call = %v, want 48", result)
|
||||
}
|
||||
|
||||
// Check Pfixtimer is updated
|
||||
if Pfixtimer != time.Duration(48) {
|
||||
t.Errorf("Pfixtimer = %v, want 48", Pfixtimer)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTimeCurrent(t *testing.T) {
|
||||
result := TimeCurrent()
|
||||
if result.IsZero() {
|
||||
t.Error("TimeCurrent() returned zero time")
|
||||
}
|
||||
|
||||
// Result should be in the past (7 years ago)
|
||||
now := time.Now()
|
||||
diff := now.Year() - result.Year()
|
||||
if diff != 7 {
|
||||
t.Errorf("TimeCurrent() year diff = %d, want 7", diff)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTimeMidnight(t *testing.T) {
|
||||
result := Time_midnight()
|
||||
if result.IsZero() {
|
||||
t.Error("Time_midnight() returned zero time")
|
||||
}
|
||||
|
||||
// Result should be midnight (with hour added, so 1:00 AM)
|
||||
if result.Minute() != 0 {
|
||||
t.Errorf("Time_midnight() minute = %d, want 0", result.Minute())
|
||||
}
|
||||
if result.Second() != 0 {
|
||||
t.Errorf("Time_midnight() second = %d, want 0", result.Second())
|
||||
}
|
||||
}
|
||||
|
||||
func TestTimeStatic(t *testing.T) {
|
||||
// Reset state for testing
|
||||
DoOnce_t = false
|
||||
Fix_t = time.Time{}
|
||||
|
||||
result := Time_static()
|
||||
if result.IsZero() {
|
||||
t.Error("Time_static() returned zero time")
|
||||
}
|
||||
|
||||
// Calling again should return same time (static)
|
||||
result2 := Time_static()
|
||||
if !result.Equal(result2) {
|
||||
t.Error("Time_static() should return same time on second call")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTstaticMidnight(t *testing.T) {
|
||||
// Reset state for testing
|
||||
DoOnce_midnight = false
|
||||
Fix_midnight = time.Time{}
|
||||
|
||||
result := Tstatic_midnight()
|
||||
if result.IsZero() {
|
||||
t.Error("Tstatic_midnight() returned zero time")
|
||||
}
|
||||
|
||||
// Calling again should return same time (static)
|
||||
result2 := Tstatic_midnight()
|
||||
if !result.Equal(result2) {
|
||||
t.Error("Tstatic_midnight() should return same time on second call")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTimeCurrentWeekUint8(t *testing.T) {
|
||||
result := Time_Current_Week_uint8()
|
||||
|
||||
// Week of month should be 1-5
|
||||
if result < 1 || result > 5 {
|
||||
t.Errorf("Time_Current_Week_uint8() = %d, expected 1-5", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTimeCurrentWeekUint32(t *testing.T) {
|
||||
result := Time_Current_Week_uint32()
|
||||
|
||||
// Week of month should be 1-5
|
||||
if result < 1 || result > 5 {
|
||||
t.Errorf("Time_Current_Week_uint32() = %d, expected 1-5", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDetectDay(t *testing.T) {
|
||||
result := Detect_Day()
|
||||
|
||||
// Result should be bool, and true only on Wednesday
|
||||
isWednesday := time.Now().Weekday() == time.Wednesday
|
||||
if result != isWednesday {
|
||||
t.Errorf("Detect_Day() = %v, expected %v (today is %v)", result, isWednesday, time.Now().Weekday())
|
||||
}
|
||||
}
|
||||
|
||||
func TestGlobalVariables(t *testing.T) {
|
||||
// Test that global variables exist and have expected default types
|
||||
_ = DoOnce_midnight
|
||||
_ = DoOnce_t2
|
||||
_ = DoOnce_t
|
||||
_ = Fix_midnight
|
||||
_ = Fix_t2
|
||||
_ = Fix_t
|
||||
_ = Pfixtimer
|
||||
_ = Pnewtime
|
||||
}
|
||||
|
||||
func TestTimeConsistency(t *testing.T) {
|
||||
// Test that TimeCurrent and Time_midnight are on the same day
|
||||
current := TimeCurrent()
|
||||
midnight := Time_midnight()
|
||||
|
||||
if current.Year() != midnight.Year() {
|
||||
t.Errorf("Year mismatch: current=%d, midnight=%d", current.Year(), midnight.Year())
|
||||
}
|
||||
if current.Month() != midnight.Month() {
|
||||
t.Errorf("Month mismatch: current=%v, midnight=%v", current.Month(), midnight.Month())
|
||||
}
|
||||
if current.Day() != midnight.Day() {
|
||||
t.Errorf("Day mismatch: current=%d, midnight=%d", current.Day(), midnight.Day())
|
||||
}
|
||||
}
|
||||
62
server/entranceserver/entrance_server_test.go
Normal file
62
server/entranceserver/entrance_server_test.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package entranceserver
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"erupe-ce/config"
|
||||
)
|
||||
|
||||
func TestNewServer(t *testing.T) {
|
||||
cfg := &Config{
|
||||
Logger: nil,
|
||||
DB: nil,
|
||||
ErupeConfig: &config.Config{},
|
||||
}
|
||||
|
||||
s := NewServer(cfg)
|
||||
if s == nil {
|
||||
t.Fatal("NewServer() returned nil")
|
||||
}
|
||||
if s.isShuttingDown {
|
||||
t.Error("New server should not be shutting down")
|
||||
}
|
||||
if s.erupeConfig == nil {
|
||||
t.Error("erupeConfig should not be nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewServerWithNilConfig(t *testing.T) {
|
||||
cfg := &Config{}
|
||||
s := NewServer(cfg)
|
||||
if s == nil {
|
||||
t.Fatal("NewServer() returned nil for empty config")
|
||||
}
|
||||
}
|
||||
|
||||
func TestServerType(t *testing.T) {
|
||||
s := &Server{}
|
||||
if s.isShuttingDown {
|
||||
t.Error("Zero value server should not be shutting down")
|
||||
}
|
||||
if s.listener != nil {
|
||||
t.Error("Zero value server should have nil listener")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigFields(t *testing.T) {
|
||||
cfg := &Config{
|
||||
Logger: nil,
|
||||
DB: nil,
|
||||
ErupeConfig: nil,
|
||||
}
|
||||
|
||||
if cfg.Logger != nil {
|
||||
t.Error("Config Logger should be nil")
|
||||
}
|
||||
if cfg.DB != nil {
|
||||
t.Error("Config DB should be nil")
|
||||
}
|
||||
if cfg.ErupeConfig != nil {
|
||||
t.Error("Config ErupeConfig should be nil")
|
||||
}
|
||||
}
|
||||
@@ -210,3 +210,59 @@ func TestFailureRespIsMinimal(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewServer(t *testing.T) {
|
||||
// Test that NewServer creates a valid server
|
||||
cfg := &Config{
|
||||
Logger: nil,
|
||||
DB: nil,
|
||||
ErupeConfig: nil,
|
||||
}
|
||||
|
||||
s := NewServer(cfg)
|
||||
if s == nil {
|
||||
t.Fatal("NewServer() returned nil")
|
||||
}
|
||||
if s.isShuttingDown {
|
||||
t.Error("New server should not be shutting down")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewServerWithNilConfig(t *testing.T) {
|
||||
// Testing with nil fields in config
|
||||
cfg := &Config{}
|
||||
s := NewServer(cfg)
|
||||
if s == nil {
|
||||
t.Fatal("NewServer() returned nil for empty config")
|
||||
}
|
||||
}
|
||||
|
||||
func TestServerType(t *testing.T) {
|
||||
// Test Server struct fields
|
||||
s := &Server{}
|
||||
if s.isShuttingDown {
|
||||
t.Error("Zero value server should not be shutting down")
|
||||
}
|
||||
if s.sessions != nil {
|
||||
t.Error("Zero value server should have nil sessions map")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigFields(t *testing.T) {
|
||||
// Test Config struct fields
|
||||
cfg := &Config{
|
||||
Logger: nil,
|
||||
DB: nil,
|
||||
ErupeConfig: nil,
|
||||
}
|
||||
|
||||
if cfg.Logger != nil {
|
||||
t.Error("Config Logger should be nil")
|
||||
}
|
||||
if cfg.DB != nil {
|
||||
t.Error("Config DB should be nil")
|
||||
}
|
||||
if cfg.ErupeConfig != nil {
|
||||
t.Error("Config ErupeConfig should be nil")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user