//***************************************************************************/
//                                                                          */
//   Filename   : WorkListManagementTest.cpp                                */
//                                                                          */
//   Description: Server message channel interface                          */
//                                                                          */
//   Copyright  : Philips Medical Systems Nederland B.V., 2014.             */
//                                                                          */
//***************************************************************************/

#include <array>
#include "WorkListManagement.h"
#include "WLMQueryDefinition.h"
#include "CommonHeaders.h"
#include "co_featuretoggle_stub.h"
#include "BackendLabelIDs.h"

using namespace FSInfra;
using namespace Common;
using namespace Utilities;
using namespace BackendTools;
using namespace BackendToolsControlsID;

namespace FieldServiceInfraTest
{
    class WorkListManagementTest : public ::testing::Test
    {
    private:
        bool m_StatusSetEnv;
        std::array<TCHAR, 256> CurrentEnvPath = { 0 };

    protected:
        WorkListManagementTest() : m_StatusSetEnv(false), CurrentEnvPath{ 0 }
        {
            // setup work for each test
            m_StatusSetEnv = true;
        }

        virtual ~WorkListManagementTest()
        {
            // clean up work, may not throw exceptions
        }

        virtual void SetUp() override
        {
            // Set envirrment variable to path of the running exe
            SetEnvVariable();

            auditTrail_stub_initialize();
        }

        virtual void TearDown() override
        {
            RestoreEnvirnVariable();
        }

        void SetEnvVariable();
        void RestoreEnvirnVariable();
    };  // class WorkListManagementTest 

//////////////////////////////////////////////////////////////////////////
// Here start the tests


    TEST_F(WorkListManagementTest, WLMTool_AvailabilityFalse)
    {
        std::unique_ptr<WorkListManagement> pTarget = std::make_unique<WorkListManagement>();
        GenericDataModel m_GenericData              = {};
        DFICommunicatorStub DfiCommunicator         = {};
        FUNCTION_TABLE_STRUCT functionTable         = {};
        co_featuretoggle_var.rv                     = FALSE;
        functionTable.dcm.worklist                  = FALSE;
        DfiCommunicator.SetMsgQueueNames("WLMTool_AvailabilityFalseSR","WLMTool_AvailabilityFalseFS");
        DfiCommunicator.Initialize();
        pTarget->Initialize("WLMTool_AvailabilityFalseSR", "WLMTool_AvailabilityFalseFS");

        // make tool Disabled
        DfiCommunicator.SetFunctionTable(functionTable);
        // get the availablity of the tool
        ASSERT_EQ(ToolState::ToolDisabled, pTarget->GetAvailability());

        Sleep(10);
        DfiCommunicator.Destroy();
        pTarget->Destroy();
        pTarget.reset(nullptr);
    }

    TEST_F(WorkListManagementTest, WLMTool_AvailabilityTrue)
    {
        std::unique_ptr<WorkListManagement> pTarget = std::make_unique<WorkListManagement>();
        GenericDataModel m_GenericData              = {};
        DFICommunicatorStub DfiCommunicator         = {};
        DfiCommunicator.SetMsgQueueNames("WLMTool_AvailabilityTrueSR", "WLMTool_AvailabilityTrueFS");
        FUNCTION_TABLE_STRUCT functionTable         = { 0 };
        co_featuretoggle_var.rv                     = FALSE;
        functionTable.dcm.worklist                  = TRUE;

        DfiCommunicator.Initialize();
        pTarget->Initialize("WLMTool_AvailabilityTrueSR", "WLMTool_AvailabilityTrueFS");

        // make tool Disabled
        DfiCommunicator.SetFunctionTable(functionTable);
        // get the availablity of the tool
        ASSERT_EQ(ToolState::ToolVisible, pTarget->GetAvailability());

        Sleep(10);
        DfiCommunicator.Destroy();
        pTarget->Destroy();
        pTarget.reset(nullptr);
    }

    TEST_F(WorkListManagementTest, WLMTool_LoadOprn)
    {
        std::unique_ptr<WorkListManagement> pTarget = std::make_unique<WorkListManagement>();
        GenericDataModel m_GenericData              = {};
        DFICommunicatorStub DfiCommunicator         = {};
        DfiCommunicator.SetMsgQueueNames("WLMTool_LoadOprnSR", "WLMTool_LoadOprnFS");
        ElementArray inputControls                  = {};
        ElementArray outputControls                 = {};
        co_featuretoggle_var.rv                     = FALSE;

        DfiCommunicator.Initialize();
        pTarget->Initialize("WLMTool_LoadOprnSR", "WLMTool_LoadOprnFS");

        // get the availablity of the tool
        ASSERT_EQ(ToolState::ToolVisible, pTarget->GetAvailability());

        m_GenericData.SetIstLevel(0);
        //WorkListManagement - WLM Targets
        m_GenericData.SetMessageType(static_cast<MessageType>(ToolsIDDefinitions::WorkListManagement));

        // check for OprnLoad
        m_GenericData.SetOperationType(OprnLoad);
        void* pMsg           = nullptr;
        unsigned int msgSize = 0u;
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        Byte* outputMessage  = nullptr;
        int outputSize       = 0;
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WorkListManagement - OprnLoad ::Process has failed";
        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        m_GenericData.GetUIElements(outputControls);

        // Default Values
        ASSERT_STREQ(L"No Name", outputControls[outputControls.GetIndexByID(WLM_NAME)].value.c_str()) << "WLM-Test Target is not saved";
        ASSERT_STREQ(L"1", outputControls[outputControls.GetIndexByID(WLM_ENABLE)].value.c_str()) << "Enable is not saved";
        //ASSERT_STREQ(L"Off", outputControls[outputControls.GetIndexByID(WLM_AUTHENTICATION_ENCRYPTION)].value.c_str()) << "Secure Communication is not saved";
        if (CoFeatureAvailability(CO_FEATURE_SECURE_COMMUNICATION))
        {
            ASSERT_STREQ(L"Off", outputControls[outputControls.GetIndexByID(WLM_AUTHENTICATION_ENCRYPTION)].value.c_str()) << "Secure Communication is not saved";
        }
        ASSERT_STREQ(L"No Name", outputControls[outputControls.GetIndexByID(WLM_AETITLE)].value.c_str()) << "AE Title is not saved";
        ASSERT_STREQ(L"", outputControls[outputControls.GetIndexByID(WLM_IPADDRESS)].value.c_str()) << "Ip address is not saved";
        ASSERT_STREQ(L"104", outputControls[outputControls.GetIndexByID(WLM_PORTNUMBER)].value.c_str()) << "Port number is not saved";
        ASSERT_STREQ(L"", outputControls[outputControls.GetIndexByID(WLM_QUERY)].value.c_str()) << "Query is not saved";
        ASSERT_STREQ(L"Requested Procedure description (0032,1060)", outputControls[outputControls.GetIndexByID(WLM_STUDYDESCRIPTION)].value.c_str()) << "Request procedure is not saved";
        ASSERT_STREQ(L"0", outputControls[outputControls.GetIndexByID(WLM_ENABLEREASON)].value.c_str()) << "Save Data is failed";

        // User guide test
        ASSERT_EQ(true, outputControls[outputControls.GetIndexByID(WLM_NAME)].validationRequired) << "Save Data is failed";
        ASSERT_EQ(true, outputControls[outputControls.GetIndexByID(WLM_NAME)].valParameters.validateEmpty) << "Save Data is failed";
        ASSERT_STREQ(L"1;25", outputControls[outputControls.GetIndexByID(WLM_NAME)].valParameters.range.c_str()) << "Save Data is failed";
        ASSERT_EQ(true, outputControls[outputControls.GetIndexByID(WLM_AETITLE)].validationRequired) << "Save Data is failed";
        ASSERT_EQ(true, outputControls[outputControls.GetIndexByID(WLM_AETITLE)].valParameters.validateEmpty) << "Save Data is failed";
        ASSERT_STREQ(L"1;16", outputControls[outputControls.GetIndexByID(WLM_AETITLE)].valParameters.range.c_str()) << "Save Data is failed";
        ASSERT_EQ(true, outputControls[outputControls.GetIndexByID(WLM_PORTNUMBER)].validationRequired) << "Save Data is failed";
        ASSERT_EQ(true, outputControls[outputControls.GetIndexByID(WLM_PORTNUMBER)].valParameters.validateEmpty) << "Save Data is failed";
        ASSERT_STREQ(L"1;65535", outputControls[outputControls.GetIndexByID(WLM_PORTNUMBER)].valParameters.range.c_str()) << "Save Data is failed";

        Sleep(10);
        DfiCommunicator.Destroy();
        pTarget->Destroy();
        pTarget.reset(nullptr);
    }

    TEST_F(WorkListManagementTest, WLMTool_Secured_SaveNameWithNoNameValue)
    {
        std::unique_ptr<WorkListManagement> pTarget = std::make_unique<WorkListManagement>();
        GenericDataModel m_GenericData = {};
        DFICommunicatorStub DfiCommunicator = {};
        DfiCommunicator.SetMsgQueueNames("WLMTool_Secured_SaveNameWithNoNameValueSR", "WLMTool_Secured_SaveNameWithNoNameValueFS");
        ElementArray inputControls = {};
        ElementArray outputControls = {};
        co_featuretoggle_var.rv = FALSE;

        DfiCommunicator.Initialize();
        pTarget->Initialize("WLMTool_Secured_SaveNameWithNoNameValueSR", "WLMTool_Secured_SaveNameWithNoNameValueFS");

        // get the availablity of the tool
        ASSERT_EQ(ToolState::ToolVisible, pTarget->GetAvailability());

        m_GenericData.SetIstLevel(0);
        //WorkListManagement - WLM Targets
        m_GenericData.SetMessageType(static_cast<MessageType>(ToolsIDDefinitions::WorkListManagement));

        // check for OprnLoad
        m_GenericData.SetOperationType(OprnLoad);
        void* pMsg = nullptr;
        unsigned int msgSize = 0u;
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        Byte* outputMessage = nullptr;
        int outputSize = 0;
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WorkListManagement - OprnLoad ::Process has failed";
        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        m_GenericData.GetUIElements(inputControls);
        // check for OprnApply
        m_GenericData.SetOperationType(OprnApply);

        // Target Name
        inputControls[inputControls.GetIndexByID(WLM_NAME)].value = L"No Name";
        // Store enable
        inputControls[inputControls.GetIndexByID(WLM_ENABLE)].value = L"0";
        // Secure Communication
        //inputControls[inputControls.GetIndexByID(WLM_AUTHENTICATION_ENCRYPTION)].value = L"Authenticate and Encrypt";
        if (CoFeatureAvailability(CO_FEATURE_SECURE_COMMUNICATION))
        {
            inputControls[inputControls.GetIndexByID(WLM_AUTHENTICATION_ENCRYPTION)].value = L"Authenticate and Encrypt";
        }

        // AE Title
        inputControls[inputControls.GetIndexByID(WLM_AETITLE)].value = L"WLM_TARGET";
        // Ip address
        inputControls[inputControls.GetIndexByID(WLM_IPADDRESS)].value = L"127.0.0.1";
        // Port number
        inputControls[inputControls.GetIndexByID(WLM_PORTNUMBER)].value = L"7777";
        // Query
        inputControls[inputControls.GetIndexByID(WLM_QUERY)].value = L"Query1";
        // Study description
        inputControls[inputControls.GetIndexByID(WLM_STUDYDESCRIPTION)].value = L"1";

        DfiCommunicator.SetCreateDicomTargetFileFlag(false); //BeCommunicator.CreateDicomTargetsFile returns NOK
        m_GenericData.SetUIElements(inputControls);
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WLM - OprnSave::Process has failed";

        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        ResultInfo ResInfo = {};
        ResInfo.Clear();
        m_GenericData.GetResult(ResInfo);
        EXPECT_EQ(0, ResInfo.resText.compare(L"‘Name’ No value specified"));
        ASSERT_EQ(ResInfo.displayMessageType, MessageArea);

        Sleep(10);
        DfiCommunicator.Destroy();
        pTarget->Destroy();
        pTarget.reset(nullptr);
    }

    TEST_F(WorkListManagementTest, WLMTool_Secured_SaveWithAETileNoNameValue)
    {
        std::unique_ptr<WorkListManagement> pTarget = std::make_unique<WorkListManagement>();
        GenericDataModel m_GenericData = {};
        DFICommunicatorStub DfiCommunicator = {};
        DfiCommunicator.SetMsgQueueNames("WLMTool_Secured_SaveWithAETileNoNameValueSR", "WLMTool_Secured_SaveWithAETileNoNameValueFS");
        ElementArray inputControls = {};
        ElementArray outputControls = {};
        co_featuretoggle_var.rv = FALSE;

        DfiCommunicator.Initialize();
        pTarget->Initialize("WLMTool_Secured_SaveWithAETileNoNameValueSR", "WLMTool_Secured_SaveWithAETileNoNameValueFS");

        // get the availablity of the tool
        ASSERT_EQ(ToolState::ToolVisible, pTarget->GetAvailability());

        m_GenericData.SetIstLevel(0);
        //WorkListManagement - WLM Targets
        m_GenericData.SetMessageType(static_cast<MessageType>(ToolsIDDefinitions::WorkListManagement));

        // check for OprnLoad
        m_GenericData.SetOperationType(OprnLoad);
        void* pMsg = nullptr;
        unsigned int msgSize = 0u;
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        Byte* outputMessage = nullptr;
        int outputSize = 0;
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WorkListManagement - OprnLoad ::Process has failed";
        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        m_GenericData.GetUIElements(inputControls);
        // check for OprnApply
        m_GenericData.SetOperationType(OprnApply);

        // Target Name
        inputControls[inputControls.GetIndexByID(WLM_NAME)].value = L"No Name";
        // Store enable
        inputControls[inputControls.GetIndexByID(WLM_ENABLE)].value = L"0";
        // Secure Communication
        //inputControls[inputControls.GetIndexByID(WLM_AUTHENTICATION_ENCRYPTION)].value = L"Authenticate and Encrypt";
        if (CoFeatureAvailability(CO_FEATURE_SECURE_COMMUNICATION))
        {
            inputControls[inputControls.GetIndexByID(WLM_AUTHENTICATION_ENCRYPTION)].value = L"Authenticate and Encrypt";
        }
        // AE Title
        inputControls[inputControls.GetIndexByID(WLM_AETITLE)].value = L"No Name";
        // Ip address
        inputControls[inputControls.GetIndexByID(WLM_IPADDRESS)].value = L"127.0.0.1";
        // Port number
        inputControls[inputControls.GetIndexByID(WLM_PORTNUMBER)].value = L"7777";
        // Query
        inputControls[inputControls.GetIndexByID(WLM_QUERY)].value = L"Query1";
        // Study description
        inputControls[inputControls.GetIndexByID(WLM_STUDYDESCRIPTION)].value = L"1";

        DfiCommunicator.SetCreateDicomTargetFileFlag(true); //BeCommunicator.CreateDicomTargetsFile returns OK
        m_GenericData.SetUIElements(inputControls);
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WLM - OprnSave::Process has failed";

        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        ResultInfo ResInfo = {};
        ResInfo.Clear();
        m_GenericData.GetResult(ResInfo);
        EXPECT_EQ(0, ResInfo.resText.compare(L"‘Name’ No value specified"));
        ASSERT_EQ(ResInfo.displayMessageType, MessageArea);

        Sleep(10);
        DfiCommunicator.Destroy();
        pTarget->Destroy();
        pTarget.reset(nullptr);
    }

