UClientUnitTest

Base class for all unit tests depending upon a MinimalClient connecting to a server.

Windows
MacOS
Linux

Inheritance Hierarchy

References

Module

NetcodeUnitTest

Header

/Engine/Plugins/NetcodeUnitTest/NetcodeUnitTest/Source/NetcodeUnitTest/Classes/ClientUnitTest.h

Include

#include "ClientUnitTest.h"

Syntax

[UCLASS](Programming/UnrealArchitecture/Reference/Classes#classdeclaration)(Abstract)
class UClientUnitTest : public UProcessUnitTest

Remarks

Base class for all unit tests depending upon a MinimalClient connecting to a server. The MinimalClient handles creation/cleanup of an entire new UWorld, UNetDriver and UNetConnection, for fast unit testing.

NOTE: See NUTEnum.h, for important flags for configuring unit tests and the minimal client.

In subclasses, implement the unit test within the ExecuteClientUnitTest function (remembering to call parent)

Variables

Name Description

Protected variable

TArray< UClass ...

 

AllowedClientActors

Actors the server is allowed replicate to client (requires AllowActors flag).

Protected variable

TArray< FString...

 

AllowedClientRPCs

Clientside RPC's that should be allowed to execute (requires minimal client NotifyProcessNetEvent flag)

Protected variable

FString

 

BaseClientParameters

The (non-URL) commandline parameters clients should be launched with

Protected variable

FString

 

BaseClientURL

The base URL clients should start with

Protected variable

FString

 

BaseServerParameters

The (non-URL) commandline parameters the server should be launched with

Protected variable

FString

 

BaseServerURL

The base URL the server should start with

Protected variable

bool

 

bBlockingClientDelay

Whether or not there is a blocking event/process preventing setup of a client

Protected variable

bool

 

bBlockingMinClientDelay

Whether or not there is a blocking event/process preventing the minimal client from connecting

Protected variable

bool

 

bBlockingServerDelay

Whether or not there is a blocking event/process preventing setup of the server

Protected variable

FString

 

BeaconAddress

The address of the server beacon (if UnitTestFlags are set to connect to a beacon)

Protected variable

bool

 

bPendingNetworkFailure

An expected network failure occurred, which will be handled during the next tick instead of immediately

Protected variable

bool

 

bReceivedPong

If EUnitTestFlags::RequirePing is true, whether or not we have already received the pong

Protected variable

bool

 

bTriggerredInitialConnect

Whether or not the initial connect of the minimal client was triggered

Protected variable

bool

 

bUnitNUTActorSetup

Whether or not UnitNUTActor is fully setup, i.e. has replicated its Owner

Protected variable

bool

 

bUnitPawnSetup

Whether or not the UnitPC Pawn was fully setup (requires EUnitTestFlags::RequirePawn)

Protected variable

bool

 

bUnitPlayerStateSetup

Whether or not the UnitPC PlayerState was fully setup (requires EUnitTestFlags::RequirePlayerState)

Protected variable

TWeakPtr< FUnit...

 

ClientHandle

Reference to the created client process handling struct (if enabled)

Protected variable UProperty

UMinimalClient ...

 

MinClient

The object which handles implementation of the minimal client

Protected variable

TSubclassOf< UM...

 

MinClientClass

The class to use for the MinimalClient

Protected variable

EMinClientFlags

 

MinClientFlags

Flags for configuring the minimal client - lots of interdependencies between these and UnitTestFlags

Protected variable

double

 

NextBlockingTimeout

When a server is launched after a blocking event/process, this delays the launch of any clients, in case of more blockages

Protected variable

FString

 

ServerAddress

The address of the launched server

Protected variable

FString

 

ServerBeaconType

If connecting to a beacon, the beacon type name we are connecting to

Protected variable

TWeakPtr< FUnit...

 

ServerHandle

Runtime variables Reference to the created server process handling struct

Protected variable

TWeakObjectPtr<...

 

UnitBeacon

If EUnitTestFlags::RequireBeacon is set, stores a reference to the replicated beacon

Protected variable

TWeakObjectPtr<...

 

UnitNUTActor

If EUnitTestFlags::RequireNUTActor is set, stores a reference to the replicated NUTActor

Protected variable

TWeakObjectPtr<...

 

UnitPC

Client state variables Stores a reference to the replicated PlayerController (if set to wait for this), after NotifyHandleClientPlayer

Protected variable

EUnitTestFlags

 

UnitTestFlags

Variables which should be specified by every subclass (some depending upon flags) All of the internal unit test parameters/flags, for controlling state and execution

Constructors

Name Description

Public function

UClientUnitTest

(
    const FObjectInitializer& ObjectIn...
)

UClientUnitTest

Functions

Name Description

Protected function Virtual

void

 

CleanupMinimalClient()

Cleans up the minimal client

Protected function Virtual

bool

 

ConnectMinimalClient

(
    const TCHAR* InNetID
)

Connects a minimal client, to the launched/launching server

Protected function Virtual

FString

 

ConstructClientParameters

(
    FString ConnectIP
)

Puts together the commandline parameters clients should use, based upon the unit test settings

Protected function Virtual

FString

 

ConstructServerParameters()

Puts together the commandline parameters the server should use, based upon the unit test settings

Public function Virtual

void

 

ExecuteClientUnitTest()

Interface and hooked events for client unit tests Override this, to implement the client unit test NOTE: Should be called last, in overridden functions IMPORTANT: EndUnitTest should be triggered, upon completion of the unit test (which may be delayed, for many unit tests)

Public function Const

FString

 

GetBeaconAddress()

Accessor for BeaconAddress

Public function Static

const TCHAR ...

 

GetGenericExploitFailLog()

Gets the generic log message that is used to indicate unit test failure

Protected function

EUnitTestFla...

 

GetMetRequirements()

Returns the requirements flags, that this unit test currently meets

Public function Static

void

 

GetNextServerPorts

(
    int32& OutServerPort,
    int32& OutBeaconPort,
    bool bAdvance
)

Determine the next unique server ports to use - incremented to a new unique number, internally

Public function

TWeakPtr< FU...

 

GetServerHandle()

Accessor for ServerHandle

Public function

EUnitTestFla...

 

GetUnitTestFlags()

Accessor for UnitTestFlags

Public function Virtual

bool

 

HasAllCustomRequirements()

Optionally, if the 'RequireCustom' flag is set, this returns whether custom conditions have been met.

Protected function

bool

 

HasAllRequirements

(
    bool bIgnoreCustom
)

Whether or not all 'requirements' flag conditions have been met

Public function Virtual

void

 

NotifyAllowNetActor

(
    UClass* ActorClass,
    bool bActorChannel,
    bool& bBlockActor
)

Notification triggered BEFORE a replicated actor has been created (allowing you to block creation, based on class)

Public function Virtual

void

 

NotifyAlterMinClient

(
    FMinClientParms& Parms
)

Gives subclass UnitTest's an opportunity to alter the MinimalClient setup parameters

Public function Virtual

void

 

NotifyControlMessage

(
    FInBunch& Bunch,
    uint8 MessageType
)

Override this, to receive notification of all other non-NMT_NUTControl control messages

Public function Virtual

void

 

NotifyHandleClientPlayer

(
    APlayerController* PC,
    UNetConnection* Connection
)

Notification that the local net connections PlayerController has been replicated and is being setup

Public function Virtual

void

 

NotifyMinClientConnected()

Notification from the minimal client, that it has fully connected

Public function Virtual

void

 

NotifyNetActor

(
    UActorChannel* ActorChannel,
    AActor* Actor
)

Override this, to receive notification AFTER an actor channel actor has been created

Public function Virtual

void

 

NotifyNetworkFailure

(
    ENetworkFailure::Type FailureType,
    const FString& ErrorString
)

Triggered upon a network connection failure

Public function Virtual

void

 

NotifyNUTControl

(
    ENUTControlCommand CmdType,
    FString Command
)

Override this, to receive notification of NMT_NUTControl messages, from the server

Public function Virtual

void

 

NotifyProcessEvent

(
    AActor* Actor,
    UFunction* Function,
    void* Parameters,
    bool& bBlockEvent
)

Overridable in subclasses - can be used to control/block any script events, other than receiving of RPC's (see NotifyReceiveRPC)

Public function Virtual

void

 

NotifyReceivedRawPacket

(
    void* Data,
    int32& Count
)

If EUnitTestFlags::CaptureReceiveRaw is set, this is triggered for every packet received from the server NOTE: Data is a uint8 array, of size 'NETWORK_MAX_PACKET', and elements can safely be modified

Public function Virtual

void

 

NotifyReceiveRPC

(
    AActor* Actor,
    UFunction* Function,
    void* Parameters,
    bool& bBlockRPC
)

Overridable in subclasses - can be used to control/block receiving of RPC's

Public function Virtual

void

 

NotifySendRPC

(
    AActor* Actor,
    UFunction* Function,
    void* Parameters,
    FOutParmRec* OutParms,
    FFrame* Stack,
    UObject* SubObject,
    bool& bBlockSendRPC
)

Overridable in subclasses - can be used to control/block sending of RPC's

Public function Virtual

void

 

NotifySocketSendRawPacket

(
    void* Data,
    int32 Count,
    bool& bBlockSend
)

Triggered for every packet sent to the server, when LowLevelSend is called.

Public function

void

 

OnRPCFailure()

Callback for when an RPC send fails on the minimal client

Public function Virtual

void

 

ReceivedControlBunch

(
    FInBunch& Bunch
)

Bunches received on the control channel.

Public function

void

 

SendGenericExploitFailLog()

Sends a generic log message to the server, which (if successfully logged) indicates unit test failure.

Public function

bool

 

SendNUTControl

(
    ENUTControlCommand CommandType,
    FString Command
)

Utility functions for use by subclasses Sends an NMT_NUTControl control channel message, for the server NUTActor.

Public function

bool

 

SendRPCChecked

(
    UObject* Target,
    FFuncReflection& FuncRefl
)

See UMinimalClient

Public function

bool

 

SendRPCChecked

(
    UObject* Target,
    const TCHAR* FunctionName,
    void* Parms,
    int16 ParmsSize,
    int16 ParmsSizeCorrection
)

See UMinimalClient

Public function

bool

 

SendUnitRPCChecked

(
    FString RPCName
)

As above, except executes a static UFunction in the unit test (must be prefixed with UnitTestServer_), on the unit test server, allowing unit tests to define and contain their own 'pseudo'-RPC's.

Public function

bool

 

SendUnitRPCChecked

(
    FString RPCName
)

As above, except allows 'UnitTestServer' RPC's to be located in an arbitrary class (e.g. if shared between unit tests), specified as the delegate parameter.

Protected function

void

 

SetFlags()

Sets and validates at compile time, that the specified flags are valid.

Protected function Virtual

TWeakPtr< FU...

 

StartUnitTestClient

(
    FString ConnectIP,
    bool bMinimized
)

Starts a client process tied to the unit test, and connects to the specified server address

Protected function Virtual

void

 

StartUnitTestServer()

Starts the server process for a particular unit test

Protected function

void

 

TriggerAutoReconnect()

Triggers an auto-reconnect (disconnect/reconnect) of the minimal client

Protected function

void

 

ValidateUnitFlags

(
    EUnitTestFlags RuntimeUnitFlags,
    EMinClientFlags RuntimeMinFlags
)

Internal base implementation and utility functions for client unit tests Validates, both at compile time (template params) or at runtime (function params), that the specified flags are valid.

Overridden from UProcessUnitTest

Name Description

Public function Virtual

void

 

NotifyProcessFinished

(
    TWeakPtr< FUnitTestProcess > InProc...
)

Notifies when a running process is detected as having finished/closed NOTE: This will not get called, when ShutdownUnitTestProcess is used, only when a program ends by itself

Public function Virtual

void

 

NotifyProcessLog

(
    TWeakPtr< FUnitTestProcess > InProc...,
    const TArray< FString >& InLogLine...
)

Interface for process unit tests For implementation in subclasses, for helping to verify success/fail upon completion of unit tests NOTE: Not called again once VerificationState is set WARNING: Be careful when iterating InLogLines in multiple different for loops, if the sequence of detected logs is important

Public function Virtual

void

 

NotifyProcessSuspendState

(
    TWeakPtr< FUnitTestProcess > InProc...,
    ESuspendState InSuspendState
)

Notifies when the suspend state of a process changes

Public function Virtual

void

 

NotifySuspendRequest()

Notifies that there was a request to suspend/resume the unit test

Protected function Virtual

void

 

PrintUnitTestProcessErrors

(
    TSharedPtr< FUnitTestProcess > InHa...
)

If any errors logs were detected upon ShutdownUnitTestProcess, this is called to print them out

Overridden from UUnitTest

Name Description

Protected function Virtual

void

 

CleanupUnitTest

(
    EUnitTestResetStage ResetStage
)

Cleans up all items needing destruction, and removes the unit test from tracking, before deleting the unit test itself

Protected function Virtual

bool

 

ExecuteUnitTest()

Executes the main unit test

Public function Virtual

void

 

GetCommandContextList

(
    TArray< TSharedPtr< FString >>& Ou...,
    FString& OutDefaultContext
)

Outputs the list of console command contexts, that this unit test supports (which can include custom contexts in subclasses)

Public function Virtual

ELogType

 

GetExpectedLogTypes()

Returns the type of log entries that this unit expects to output, for setting up log window filters (only needs to return values which affect what tabs are shown)

Protected function Virtual

void

 

LogComplete()

Triggered upon unit test completion, for outputting that the unit test has completed - plus other unit test state information

Public function Virtual

bool

 

NotifyConsoleCommandRequest

(
    FString CommandContext,
    FString Command
)

Notifies that there was a request to execute a console command for the unit test, which can occur in a specific context, e.g. for a unit test server, for a local minimal-client (within the unit test), or for a separate unit test client process

Protected function Virtual

void

 

ResetTimeout

(
    FString ResetReason,
    bool bResetConnTimeout,
    uint32 MinDuration
)

Resets the unit test timeout code - should be used liberally, within every unit test, when progress is made during execution

Protected function Virtual

void

 

UnblockEvents

(
    EUnitTaskFlags ReadyEvents
)

When events that were pending but blocked by a UnitTask, are unblocked, this function triggers them.

Protected function Virtual

bool

 

ValidateUnitTestSettings

(
    bool bCDOCheck
)

Validate that the unit test settings/flags specified for this unit test, are compatible with one another, and that the engine settings/environment, support running the unit test.

Overridden from UUnitTestBase

Name Description

Protected function Virtual Const

bool

 

IsTickable()

Must override in subclasses, that need ticking.

Protected function Virtual

void

 

UnitTick

(
    float DeltaTime
)

Main tick function for the unit test

Overridden from FUnitLogInterface

Name Description

Protected function Virtual

bool

 

IsConnectionLogSource

(
    UNetConnection* InConnection
)

Whether or not this log interface is the source of a UNetConnection - used for deciding where to direct, UNetConnection log hooks

Constants

Name

Description

OnlineBeaconClass

Static variables Static reference to the OnlineBeaconClient static class

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey
Dismiss