/**
 * @file UDPStreamerTest.h
 * @brief Header file for class UDPStreamerTest
 * @date 13/05/2026
 * @author Martino Ferrari
 *
 * @copyright Copyright 2015 F4E | European Joint Undertaking for ITER and
 * the Development of Fusion Energy ('Fusion for Energy').
 * Licensed under the EUPL, Version 1.1 or - as soon they will be approved
 * by the European Commission - subsequent versions of the EUPL (the "Licence")
 * You may not use this work except in compliance with the Licence.
 * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl
 *
 * @warning Unless required by applicable law or agreed to in writing,
 * software distributed under the Licence is distributed on an "AS IS"
 * basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the Licence permissions and limitations under the Licence.
 *
 * @details This header file contains the declaration of the class UDPStreamerTest
 * with all of its public, protected and private members. It may also include
 * definitions for inline methods which need to be visible to the compiler.
 */

#ifndef UDPSTREAMERTEST_H_
#define UDPSTREAMERTEST_H_

/*---------------------------------------------------------------------------*/
/*                        Standard header includes                           */
/*---------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------*/
/*                        Project header includes                            */
/*---------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------*/
/*                           Class declaration                               */
/*---------------------------------------------------------------------------*/

/**
 * @brief Tests the UDPStreamer DataSource public methods.
 */
class UDPStreamerTest {
public:

    /**
     * @brief Tests the default constructor.
     */
    bool TestConstructor();

    /**
     * @brief Tests Initialise with a fully valid configuration.
     */
    bool TestInitialise_Valid();

    /**
     * @brief Tests that a missing Port uses the default (44500).
     */
    bool TestInitialise_DefaultPort();

    /**
     * @brief Tests that MaxPayloadSize below the minimum is rejected.
     */
    bool TestInitialise_InvalidMaxPayloadSize();

    /**
     * @brief Tests that StackSize = 0 is rejected.
     */
    bool TestInitialise_ZeroStackSize();

    /**
     * @brief Tests GetBrokerName returns the correct broker for OutputSignals.
     */
    bool TestGetBrokerName_Output();

    /**
     * @brief Tests GetBrokerName returns empty string for InputSignals.
     */
    bool TestGetBrokerName_Input();

    /**
     * @brief Tests AllocateMemory allocates readyBuffer, scratchBuffer, wireBuffer.
     */
    bool TestAllocateMemory();

    /**
     * @brief Tests SetConfiguredDatabase with basic signal types.
     */
    bool TestSetConfiguredDatabase_BasicSignals();

    /**
     * @brief Tests SetConfiguredDatabase with a quantized float signal.
     */
    bool TestSetConfiguredDatabase_Quantized();

    /**
     * @brief Tests that quantization on a non-float signal is rejected.
     */
    bool TestSetConfiguredDatabase_InvalidQuantOnInteger();

    /**
     * @brief Tests that an unknown QuantizedType is rejected.
     */
    bool TestSetConfiguredDatabase_UnknownQuantType();

    /**
     * @brief Tests TimeMode = PacketTime (default).
     */
    bool TestSetConfiguredDatabase_TimeModePacket();

    /**
     * @brief Tests TimeMode = FullArray with a matching time signal.
     */
    bool TestSetConfiguredDatabase_TimeModeFullArray();

    /**
     * @brief Tests TimeMode = FirstSample with a scalar time signal.
     */
    bool TestSetConfiguredDatabase_TimeModeFirstSample();

    /**
     * @brief Tests that FirstSample without SamplingRate is rejected.
     */
    bool TestSetConfiguredDatabase_MissingSamplingRate();

    /**
     * @brief Tests that TimeSignal pointing to a non-existent signal is rejected.
     */
    bool TestSetConfiguredDatabase_InvalidTimeSignal();

    /**
     * @brief Tests that FullArray TimeMode with mismatched element counts is rejected.
     */
    bool TestSetConfiguredDatabase_FullArrayMismatch();

    /**
     * @brief Tests PrepareNextState starts the thread and opens the socket.
     */
    bool TestPrepareNextState();

    /**
     * @brief Tests Synchronise when no client is connected (must return true, no crash).
     */
    bool TestSynchronise_NoClient();

    /**
     * @brief Tests the full CONNECT → CONFIG → DATA → DISCONNECT flow via loopback UDP.
     */
    bool TestExecute_ConnectDataDisconnect();

    /**
     * @brief Tests that DATA packets are fragmented correctly for large payloads.
     */
    bool TestExecute_Fragmentation();

    /**
     * @brief Tests uint16 quantization: verifies that 0 maps to 0 and max maps to 65535.
     */
    bool TestQuantization_Uint16Extremes();

    /**
     * @brief Tests uint8 quantization: verifies clamping of out-of-range values.
     */
    bool TestQuantization_Uint8Clamping();

    /**
     * @brief Tests PublishingMode = "Auto" with a valid MinRefreshRate.
     */
    bool TestInitialise_AutoMode_Valid();

    /**
     * @brief Tests that PublishingMode = "Auto" without MinRefreshRate is rejected.
     */
    bool TestInitialise_AutoMode_MissingRefreshRate();

    /**
     * @brief Tests that an unknown PublishingMode string is rejected.
     */
    bool TestInitialise_UnknownPublishingMode();

    /**
     * @brief Tests the GetPort() accessor.
     */
    bool TestGetPort();

    /**
     * @brief Tests the GetMaxPayloadSize() accessor.
     */
    bool TestGetMaxPayloadSize();

    /**
     * @brief Tests that IsClientConnected() returns false before any CONNECT.
     */
    bool TestIsClientConnected_InitiallyFalse();

    /**
     * @brief Tests AllocateMemory with 4 high-frequency int16[1000] packed channels (1 MSps).
     */
    bool TestHighFrequency_AllocateMemory();

    /**
     * @brief Tests that 4 int16[1000] channels produce exactly 6 fragments at MaxPayloadSize=1400.
     * Payload: 8 (HRT) + 8 (T0/uint64) + 4×2000 (int16[1000]) = 8016 bytes;
     * chunk = 1383 bytes → ceil(8016/1383) = 6 fragments.
     */
    bool TestHighFrequency_Fragmentation();

    /**
     * @brief Tests full CONNECT→DATA→DISCONNECT cycle with high-frequency packed signals.
     * Reassembles all fragments and verifies the total payload size.
     */
    bool TestHighFrequency_DataIntegrity();

    /**
     * @brief Tests Initialise with MulticastGroup and explicit DataPort.
     */
    bool TestInitialise_MulticastMode_Valid();

    /**
     * @brief Tests that DataPort defaults to Port+1 when MulticastGroup is set but DataPort is absent.
     */
    bool TestInitialise_MulticastMode_DefaultDataPort();

    /**
     * @brief Tests that DataPort equal to Port is rejected.
     */
    bool TestInitialise_MulticastMode_InvalidDataPort();

    /**
     * @brief Tests PrepareNextState in multicast mode: TCP listener opens, data socket connects.
     */
    bool TestPrepareNextState_Multicast();

    /**
     * @brief Tests full TCP CONNECT → CONFIG → DATA via multicast → DISCONNECT on loopback.
     */
    bool TestExecute_MulticastConnectDataDisconnect();
};

#endif /* UDPSTREAMERTEST_H_ */