    TEST_F(WorkListManagementTest, WLMTool_Secured_OkNameWithNoNameValue)
    {
        std::unique_ptr<WorkListManagement> pTarget = std::make_unique<WorkListManagement>();
        GenericDataModel m_GenericData = {};
        DFICommunicatorStub DfiCommunicator = {};
        DfiCommunicator.SetMsgQueueNames("WLMTool_Secured_OkNameWithNoNameValueSR", "WLMTool_Secured_OkNameWithNoNameValueFS");
        ElementArray inputControls = {};
        ElementArray outputControls = {};
        co_featuretoggle_var.rv = FALSE;

        DfiCommunicator.Initialize();
        pTarget->Initialize("WLMTool_Secured_OkNameWithNoNameValueSR", "WLMTool_Secured_OkNameWithNoNameValueFS");

        // get the availablity of the tool
        ASSERT_EQ(ToolState::ToolVisible, pTarget->GetAvailability());

        m_GenericData.SetIstLevel(0);
        //WorkListManagement - WLM Targets
        m_GenericData.SetMessageType(static_cast<MessageType>(ToolsIDDefinitions::WorkListManagement));

        // check for OprnLoad
        m_GenericData.SetOperationType(OprnLoad);
        void* pMsg = nullptr;
        unsigned int msgSize = 0u;
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        Byte* outputMessage = nullptr;
        int outputSize = 0;
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WorkListManagement - OprnLoad ::Process has failed";
        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        m_GenericData.GetUIElements(inputControls);
        // check for OprnOk
        m_GenericData.SetOperationType(OprnOk);

        // Target Name
        inputControls[inputControls.GetIndexByID(WLM_NAME)].value = L"No Name";
        // Store enable
        inputControls[inputControls.GetIndexByID(WLM_ENABLE)].value = L"0";
        // Secure Communication
        //inputControls[inputControls.GetIndexByID(WLM_AUTHENTICATION_ENCRYPTION)].value = L"Authenticate and Encrypt";
        if (CoFeatureAvailability(CO_FEATURE_SECURE_COMMUNICATION))
        {
            inputControls[inputControls.GetIndexByID(WLM_AUTHENTICATION_ENCRYPTION)].value = L"Authenticate and Encrypt";
        }
        // AE Title
        inputControls[inputControls.GetIndexByID(WLM_AETITLE)].value = L"WLM_TARGET";
        // Ip address
        inputControls[inputControls.GetIndexByID(WLM_IPADDRESS)].value = L"127.0.0.1";
        // Port number
        inputControls[inputControls.GetIndexByID(WLM_PORTNUMBER)].value = L"7777";
        // Query
        inputControls[inputControls.GetIndexByID(WLM_QUERY)].value = L"Query1";
        // Study description
        inputControls[inputControls.GetIndexByID(WLM_STUDYDESCRIPTION)].value = L"1";

        m_GenericData.SetUIElements(inputControls);
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize));
        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        ResultInfo ResInfo = {};
        ResInfo.Clear();
        m_GenericData.GetResult(ResInfo);
        EXPECT_EQ(0, ResInfo.resText.compare(L"‘Name’ No value specified"));
        ASSERT_EQ(ResInfo.displayMessageType, MessageArea);

        Sleep(10);
        DfiCommunicator.Destroy();
        pTarget->Destroy();
        pTarget.reset(nullptr);
    }

    TEST_F(WorkListManagementTest, WLMTool_Secured_OkWithAETileNoNameValue)
    {
        std::unique_ptr<WorkListManagement> pTarget = std::make_unique<WorkListManagement>();
        GenericDataModel m_GenericData = {};
        DFICommunicatorStub DfiCommunicator = {};
        DfiCommunicator.SetMsgQueueNames("WLMTool_Secured_OkWithAETileNoNameValueSR", "WLMTool_Secured_OkWithAETileNoNameValueFS");
        ElementArray inputControls = {};
        ElementArray outputControls = {};
        co_featuretoggle_var.rv = FALSE;

        DfiCommunicator.Initialize();
        pTarget->Initialize("WLMTool_Secured_OkWithAETileNoNameValueSR", "WLMTool_Secured_OkWithAETileNoNameValueFS");

        // get the availablity of the tool
        ASSERT_EQ(ToolState::ToolVisible, pTarget->GetAvailability());

        m_GenericData.SetIstLevel(0);
        //WorkListManagement - WLM Targets
        m_GenericData.SetMessageType(static_cast<MessageType>(ToolsIDDefinitions::WorkListManagement));

        // check for OprnLoad
        m_GenericData.SetOperationType(OprnLoad);
        void* pMsg = nullptr;
        unsigned int msgSize = 0u;
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        Byte* outputMessage = nullptr;
        int outputSize = 0;
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WorkListManagement - OprnLoad ::Process has failed";
        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        m_GenericData.GetUIElements(inputControls);
        // check for OprnOk
        m_GenericData.SetOperationType(OprnOk);

        // Target Name
        inputControls[inputControls.GetIndexByID(WLM_NAME)].value = L"No Name";
        // Store enable
        inputControls[inputControls.GetIndexByID(WLM_ENABLE)].value = L"0";
        // Secure Communication
        if (CoFeatureAvailability(CO_FEATURE_SECURE_COMMUNICATION))
        inputControls[inputControls.GetIndexByID(WLM_AUTHENTICATION_ENCRYPTION)].value = L"Authenticate and Encrypt";
        // AE Title
        inputControls[inputControls.GetIndexByID(WLM_AETITLE)].value = L"No Name";
        // Ip address
        inputControls[inputControls.GetIndexByID(WLM_IPADDRESS)].value = L"127.0.0.1";
        // Port number
        inputControls[inputControls.GetIndexByID(WLM_PORTNUMBER)].value = L"7777";
        // Query
        inputControls[inputControls.GetIndexByID(WLM_QUERY)].value = L"Query1";
        // Study description
        inputControls[inputControls.GetIndexByID(WLM_STUDYDESCRIPTION)].value = L"1";

        m_GenericData.SetUIElements(inputControls);
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WLM - OprnSave::Process has failed";

        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        ResultInfo ResInfo = {};
        ResInfo.Clear();
        m_GenericData.GetResult(ResInfo);
        EXPECT_EQ(0, ResInfo.resText.compare(L"‘Name’ No value specified"));
        ASSERT_EQ(ResInfo.displayMessageType, MessageArea);

        Sleep(10);
        DfiCommunicator.Destroy();
        pTarget->Destroy();
        pTarget.reset(nullptr);
    }

    TEST_F(WorkListManagementTest, WLMTool_SaveNameWithNoNameValue)
    {
        std::unique_ptr<WorkListManagement> pTarget = std::make_unique<WorkListManagement>();
        GenericDataModel m_GenericData              = {};
        DFICommunicatorStub DfiCommunicator         = {};
        DfiCommunicator.SetMsgQueueNames("WLMTool_SaveNameWithNoNameValueSR", "WLMTool_SaveNameWithNoNameValueFS");
        ElementArray inputControls                  = {};
        ElementArray outputControls                 = {};
        co_featuretoggle_var.rv                     = FALSE;

        DfiCommunicator.Initialize();
        pTarget->Initialize("WLMTool_SaveNameWithNoNameValueSR", "WLMTool_SaveNameWithNoNameValueFS");

        // get the availablity of the tool
        ASSERT_EQ(ToolState::ToolVisible, pTarget->GetAvailability());

        m_GenericData.SetIstLevel(0);
        //WorkListManagement - WLM Targets
        m_GenericData.SetMessageType(static_cast<MessageType>(ToolsIDDefinitions::WorkListManagement));

        // check for OprnLoad
        m_GenericData.SetOperationType(OprnLoad);
        void* pMsg           = nullptr;
        unsigned int msgSize = 0u;
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        Byte* outputMessage  = nullptr;
        int outputSize       = 0;
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WorkListManagement - OprnLoad ::Process has failed";
        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        m_GenericData.GetUIElements(inputControls);
        // check for OprnApply
        m_GenericData.SetOperationType(OprnApply);

        // Target Name
        inputControls[inputControls.GetIndexByID(WLM_NAME)].value = L"No Name";
        // Store enable
        inputControls[inputControls.GetIndexByID(WLM_ENABLE)].value = L"0";
        // Secure Communication
        if (CoFeatureAvailability(CO_FEATURE_SECURE_COMMUNICATION))
        inputControls[inputControls.GetIndexByID(WLM_AUTHENTICATION_ENCRYPTION)].value = L"Off";
        // AE Title
        inputControls[inputControls.GetIndexByID(WLM_AETITLE)].value = L"WLM_TARGET";
        // Ip address
        inputControls[inputControls.GetIndexByID(WLM_IPADDRESS)].value = L"127.0.0.1";
        // Port number
        inputControls[inputControls.GetIndexByID(WLM_PORTNUMBER)].value = L"7777";
        // Query
        inputControls[inputControls.GetIndexByID(WLM_QUERY)].value = L"Query1";
        // Study description
        inputControls[inputControls.GetIndexByID(WLM_STUDYDESCRIPTION)].value = L"1";

        DfiCommunicator.SetCreateDicomTargetFileFlag(false); //BeCommunicator.CreateDicomTargetsFile returns NOK
        m_GenericData.SetUIElements(inputControls);
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WLM - OprnSave::Process has failed";

        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        ResultInfo ResInfo = {};
        ResInfo.Clear();
        m_GenericData.GetResult(ResInfo);
        EXPECT_EQ(0, ResInfo.resText.compare(L"‘Name’ No value specified"));
        ASSERT_EQ(ResInfo.displayMessageType, MessageArea);

        Sleep(10);
        DfiCommunicator.Destroy();
        pTarget->Destroy();
        pTarget.reset(nullptr);
    }

    TEST_F(WorkListManagementTest, WLMTool_SaveWithAETileNoNameValue)
    {
        std::unique_ptr<WorkListManagement> pTarget = std::make_unique<WorkListManagement>();
        GenericDataModel m_GenericData              = {};
        DFICommunicatorStub DfiCommunicator         = {};
        DfiCommunicator.SetMsgQueueNames("WLMTool_SaveWithAETileNoNameValueSR", "WLMTool_SaveWithAETileNoNameValueFS");
        ElementArray inputControls                  = {};
        ElementArray outputControls                 = {};
        co_featuretoggle_var.rv                     = FALSE;

        DfiCommunicator.Initialize();
        pTarget->Initialize("WLMTool_SaveWithAETileNoNameValueSR", "WLMTool_SaveWithAETileNoNameValueFS");

        // get the availablity of the tool
        ASSERT_EQ(ToolState::ToolVisible, pTarget->GetAvailability());

        m_GenericData.SetIstLevel(0);
        //WorkListManagement - WLM Targets
        m_GenericData.SetMessageType(static_cast<MessageType>(ToolsIDDefinitions::WorkListManagement));

        // check for OprnLoad
        m_GenericData.SetOperationType(OprnLoad);
        void* pMsg           = nullptr;
        unsigned int msgSize = 0u;
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        Byte* outputMessage  = nullptr;
        int outputSize       = 0;
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WorkListManagement - OprnLoad ::Process has failed";
        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        m_GenericData.GetUIElements(inputControls);
        // check for OprnApply
        m_GenericData.SetOperationType(OprnApply);

        // Target Name
        inputControls[inputControls.GetIndexByID(WLM_NAME)].value = L"No Name";
        // Store enable
        inputControls[inputControls.GetIndexByID(WLM_ENABLE)].value = L"0";
        // Secure Communication
        if (CoFeatureAvailability(CO_FEATURE_SECURE_COMMUNICATION))
        inputControls[inputControls.GetIndexByID(WLM_AUTHENTICATION_ENCRYPTION)].value = L"Off";
        // AE Title
        inputControls[inputControls.GetIndexByID(WLM_AETITLE)].value = L"No Name";
        // Ip address
        inputControls[inputControls.GetIndexByID(WLM_IPADDRESS)].value = L"127.0.0.1";
        // Port number
        inputControls[inputControls.GetIndexByID(WLM_PORTNUMBER)].value = L"7777";
        // Query
        inputControls[inputControls.GetIndexByID(WLM_QUERY)].value = L"Query1";
        // Study description
        inputControls[inputControls.GetIndexByID(WLM_STUDYDESCRIPTION)].value = L"1";

        DfiCommunicator.SetCreateDicomTargetFileFlag(true); //BeCommunicator.CreateDicomTargetsFile returns OK
        m_GenericData.SetUIElements(inputControls);
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WLM - OprnSave::Process has failed";

        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        ResultInfo ResInfo = {};
        ResInfo.Clear();
        m_GenericData.GetResult(ResInfo);
        EXPECT_EQ(0, ResInfo.resText.compare(L"‘Name’ No value specified"));
        ASSERT_EQ(ResInfo.displayMessageType, MessageArea);

        Sleep(10);
        DfiCommunicator.Destroy();
        pTarget->Destroy();
        pTarget.reset(nullptr);
    }

    TEST_F(WorkListManagementTest, WLMTool_OkNameWithNoNameValue)
    {
        std::unique_ptr<WorkListManagement> pTarget = std::make_unique<WorkListManagement>();
        GenericDataModel m_GenericData              = {};
        DFICommunicatorStub DfiCommunicator         = {};
        DfiCommunicator.SetMsgQueueNames("WLMTool_OkNameWithNoNameValueSR", "WLMTool_OkNameWithNoNameValueFS");
        ElementArray inputControls                  = {};
        ElementArray outputControls                 = {};
        co_featuretoggle_var.rv                     = FALSE;

        DfiCommunicator.Initialize();
        pTarget->Initialize("WLMTool_OkNameWithNoNameValueSR", "WLMTool_OkNameWithNoNameValueFS");

        // get the availablity of the tool
        ASSERT_EQ(ToolState::ToolVisible, pTarget->GetAvailability());

        m_GenericData.SetIstLevel(0);
        //WorkListManagement - WLM Targets
        m_GenericData.SetMessageType(static_cast<MessageType>(ToolsIDDefinitions::WorkListManagement));

        // check for OprnLoad
        m_GenericData.SetOperationType(OprnLoad);
        void* pMsg           = nullptr;
        unsigned int msgSize = 0u;
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        Byte* outputMessage  = nullptr;
        int outputSize       = 0;
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WorkListManagement - OprnLoad ::Process has failed";
        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        m_GenericData.GetUIElements(inputControls);
        // check for OprnOk
        m_GenericData.SetOperationType(OprnOk);

        // Target Name
        inputControls[inputControls.GetIndexByID(WLM_NAME)].value = L"No Name";
        // Store enable
        inputControls[inputControls.GetIndexByID(WLM_ENABLE)].value = L"0";
        // Secure Communication
        if (CoFeatureAvailability(CO_FEATURE_SECURE_COMMUNICATION))
        inputControls[inputControls.GetIndexByID(WLM_AUTHENTICATION_ENCRYPTION)].value = L"Off";
        // AE Title
        inputControls[inputControls.GetIndexByID(WLM_AETITLE)].value = L"WLM_TARGET";
        // Ip address
        inputControls[inputControls.GetIndexByID(WLM_IPADDRESS)].value = L"127.0.0.1";
        // Port number
        inputControls[inputControls.GetIndexByID(WLM_PORTNUMBER)].value = L"7777";
        // Query
        inputControls[inputControls.GetIndexByID(WLM_QUERY)].value = L"Query1";
        // Study description
        inputControls[inputControls.GetIndexByID(WLM_STUDYDESCRIPTION)].value = L"1";

        m_GenericData.SetUIElements(inputControls);
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize));
        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        ResultInfo ResInfo = {};
        ResInfo.Clear();
        m_GenericData.GetResult(ResInfo);
        EXPECT_EQ(0, ResInfo.resText.compare(L"‘Name’ No value specified"));
        ASSERT_EQ(ResInfo.displayMessageType, MessageArea);

        Sleep(10);
        DfiCommunicator.Destroy();
        pTarget->Destroy();
        pTarget.reset(nullptr);
    }

    TEST_F(WorkListManagementTest, WLMTool_OkWithAETileNoNameValue)
    {
        std::unique_ptr<WorkListManagement> pTarget = std::make_unique<WorkListManagement>();
        GenericDataModel m_GenericData              = {};
        DFICommunicatorStub DfiCommunicator         = {};
        DfiCommunicator.SetMsgQueueNames("WLMTool_OkWithAETileNoNameValueSR", "WLMTool_OkWithAETileNoNameValueFS");
        ElementArray inputControls                  = {};
        ElementArray outputControls                 = {};
        co_featuretoggle_var.rv                     = FALSE;

        DfiCommunicator.Initialize();
        pTarget->Initialize("WLMTool_OkWithAETileNoNameValueSR", "WLMTool_OkWithAETileNoNameValueFS");

        // get the availablity of the tool
        ASSERT_EQ(ToolState::ToolVisible, pTarget->GetAvailability());

        m_GenericData.SetIstLevel(0);
        //WorkListManagement - WLM Targets
        m_GenericData.SetMessageType(static_cast<MessageType>(ToolsIDDefinitions::WorkListManagement));

        // check for OprnLoad
        m_GenericData.SetOperationType(OprnLoad);
        void* pMsg           = nullptr;
        unsigned int msgSize = 0u;
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        Byte* outputMessage  = nullptr;
        int outputSize       = 0;
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WorkListManagement - OprnLoad ::Process has failed";
        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        m_GenericData.GetUIElements(inputControls);
        // check for OprnOk
        m_GenericData.SetOperationType(OprnOk);

        // Target Name
        inputControls[inputControls.GetIndexByID(WLM_NAME)].value = L"No Name";
        // Store enable
        inputControls[inputControls.GetIndexByID(WLM_ENABLE)].value = L"0";
        // Secure Communication
        if (CoFeatureAvailability(CO_FEATURE_SECURE_COMMUNICATION))
        inputControls[inputControls.GetIndexByID(WLM_AUTHENTICATION_ENCRYPTION)].value = L"Off";
        // AE Title
        inputControls[inputControls.GetIndexByID(WLM_AETITLE)].value = L"No Name";
        // Ip address
        inputControls[inputControls.GetIndexByID(WLM_IPADDRESS)].value = L"127.0.0.1";
        // Port number
        inputControls[inputControls.GetIndexByID(WLM_PORTNUMBER)].value = L"7777";
        // Query
        inputControls[inputControls.GetIndexByID(WLM_QUERY)].value = L"Query1";
        // Study description
        inputControls[inputControls.GetIndexByID(WLM_STUDYDESCRIPTION)].value = L"1";

        m_GenericData.SetUIElements(inputControls);
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WLM - OprnSave::Process has failed";

        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        ResultInfo ResInfo = {};
        ResInfo.Clear();
        m_GenericData.GetResult(ResInfo);
        EXPECT_EQ(0, ResInfo.resText.compare(L"‘Name’ No value specified"));
        ASSERT_EQ(ResInfo.displayMessageType, MessageArea);

        Sleep(10);
        DfiCommunicator.Destroy();
        pTarget->Destroy();
        pTarget.reset(nullptr);
    }

    TEST_F(WorkListManagementTest, WLMTool_ValidateEmptyQuery)
    {
        std::unique_ptr<WorkListManagement> pTarget = std::make_unique<WorkListManagement>();
        GenericDataModel m_GenericData              = {};
        DFICommunicatorStub DfiCommunicator         = {};
        DfiCommunicator.SetMsgQueueNames("WLMTool_ValidateEmptyQuerySR", "WLMTool_ValidateEmptyQueryFS");
        ElementArray inputControls                  = {};
        ElementArray outputControls                 = {};
        co_featuretoggle_var.rv                     = FALSE;

        DfiCommunicator.Initialize();
        pTarget->Initialize("WLMTool_ValidateEmptyQuerySR", "WLMTool_ValidateEmptyQueryFS");

        // get the availablity of the tool
        ASSERT_EQ(ToolState::ToolVisible, pTarget->GetAvailability());

        m_GenericData.SetIstLevel(0);
        //WorkListManagement - WLM Targets
        m_GenericData.SetMessageType(static_cast<MessageType>(ToolsIDDefinitions::WorkListManagement));

        // check for OprnLoad
        m_GenericData.SetOperationType(OprnLoad);
        void* pMsg           = nullptr;
        unsigned int msgSize = 0u;
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        Byte* outputMessage  = nullptr;
        int outputSize       = 0;
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WorkListManagement - OprnLoad ::Process has failed";
        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        // check for OprnOk
        m_GenericData.GetUIElements(inputControls);
        m_GenericData.SetOperationType(OprnOk);

        // Target Name
        inputControls[inputControls.GetIndexByID(WLM_NAME)].value = L"WLM-Test Target";
        // Store enable
        inputControls[inputControls.GetIndexByID(WLM_ENABLE)].value = L"1";
        // Secure Communication
        if (CoFeatureAvailability(CO_FEATURE_SECURE_COMMUNICATION))
        inputControls[inputControls.GetIndexByID(WLM_AUTHENTICATION_ENCRYPTION)].value = L"Authenticate and Encrypt";
        // AE Title
        inputControls[inputControls.GetIndexByID(WLM_AETITLE)].value = L"WLM_AE";
        // Ip address
        inputControls[inputControls.GetIndexByID(WLM_IPADDRESS)].value = L"127.0.0.1";
        // Port number
        inputControls[inputControls.GetIndexByID(WLM_PORTNUMBER)].value = L"7777";
        // Study description
        inputControls[inputControls.GetIndexByID(WLM_STUDYDESCRIPTION)].value = L"1";

        m_GenericData.SetOperationType(OprnOk);

        m_GenericData.SetUIElements(inputControls);
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WLM - OprnSave::Process has failed";

        //recheck whether previous configuration is saved or not to the db(DICOM_TARGETS)
        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        ResultInfo ResInfo = {};
        ResInfo.Clear();
        m_GenericData.GetResult(ResInfo);
        EXPECT_EQ(0, ResInfo.resText.compare(BackendMessage::QueryFieldNotBeEmpty));
        ASSERT_EQ(ResInfo.msgArType, MessageAreaType::Error);
        ASSERT_EQ(ResInfo.displayMessageType, MessageArea);

        m_GenericData.GetUIElements(inputControls);

        // Check the whether configurations are saved or not for the "WLM-Test Target"
        m_GenericData.SetOperationType(OprnLoad);
        pMsg          = nullptr;
        msgSize       = 0u;
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        outputMessage = nullptr;
        outputSize    = 0;
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WLM - OprnLoad ::Process has failed";
        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        m_GenericData.GetUIElements(outputControls);

        ASSERT_STREQ(L"No Name", outputControls[outputControls.GetIndexByID(WLM_NAME)].value.c_str()) << "WLM-Test Target is not saved";
        ASSERT_STREQ(L"1", outputControls[outputControls.GetIndexByID(WLM_ENABLE)].value.c_str()) << "Enable is not saved";
        if (CoFeatureAvailability(CO_FEATURE_SECURE_COMMUNICATION))
        ASSERT_STREQ(L"Off", outputControls[outputControls.GetIndexByID(WLM_AUTHENTICATION_ENCRYPTION)].value.c_str()) << "Secure Communication is not saved";
        ASSERT_STREQ(L"No Name", outputControls[outputControls.GetIndexByID(WLM_AETITLE)].value.c_str()) << "AE Title is not saved";
        ASSERT_STREQ(L"", outputControls[outputControls.GetIndexByID(WLM_IPADDRESS)].value.c_str()) << "Ip address is not saved";
        ASSERT_STREQ(L"104", outputControls[outputControls.GetIndexByID(WLM_PORTNUMBER)].value.c_str()) << "Port number is not saved";
        ASSERT_STREQ(L"", outputControls[outputControls.GetIndexByID(WLM_QUERY)].value.c_str()) << "Query is not saved";
        ASSERT_STREQ(L"Requested Procedure description (0032,1060)", outputControls[outputControls.GetIndexByID(WLM_STUDYDESCRIPTION)].value.c_str()) << "Request procedure is not saved";

        Sleep(10);
        DfiCommunicator.Destroy();
        pTarget->Destroy();
        pTarget.reset(nullptr);
    }

    TEST_F(WorkListManagementTest, WLMTool_ValidQuery)
    {
        std::unique_ptr<WorkListManagement> pTarget = std::make_unique<WorkListManagement>();
        GenericDataModel m_GenericData              = {};
        DFICommunicatorStub DfiCommunicator         = {};
        DfiCommunicator.SetMsgQueueNames("WLMTool_ValidQuerySR", "WLMTool_ValidQueryFS");
        ElementArray inputControls                  = {};
        ElementArray outputControls                 = {};
        co_featuretoggle_var.rv                     = FALSE;

        DfiCommunicator.Initialize();
        pTarget->Initialize("WLMTool_ValidQuerySR", "WLMTool_ValidQueryFS");

        // get the availablity of the tool
        ASSERT_EQ(ToolState::ToolVisible, pTarget->GetAvailability());

        m_GenericData.SetIstLevel(0);
        //1005 - WLM Targets
        m_GenericData.SetMessageType(static_cast<MessageType>(ToolsIDDefinitions::WorkListManagement));

        // check for OprnLoad
        m_GenericData.SetOperationType(OprnLoad);
        void* pMsg           = nullptr;
        unsigned int msgSize = 0u;
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        Byte* outputMessage  = nullptr;
        int outputSize       = 0;
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WorkListManagement - OprnLoad ::Process has failed";
        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        m_GenericData.GetUIElements(inputControls);
        // check for OprnOk
        m_GenericData.SetOperationType(OprnOk);

        // Target Name
        inputControls[inputControls.GetIndexByID(WLM_NAME)].value = L"WLM-Test Target";
        // Store enable
        inputControls[inputControls.GetIndexByID(WLM_ENABLE)].value = L"1";
        // Secure Communication
        if (CoFeatureAvailability(CO_FEATURE_SECURE_COMMUNICATION))
        inputControls[inputControls.GetIndexByID(WLM_AUTHENTICATION_ENCRYPTION)].value = L"Authenticate and Encrypt";
        // AE Title
        inputControls[inputControls.GetIndexByID(WLM_AETITLE)].value = L"WLM_AE";
        // Ip address
        inputControls[inputControls.GetIndexByID(WLM_IPADDRESS)].value = L"127.0.0.1";
        // Port number
        inputControls[inputControls.GetIndexByID(WLM_PORTNUMBER)].value = L"7777";
        // Query
        inputControls[inputControls.GetIndexByID(WLM_QUERY)].value = L"Query1";
        // Study description
        inputControls[inputControls.GetIndexByID(WLM_STUDYDESCRIPTION)].value = L"1";

        // check for OprnOk
        m_GenericData.SetOperationType(OprnOk);

        m_GenericData.SetUIElements(inputControls);
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WLM - OprnSave::Process has failed";

        //recheck whether previous configuration is saved or not to the db(DICOM_TARGETS)
        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));
        m_GenericData.GetUIElements(inputControls);

        // Check the whether configurations are saved or not for the "WLM-Test Target"
        m_GenericData.SetOperationType(OprnLoad);
        pMsg          = nullptr;
        msgSize       = 0u;
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        outputMessage = nullptr;
        outputSize    = 0;
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WLM - OprnLoad ::Process has failed";
        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        m_GenericData.GetUIElements(outputControls);

        ASSERT_STREQ(L"WLM-Test Target", outputControls[outputControls.GetIndexByID(WLM_NAME)].value.c_str()) << "WLM-Test Target is not saved";
        ASSERT_STREQ(L"1", outputControls[outputControls.GetIndexByID(WLM_ENABLE)].value.c_str()) << "Enable is not saved";
        if (CoFeatureAvailability(CO_FEATURE_SECURE_COMMUNICATION))
        ASSERT_STREQ(L"Authenticate and Encrypt", outputControls[outputControls.GetIndexByID(WLM_AUTHENTICATION_ENCRYPTION)].value.c_str()) << "Secure Communication is not saved";
        ASSERT_STREQ(L"WLM_AE", outputControls[outputControls.GetIndexByID(WLM_AETITLE)].value.c_str()) << "AE Title is not saved";
        ASSERT_STREQ(L"127.0.0.1", outputControls[outputControls.GetIndexByID(WLM_IPADDRESS)].value.c_str()) << "Ip address is not saved";
        ASSERT_STREQ(L"7777", outputControls[outputControls.GetIndexByID(WLM_PORTNUMBER)].value.c_str()) << "Port number is not saved";
        ASSERT_STREQ(L"Query1", outputControls[outputControls.GetIndexByID(WLM_QUERY)].value.c_str()) << "Query is not saved";
        ASSERT_STREQ(L"Requested Procedure description (0032,1060)", outputControls[outputControls.GetIndexByID(WLM_STUDYDESCRIPTION)].value.c_str()) << "Request procedure is not saved";

        ASSERT_EQ(LogNetworkEntry_var.netEntry[0].auditData.AuditID, AUDT_NETWORK_ENTRY);
        ASSERT_EQ(LogNetworkEntry_var.netEntry[0].NetworkAction, TRUE);

        Sleep(10);
        DfiCommunicator.Destroy();
        pTarget->Destroy();
        pTarget.reset(nullptr);
    }

    TEST_F(WorkListManagementTest, WLMTool_CheckIPv4AddressValidation_NoValueSpecified)
    {
        std::unique_ptr<WorkListManagement> pTarget = std::make_unique<WorkListManagement>();
        GenericDataModel m_GenericData              = {};
        DFICommunicatorStub DfiCommunicator         = {};
        DfiCommunicator.SetMsgQueueNames("WLMTool_CheckIPv4AddressValidation_NoValueSpecifiedSR", "WLMTool_CheckIPv4AddressValidation_NoValueSpecifiedFS");
        ElementArray inputControls                  = {};
        ElementArray outputControls                 = {};
        co_featuretoggle_var.rv                     = FALSE;

        DfiCommunicator.Initialize();
        pTarget->Initialize("WLMTool_CheckIPv4AddressValidation_NoValueSpecifiedSR", "WLMTool_CheckIPv4AddressValidation_NoValueSpecifiedFS");

        // get the availablity of the tool
        ASSERT_EQ(ToolState::ToolVisible, pTarget->GetAvailability());

        m_GenericData.SetIstLevel(0);
        //WorkListManagement - WLM Targets
        m_GenericData.SetMessageType(static_cast<MessageType>(ToolsIDDefinitions::WorkListManagement));

        // check for OprnLoad
        m_GenericData.SetOperationType(OprnLoad);
        void* pMsg           = nullptr;
        unsigned int msgSize = 0u;
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        Byte* outputMessage  = nullptr;
        int outputSize       = 0;
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WorkListManagement - OprnLoad ::Process has failed";
        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        m_GenericData.GetUIElements(inputControls);
        // check for OprnApply
        m_GenericData.SetOperationType(OprnApply);

        // Target Name
        inputControls[inputControls.GetIndexByID(WLM_NAME)].value = L"WLM-Test Target";
        // Store enable
        inputControls[inputControls.GetIndexByID(WLM_ENABLE)].value = L"0";
        // Secure Communication
        if (CoFeatureAvailability(CO_FEATURE_SECURE_COMMUNICATION))
        inputControls[inputControls.GetIndexByID(WLM_AUTHENTICATION_ENCRYPTION)].value = L"Authenticate and Encrypt";
        // AE Title
        inputControls[inputControls.GetIndexByID(WLM_AETITLE)].value = L"WLM_TARGET";
        // Ip address
        inputControls[inputControls.GetIndexByID(WLM_IPADDRESS)].value = L"";
        // Port number
        inputControls[inputControls.GetIndexByID(WLM_PORTNUMBER)].value = L"7777";
        // Query
        inputControls[inputControls.GetIndexByID(WLM_QUERY)].value = L"Query1";
        // Study description
        inputControls[inputControls.GetIndexByID(WLM_STUDYDESCRIPTION)].value = L"1";

        m_GenericData.SetUIElements(inputControls);
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WLM - OprnSave::Process has failed";

        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        ResultInfo ResInfo = {};
        ResInfo.Clear();
        m_GenericData.GetResult(ResInfo);
        EXPECT_EQ(0, ResInfo.resText.compare(L"‘IP address’ No value specified"));
        ASSERT_EQ(ResInfo.displayMessageType, MessageArea);
        ASSERT_EQ(ResInfo.msgArType, Error);
        ASSERT_EQ(ResInfo.controlId, WLM_IPADDRESS);

        Sleep(10);
        DfiCommunicator.Destroy();
        pTarget->Destroy();
    }

    TEST_F(WorkListManagementTest, WLMTool_CheckIPv4AddressValidation_InvalidSyntax)
    {
        std::unique_ptr<WorkListManagement> pTarget = std::make_unique<WorkListManagement>();
        GenericDataModel m_GenericData              = {};
        DFICommunicatorStub DfiCommunicator         = {};
        DfiCommunicator.SetMsgQueueNames("WLMTool_CheckIPv4AddressValidation_InvalidSyntaxSR", "WLMTool_CheckIPv4AddressValidation_InvalidSyntaxFS");
        ElementArray inputControls                  = {};
        ElementArray outputControls                 = {};
        co_featuretoggle_var.rv                     = FALSE;

        DfiCommunicator.Initialize();
        pTarget->Initialize("WLMTool_CheckIPv4AddressValidation_InvalidSyntaxSR", "WLMTool_CheckIPv4AddressValidation_InvalidSyntaxFS");

        // get the availablity of the tool
        ASSERT_EQ(ToolState::ToolVisible, pTarget->GetAvailability());

        m_GenericData.SetIstLevel(0);
        //WorkListManagement - WLM Targets
        m_GenericData.SetMessageType(static_cast<MessageType>(ToolsIDDefinitions::WorkListManagement));

        // check for OprnLoad
        m_GenericData.SetOperationType(OprnLoad);
        void* pMsg           = nullptr;
        unsigned int msgSize = 0u;
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        Byte* outputMessage  = nullptr;
        int outputSize       = 0;
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WorkListManagement - OprnLoad ::Process has failed";
        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        m_GenericData.GetUIElements(inputControls);
        // check for OprnApply
        m_GenericData.SetOperationType(OprnApply);

        // Target Name
        inputControls[inputControls.GetIndexByID(WLM_NAME)].value = L"WLM-Test Target";
        // Store enable
        inputControls[inputControls.GetIndexByID(WLM_ENABLE)].value = L"0";
        // Secure Communication
        if (CoFeatureAvailability(CO_FEATURE_SECURE_COMMUNICATION))
        inputControls[inputControls.GetIndexByID(WLM_AUTHENTICATION_ENCRYPTION)].value = L"Authenticate and Encrypt";
        // AE Title
        inputControls[inputControls.GetIndexByID(WLM_AETITLE)].value = L"WLM_TARGET";
        // Ip address
        inputControls[inputControls.GetIndexByID(WLM_IPADDRESS)].value = L"xx.10.12.1";
        // Port number
        inputControls[inputControls.GetIndexByID(WLM_PORTNUMBER)].value = L"7777";
        // Query
        inputControls[inputControls.GetIndexByID(WLM_QUERY)].value = L"Query1";
        // Study description
        inputControls[inputControls.GetIndexByID(WLM_STUDYDESCRIPTION)].value = L"1";

        m_GenericData.SetUIElements(inputControls);
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WLM - OprnSave::Process has failed";

        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        ResultInfo ResInfo = {};
        ResInfo.Clear();
        m_GenericData.GetResult(ResInfo);
        EXPECT_EQ(0, ResInfo.resText.compare(L"‘IP address’ Wrong syntax."));
        ASSERT_EQ(ResInfo.displayMessageType, MessageArea);
        ASSERT_EQ(ResInfo.msgArType, Error);
        ASSERT_EQ(ResInfo.controlId, WLM_IPADDRESS);

        Sleep(10);
        DfiCommunicator.Destroy();
        pTarget->Destroy();
        pTarget.reset(nullptr);
    }

    TEST_F(WorkListManagementTest, WLMTool_CheckWithValidValue)
    {
        std::unique_ptr<WorkListManagement> pTarget = std::make_unique<WorkListManagement>();
        GenericDataModel m_GenericData              = {};
        DFICommunicatorStub DfiCommunicator         = {};
        DfiCommunicator.SetMsgQueueNames("WLMTool_CheckWithValidValueSR", "WLMTool_CheckWithValidValueFS");
        ElementArray inputControls                  = {};
        ElementArray outputControls                 = {};
        co_featuretoggle_var.rv                     = FALSE;

        DfiCommunicator.Initialize();
        pTarget->Initialize("WLMTool_CheckWithValidValueSR", "WLMTool_CheckWithValidValueFS");

        // get the availablity of the tool
        ASSERT_EQ(ToolState::ToolVisible, pTarget->GetAvailability());

        m_GenericData.SetIstLevel(0);
        //WorkListManagement - WLM Targets
        m_GenericData.SetMessageType(static_cast<MessageType>(ToolsIDDefinitions::WorkListManagement));

        // check for OprnLoad
        m_GenericData.SetOperationType(OprnLoad);
        void* pMsg           = nullptr;
        unsigned int msgSize = 0u;
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        Byte* outputMessage  = nullptr;
        int outputSize       = 0;
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WorkListManagement - OprnLoad ::Process has failed";
        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        m_GenericData.GetUIElements(inputControls);
        // check for OprnCheck
        m_GenericData.SetOperationType(OprnCheck);

        // Target Name
        inputControls[inputControls.GetIndexByID(WLM_NAME)].value = L"WLM-Test Target";
        // Store enable
        inputControls[inputControls.GetIndexByID(WLM_ENABLE)].value = L"0";
        // Secure Communication
        if (CoFeatureAvailability(CO_FEATURE_SECURE_COMMUNICATION))
        inputControls[inputControls.GetIndexByID(WLM_AUTHENTICATION_ENCRYPTION)].value = L"Authenticate and Encrypt";
        // AE Title
        inputControls[inputControls.GetIndexByID(WLM_AETITLE)].value = L"WLM_AE";
        // Ip address
        inputControls[inputControls.GetIndexByID(WLM_IPADDRESS)].value = L"127.0.0.1";
        // Port number
        inputControls[inputControls.GetIndexByID(WLM_PORTNUMBER)].value = L"7777";
        // Query
        inputControls[inputControls.GetIndexByID(WLM_QUERY)].value = L"Query1";
        // Study description
        inputControls[inputControls.GetIndexByID(WLM_STUDYDESCRIPTION)].value = L"1";

        m_GenericData.SetUIElements(inputControls);
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WLM - OprnSave::Process has failed";

        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        ResultInfo ResInfo = {};
        ResInfo.Clear();
        m_GenericData.GetResult(ResInfo);
        EXPECT_EQ(0, ResInfo.resText.compare(BackendMessage::DcmEcoOk));
        ASSERT_EQ(ResInfo.msgArType, MessageAreaType::Info);

        Sleep(10);
        DfiCommunicator.Destroy();
        pTarget->Destroy();
        pTarget.reset(nullptr);
    }

    TEST_F(WorkListManagementTest, WLMTool_CheckWithEmptyValue)
    {
        std::unique_ptr<WorkListManagement> pTarget = std::make_unique<WorkListManagement>();
        GenericDataModel m_GenericData              = {};
        DFICommunicatorStub DfiCommunicator         = {};
        DfiCommunicator.SetMsgQueueNames("WLMTool_CheckWithEmptyValueSR", "WLMTool_CheckWithEmptyValueFS");
        ElementArray inputControls                  = {};
        ElementArray outputControls                 = {};
        co_featuretoggle_var.rv                     = FALSE;

        DfiCommunicator.Initialize();
        pTarget->Initialize("WLMTool_CheckWithEmptyValueSR", "WLMTool_CheckWithEmptyValueFS");

        // get the availablity of the tool
        ASSERT_EQ(ToolState::ToolVisible, pTarget->GetAvailability());

        m_GenericData.SetIstLevel(0);
        //WorkListManagement - WLM Targets
        m_GenericData.SetMessageType(static_cast<MessageType>(ToolsIDDefinitions::WorkListManagement));

        // check for OprnLoad
        m_GenericData.SetOperationType(OprnLoad);
        void* pMsg           = nullptr;
        unsigned int msgSize = 0u;
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        Byte* outputMessage  = nullptr;
        int outputSize       = 0;
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WorkListManagement - OprnLoad ::Process has failed";
        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        m_GenericData.GetUIElements(inputControls);
        // check for OprnCheck
        m_GenericData.SetOperationType(OprnCheck);

        // Target Name
        inputControls[inputControls.GetIndexByID(WLM_NAME)].value = L"WLM-Test Target";
        // Port number
        inputControls[inputControls.GetIndexByID(WLM_PORTNUMBER)].value = L"7777";
        // Query
        inputControls[inputControls.GetIndexByID(WLM_QUERY)].value = L"Query1";
        // Study description
        inputControls[inputControls.GetIndexByID(WLM_STUDYDESCRIPTION)].value = L"1";

        m_GenericData.SetUIElements(inputControls);
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WLM - OprnSave::Process has failed";

        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        Sleep(10);
        DfiCommunicator.Destroy();
        pTarget->Destroy();
        pTarget.reset(nullptr);
    }

    TEST_F(WorkListManagementTest, WLMTool_CheckWithEnable)
    {
        std::unique_ptr<WorkListManagement> pTarget = std::make_unique<WorkListManagement>();
        GenericDataModel m_GenericData              = {};
        DFICommunicatorStub DfiCommunicator         = {};
        DfiCommunicator.SetMsgQueueNames("WLMTool_CheckWithEnableSR", "WLMTool_CheckWithEnableFS");
        ElementArray inputControls                  = {};
        ElementArray outputControls                 = {};
        co_featuretoggle_var.rv                     = FALSE;

        DfiCommunicator.Initialize();
        pTarget->Initialize("WLMTool_CheckWithEnableSR", "WLMTool_CheckWithEnableFS");

        // get the availablity of the tool
        ASSERT_EQ(ToolState::ToolVisible, pTarget->GetAvailability());

        m_GenericData.SetIstLevel(0);
        //WorkListManagement - WLM Targets
        m_GenericData.SetMessageType(static_cast<MessageType>(ToolsIDDefinitions::WorkListManagement));

        // check for OprnLoad
        m_GenericData.SetOperationType(OprnLoad);
        void* pMsg           = nullptr;
        unsigned int msgSize = 0u;
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        Byte* outputMessage  = nullptr;
        int outputSize       = 0;
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WorkListManagement - OprnLoad ::Process has failed";
        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        m_GenericData.GetUIElements(inputControls);
        // check for OprnCheck
        m_GenericData.SetOperationType(OprnCheck);

        // Target Name
        inputControls[inputControls.GetIndexByID(WLM_NAME)].value = L"WLM-Test Target";
        // Store enable
        inputControls[inputControls.GetIndexByID(WLM_ENABLE)].value = L"0";
        // Secure Communication
        if (CoFeatureAvailability(CO_FEATURE_SECURE_COMMUNICATION))
        inputControls[inputControls.GetIndexByID(WLM_AUTHENTICATION_ENCRYPTION)].value = L"Authenticate and Encrypt";
        // AE Title
        inputControls[inputControls.GetIndexByID(WLM_AETITLE)].value = L"WLM_AE";
        // Ip address
        inputControls[inputControls.GetIndexByID(WLM_IPADDRESS)].value = L"127.0.0.1";
        // Port number
        inputControls[inputControls.GetIndexByID(WLM_PORTNUMBER)].value = L"7777";
        // Query
        inputControls[inputControls.GetIndexByID(WLM_QUERY)].value = L"Query1";
        // Study description
        inputControls[inputControls.GetIndexByID(WLM_STUDYDESCRIPTION)].value = L"1";

        m_GenericData.SetUIElements(inputControls);
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WLM - OprnSave::Process has failed";

        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        ResultInfo ResInfo = {};
        ResInfo.Clear();
        m_GenericData.GetResult(ResInfo);
        EXPECT_EQ(0, ResInfo.resText.compare(BackendMessage::DcmEcoOk));
        ASSERT_EQ(ResInfo.msgArType, MessageAreaType::Info);

        Sleep(10);
        DfiCommunicator.Destroy();
        pTarget->Destroy();
        pTarget.reset(nullptr);
    }

    TEST_F(WorkListManagementTest, WLMTool_CheckWithDisable)
    {
        std::unique_ptr<WorkListManagement> pTarget = std::make_unique<WorkListManagement>();
        GenericDataModel m_GenericData              = {};
        DFICommunicatorStub DfiCommunicator         = {};
        DfiCommunicator.SetMsgQueueNames("WLMTool_CheckWithDisableSR", "WLMTool_CheckWithDisableFS");
        ElementArray inputControls                  = {};
        ElementArray outputControls                 = {};
        co_featuretoggle_var.rv                     = FALSE;

        DfiCommunicator.Initialize();
        pTarget->Initialize("WLMTool_CheckWithDisableSR", "WLMTool_CheckWithDisableFS");

        // get the availablity of the tool
        ASSERT_EQ(ToolState::ToolVisible, pTarget->GetAvailability());

        m_GenericData.SetIstLevel(0);
        //WorkListManagement - WLM Targets
        m_GenericData.SetMessageType(static_cast<MessageType>(ToolsIDDefinitions::WorkListManagement));

        // check for OprnLoad
        m_GenericData.SetOperationType(OprnLoad);
        void* pMsg           = nullptr;
        unsigned int msgSize = 0u;
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        Byte* outputMessage  = nullptr;
        int outputSize       = 0;
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WorkListManagement - OprnLoad ::Process has failed";
        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        m_GenericData.GetUIElements(inputControls);
        // check for OprnCheck
        m_GenericData.SetOperationType(OprnCheck);

        // Target Name
        inputControls[inputControls.GetIndexByID(WLM_NAME)].value = L"WLM-Test Target";
        // Store enable
        inputControls[inputControls.GetIndexByID(WLM_ENABLE)].value = L"1";
        // Secure Communication
        if (CoFeatureAvailability(CO_FEATURE_SECURE_COMMUNICATION))
        inputControls[inputControls.GetIndexByID(WLM_AUTHENTICATION_ENCRYPTION)].value = L"Authenticate and Encrypt";
        // AE Title
        inputControls[inputControls.GetIndexByID(WLM_AETITLE)].value = L"WLM_AE";
        // Ip address
        inputControls[inputControls.GetIndexByID(WLM_IPADDRESS)].value = L"127.0.0.1";
        // Port number
        inputControls[inputControls.GetIndexByID(WLM_PORTNUMBER)].value = L"7777";
        // Query
        inputControls[inputControls.GetIndexByID(WLM_QUERY)].value = L"Query1";
        // Study description
        inputControls[inputControls.GetIndexByID(WLM_STUDYDESCRIPTION)].value = L"1";

        m_GenericData.SetUIElements(inputControls);
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WLM - OprnSave::Process has failed";

        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        Sleep(10);
        DfiCommunicator.Destroy();
        pTarget->Destroy();
        pTarget.reset(nullptr);
    }

    TEST_F(WorkListManagementTest, WLMTool_ProcessInvalidInput)
    {
        std::unique_ptr<WorkListManagement> pTarget = std::make_unique<WorkListManagement>();
        void* pMsg                                  = nullptr;
        unsigned int msgSize                        = 0u;
        Byte* outputMessage                         = nullptr;
        int outputSize                              = 0;
        co_featuretoggle_var.rv                     = FALSE;
        DFICommunicatorStub  DfiCommunicator        = {};

        DfiCommunicator.SetMsgQueueNames("WLMTool_ProcessInvalidInputSR","WLMTool_ProcessInvalidInputFS");
        DfiCommunicator.Initialize();
        pTarget->Initialize("WLMTool_ProcessInvalidInputSR", "WLMTool_ProcessInvalidInputFS");

        ASSERT_EQ(false, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WorkListManagementTest::Process has failed";
        Sleep(10);
        DfiCommunicator.Destroy();
        pTarget->Destroy();
        pTarget.reset(nullptr);
    }

#pragma region IPv6_Test_Cases

    TEST_F(WorkListManagementTest, WLMTool_CheckIPv6AddressValidation_NoValueSpecified)
    {
        std::unique_ptr<WorkListManagement> pTarget = std::make_unique<WorkListManagement>();
        GenericDataModel m_GenericData              = {};
        DFICommunicatorStub DfiCommunicator         = {};
        DfiCommunicator.SetMsgQueueNames("WLMTool_CheckIPv6AddressValidation_NoValueSpecifiedSR", "WLMTool_CheckIPv6AddressValidation_NoValueSpecifiedFS");
        ElementArray inputControls                  = {};
        ElementArray outputControls                 = {};
        co_featuretoggle_var.rv                     = TRUE;

        DfiCommunicator.Initialize();
        pTarget->Initialize("WLMTool_CheckIPv6AddressValidation_NoValueSpecifiedSR", "WLMTool_CheckIPv6AddressValidation_NoValueSpecifiedFS");

        // get the availablity of the tool
        ASSERT_EQ(ToolState::ToolVisible, pTarget->GetAvailability());

        m_GenericData.SetIstLevel(0);
        //WorkListManagement - WLM Targets
        m_GenericData.SetMessageType(static_cast<MessageType>(ToolsIDDefinitions::WorkListManagement));

        // check for OprnLoad
        m_GenericData.SetOperationType(OprnLoad);
        void* pMsg           = nullptr;
        unsigned int msgSize = 0u;
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        Byte* outputMessage  = nullptr;
        int outputSize       = 0;
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WorkListManagement - OprnLoad ::Process has failed";
        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        m_GenericData.GetUIElements(inputControls);
        // check for OprnApply
        m_GenericData.SetOperationType(OprnApply);

        // Target Name
        inputControls[inputControls.GetIndexByID(WLM_NAME)].value = L"WLM-Test Target";
        // Store enable
        inputControls[inputControls.GetIndexByID(WLM_ENABLE)].value = L"0";
        // Secure Communication
        if (CoFeatureAvailability(CO_FEATURE_SECURE_COMMUNICATION))
        inputControls[inputControls.GetIndexByID(WLM_AUTHENTICATION_ENCRYPTION)].value = L"Authenticate and Encrypt";
        // AE Title
        inputControls[inputControls.GetIndexByID(WLM_AETITLE)].value = L"WLM_TARGET";
        // Ip address
        inputControls[inputControls.GetIndexByID(WLM_IPADDRESS)].value = L"";
        // Port number
        inputControls[inputControls.GetIndexByID(WLM_PORTNUMBER)].value = L"7777";
        // Query
        inputControls[inputControls.GetIndexByID(WLM_QUERY)].value = L"Query1";
        // Study description
        inputControls[inputControls.GetIndexByID(WLM_STUDYDESCRIPTION)].value = L"1";

        m_GenericData.SetUIElements(inputControls);
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WLM - OprnSave::Process has failed";

        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        ResultInfo ResInfo = {};
        ResInfo.Clear();
        m_GenericData.GetResult(ResInfo);

        // expectedValue = "'Host Name or IP Address' No value specified"
        std::wstring expectedValue = L"‘" + inputControls[inputControls.GetIndexByID(WLM_IPADDRESS)].label + L"’" + BackendMessage::NoValueSpecified;
        EXPECT_EQ(0, ResInfo.resText.compare(expectedValue));
        ASSERT_EQ(ResInfo.displayMessageType, MessageArea);
        ASSERT_EQ(ResInfo.msgArType, Error);
        ASSERT_EQ(ResInfo.controlId, WLM_IPADDRESS);

        Sleep(10);
        DfiCommunicator.Destroy();
        pTarget->Destroy();

        // Disable IPv6
        co_featuretoggle_var.rv = FALSE;
    }

    TEST_F(WorkListManagementTest, WLMTool_SaveTarget_WhenIPv6IsEnabled_With_Cofeature)
    {
        std::unique_ptr<WorkListManagement> pTarget = std::make_unique<WorkListManagement>();
        GenericDataModel m_GenericData              = {};
        DFICommunicatorStub DfiCommunicator         = {};
        DfiCommunicator.SetMsgQueueNames("WLMTool_SaveTarget_WhenIPv6IsEnabledSR", "WLMTool_SaveTarget_WhenIPv6IsEnabledFS");
        ElementArray inputControls                  = {};
        ElementArray outputControls                 = {};
        ControlElement control                      = {};
        co_featuretoggle_var.rv                     = TRUE;

        DfiCommunicator.Initialize();
        pTarget->Initialize("WLMTool_SaveTarget_WhenIPv6IsEnabledSR", "WLMTool_SaveTarget_WhenIPv6IsEnabledFS");

        // get the availablity of the tool
        ASSERT_EQ(ToolState::ToolVisible, pTarget->GetAvailability());

        m_GenericData.SetIstLevel(0);
        //1005 - WLM Targets
        m_GenericData.SetMessageType(static_cast<MessageType>(ToolsIDDefinitions::WorkListManagement));

        // check for OprnLoad
        m_GenericData.SetOperationType(OprnLoad);
        void* pMsg           = nullptr;
        unsigned int msgSize = 0u;
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        Byte* outputMessage  = nullptr;
        int outputSize       = 0;
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WorkListManagement - OprnLoad ::Process has failed";
        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        m_GenericData.GetUIElements(inputControls);
        // check for OprnOk
        m_GenericData.SetOperationType(OprnOk);

        // Target Name
        inputControls[inputControls.GetIndexByID(WLM_NAME)].value = L"WLM-Test Target";
        // Store enable
        inputControls[inputControls.GetIndexByID(WLM_ENABLE)].value = L"1";
        // Secure Communication
        if (CoFeatureAvailability(CO_FEATURE_SECURE_COMMUNICATION))
        inputControls[inputControls.GetIndexByID(WLM_AUTHENTICATION_ENCRYPTION)].value = L"Authenticate and Encrypt";
        // AE Title
        inputControls[inputControls.GetIndexByID(WLM_AETITLE)].value = L"WLM_AE";
        // Ip address
        inputControls[inputControls.GetIndexByID(WLM_IPADDRESS)].value = L"2001:2470:2026:307:4b24:eb9e:f057:5f2a";
        // Port number
        inputControls[inputControls.GetIndexByID(WLM_PORTNUMBER)].value = L"7777";
        // Query
        inputControls[inputControls.GetIndexByID(WLM_QUERY)].value = L"Query1";
        // Study description
        inputControls[inputControls.GetIndexByID(WLM_STUDYDESCRIPTION)].value = L"1";

        // check for OprnOk
        m_GenericData.SetOperationType(OprnOk);

        m_GenericData.SetUIElements(inputControls);
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WLM - OprnSave::Process has failed";

        //recheck whether previous configuration is saved or not to the db(DICOM_TARGETS)
        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));
        m_GenericData.GetUIElements(inputControls);

        // Check the whether configurations are saved or not for the "WLM-Test Target"
        m_GenericData.SetOperationType(OprnLoad);
        pMsg          = nullptr;
        msgSize       = 0u;
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        outputMessage = nullptr;
        outputSize    = 0;
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WLM - OprnLoad ::Process has failed";
        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        m_GenericData.GetUIElements(outputControls);

        ASSERT_STREQ(L"WLM-Test Target", outputControls[outputControls.GetIndexByID(WLM_NAME)].value.c_str()) << "WLM-Test Target is not saved";
        ASSERT_STREQ(L"1", outputControls[outputControls.GetIndexByID(WLM_ENABLE)].value.c_str()) << "Enable is not saved";
        if (CoFeatureAvailability(CO_FEATURE_SECURE_COMMUNICATION))
        ASSERT_STREQ(L"Authenticate and Encrypt", outputControls[outputControls.GetIndexByID(WLM_AUTHENTICATION_ENCRYPTION)].value.c_str()) << "Secure Communication is not saved";
        ASSERT_STREQ(L"WLM_AE", outputControls[outputControls.GetIndexByID(WLM_AETITLE)].value.c_str()) << "AE Title is not saved";
        ASSERT_STREQ(L"2001:2470:2026:307:4b24:eb9e:f057:5f2a", outputControls[outputControls.GetIndexByID(WLM_IPADDRESS)].value.c_str()) << "Ip address is not saved";
        ASSERT_STREQ(L"7777", outputControls[outputControls.GetIndexByID(WLM_PORTNUMBER)].value.c_str()) << "Port number is not saved";
        ASSERT_STREQ(L"Query1", outputControls[outputControls.GetIndexByID(WLM_QUERY)].value.c_str()) << "Query is not saved";
        ASSERT_STREQ(L"Requested Procedure description (0032,1060)", outputControls[outputControls.GetIndexByID(WLM_STUDYDESCRIPTION)].value.c_str()) << "Request procedure is not saved";

        ASSERT_EQ(LogNetworkEntry_var.netEntry[0].auditData.AuditID, AUDT_NETWORK_ENTRY);
        ASSERT_EQ(LogNetworkEntry_var.netEntry[0].NetworkAction, TRUE);

        // User guide test
        ASSERT_EQ(true, outputControls.GetControlByID(WLM_WLMMESSAGE, control)) << WLM_WLMMESSAGE << "'s control is missing";
        ASSERT_STREQ(L"Worklist management server customization:", control.label.c_str()) << WLM_WLMMESSAGE << "'s label has changed.";
        ASSERT_EQ(ControlType::TextArea,                           control.type)          << WLM_WLMMESSAGE << "'s control type has changed.";

        ASSERT_EQ(true, outputControls.GetControlByID(WLM_WLMTARGET, control)) << WLM_WLMTARGET << " control is missing";
        ASSERT_EQ(false,                     control.validationRequired)          << "WLM Target Name's validation required has changed.";
        ASSERT_STREQ(L"",                    control.valParameters.range.c_str()) << "WLM Target Name's range value has changed.";
        ASSERT_EQ(ControlType::TextBoxWider, control.type)                        << "WLM Target Name's control type has changed.";

        ASSERT_EQ(true, outputControls.GetControlByID(WLM_NAME, control)) << WLM_NAME << " control is missing";
        ASSERT_EQ(true,                      control.validationRequired) << "Name's validation required has changed.";
        ASSERT_EQ(true,                      control.valParameters.validateEmpty)<< "Name's validate empty has changed.";
        ASSERT_STREQ(L"1;25",                control.valParameters.range.c_str()) << "Name's range value has changed.";
        ASSERT_EQ(ControlType::TextBoxWider, control.type)                        << "Name's control type has changed.";

        ASSERT_EQ(true, outputControls.GetControlByID(WLM_ENABLE, control)) << WLM_ENABLE << " control is missing";
        ASSERT_EQ(false,                    control.validationRequired) << "Enable's validation required has changed.";
        ASSERT_STREQ(L"Yes;No",             control.contents.c_str())   << "Enable's contents has changed.";
        ASSERT_EQ(ControlType::RadioButton, control.type)               << "Enable's control type has changed.";
        
        if (CoFeatureAvailability(CO_FEATURE_SECURE_COMMUNICATION))
        ASSERT_EQ(true, outputControls.GetControlByID(WLM_AUTHENTICATION_ENCRYPTION, control)) << WLM_AUTHENTICATION_ENCRYPTION << " control is missing";
        ASSERT_EQ(ControlType::ComboBox, control.type) << "Secure Communication's control type has changed.";
        ASSERT_STREQ(L"Off;Authenticate;Authenticate and Encrypt", control.contents.c_str()) << "Enable's contents has changed.";
        ASSERT_EQ(DataType::StringType, control.dataType) << "Secure Communication's data type required has changed.";
        ASSERT_STREQ(L"Authenticate and Encrypt", control.value.c_str()) << "Enable's value has changed.";

        ASSERT_EQ(true, outputControls.GetControlByID(WLM_AETITLE, control)) << WLM_AETITLE << " control is missing";
        ASSERT_EQ(true,                      control.validationRequired)          << "AE Title's validation required has changed.";
        ASSERT_EQ(true,                      control.valParameters.validateEmpty) << "AE Title 's validate empty has changed.";
        ASSERT_STREQ(L"1;16",                control.valParameters.range.c_str()) << "AE Title's range value has changed.";
        ASSERT_EQ(ControlType::TextBoxWider, control.type)                        << "AE Title's control type has changed.";

        ASSERT_EQ(true, outputControls.GetControlByID(WLM_IPADDRESS, control)) << WLM_IPADDRESS << " control is missing";
        ASSERT_EQ(true,                         control.validationRequired)          << "Host address's validation required has changed.";
        ASSERT_EQ(true,                         control.valParameters.validateEmpty) << "Host address's validate empty has changed.";
        ASSERT_STREQ(L"1;39",                   control.valParameters.range.c_str()) << "Host address's range value has changed.";
        ASSERT_EQ(DataType::AlphanumericString, control.dataType)                    << "Host address's data type has changed.";
        ASSERT_EQ(ControlType::TextBoxWider,    control.type)                        << "Host address's control type has changed.";
        ASSERT_EQ(L"Host Name or IP Address",   control.label)                       << "Host address's label has changed.";

        ASSERT_EQ(true, outputControls.GetControlByID(WLM_PORTNUMBER, control)) << WLM_PORTNUMBER << " control is missing";
        ASSERT_EQ(true,                      control.validationRequired)          << "Port number's validation required has changed.";
        ASSERT_EQ(true,                      control.valParameters.validateEmpty) << "Port number's validate empty has changed.";
        ASSERT_STREQ(L"1;65535",             control.valParameters.range.c_str()) << "Port number's range value has changed.";
        ASSERT_EQ(ControlType::TextBoxWider, control.type)                        << "Port number's control type has changed.";
        ASSERT_EQ(DataType::IntegerType,     control.dataType)                    << "Port number's data type has changed.";

        ASSERT_EQ(true, outputControls.GetControlByID(WLM_QUERY, control)) << WLM_QUERY << " control is missing";
        ASSERT_EQ(true,                       control.validationRequired)          << "Query's validation required has changed.";
        ASSERT_STREQ(L"1;65535",              control.valParameters.range.c_str()) << "Query's range value has changed.";
        ASSERT_EQ(ControlType::ComboBoxWider, control.type)                        << "Query's control type has changed.";

        ASSERT_EQ(true, outputControls.GetControlByID(WLM_STUDYDESCRIPTION, control)) << WLM_STUDYDESCRIPTION << " control is missing";
        ASSERT_EQ(true,                       control.validationRequired)          << "Study description's validation required has changed.";
        ASSERT_EQ(ControlType::ComboBoxWider, control.type)                        << "Study description's control type has changed.";

        ASSERT_EQ(true, outputControls.GetControlByID(WLM_ENABLEREASON, control)) << WLM_ENABLEREASON << " control is missing";
        ASSERT_EQ(false,                    control.validationRequired) << "Enable Reason's validation required has changed.";
        ASSERT_STREQ(L"Yes;No",             control.contents.c_str())   << "Enable Reason's contents has changed.";
        ASSERT_EQ(ControlType::RadioButton, control.type)               << "Enable Reason's control type has changed.";

        Sleep(10);
        DfiCommunicator.Destroy();
        pTarget->Destroy();
        pTarget.reset(nullptr);

        // Disable IPv6
        co_featuretoggle_var.rv = FALSE;
    }

    TEST_F(WorkListManagementTest, WLMTool_SaveTarget_WhenIPv6IsEnabled_Without_Cofeature)
    {
        std::unique_ptr<WorkListManagement> pTarget = std::make_unique<WorkListManagement>();
        GenericDataModel m_GenericData = {};
        DFICommunicatorStub DfiCommunicator = {};
        DfiCommunicator.SetMsgQueueNames("WLMTool_SaveTarget_WhenIPv6IsEnabledSR", "WLMTool_SaveTarget_WhenIPv6IsEnabledFS");
        ElementArray inputControls = {};
        ElementArray outputControls = {};
        ControlElement control = {};
        co_featuretoggle_var.rv = FALSE;

        DfiCommunicator.Initialize();
        pTarget->Initialize("WLMTool_SaveTarget_WhenIPv6IsEnabledSR", "WLMTool_SaveTarget_WhenIPv6IsEnabledFS");

        // get the availablity of the tool
        ASSERT_EQ(ToolState::ToolVisible, pTarget->GetAvailability());

        m_GenericData.SetIstLevel(0);
        //1005 - WLM Targets
        m_GenericData.SetMessageType(static_cast<MessageType>(ToolsIDDefinitions::WorkListManagement));

        // check for OprnLoad
        m_GenericData.SetOperationType(OprnLoad);
        void* pMsg = nullptr;
        unsigned int msgSize = 0u;
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        Byte* outputMessage = nullptr;
        int outputSize = 0;
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WorkListManagement - OprnLoad ::Process has failed";
        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        m_GenericData.GetUIElements(inputControls);
        // check for OprnOk
        m_GenericData.SetOperationType(OprnOk);

        // Target Name
        inputControls[inputControls.GetIndexByID(WLM_NAME)].value = L"WLM-Test Target";
        // Store enable
        inputControls[inputControls.GetIndexByID(WLM_ENABLE)].value = L"1";
        // Secure Communication
        if (CoFeatureAvailability(CO_FEATURE_SECURE_COMMUNICATION))
        inputControls[inputControls.GetIndexByID(WLM_AUTHENTICATION_ENCRYPTION)].value = L"Authenticate and Encrypt";
        // AE Title
        inputControls[inputControls.GetIndexByID(WLM_AETITLE)].value = L"WLM_AE";
        // Ip address
        inputControls[inputControls.GetIndexByID(WLM_IPADDRESS)].value = L"2001:2470:2026:307:4b24:eb9e:f057:5f2a";
        // Port number
        inputControls[inputControls.GetIndexByID(WLM_PORTNUMBER)].value = L"7777";
        // Query
        inputControls[inputControls.GetIndexByID(WLM_QUERY)].value = L"Query1";
        // Study description
        inputControls[inputControls.GetIndexByID(WLM_STUDYDESCRIPTION)].value = L"1";

        // check for OprnOk
        m_GenericData.SetOperationType(OprnOk);

        m_GenericData.SetUIElements(inputControls);
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WLM - OprnSave::Process has failed";

        //recheck whether previous configuration is saved or not to the db(DICOM_TARGETS)
        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));
        m_GenericData.GetUIElements(inputControls);

        // Check the whether configurations are saved or not for the "WLM-Test Target"
        m_GenericData.SetOperationType(OprnLoad);
        pMsg = nullptr;
        msgSize = 0u;
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        outputMessage = nullptr;
        outputSize = 0;
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WLM - OprnLoad ::Process has failed";
        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        m_GenericData.GetUIElements(outputControls);

        ASSERT_STREQ(L"WLM-Test Target", outputControls[outputControls.GetIndexByID(WLM_NAME)].value.c_str()) << "WLM-Test Target is not saved";
        ASSERT_STREQ(L"1", outputControls[outputControls.GetIndexByID(WLM_ENABLE)].value.c_str()) << "Enable is not saved";
        if (CoFeatureAvailability(CO_FEATURE_SECURE_COMMUNICATION))
        ASSERT_STREQ(L"Authenticate and Encrypt", outputControls[outputControls.GetIndexByID(WLM_AUTHENTICATION_ENCRYPTION)].value.c_str()) << "Secure Communication is not saved";
        ASSERT_STREQ(L"WLM_AE", outputControls[outputControls.GetIndexByID(WLM_AETITLE)].value.c_str()) << "AE Title is not saved";
        ASSERT_STREQ(L"2001:2470:2026:307:4b24:eb9e:f057:5f2a", outputControls[outputControls.GetIndexByID(WLM_IPADDRESS)].value.c_str()) << "Ip address is not saved";
        ASSERT_STREQ(L"7777", outputControls[outputControls.GetIndexByID(WLM_PORTNUMBER)].value.c_str()) << "Port number is not saved";
        ASSERT_STREQ(L"Query1", outputControls[outputControls.GetIndexByID(WLM_QUERY)].value.c_str()) << "Query is not saved";
        ASSERT_STREQ(L"Requested Procedure description (0032,1060)", outputControls[outputControls.GetIndexByID(WLM_STUDYDESCRIPTION)].value.c_str()) << "Request procedure is not saved";

        ASSERT_EQ(LogNetworkEntry_var.netEntry[0].auditData.AuditID, AUDT_NETWORK_ENTRY);
        ASSERT_EQ(LogNetworkEntry_var.netEntry[0].NetworkAction, TRUE);

        // User guide test
        ASSERT_EQ(true, outputControls.GetControlByID(WLM_WLMMESSAGE, control)) << WLM_WLMMESSAGE << "'s control is missing";
        ASSERT_STREQ(L"Worklist management server customization:", control.label.c_str()) << WLM_WLMMESSAGE << "'s label has changed.";
        ASSERT_EQ(ControlType::TextArea, control.type) << WLM_WLMMESSAGE << "'s control type has changed.";

        ASSERT_EQ(true, outputControls.GetControlByID(WLM_WLMTARGET, control)) << WLM_WLMTARGET << " control is missing";
        ASSERT_EQ(false, control.validationRequired) << "WLM Target Name's validation required has changed.";
        ASSERT_STREQ(L"", control.valParameters.range.c_str()) << "WLM Target Name's range value has changed.";
        ASSERT_EQ(ControlType::TextBoxWider, control.type) << "WLM Target Name's control type has changed.";

        ASSERT_EQ(true, outputControls.GetControlByID(WLM_NAME, control)) << WLM_NAME << " control is missing";
        ASSERT_EQ(true, control.validationRequired) << "Name's validation required has changed.";
        ASSERT_EQ(true, control.valParameters.validateEmpty) << "Name's validate empty has changed.";
        ASSERT_STREQ(L"1;25", control.valParameters.range.c_str()) << "Name's range value has changed.";
        ASSERT_EQ(ControlType::TextBoxWider, control.type) << "Name's control type has changed.";

        ASSERT_EQ(true, outputControls.GetControlByID(WLM_ENABLE, control)) << WLM_ENABLE << " control is missing";
        ASSERT_EQ(false, control.validationRequired) << "Enable's validation required has changed.";
        ASSERT_STREQ(L"Yes;No", control.contents.c_str()) << "Enable's contents has changed.";
        ASSERT_EQ(ControlType::RadioButton, control.type) << "Enable's control type has changed.";

        if (CoFeatureAvailability(CO_FEATURE_SECURE_COMMUNICATION))
        ASSERT_EQ(true, outputControls.GetControlByID(WLM_AUTHENTICATION_ENCRYPTION, control)) << WLM_AUTHENTICATION_ENCRYPTION << " control is missing";
        ASSERT_EQ(ControlType::ComboBox, control.type) << "Secure Communication's control type has changed.";
        ASSERT_STREQ(L"Off;Authenticate;Authenticate and Encrypt", control.contents.c_str()) << "Enable's contents has changed.";
        ASSERT_EQ(DataType::StringType, control.dataType) << "Secure Communication's data type required has changed.";
        ASSERT_STREQ(L"Authenticate and Encrypt", control.value.c_str()) << "Enable's value has changed.";

        ASSERT_EQ(true, outputControls.GetControlByID(WLM_AETITLE, control)) << WLM_AETITLE << " control is missing";
        ASSERT_EQ(true, control.validationRequired) << "AE Title's validation required has changed.";
        ASSERT_EQ(true, control.valParameters.validateEmpty) << "AE Title 's validate empty has changed.";
        ASSERT_STREQ(L"1;16", control.valParameters.range.c_str()) << "AE Title's range value has changed.";
        ASSERT_EQ(ControlType::TextBoxWider, control.type) << "AE Title's control type has changed.";

        ASSERT_EQ(true, outputControls.GetControlByID(WLM_IPADDRESS, control)) << WLM_IPADDRESS << " control is missing";
        ASSERT_EQ(true, control.validationRequired) << "Host address's validation required has changed.";
        ASSERT_EQ(true, control.valParameters.validateEmpty) << "Host address's validate empty has changed.";
        ASSERT_STREQ(L"1;39", control.valParameters.range.c_str()) << "Host address's range value has changed.";
        ASSERT_EQ(DataType::AlphanumericString, control.dataType) << "Host address's data type has changed.";
        ASSERT_EQ(ControlType::TextBoxWider, control.type) << "Host address's control type has changed.";
        ASSERT_EQ(L"Host Name or IP Address", control.label) << "Host address's label has changed.";

        ASSERT_EQ(true, outputControls.GetControlByID(WLM_PORTNUMBER, control)) << WLM_PORTNUMBER << " control is missing";
        ASSERT_EQ(true, control.validationRequired) << "Port number's validation required has changed.";
        ASSERT_EQ(true, control.valParameters.validateEmpty) << "Port number's validate empty has changed.";
        ASSERT_STREQ(L"1;65535", control.valParameters.range.c_str()) << "Port number's range value has changed.";
        ASSERT_EQ(ControlType::TextBoxWider, control.type) << "Port number's control type has changed.";
        ASSERT_EQ(DataType::IntegerType, control.dataType) << "Port number's data type has changed.";

        ASSERT_EQ(true, outputControls.GetControlByID(WLM_QUERY, control)) << WLM_QUERY << " control is missing";
        ASSERT_EQ(true, control.validationRequired) << "Query's validation required has changed.";
        ASSERT_STREQ(L"1;65535", control.valParameters.range.c_str()) << "Query's range value has changed.";
        ASSERT_EQ(ControlType::ComboBoxWider, control.type) << "Query's control type has changed.";

        ASSERT_EQ(true, outputControls.GetControlByID(WLM_STUDYDESCRIPTION, control)) << WLM_STUDYDESCRIPTION << " control is missing";
        ASSERT_EQ(true, control.validationRequired) << "Study description's validation required has changed.";
        ASSERT_EQ(ControlType::ComboBoxWider, control.type) << "Study description's control type has changed.";

        ASSERT_EQ(true, outputControls.GetControlByID(WLM_ENABLEREASON, control)) << WLM_ENABLEREASON << " control is missing";
        ASSERT_EQ(false, control.validationRequired) << "Enable Reason's validation required has changed.";
        ASSERT_STREQ(L"Yes;No", control.contents.c_str()) << "Enable Reason's contents has changed.";
        ASSERT_EQ(ControlType::RadioButton, control.type) << "Enable Reason's control type has changed.";

        Sleep(10);
        DfiCommunicator.Destroy();
        pTarget->Destroy();
        pTarget.reset(nullptr);


    }

    TEST_F(WorkListManagementTest, WLMTool_Hide_IPv6_Controls_When_Toggle_IPv6_Is_False)
    {
        std::unique_ptr<WorkListManagement> pTarget = std::make_unique<WorkListManagement>();
        GenericDataModel m_GenericData              = {};
        DFICommunicatorStub DfiCommunicator         = {};
        DfiCommunicator.SetMsgQueueNames("WLMTool_Hide_IPv6_Controls_When_Toggle_IPv6_Is_FalseSR", "WLMTool_Hide_IPv6_Controls_When_Toggle_IPv6_Is_FalseFS");
        ElementArray outputControls                 = {};
        co_featuretoggle_var.rv                     = FALSE;

        DfiCommunicator.Initialize();
        pTarget->Initialize("WLMTool_Hide_IPv6_Controls_When_Toggle_IPv6_Is_FalseSR", "WLMTool_Hide_IPv6_Controls_When_Toggle_IPv6_Is_FalseFS");

        // get the availablity of the tool
        ASSERT_EQ(ToolState::ToolVisible, pTarget->GetAvailability());

        m_GenericData.SetIstLevel(0);
        //1005 - WLM Targets
        m_GenericData.SetMessageType(static_cast<MessageType>(ToolsIDDefinitions::WorkListManagement));

        // check for OprnLoad
        m_GenericData.SetOperationType(OprnLoad);
        void* pMsg           = nullptr;
        unsigned int msgSize = 0u;
        Serializer::Serialize(m_GenericData, pMsg, msgSize);
        Byte* outputMessage  = nullptr;
        int outputSize       = 0;
        ASSERT_EQ(true, pTarget->Process((const Byte*)pMsg, msgSize, outputMessage, outputSize)) << "WorkListManagement - OprnLoad ::Process has failed";
        ASSERT_EQ(true, Serializer::Deserialize(outputMessage, outputSize, m_GenericData));

        m_GenericData.GetUIElements(outputControls);
        ASSERT_EQ(outputControls.GetCount(), 9); //Number of controls in the tool
        //int expectedCount = 9; // TextArea, WLM Target, Name, Enable, AETitle, IPAddress, Port, Query, StudyDescription, EnableReason
        //if (CoFeatureAvailability(CO_FEATURE_SECURE_COMMUNICATION))
        //    expectedCount++;
        //ASSERT_EQ(outputControls.GetCount(), expectedCount) << "Mismatch in number of UI controls";

        // Reference Section
        ASSERT_EQ(ControlType::TextBox, outputControls[outputControls.GetIndexByID(BackendToolsControlsID::WLM_WLMTARGET)].type)
            << BackendToolsControlsID::WLM_WLMTARGET + L" text box is not seen.";

        // Settings Section
        ASSERT_EQ(ControlType::TextBox, outputControls[outputControls.GetIndexByID(BackendToolsControlsID::WLM_NAME)].type)
            << BackendToolsControlsID::WLM_NAME + L" text box is not seen.";
        ASSERT_EQ(ControlType::RadioButton, outputControls[outputControls.GetIndexByID(BackendToolsControlsID::WLM_ENABLE)].type)
            << BackendToolsControlsID::WLM_ENABLE + L" radio box is not seen.";
        if (CoFeatureAvailability(CO_FEATURE_SECURE_COMMUNICATION))
        ASSERT_EQ(ControlType::ComboBox, outputControls[outputControls.GetIndexByID(BackendToolsControlsID::WLM_AUTHENTICATION_ENCRYPTION)].type)
            << BackendToolsControlsID::WLM_AUTHENTICATION_ENCRYPTION + L" combo box is not seen.";
        ASSERT_EQ(ControlType::TextBox, outputControls[outputControls.GetIndexByID(BackendToolsControlsID::WLM_AETITLE)].type)
            << BackendToolsControlsID::WLM_AETITLE + L" text box is not seen.";
        ASSERT_EQ(BackendToolsLabelID::WLM_LBL_IPADDRESS, outputControls[outputControls.GetIndexByID(BackendToolsControlsID::WLM_IPADDRESS)].label.c_str())
            << BackendToolsControlsID::WLM_IPADDRESS + L" label is not seen.";
        ASSERT_NE(BackendToolsLabelID::WLM_LBL_HOST_ADDRESS, outputControls[outputControls.GetIndexByID(BackendToolsControlsID::WLM_IPADDRESS)].label.c_str())
            << BackendToolsControlsID::WLM_IPADDRESS + L" label is not hidden.";
        ASSERT_EQ(ControlType::TextBox, outputControls[outputControls.GetIndexByID(BackendToolsControlsID::WLM_IPADDRESS)].type)
            << BackendToolsControlsID::WLM_IPADDRESS + L" text box is not seen.";
        ASSERT_EQ(ControlType::TextBox, outputControls[outputControls.GetIndexByID(BackendToolsControlsID::WLM_PORTNUMBER)].type)
            << BackendToolsControlsID::WLM_PORTNUMBER + L" text box is not seen.";
        ASSERT_EQ(ControlType::ComboBox, outputControls[outputControls.GetIndexByID(BackendToolsControlsID::WLM_QUERY)].type)
            << BackendToolsControlsID::WLM_QUERY + L" combo box is not seen.";
        ASSERT_EQ(ControlType::ComboBox, outputControls[outputControls.GetIndexByID(BackendToolsControlsID::WLM_STUDYDESCRIPTION)].type)
            << BackendToolsControlsID::WLM_STUDYDESCRIPTION + L" combo box is not seen.";
        ASSERT_EQ(ControlType::RadioButton, outputControls[outputControls.GetIndexByID(BackendToolsControlsID::WLM_ENABLEREASON)].type)
            << BackendToolsControlsID::WLM_ENABLEREASON + L" radio box is not seen.";
        
        Sleep(10);
        DfiCommunicator.Destroy();
        pTarget->Destroy();
        pTarget.reset(nullptr);
    }

#pragma endregion

    void WorkListManagementTest::SetEnvVariable()
    {
        static_cast<void>(GetEnvironmentVariable("DFI_WORKDIR", CurrentEnvPath.data(), 256));
        if (GetLastError() == static_cast<DWORD>(ERROR_ENVVAR_NOT_FOUND))
        {
            m_StatusSetEnv = false;
        }

        TCHAR szEXEPath[256] = { 0 };
        GetModuleFileName(NULL, szEXEPath, 256);

        TCHAR szTestEnvPath[256] = { 0 };
        strncpy_s(szTestEnvPath, szEXEPath, strlen(szEXEPath) - strlen("TestFieldServiceInfraParallel.exe"));

        if (FALSE == SetEnvironmentVariable("DFI_WORKDIR", szTestEnvPath))
        {
            std::cout << "Error : Not possible to set the Envirnment variable" << GetLastError() << "\n";
        }
    }

    void WorkListManagementTest::RestoreEnvirnVariable()
    {
        if (m_StatusSetEnv)
        {
            (void)SetEnvironmentVariable("DFI_WORKDIR", CurrentEnvPath.data());
        }
    }

}


//****************************************************************************//
//                                                                            //
//   Filename   : WorkListManagement.cpp                                      //
//                                                                            //
//   Description: WorkListManagement                                          //
//                                                                            //
//   Copyright  : Philips Medical Systems Nederland B.V., 2014.               //
//                                                                            //
//****************************************************************************//


#include <fstream>
#include "Utilities/inc/Serializer.h"
#include "Common/InterfaceData.h"
#include "Utilities/inc/CommonUtility.h"
#include "target.h"
#include "inc/BackendUtility.h"
#include "inc/WorkListManagement.h"
#include "inc/BackendMessages.h"
#include "inc/BackendControlIDs.h"
#include "inc/BackendLabelIDs.h"
#include "Logger.h"
#include "AuditTrail\AuditTrail.h"

//TICS -OLC#009   numbers are used to access the UI element

using namespace std;
using namespace FSInfra::Common;
using namespace FSInfra::Utilities;
using namespace BackendTools;
using namespace ToolsDefinitions;
using namespace BackendToolsControlsID;
using namespace BackendToolsLabelID; 

namespace BackendTools
{
    const std::array <ID_DESC_PAIR_STRUCT ,2>  WorkListManagement::m_StudyEntries =                                  //TICS !PCA#009 no need for instance of an array class
    {{
            // value,                                    name                                      
            { STUDY_DESCR_MAPPING_REQ_PROC,         L"Requested Procedure description (0032,1060)" },       //TICS -CON#004   Defined in existing in target.h
            { STUDY_DESCR_MAPPING_SCHED_PROC_STEP,  L"Scheduled Procedure Step description (0040,0007)" }   //TICS -CON#004   Defined in existing in target.h
    }};

    const ID_DESC_PAIR_STRUCT WorkListManagement::ComboBoxEntries[] =
    {
        { SECURE_DICOM_OFF, L"Off" },
        { ONLY_AUTHENTICATE, L"Authenticate" },
        { AUTHENTICATE_ENCRYPTION, L"Authenticate and Encrypt" }
    };

    WorkListManagement::WorkListManagement() : configRecord()
    {

    }

    WorkListManagement::~WorkListManagement()
    {
    }

    void WorkListManagement::Initialize() 
    {
        BeCommunicator.Intialize();
    }

    void WorkListManagement::Initialize(std::string serviceResponseMsgQ, std::string fieldServiceMsgQ)
    {
        BeCommunicator.Initialize(serviceResponseMsgQ, fieldServiceMsgQ);
    }

    bool WorkListManagement::Process(const Byte* const inputMessage, const int inputSize, Byte*& outputMessage, int& outputSize) 
    {
        LOG_FUNCTION(LOG_MI_FSBE, "WorkListManagement::Process");

        bool statusProcess = false;
        if ( Serializer::Deserialize(inputMessage, inputSize, m_WlmDataModel) )
        {
            ElementArray controls;
            ResultInfo info;
            void *outputStream = nullptr;
            unsigned int sizeStream = static_cast<unsigned int>(0);

            //set button states
            ButtonStates buttonState;
            buttonState.nextBtn = Hidden;
            buttonState.prevBtn = Hidden;
            buttonState.cancelBtn = Visible;
            buttonState.checkBtn = Visible;
            buttonState.applyBtn = Visible; 
            buttonState.repeatBtn = Hidden;
            buttonState.saveBtn = Hidden;
            buttonState.okBtn = Visible;

            switch(m_WlmDataModel.GetOperationType())
            {
            case OprnApply:
            case OprnOk:
                {
                    BeCommunicator.EnterServiceMode();
                    if(GetWLMExportTarget())
                    {
                        controls.Clear();
                        m_WlmDataModel.GetUIElements(controls);
                        info.Clear();
                        info.displayMessage = true;
                        ControlElement element;

                        if(controls.GetControlByID(BackendToolsControlsID::WLM_NAME, element))
                        {
                            if( element.value.compare(L"No Name") ==  0)
                            {
                                info.resText = L"‘" + element.label + L"’" + L" " + BackendMessage::NoValueSpecified;
                                info.controlId = element.controlID;
                                info.displayMessageType = DisplayMessageType::MessageArea;
                                info.msgArType = MessageAreaType::Error;
                            }

                            if(DisplayIPAddressError(controls, info))
                            {
                                StoreConfiguration(controls, info);
                                controls[controls.GetIndexByID(WLM_WLMTARGET)].value = controls[controls.GetIndexByID(WLM_NAME)].value;
                                m_WlmDataModel.SetUIElements(controls);

                                if(Success == info.resCode)
                                {
                                    if( m_WlmDataModel.GetOperationType() == OprnOk )
                                    {
                                        info.resCode = Exit;
                                    }
                                    else
                                    {
                                        info.resCode = Success;
                                    }
                                }
                                else
                                {
                                    info.resCode = Success;
                                }
                            }
                            else
                            {
                                LOG_WARNING("DisplayIPAddressError returned error while OprnApply or OprnOk.");
                            }
                        }
                        m_WlmDataModel.SetResult(info);
                        m_WlmDataModel.SetButtonStates(buttonState);

                        statusProcess = Serializer::Serialize(m_WlmDataModel, outputStream, sizeStream);
                        if( statusProcess )
                        {
                            outputMessage = static_cast<Byte*>( outputStream );
                            outputSize = sizeStream;
                        }
                        else
                        {
                            LOG_WARNING("OprnApply or OprnOk Serializer failed");
                        }
                    }
                    else
                    {
                        LOG_WARNING("Getting WLM Export Target is failed while OprnApply or OprnOk Operation");
                    }

                    int result = BeCommunicator.CreateDicomTargetsFile(DICOM_TARGET_FILE_PATH);
                    if (OK != result)
                    {
                        LOG_WARNING("Error in creating DICOM targets file.");
                    }
                    BeCommunicator.ExitServiceMode();
                    break;
                }

            case OprnLoad:
                {
                    BeCommunicator.EnterServiceMode();
                    if(GetWLMExportTarget())
                    {
                        controls.Clear();
                        PopulateUIElements(controls);
                        m_WlmDataModel.SetUIElements(controls);

                        m_WlmDataModel.SetButtonStates(buttonState);
                        m_WlmDataModel.SetOperationType(OprnLoad);

                        info.displayMessage = false;
                        info.resCode = Success;
                        m_WlmDataModel.SetResult(info);
                        m_WlmDataModel.SetInfoFile(L"Info1.html");

                        statusProcess = Serializer::Serialize(m_WlmDataModel, outputStream, sizeStream);
                        if( statusProcess )
                        {
                            outputMessage = static_cast<Byte*>( outputStream );
                            outputSize = sizeStream;
                        }
                        else
                        {
                            LOG_WARNING("OprnLoad Serializer failed");
                        }
                    }
                    else
                    {
                        LOG_WARNING("Getting WLM Export Target is failed while OprnLoad Operation");
                    }
                    BeCommunicator.ExitServiceMode();
                    break;
                }

            case OprnCancel:
            case OprnConfirm:
                {
                    info.displayMessage = false;
                    info.resCode = Exit;
                    m_WlmDataModel.SetResult(info);

                    statusProcess = Serializer::Serialize(m_WlmDataModel, outputStream, sizeStream);
                    if( statusProcess )
                    {
                        outputMessage = static_cast<Byte*>( outputStream );
                        outputSize = sizeStream;
                    }
                    else
                    {
                        LOG_WARNING("OprnConfirm Serializer failed");
                    }
                    break;
                }

            case OprnCheck:
                {
                    controls.Clear();
                    m_WlmDataModel.GetUIElements(controls);
                    info.displayMessage = true;
                    info.displayMessageType = MessageArea;
                    info.resCode = Success;
                    if(DisplayIPAddressError(controls, info))
                    {
                        ControlElement element;
                        controls.GetControlByID(WLM_ENABLE, element);
                        if(RadioButtonStatus ::YES == std::stoi(element.value))
                        {
                            if (!CheckTargets(controls,info.resText))
                            {
                                info.msgArType = MessageAreaType::Error;
                                info.resText = BackendMessage::DcmNotOk;
                            }
                        }
                    }

                    m_WlmDataModel.SetResult(info);
                    m_WlmDataModel.SetButtonStates(buttonState);
                    statusProcess = Serializer::Serialize(m_WlmDataModel, outputStream, sizeStream);
                    if ( statusProcess )
                    {
                        outputMessage = static_cast<Byte*>( outputStream );
                        outputSize = sizeStream;
                    }
                    else
                    {
                        LOG_WARNING("OprnCheck Serializer failed");
                    }
                }
                break;

            default:
                statusProcess = false;
                break;
            }
        }
        else
        {
            LOG_DEBUG("Serializer::Deserialize failed");
        }
        return statusProcess;
    }

    ToolState WorkListManagement::GetAvailability()
    {
        FUNCTION_TABLE_STRUCT tableContent;
        ToolState status = ToolVisible ;
        if(BeCommunicator.GetFunctionTable(tableContent))
        {
            status = (tableContent.dcm.worklist == static_cast<BOOLEAN> (TRUE))? ToolState::ToolVisible : ToolState::ToolDisabled;
        }
        return status;
    }

    void WorkListManagement::Destroy()
    {
        BeCommunicator.Destroy();
    }

    bool WorkListManagement::GetWLMExportTarget()
    {
        return BeCommunicator.ReadAllDicomData(STORE, reinterpret_cast<UCHAR*>(&m_WlmConfig));
    }

    void WorkListManagement::PopulateUIElements(ElementArray &controls)
    {
        LOG_FUNCTION(LOG_MI_FSBE, "WorkListManagement::PopulateUIElements");

        controls.Clear();
        ControlElement control;
        BOOLEAN isIPv6Enabled = CoFeatureAvailability(CO_FEATURE_IPV6);

        control.label     = WLM_LBL_WLMMESSAGE;
        control.controlID = WLM_WLMMESSAGE;
        control.type      = TextArea;
        control.group     = Reference; 
        control.dataType  = StringType;
        control.contents.clear();
        controls.Add(control);

        control.Clear();
        control.label     = WLM_LBL_WLMTARGET;
        control.controlID = WLM_WLMTARGET;
        control.type      = isIPv6Enabled ? TextBoxWider : TextBox;
        control.group     = Reference; 
        control.state     = Disabled;
        control.dataType  = StringType;
        control.value     = std::wstring(m_WlmConfig.targetInstance[START_WLM_TARGET].name);
        controls.Add(control);

        control.Clear();
        control.label                       = WLM_LBL_NAME;
        control.controlID                   = WLM_NAME;
        control.type                        = isIPv6Enabled ? TextBoxWider : TextBox;
        control.group                       = Settings; 
        control.state                       = Visible;
        control.value                       = std::wstring(m_WlmConfig.targetInstance[START_WLM_TARGET].name);
        control.validationRequired          = true;
        control.valParameters.validateEmpty = true;
        control.valParameters.range         = L"1;25";
        control.dataType                    = AlphanumericString;
        controls.Add(control);

        control.contents.clear();
        control.label              = WLM_LBL_ENABLE;
        control.controlID          = WLM_ENABLE;
        control.type               = RadioButton;
        control.contents           = L"Yes;No";
        control.dataType           = IntegerType;
        control.validationRequired = false;
        control.value              = std::to_wstring(FSInfra::BackendUtility::RadioButtonStatusToClient(m_WlmConfig.targetInstance[START_WLM_TARGET].enable));
        controls.Add(control);

        if (TRUE == CoFeatureAvailability(CO_FEATURE_SECURE_COMMUNICATION))
        {
            control.contents.clear();
            control.label = WLM_LBL_AUTHENTICATION_ENCRYPTION;
            control.controlID = WLM_AUTHENTICATION_ENCRYPTION;
            control.type = ComboBox;
            control.contents += ComboBoxEntries[0].description + L";" + ComboBoxEntries[1].description + L";" + ComboBoxEntries[2].description;
            control.dataType = StringType;
            control.value = GetComboValue(m_WlmConfig.targetInstance[START_WLM_TARGET]);
            controls.Add(control);
        }

        control.contents.clear();
        control.label                       = WLM_LBL_AETITLE;
        control.controlID                   = WLM_AETITLE;
        control.type                        = isIPv6Enabled ? TextBoxWider : TextBox;
        control.dataType                    = DicomAEString;
        control.validationRequired          = true;
        control.valParameters.validateEmpty = true;
        control.valParameters.range         = L"1;16";
        control.value                       = CommonUtility::ConvertToWstring(m_WlmConfig.targetInstance[START_WLM_TARGET].aeTitle);
        controls.Add(control);

        if (isIPv6Enabled)
        {
            control.label                       = WLM_LBL_HOST_ADDRESS;
            control.validationRequired          = true;
            control.valParameters.validateEmpty = true;
            control.valParameters.range         = L"1;39";
            control.dataType                    = AlphanumericString;
        }
        else
        {
            control.label                       = WLM_LBL_IPADDRESS;
            control.validationRequired          = false;
            control.valParameters.validateEmpty = false;
            control.dataType                    = IpAddress;
            control.customUserGuidanceMessage   = BackendMessage::IPAddressCustomMessage;
        }
        control.controlID                   = WLM_IPADDRESS;
        control.value                       = CommonUtility::ConvertToWstring(m_WlmConfig.targetInstance[START_WLM_TARGET].ipAddress);
        controls.Add(control);

        control.label               = WLM_LBL_PORTNUMBER;
        control.controlID           = WLM_PORTNUMBER;
        control.dataType            = IntegerType;
        control.validationRequired  = true;
        control.valParameters.validateEmpty  = true;
        control.valParameters.range = L"1;65535";
        control.value               = std::to_wstring(m_WlmConfig.targetInstance[START_WLM_TARGET].portNumber);
        control.customUserGuidanceMessage.clear();
        controls.Add(control);

        control.label     = WLM_LBL_QUERY;
        control.controlID = WLM_QUERY;
        control.type      = isIPv6Enabled ? ComboBoxWider : ComboBox;
        control.dataType  = StringType;
        control.contents.clear();
        GetWorkQueriesList(control.contents);
        if((m_WlmConfig.targetInstance[START_WLM_TARGET].wlm.selectedQuery < 4) && (m_WlmConfig.targetInstance[START_WLM_TARGET].wlm.selectedQuery >= 0)
            &&(m_Query.queryInstance[m_WlmConfig.targetInstance[START_WLM_TARGET].wlm.selectedQuery].enable == static_cast<BOOLEAN>(TRUE)))
        {
            control.value = CommonUtility::ConvertToWstring(m_Query.queryInstance[m_WlmConfig.targetInstance[START_WLM_TARGET].wlm.selectedQuery].name);
        }
        else
        {
            control.value.clear();
        }
        controls.Add(control);

        control.label     = WLM_LBL_STUDYDESCRIPTION;
        control.controlID = WLM_STUDYDESCRIPTION;
        control.wordWrap  = true;
        control.group     = Settings; 
        control.dataType  = StringType;
        control.value     = GetStudyDesMapping(m_WlmConfig.targetInstance[START_WLM_TARGET].studyDescriptionMapping);
        control.contents.clear();
        control.contents += m_StudyEntries[0].description + L";" + m_StudyEntries[1].description;
        controls.Add(control);

        bool status;
        status = BeCommunicator.GetConfigRecord(configRecord);
        if (!status)
        {
            LOG_WARNING("GetConfigRecord is failed");
        }

        control.contents.clear();
        control.label              = WLM_LBL_ENABLEREASON;
        control.controlID          = WLM_ENABLEREASON;
        control.type               = RadioButton;
        control.contents           = L"Yes;No";
        control.dataType           = IntegerType;
        control.validationRequired = false;
        control.value              = std::to_wstring(FSInfra::BackendUtility::RadioButtonStatusToClient(configRecord.reasonForRequestedProcedureCsEnabled));
        controls.Add(control);
    }

    void WorkListManagement::StoreConfiguration(const ElementArray &controls, ResultInfo &resultInfo)
    {
        LOG_FUNCTION(LOG_MI_FSBE, "WorkListManagement::StoreConfiguration");

        if(controls[controls.GetIndexByID(WLM_NAME)].value.compare(L"No Name")  !=  0)
        {
            ControlElement element;
            if( controls.GetControlByID(WLM_QUERY, element) )
            {
                if( !element.value.empty() && !(element.value == L" "))
                {
                    // Save name
                    wcscpy_s(m_WlmConfig.targetInstance[START_WLM_TARGET].name, controls[controls.GetIndexByID(WLM_NAME)].value.data());

                    // Save Enable
                    m_WlmConfig.targetInstance[START_WLM_TARGET].enable = FSInfra::BackendUtility::RadioButtonStatusToDB(std::stoi(controls[controls.GetIndexByID(WLM_ENABLE)].value));

                    if (TRUE == CoFeatureAvailability(CO_FEATURE_SECURE_COMMUNICATION))
                    {
                        // Secure Communication
                        controls.GetControlByID(BackendToolsControlsID::WLM_AUTHENTICATION_ENCRYPTION, element);
                        SetComboValue(element.value);
                    }

                    // AE Title
                    CommonUtility::ConvertToCharArray(controls[controls.GetIndexByID(WLM_AETITLE)].value, m_WlmConfig.targetInstance[START_WLM_TARGET].aeTitle, static_cast<size_t>(TARGET_AE_TITLE_LENGTH+1));

                    // Ip address
                    CommonUtility::ConvertToCharArray(controls[controls.GetIndexByID(WLM_IPADDRESS)].value, m_WlmConfig.targetInstance[START_WLM_TARGET].ipAddress, static_cast<size_t>(TARGET_IP_ADDRESS_LENGTH+1));

                    // SC port number
                    m_WlmConfig.targetInstance[START_WLM_TARGET].portNumber = std::stoi(controls[controls.GetIndexByID(WLM_PORTNUMBER)].value);

                    // Selected query
                    m_WlmConfig.targetInstance[START_WLM_TARGET].wlm.selectedQuery = GetQueryIndex(controls[controls.GetIndexByID(WLM_QUERY)].value);      

                    m_WlmConfig.targetInstance[START_WLM_TARGET].studyDescriptionMapping = GetStudyDesMappinEnum(controls[controls.GetIndexByID(WLM_STUDYDESCRIPTION)].value);

                    m_WlmConfig.targetInstance[START_WLM_TARGET].type = TARGET_TYPE_WLM;

                    bool saveConfigrecord = false;

                    // Save Enable
                    if( controls.GetControlByID(WLM_ENABLEREASON, element) )
                    {
                        configRecord.reasonForRequestedProcedureCsEnabled = FSInfra::BackendUtility::RadioButtonStatusToDB(std::stoi(element.value));
                        saveConfigrecord = BeCommunicator.SetConfigRecord(configRecord);
                    }

                    if ( BeCommunicator.WriteAllDicomData(WLM, reinterpret_cast<UCHAR*>(&m_WlmConfig)) && saveConfigrecord)
                    {
                        resultInfo.resCode = Success;
                        resultInfo.resText = BackendMessage::RestartSystemMessage;

                        LogDCMNodeAuditTrail(START_WLM_TARGET);
                    }
                    else
                    {
                        resultInfo.resCode = Failed;
                        resultInfo.displayMessageType = MessageArea;
                        resultInfo.msgArType = MessageAreaType::Error;
                        resultInfo.resText =BackendMessage::SaveDatafailed;
                        LOG_WARNING("Saving DICOM WLM configuration data failed");
                    }
                }
                else
                {
                    resultInfo.resCode = Failed;
                    resultInfo.displayMessageType = MessageArea;
                    resultInfo.msgArType = MessageAreaType::Error;
                    resultInfo.resText = BackendMessage::QueryFieldNotBeEmpty;
                    LOG_WARNING("Query field is empty");
                }
            }
        }
        else
        {
            resultInfo.resCode = Failed;
            resultInfo.displayMessageType = MessageArea;
            resultInfo.msgArType = MessageAreaType::Error;
            resultInfo.resText = L"‘" + controls[controls.GetIndexByID(WLM_NAME)].label + L"’" + BackendMessage::NoValueSpecified;
            resultInfo.controlId = controls[controls.GetIndexByID(WLM_NAME)].controlID;
        }

    }

    bool WorkListManagement::CheckTargets(const ElementArray &controls, std::wstring &targetResult)
    {
        LOG_FUNCTION(LOG_MI_FSBE, "WorkListManagement::CheckTargets");

        //TARGET_INSTANCE_STRUCT target;
        bool status = false;
        //FSInfra::BackendUtility::GetTargets( controls, target);
        ControlElement element;

        //this is a target ping
        controls.GetControlByID(WLM_ENABLE, element);

        if(RadioButtonStatus ::YES == std::stoi(element.value))
        {
            std::wstring ipAddress;
            std::wstring portNumber;
            std::wstring aeTitle;
            std::wstring authenticate_Encrypt;
            BOOLEAN authenticate FALSE;
            BOOLEAN encrypt = FALSE;

            controls.GetControlByID(WLM_AETITLE, element);
            aeTitle = element.value;

            controls.GetControlByID(WLM_IPADDRESS, element);
            ipAddress = element.value;

            controls.GetControlByID(WLM_PORTNUMBER, element);
            portNumber = element.value;

            if (TRUE == CoFeatureAvailability(CO_FEATURE_SECURE_COMMUNICATION))
            {
                controls.GetControlByID(BackendToolsControlsID::WLM_AUTHENTICATION_ENCRYPTION, element);
                authenticate_Encrypt = element.value;

                if (ComboBoxEntries[0].description == authenticate_Encrypt)
                {
                    authenticate = FALSE;
                    encrypt = FALSE;
                }
                else if (ComboBoxEntries[1].description == authenticate_Encrypt)
                {
                    authenticate = TRUE;
                    encrypt = FALSE;
                }
                else if (ComboBoxEntries[2].description == authenticate_Encrypt)
                {
                    authenticate = TRUE;
                    encrypt = TRUE;
                }
                else
                {
                    // do nothing
                }
            }

            BeCommunicator.EnterServiceMode();
            //this is target ping.
            if(BeCommunicator.CheckTarget(aeTitle, ipAddress, portNumber, authenticate, encrypt, L""))
            {
                targetResult = BackendMessage::DcmEcoOk;
                status = true;
            }
            BeCommunicator.ExitServiceMode();
        }
        return status;
    }

    std::wstring WorkListManagement::GetStudyDesMapping(const UINT8 desc)
    {
        UINT8 index = 0u;
        std::wstring foundStudyDes= L"None";
        bool found = false;
        while ( (index < 2u) && !found)
        {
            if( m_StudyEntries[index].id == desc )
            {
                found = true;
                foundStudyDes = m_StudyEntries[index].description;
            }
            else
            {
                index++;
            }
        }
        return foundStudyDes;
    }

    UINT8 WorkListManagement::GetStudyDesMappinEnum(const std::wstring& descName)
    {
        UINT8 index = 0u;
        UINT8 foundMappingIndex = 0u;
        bool found = false;
        while ( (index < 2u) && !found)
        {
            if( m_StudyEntries[index].description == descName )
            {
                found = true;
                foundMappingIndex = m_StudyEntries[index].id;
            }
            else
            {
                index++;
            }
        }
        return foundMappingIndex;
    }

    void WorkListManagement::GetWorkQueriesList(std::wstring &queryList)
    {
        LOG_FUNCTION(LOG_MI_FSBE, "WorkListManagement::GetWorkQueriesList");

        if(BeCommunicator.ReadAllDicomData(WL_QUERY_DEFINITION,reinterpret_cast<UCHAR*>(&m_Query)) )
        {
            queryList.append(L" ");
            for(int queryIndex = 0; queryIndex < MAX_QUERY_INSTANCES; queryIndex ++)
            {
                if( strcmp(m_Query.queryInstance[queryIndex].name, QUERY_NO_NAME) != 0 && ( m_Query.queryInstance[queryIndex].enable == static_cast<BYTE>(TRUE)))
                {
                    queryList.append(L";");
                    queryList.append(CommonUtility::ConvertToWstring(m_Query.queryInstance[queryIndex].name));
                }
            }
        }
        else
        {
            LOG_WARNING("Reading all targets failed");
        }
    }

    int WorkListManagement::GetQueryIndex(const std::wstring &QueryName)
    {
        int foundIndex = -1;
        for(int queryIndex = 0; ( queryIndex < MAX_QUERY_INSTANCES ) && (foundIndex == -1); queryIndex ++)
        {
            if( (CommonUtility::ConvertToWstring(m_Query.queryInstance[queryIndex].name)) == QueryName )
            {
                foundIndex = queryIndex;
            }
        }
        return foundIndex;
    }

    void WorkListManagement::LogDCMNodeAuditTrail(int storedIndex)
    {
        LOG_FUNCTION(LOG_MI_FSBE, "WorkListManagement::LogDCMNodeAuditTrail");

        AUDT_NETWORK_ENTRY_STRUCT netEntry;
        netEntry.auditData.AuditID = AUDT_NETWORK_ENTRY;
        netEntry.NetworkAction = (m_WlmConfig.targetInstance[storedIndex].type == TARGET_TYPE_UNKNOWN)?(FALSE):(TRUE);
        OsaWcsCpy(netEntry.NodeIdentifier, TARGT_NAME_LENGTH, m_WlmConfig.targetInstance[storedIndex].name);
        netEntry.auditData.EventResult = AUDT_SUCCESS;
        LogNetworkEntry(&netEntry);
    }

    bool WorkListManagement::DisplayIPAddressError(const ElementArray &controls, ResultInfo &resultInfo)
    {
        bool statusIpValidation = true;

        ControlElement enable;
        ControlElement ipAddress;
        controls.GetControlByID(WLM_ENABLE, enable);
        controls.GetControlByID(WLM_IPADDRESS, ipAddress);

        if(RadioButtonStatus ::YES == std::stoi(enable.value) ||
            ((RadioButtonStatus ::NO == std::stoi(enable.value)) && !(ipAddress.value.empty())))
        {
            statusIpValidation = FSInfra::BackendUtility::CheckIpAddressValidation(ipAddress.value,  resultInfo.resText );
            if( !statusIpValidation )
            {
                resultInfo.resText = L"‘" + ipAddress.label + L"’" + resultInfo.resText;
                resultInfo.controlId = ipAddress.controlID;
                resultInfo.displayMessageType = MessageArea;
                resultInfo.msgArType = MessageAreaType::Error;
            }
        }
        return statusIpValidation;
    }

    void WorkListManagement::SetComboValue(const std::wstring &comboBoxType)
    {
        if (ComboBoxEntries[0].description == comboBoxType)
        {
            m_WlmConfig.targetInstance[START_WLM_TARGET].authenticate = FALSE;
            m_WlmConfig.targetInstance[START_WLM_TARGET].encrypt = FALSE;
        }
        else if (ComboBoxEntries[1].description == comboBoxType)
        {
            m_WlmConfig.targetInstance[START_WLM_TARGET].authenticate = TRUE;
            m_WlmConfig.targetInstance[START_WLM_TARGET].encrypt = FALSE;
        }
        else if (ComboBoxEntries[2].description == comboBoxType)
        {
            m_WlmConfig.targetInstance[START_WLM_TARGET].authenticate = TRUE;
            m_WlmConfig.targetInstance[START_WLM_TARGET].encrypt = TRUE;
        }
        else
        {
            // do nothing
        }
    }

    std::wstring WorkListManagement::GetComboValue(TARGET_INSTANCE_STRUCT targetValue)
    {
        std::wstring description = L"";

        if (FALSE == targetValue.authenticate && FALSE == targetValue.encrypt)
        {
            description = ComboBoxEntries[0].description;
        }
        else if (TRUE == targetValue.authenticate && FALSE == targetValue.encrypt)
        {
            description = ComboBoxEntries[1].description;
        }
        else if (TRUE == targetValue.authenticate && TRUE == targetValue.encrypt)
        {
            description = ComboBoxEntries[2].description;
        }
        else
        {
            // do nothing
        }

        return description;
    }
}this is the backend code. all these tcs were passing before i added co feature to several areas of CO_FEATURE_SECURE_COMMUNICATION. so like wise the tc shud also change. now that im a complete noob to gtest. i have added certain fixes here and there but still 
[ RUN      ] WorkListManagementTest.WLMTool_SaveTarget_WhenIPv6IsEnabled_Without_Cofeature
Get function table
Entering service mode
Get all store targets
Get WLM Query Definition file
Get the configuration
Exit service mode
Entering service mode
Get all store targets
Create Dicom target file
file creation is successful
Exit service mode
Entering service mode
Get all store targets
Get WLM Query Definition file
Get the configuration
Exit service mode
..\..\..\DFI\modules\Backend\test\src\WorkListManagementTest.cpp(1677): error: Value of: outputControls[outputControls.GetIndexByID(WLM_NAME)].value.c_str()
  Actual: L"No Name"
Expected: L"WLM-Test Target"
WLM-Test Target is not saved
[  FAILED  ] WorkListManagementTest.WLMTool_SaveTarget_WhenIPv6IsEnabled_Without_Cofeature (18 ms)
[ RUN      ] WorkListManagementTest.WLMTool_Hide_IPv6_Controls_When_Toggle_IPv6_Is_False
Get function table
Entering service mode
Get all store targets
Get WLM Query Definition file
Get the configuration
Exit service mode
..\..\..\DFI\modules\Backend\test\src\WorkListManagementTest.cpp(1791): error: Value of: 9
Expected: outputControls.GetCount()
Which is: 10
[  FAILED  ] WorkListManagementTest.WLMTool_Hide_IPv6_Controls_When_Toggle_IPv6_Is_False (4 ms)
[----------] 24 tests from WorkListManagementTest (439 ms total)

[----------] Global test environment tear-down
[==========] 24 tests from 1 test case ran. (440 ms total)
[  PASSED  ] 22 tests.
[  FAILED  ] 2 tests, listed below:
[  FAILED  ] WorkListManagementTest.WLMTool_SaveTarget_WhenIPv6IsEnabled_Without_Cofeature
[  FAILED  ] WorkListManagementTest.WLMTool_Hide_IPv6_Controls_When_Toggle_IPv6_Is_False

 2 FAILED TESTS
Press any key to continue . . . these many still exis. so my friend suggested 
coFeature ka stub initialize function add akrna setUp function mein 
 
fir try kr
 
2. functionality check kr jab coFeature disable hoga tab kya hoga
 can u help?