text:
using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Protocols.TestTools;
using Microsoft.Protocols.TestTools.StackSdk;
using Microsoft.Protocols.TestTools.StackSdk.RemoteDesktop.Rdpbcgr;

namespace Microsoft.Protocols.TestSuites.Rdpbcgr
{
    public partial class RdpbcgrTestSuite
    {
        [TestMethod]
        [Priority(1)]
        [TestCategory("RDP7.0")]
        [TestCategory("RDPBCGR")]
        [Description(@"This test case is used to verify
                      SUT drops the connection if the length field within tpktHeader in MCS Attach User Confirm PDU is not consistent with the received data.")]
        public void S1_ConnectionTest_ChannelConnection_NegativeTest_MCSAttachUserConfirm_InvalidTPKTLength()
        {
            #region Test Description
            //1.	Trigger SUT to initiate a RDP connection and complete the Connection Initiation phase and Basic Setting Exchange phase.
            //2.	Test Suite expects SUT continue the connection with sending a Client MCS Erect Domain Request PDU and a Client MCS Attach User Request PDU.
            //3.	Test Suite responds a Server MCS Attach User Confirm PDU to SUT and set the length field of tpktHeader to an invalid value (less than 11).
            //4.	Test Suite expects SUT drop the connection.
            #endregion

            #region Test Implementation
            //Start RDP listening.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Starting RDP listening with transport protocol: {0}", transportProtocol.ToString());
            this.rdpbcgrAdapter.StartRDPListening(transportProtocol);

            #region Trigger client to initiate a RDP connection
            //Trigger client to initiate a RDP connection.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Triggering SUT to initiate a RDP connection to server.");
            triggerClientRDPConnect(transportProtocol);
            #endregion

            //Expect the transport layer connection request.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to start a transport layer connection request (TCP).");
            this.rdpbcgrAdapter.ExpectTransportConnection(RDPSessionType.Normal);

            #region Connection Initiation phase
            //Expect SUT send a Client X.224 Connection Request PDU.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to send a Client X.224 Connection Request PDU");
            this.rdpbcgrAdapter.ExpectPacket<Client_X_224_Connection_Request_Pdu>(waitTime);

            //Respond a Server X.224 Connection Confirm PDU and set the EXTENDED_CLIENT_DATA_SUPPORTED flag.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Sending Server X.224 Connection Confirm PDU to SUT. Selected protocol: {0}; Extended Client Data supported: true", selectedProtocol.ToString());
            this.rdpbcgrAdapter.Server_X_224_Connection_Confirm(selectedProtocol, true, true, NegativeType.None);
            #endregion

            #region Basic Setting Exchange phase
            //Expect SUT send Client MCS Connect Initial PDU.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to send a Client MCS Connect Initial PDU.");
            this.rdpbcgrAdapter.ExpectPacket<Client_MCS_Connect_Initial_Pdu_with_GCC_Conference_Create_Request>(waitTime);

            //Respond a Server MCS Connect Response PDU with GCC Conference Create Response.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Sending Server MCS Connect Response PDU to SUT. Encryption Method {0}; Encryption Level: {1}; RDP Version Code: {2}.", enMethod.ToString(), enLevel.ToString(), TS_UD_SC_CORE_version_Values.V2.ToString());
            this.rdpbcgrAdapter.Server_MCS_Connect_Response(enMethod, enLevel, TS_UD_SC_CORE_version_Values.V2, NegativeType.None);
            #endregion

            //Expect a Client MCS Erect Domain Request PDU.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to send a Client MCS Erect Domain Request PDU.");
            this.rdpbcgrAdapter.ExpectPacket<Client_MCS_Erect_Domain_Request>(waitTime);

            //Expect a Client MCS Attach User Request PDU
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to send a Client MCS Attach User Request PDU.");
            this.rdpbcgrAdapter.ExpectPacket<Client_MCS_Attach_User_Request>(waitTime);

            //Respond a Server MCS Attach User Confirm PDU
            this.TestSite.Log.Add(LogEntryKind.Comment, "Sending Server MCS Attach User Confirm PDU to SUT with invalid TPK header length");
            this.rdpbcgrAdapter.MCSAttachUserConfirm(NegativeType.InvalidTPKLength);

            //Expect SUT to drop the connection
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expect SUT to drop the connection");
            bool bDisconnected = this.rdpbcgrAdapter.WaitForDisconnection(waitTime);
            this.TestSite.Assert.IsTrue(bDisconnected, "SUT should drop the connection if the length field within tpktHeader in MCS Attach User Confirm PDU is not consistent with the received data.");
            #endregion
        }

        [TestMethod]
        [Priority(1)]
        [TestCategory("RDP7.0")]
        [TestCategory("RDPBCGR")]
        [Description(@"This test case is used to verify
                      SUT drops the connection connection if the result field in MCS Attach User Confirm PDU is not set to rt-successful (0).")]
        public void S1_ConnectionTest_ChannelConnection_NegativeTest_MCSAttachUserConfirm_Failure()
        {
            #region Test Description
            //1.	Trigger SUT to initiate a RDP connection and complete the Connection Initiation phase and Basic Setting Exchange phase.
            //2.	Test Suite expects SUT continue the connection with sending a Client MCS Erect Domain Request PDU and a Client MCS Attach User Request PDU.
            //3.	Test Suite responds a Server MCS Attach User Confirm PDU to SUT and set the result field in MCS Attach User Confirm PDU is not set to rt-successful (0).
            //4.	Test Suite expects SUT drop the connection.
            #endregion

            #region Test Implementation
            //Start RDP listening.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Starting RDP listening with transport protocol: {0}", transportProtocol.ToString());
            this.rdpbcgrAdapter.StartRDPListening(transportProtocol);

            #region Trigger client to initiate a RDP connection
            //Trigger client to initiate a RDP connection.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Triggering SUT to initiate a RDP connection to server.");
            triggerClientRDPConnect(transportProtocol);
            #endregion

            //Expect the transport layer connection request.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to start a transport layer connection request (TCP).");
            this.rdpbcgrAdapter.ExpectTransportConnection(RDPSessionType.Normal);

            #region Connection Initiation phase
            //Expect SUT send a Client X.224 Connection Request PDU.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to send a Client X.224 Connection Request PDU");
            this.rdpbcgrAdapter.ExpectPacket<Client_X_224_Connection_Request_Pdu>(waitTime);

            //Respond a Server X.224 Connection Confirm PDU and set the EXTENDED_CLIENT_DATA_SUPPORTED flag.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Sending Server X.224 Connection Confirm PDU to SUT. Selected protocol: {0}; Extended Client Data supported: true", selectedProtocol.ToString());
            this.rdpbcgrAdapter.Server_X_224_Connection_Confirm(selectedProtocol, true, true, NegativeType.None);
            #endregion

            #region Basic Setting Exchange phase
            //Expect SUT send Client MCS Connect Initial PDU.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to send a Client MCS Connect Initial PDU.");
            this.rdpbcgrAdapter.ExpectPacket<Client_MCS_Connect_Initial_Pdu_with_GCC_Conference_Create_Request>(waitTime);

            //Respond a Server MCS Connect Response PDU with GCC Conference Create Response.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Sending Server MCS Connect Response PDU to SUT. Encryption Method {0}; Encryption Level: {1}; RDP Version Code: {2}.", enMethod.ToString(), enLevel.ToString(), TS_UD_SC_CORE_version_Values.V2.ToString());
            this.rdpbcgrAdapter.Server_MCS_Connect_Response(enMethod, enLevel, TS_UD_SC_CORE_version_Values.V2, NegativeType.None);
            #endregion

            //Expect a Client MCS Erect Domain Request PDU.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to send a Client MCS Erect Domain Request PDU.");
            this.rdpbcgrAdapter.ExpectPacket<Client_MCS_Erect_Domain_Request>(waitTime);

            //Expect a Client MCS Attach User Request PDU
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to send a Client MCS Attach User Request PDU.");
            this.rdpbcgrAdapter.ExpectPacket<Client_MCS_Attach_User_Request>(waitTime);

            //Respond a Server MCS Attach User Confirm PDU
            this.TestSite.Log.Add(LogEntryKind.Comment, "Sending Server MCS Attach User Confirm PDU to SUT with invalid result value (not rt-successful)");
            this.rdpbcgrAdapter.MCSAttachUserConfirm(NegativeType.InvalidResult);

            //Expect SUT to drop the connection
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expect SUT to drop the connection");
            bool bDisconnected = this.rdpbcgrAdapter.WaitForDisconnection(waitTime);
            this.TestSite.Assert.IsTrue(bDisconnected, "SUT should drop the connection if the result field in MCS Attach User Confirm PDU is not set to rt-successful (0).");
            #endregion
        }

        [TestMethod]
        [Priority(1)]
        [TestCategory("RDP7.0")]
        [TestCategory("RDPBCGR")]
        [Description(@"This test case is used to verify
                      SUT drops the connection connection if the initiator field in MCS Attach User Confirm PDU is not present")]
        public void S1_ConnectionTest_ChannelConnection_NegativeTest_MCSAttachUserConfirm_InitiatorNotPresent()
        {
            #region Test Description
            //1.	Trigger SUT to initiate a RDP connection and complete the Connection Initiation phase and Basic Setting Exchange phase.
            //2.	Test Suite expects SUT continue the connection with sending a Client MCS Erect Domain Request PDU and a Client MCS Attach User Request PDU.
            //3.	Test Suite responds a Server MCS Attach User Confirm PDU to SUT and does not present initiator field.
            //4.	Test Suite expects SUT drop the connection.
            #endregion

            #region Test Implementation
            //Start RDP listening.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Starting RDP listening with transport protocol: {0}", transportProtocol.ToString());
            this.rdpbcgrAdapter.StartRDPListening(transportProtocol);

            #region Trigger client to initiate a RDP connection
            //Trigger client to initiate a RDP connection.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Triggering SUT to initiate a RDP connection to server.");
            triggerClientRDPConnect(transportProtocol);
            #endregion

            //Expect the transport layer connection request.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to start a transport layer connection request (TCP).");
            this.rdpbcgrAdapter.ExpectTransportConnection(RDPSessionType.Normal);

            #region Connection Initiation phase
            //Expect SUT send a Client X.224 Connection Request PDU.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to send a Client X.224 Connection Request PDU");
            this.rdpbcgrAdapter.ExpectPacket<Client_X_224_Connection_Request_Pdu>(waitTime);

            //Respond a Server X.224 Connection Confirm PDU and set the EXTENDED_CLIENT_DATA_SUPPORTED flag.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Sending Server X.224 Connection Confirm PDU to SUT. Selected protocol: {0}; Extended Client Data supported: true", selectedProtocol.ToString());
            this.rdpbcgrAdapter.Server_X_224_Connection_Confirm(selectedProtocol, true, true, NegativeType.None);
            #endregion

            #region Basic Setting Exchange phase
            //Expect SUT send Client MCS Connect Initial PDU.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to send a Client MCS Connect Initial PDU.");
            this.rdpbcgrAdapter.ExpectPacket<Client_MCS_Connect_Initial_Pdu_with_GCC_Conference_Create_Request>(waitTime);

            //Respond a Server MCS Connect Response PDU with GCC Conference Create Response.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Sending Server MCS Connect Response PDU to SUT. Encryption Method {0}; Encryption Level: {1}; RDP Version Code: {2}.", enMethod.ToString(), enLevel.ToString(), TS_UD_SC_CORE_version_Values.V2.ToString());
            this.rdpbcgrAdapter.Server_MCS_Connect_Response(enMethod, enLevel, TS_UD_SC_CORE_version_Values.V2, NegativeType.None);
            #endregion

            //Expect a Client MCS Erect Domain Request PDU.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to send a Client MCS Erect Domain Request PDU.");
            this.rdpbcgrAdapter.ExpectPacket<Client_MCS_Erect_Domain_Request>(waitTime);

            //Expect a Client MCS Attach User Request PDU
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to send a Client MCS Attach User Request PDU.");
            this.rdpbcgrAdapter.ExpectPacket<Client_MCS_Attach_User_Request>(waitTime);

            //Respond a Server MCS Attach User Confirm PDU
            this.TestSite.Log.Add(LogEntryKind.Comment, "Sending Server MCS Attach User Confirm PDU to SUT and does not present initiator field");
            this.rdpbcgrAdapter.MCSAttachUserConfirm(NegativeType.InvalidInitiatorField);

            //Expect SUT to drop the connection
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expect SUT to drop the connection");
            bool bDisconnected = this.rdpbcgrAdapter.WaitForDisconnection(waitTime);
            this.TestSite.Assert.IsTrue(bDisconnected, "SUT should drop the connection if the initiator field in MCS Attach User Confirm PDU is not present.");
            #endregion
        }

        [TestMethod]
        [Priority(1)]
        [TestCategory("RDP7.0")]
        [TestCategory("RDPBCGR")]
        [Description(@"This test case is used to verify
                      SUT drops the connection if the length field within tpktHeader in MCS Channel Join Confirm PDU is not consistent with the received data.")]
        public void S1_ConnectionTest_ChannelConnection_NegativeTest_MCSChannelJoinConfirm_InvalidTPKTLength()
        {
            #region Test Description
            //1.	Trigger SUT to initiate a RDP connection and complete the Connection Initiation phase and Basic Setting Exchange phase.
            //2.	Test Suite expects SUT continue the connection with sending a Client MCS Erect Domain Request PDU and a Client MCS Attach User Request PDU.
            //3.	Test Suite verifies the received Client MCS Erect Domain Request PDU and Client MCS Attach User Request PDU, and then responds a Server MCS Attach User Confirm PDU to SUT.
            //4.	Test Suite expects SUT starts the channel join sequence. SUT should use the MCS Channel Join Request PDU to join the user channel obtained from the Attach User Confirm PDU, the I/O channel and all of the static virtual channels obtained from the Server Network Data structure.
            //5.	After Test Suite received the first MCS Channel Join Request PDU, it responds a Server MCS Channel Join Confirm PDU and set the length field within tpktHeader to an invalid value (less than the actual value).
            //6.	Test Suite expects SUT drop the connection.
            #endregion

            #region Test Implementation
            //Start RDP listening.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Starting RDP listening with transport protocol: {0}", transportProtocol.ToString());
            this.rdpbcgrAdapter.StartRDPListening(transportProtocol);

            #region Trigger client to initiate a RDP connection
            //Trigger client to initiate a RDP connection.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Triggering SUT to initiate a RDP connection to server.");
            triggerClientRDPConnect(transportProtocol);
            #endregion

            //Expect the transport layer connection request.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to start a transport layer connection request (TCP).");
            this.rdpbcgrAdapter.ExpectTransportConnection(RDPSessionType.Normal);

            #region Connection Initiation phase
            //Expect SUT send a Client X.224 Connection Request PDU.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to send a Client X.224 Connection Request PDU");
            this.rdpbcgrAdapter.ExpectPacket<Client_X_224_Connection_Request_Pdu>(waitTime);

            //Respond a Server X.224 Connection Confirm PDU and set the EXTENDED_CLIENT_DATA_SUPPORTED flag.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Sending Server X.224 Connection Confirm PDU to SUT. Selected protocol: {0}; Extended Client Data supported: true", selectedProtocol.ToString());
            this.rdpbcgrAdapter.Server_X_224_Connection_Confirm(selectedProtocol, true, true, NegativeType.None);
            #endregion

            #region Basic Setting Exchange phase
            //Expect SUT send Client MCS Connect Initial PDU.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to send a Client MCS Connect Initial PDU.");
            this.rdpbcgrAdapter.ExpectPacket<Client_MCS_Connect_Initial_Pdu_with_GCC_Conference_Create_Request>(waitTime);

            //Respond a Server MCS Connect Response PDU with GCC Conference Create Response.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Sending Server MCS Connect Response PDU to SUT. Encryption Method {0}; Encryption Level: {1}; RDP Version Code: {2}.", enMethod.ToString(), enLevel.ToString(), TS_UD_SC_CORE_version_Values.V2.ToString());
            this.rdpbcgrAdapter.Server_MCS_Connect_Response(enMethod, enLevel, TS_UD_SC_CORE_version_Values.V2, NegativeType.None);
            #endregion

            //Expect a Client MCS Erect Domain Request PDU.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to send a Client MCS Erect Domain Request PDU.");
            this.rdpbcgrAdapter.ExpectPacket<Client_MCS_Erect_Domain_Request>(waitTime);

            //Expect a Client MCS Attach User Request PDU
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to send a Client MCS Attach User Request PDU.");
            this.rdpbcgrAdapter.ExpectPacket<Client_MCS_Attach_User_Request>(waitTime);

            //Respond a Server MCS Attach User Confirm PDU
            this.TestSite.Log.Add(LogEntryKind.Comment, "Sending Server MCS Attach User Confirm PDU to SUT");
            this.rdpbcgrAdapter.MCSAttachUserConfirm(NegativeType.None);

            //Expect SUT start a channel join sequence
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expect SUT to start the  channel join request and respond a pdu with the length field within tpktHeader to an invalid value (less than the actual value) .");
            this.rdpbcgrAdapter.ChannelJoinRequestAndConfirm(NegativeType.InvalidTPKLength);

            #endregion
        }

        [TestMethod]
        [Priority(1)]
        [TestCategory("RDP7.0")]
        [TestCategory("RDPBCGR")]
        [Description(@"This test case is used to verify
                      SUT drops the connection if the channelId field is not present in MCS Channel Join Confirm PDU.")]
        public void S1_ConnectionTest_ChannelConnection_NegativeTest_MCSChannelJoinConfirm_ChannelIdNotPresent()
        {
            #region Test Description
            //1.	Trigger SUT to initiate a RDP connection and complete the Connection Initiation phase and Basic Setting Exchange phase.
            //2.	Test Suite expects SUT continue the connection with sending a Client MCS Erect Domain Request PDU and a Client MCS Attach User Request PDU.
            //3.	Test Suite verifies the received Client MCS Erect Domain Request PDU and Client MCS Attach User Request PDU, and then responds a Server MCS Attach User Confirm PDU to SUT.
            //4.	Test Suite expects SUT starts the channel join sequence. SUT should use the MCS Channel Join Request PDU to join the user channel obtained from the Attach User Confirm PDU, the I/O channel and all of the static virtual channels obtained from the Server Network Data structure.
            //5.	After Test Suite received the first MCS Channel Join Request PDU, it responds a Server MCS Channel Join Confirm PDU and does not present the channelId field.
            //6.	Test Suite expects SUT drop the connection.
            #endregion

            #region Test Implementation
            //Start RDP listening.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Starting RDP listening with transport protocol: {0}", transportProtocol.ToString());
            this.rdpbcgrAdapter.StartRDPListening(transportProtocol);

            #region Trigger client to initiate a RDP connection
            //Trigger client to initiate a RDP connection.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Triggering SUT to initiate a RDP connection to server.");
            triggerClientRDPConnect(transportProtocol);
            #endregion

            //Expect the transport layer connection request.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to start a transport layer connection request (TCP).");
            this.rdpbcgrAdapter.ExpectTransportConnection(RDPSessionType.Normal);

            #region Connection Initiation phase
            //Expect SUT send a Client X.224 Connection Request PDU.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to send a Client X.224 Connection Request PDU");
            this.rdpbcgrAdapter.ExpectPacket<Client_X_224_Connection_Request_Pdu>(waitTime);

            //Respond a Server X.224 Connection Confirm PDU and set the EXTENDED_CLIENT_DATA_SUPPORTED flag.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Sending Server X.224 Connection Confirm PDU to SUT. Selected protocol: {0}; Extended Client Data supported: true", selectedProtocol.ToString());
            this.rdpbcgrAdapter.Server_X_224_Connection_Confirm(selectedProtocol, true, true, NegativeType.None);
            #endregion

            #region Basic Setting Exchange phase
            //Expect SUT send Client MCS Connect Initial PDU.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to send a Client MCS Connect Initial PDU.");
            this.rdpbcgrAdapter.ExpectPacket<Client_MCS_Connect_Initial_Pdu_with_GCC_Conference_Create_Request>(waitTime);

            //Respond a Server MCS Connect Response PDU with GCC Conference Create Response.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Sending Server MCS Connect Response PDU to SUT. Encryption Method {0}; Encryption Level: {1}; RDP Version Code: {2}.", enMethod.ToString(), enLevel.ToString(), TS_UD_SC_CORE_version_Values.V2.ToString());
            this.rdpbcgrAdapter.Server_MCS_Connect_Response(enMethod, enLevel, TS_UD_SC_CORE_version_Values.V2, NegativeType.None);
            #endregion

            //Expect a Client MCS Erect Domain Request PDU.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to send a Client MCS Erect Domain Request PDU.");
            this.rdpbcgrAdapter.ExpectPacket<Client_MCS_Erect_Domain_Request>(waitTime);

            //Expect a Client MCS Attach User Request PDU
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to send a Client MCS Attach User Request PDU.");
            this.rdpbcgrAdapter.ExpectPacket<Client_MCS_Attach_User_Request>(waitTime);

            //Respond a Server MCS Attach User Confirm PDU
            this.TestSite.Log.Add(LogEntryKind.Comment, "Sending Server MCS Attach User Confirm PDU to SUT");
            this.rdpbcgrAdapter.MCSAttachUserConfirm(NegativeType.None);

            //Expect SUT start a channel join sequence
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expect SUT to start the  channel join request and respond a pdu without presenting the channelId field.");
            this.rdpbcgrAdapter.ChannelJoinRequestAndConfirm(NegativeType.InvalidEmptyChannelIdField);

            #endregion
        }

        [TestMethod]
        [Priority(1)]
        [TestCategory("RDP7.0")]
        [TestCategory("RDPBCGR")]
        [Description(@"This test case is used to verify
                      SUT drops the connection if the result field is not set to rt-successful (0) in MCS Channel Join Confirm PDU")]
        public void S1_ConnectionTest_ChannelConnection_NegativeTest_MCSChannelJoinConfirm_Failure()
        {
            #region Test Description
            //1.	Trigger SUT to initiate a RDP connection and complete the Connection Initiation phase and Basic Setting Exchange phase.
            //2.	Test Suite expects SUT continue the connection with sending a Client MCS Erect Domain Request PDU and a Client MCS Attach User Request PDU.
            //3.	Test Suite verifies the received Client MCS Erect Domain Request PDU and Client MCS Attach User Request PDU, and then responds a Server MCS Attach User Confirm PDU to SUT.
            //4.	Test Suite expects SUT starts the channel join sequence. SUT should use the MCS Channel Join Request PDU to join the user channel obtained from the Attach User Confirm PDU, the I/O channel and all of the static virtual channels obtained from the Server Network Data structure.
            //5.	After Test Suite received the first MCS Channel Join Request PDU, it responds a Server MCS Channel Join Confirm PDU and does not set the result field to rt-successful (0).
            //6.	Test Suite expects SUT drop the connection.
            #endregion

            #region Test Implementation
                        //Start RDP listening.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Starting RDP listening with transport protocol: {0}", transportProtocol.ToString());
            this.rdpbcgrAdapter.StartRDPListening(transportProtocol);

            #region Trigger client to initiate a RDP connection
            //Trigger client to initiate a RDP connection.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Triggering SUT to initiate a RDP connection to server.");
            triggerClientRDPConnect(transportProtocol);
            #endregion

            //Expect the transport layer connection request.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to start a transport layer connection request (TCP).");
            this.rdpbcgrAdapter.ExpectTransportConnection(RDPSessionType.Normal);

            #region Connection Initiation phase
            //Expect SUT send a Client X.224 Connection Request PDU.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to send a Client X.224 Connection Request PDU");
            this.rdpbcgrAdapter.ExpectPacket<Client_X_224_Connection_Request_Pdu>(waitTime);

            //Respond a Server X.224 Connection Confirm PDU and set the EXTENDED_CLIENT_DATA_SUPPORTED flag.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Sending Server X.224 Connection Confirm PDU to SUT. Selected protocol: {0}; Extended Client Data supported: true", selectedProtocol.ToString());
            this.rdpbcgrAdapter.Server_X_224_Connection_Confirm(selectedProtocol, true, true, NegativeType.None);
            #endregion

            #region Basic Setting Exchange phase
            //Expect SUT send Client MCS Connect Initial PDU.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to send a Client MCS Connect Initial PDU.");
            this.rdpbcgrAdapter.ExpectPacket<Client_MCS_Connect_Initial_Pdu_with_GCC_Conference_Create_Request>(waitTime);

            //Respond a Server MCS Connect Response PDU with GCC Conference Create Response.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Sending Server MCS Connect Response PDU to SUT. Encryption Method {0}; Encryption Level: {1}; RDP Version Code: {2}.", enMethod.ToString(), enLevel.ToString(), TS_UD_SC_CORE_version_Values.V2.ToString());
            this.rdpbcgrAdapter.Server_MCS_Connect_Response(enMethod, enLevel, TS_UD_SC_CORE_version_Values.V2, NegativeType.None);
            #endregion

            //Expect a Client MCS Erect Domain Request PDU.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to send a Client MCS Erect Domain Request PDU.");
            this.rdpbcgrAdapter.ExpectPacket<Client_MCS_Erect_Domain_Request>(waitTime);

            //Expect a Client MCS Attach User Request PDU
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to send a Client MCS Attach User Request PDU.");
            this.rdpbcgrAdapter.ExpectPacket<Client_MCS_Attach_User_Request>(waitTime);

            //Respond a Server MCS Attach User Confirm PDU
            this.TestSite.Log.Add(LogEntryKind.Comment, "Sending Server MCS Attach User Confirm PDU to SUT");
            this.rdpbcgrAdapter.MCSAttachUserConfirm(NegativeType.None);

            //Expect SUT start a channel join sequence
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expect SUT to start the  channel join request and respond a pdu without setting result field to rt-successful.");
            this.rdpbcgrAdapter.ChannelJoinRequestAndConfirm(NegativeType.InvalidResult);

            #endregion
        }

        [TestMethod]
        [Priority(1)]
        [TestCategory("RDP7.0")]
        [TestCategory("RDPBCGR")]
        [Description(@"This test case is used to verify
                      SUT drops the connection if the channelId field is not valid in MCS Channel Join Confirm PDU.")]
        public void S1_ConnectionTest_ChannelConnection_NegativeTest_MCSChannelJoinConfirm_InvalidChannelId()
        {
            #region Test Description
            //1.	Trigger SUT to initiate a RDP connection and complete the Connection Initiation phase and Basic Setting Exchange phase.
            //2.	Test Suite expects SUT continue the connection with sending a Client MCS Erect Domain Request PDU and a Client MCS Attach User Request PDU.
            //3.	Test Suite verifies the received Client MCS Erect Domain Request PDU and Client MCS Attach User Request PDU, and then responds a Server MCS Attach User Confirm PDU to SUT.
            //4.	Test Suite expects SUT starts the channel join sequence. SUT should use the MCS Channel Join Request PDU to join the user channel obtained from the Attach User Confirm PDU, the I/O channel and all of the static virtual channels obtained from the Server Network Data structure.
            //5.	After Test Suite received the first MCS Channel Join Request PDU, it responds a Server MCS Channel Join Confirm PDU and set the channelId field to an invalid value that not correspond with the value of the channelId field received in MCS Channel Join Request PDU.
            //6.	Test Suite expects SUT drop the connection.
            #endregion

            #region Test Implementation
            //Start RDP listening.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Starting RDP listening with transport protocol: {0}", transportProtocol.ToString());
            this.rdpbcgrAdapter.StartRDPListening(transportProtocol);

            #region Trigger client to initiate a RDP connection
            //Trigger client to initiate a RDP connection.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Triggering SUT to initiate a RDP connection to server.");
            triggerClientRDPConnect(transportProtocol);
            #endregion

            //Expect the transport layer connection request.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to start a transport layer connection request (TCP).");
            this.rdpbcgrAdapter.ExpectTransportConnection(RDPSessionType.Normal);

            #region Connection Initiation phase
            //Expect SUT send a Client X.224 Connection Request PDU.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to send a Client X.224 Connection Request PDU");
            this.rdpbcgrAdapter.ExpectPacket<Client_X_224_Connection_Request_Pdu>(waitTime);

            //Respond a Server X.224 Connection Confirm PDU and set the EXTENDED_CLIENT_DATA_SUPPORTED flag.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Sending Server X.224 Connection Confirm PDU to SUT. Selected protocol: {0}; Extended Client Data supported: true", selectedProtocol.ToString());
            this.rdpbcgrAdapter.Server_X_224_Connection_Confirm(selectedProtocol, true, true, NegativeType.None);
            #endregion

            #region Basic Setting Exchange phase
            //Expect SUT send Client MCS Connect Initial PDU.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to send a Client MCS Connect Initial PDU.");
            this.rdpbcgrAdapter.ExpectPacket<Client_MCS_Connect_Initial_Pdu_with_GCC_Conference_Create_Request>(waitTime);

            //Respond a Server MCS Connect Response PDU with GCC Conference Create Response.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Sending Server MCS Connect Response PDU to SUT. Encryption Method {0}; Encryption Level: {1}; RDP Version Code: {2}.", enMethod.ToString(), enLevel.ToString(), TS_UD_SC_CORE_version_Values.V2.ToString());
            this.rdpbcgrAdapter.Server_MCS_Connect_Response(enMethod, enLevel, TS_UD_SC_CORE_version_Values.V2, NegativeType.None);
            #endregion

            //Expect a Client MCS Erect Domain Request PDU.
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to send a Client MCS Erect Domain Request PDU.");
            this.rdpbcgrAdapter.ExpectPacket<Client_MCS_Erect_Domain_Request>(waitTime);

            //Expect a Client MCS Attach User Request PDU
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expecting SUT to send a Client MCS Attach User Request PDU.");
            this.rdpbcgrAdapter.ExpectPacket<Client_MCS_Attach_User_Request>(waitTime);

            //Respond a Server MCS Attach User Confirm PDU
            this.TestSite.Log.Add(LogEntryKind.Comment, "Sending Server MCS Attach User Confirm PDU to SUT");
            this.rdpbcgrAdapter.MCSAttachUserConfirm(NegativeType.None);

            //Expect SUT start a channel join sequence
            this.TestSite.Log.Add(LogEntryKind.Comment, "Expect SUT to start the  channel join request and respond a pdu with the channelId field to an invalid value that not correspond with the value of the channelId field received in MCS Channel Join Request PDU..");
            this.rdpbcgrAdapter.ChannelJoinRequestAndConfirm(NegativeType.InvalidMismatchChannelIdField);

            #endregion
        }
    }
}


text:
from collections import OrderedDict
from typing import Dict, Type

from .base import IAMCredentialsTransport
from .grpc import IAMCredentialsGrpcTransport
from .grpc_asyncio import IAMCredentialsGrpcAsyncIOTransport
from .rest import IAMCredentialsRestTransport
from .rest import IAMCredentialsRestInterceptor

# Compile a registry of transports.
_transport_registry = OrderedDict()  # type: Dict[str, Type[IAMCredentialsTransport]]
_transport_registry['grpc'] = IAMCredentialsGrpcTransport
_transport_registry['grpc_asyncio'] = IAMCredentialsGrpcAsyncIOTransport
_transport_registry['rest'] = IAMCredentialsRestTransport

__all__ = (
    'IAMCredentialsTransport',
    'IAMCredentialsGrpcTransport',
    'IAMCredentialsGrpcAsyncIOTransport',
    'IAMCredentialsRestTransport',
    'IAMCredentialsRestInterceptor',
)

redpajama_set_name: RedPajamaGithub


text:
var util = require('util');

util.print('Hello World');


text:
namespace Glyph3
{
	class Entity3D;

	class ViewLightPrepassRenderer : public SceneRenderTask
	{
	public:
		ViewLightPrepassRenderer( RendererDX11& Renderer, ResourcePtr RenderTarget );
		virtual ~ViewLightPrepassRenderer();

		virtual void Update( float fTime );
		virtual void QueuePreTasks( RendererDX11* pRenderer );
		virtual void ExecuteTask( PipelineManagerDX11* pPipelineManager, IParameterManager* pParamManager );
		virtual void Resize( UINT width, UINT height );

		virtual void SetEntity( Entity3D* pEntity );
		virtual void SetScene( Scene* pScene );

		virtual void SetRenderParams( IParameterManager* pParamManager );
		virtual void SetUsageParams( IParameterManager* pParamManager );

		virtual void SetViewMatrix( const Matrix4f& matrix );
		virtual void SetProjMatrix( const Matrix4f& matrix );

		void SetClipPlanes( float NearClip, float FarClip );
		void SetupLights();

		virtual std::wstring GetName();

	protected:

		int						ResolutionX;
		int						ResolutionY;

        float					m_fNearClip;
        float					m_fFarClip;

		ResourcePtr     		m_GBufferTarget;
		ResourcePtr             m_LightTarget;
		ResourcePtr				m_DepthTarget;
		ResourcePtr             m_ReadOnlyDepthTarget;
		ResourcePtr             m_FinalTarget;
		ResourcePtr             m_ResolveTarget;

		ResourcePtr				m_BackBuffer;

		ViewGBuffer*			m_pGBufferView;
		ViewLights*             m_pLightsView;
		ViewFinalPass*          m_pFinalPassView;

		SpriteRendererDX11		m_SpriteRenderer;
	};
};
//--------------------------------------------------------------------------------
#endif // ViewLightPrepassRenderer_h


text:
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe "Nonterminal" do

  before (:each) do
    @n = Panini::Nonterminal.new
  end

  it "responds to #add_production" do
    expect(@n).to respond_to(:add_production)
  end

  it "responds to #productions" do
    expect(@n).to respond_to(:productions)
  end

end

describe "Nonterminal#add_production with a non-Array arument" do

  before (:each) do
    @n = Panini::Nonterminal.new
  end

  it "throws an error" do
    expect do
     @n.add_production('a')
   end.to raise_error(ArgumentError, "The production must be an Array.")
  end

end

describe "Nonterminal#add_production with a single production" do

  before (:each) do
    @n = Panini::Nonterminal.new
    @p = @n.add_production(['a', 'b', 'c'])
  end

  it "returns nil" do
    expect(@p).to be_nil
  end

  it "stores the production" do
    expect(@n.productions.count).to eq(1)
    expect(@n.productions[0]).to eq(['a', 'b', 'c'])
  end

end

describe "Nonterminal#add_production with two productions" do

  before (:each) do
    @n = Panini::Nonterminal.new
    @p1 = @n.add_production(['a', 'b', 'c'])
    @p2 = @n.add_production(['x', 'y', 'z'])
  end

  it "returns nil" do
    expect(@p1).to be_nil
    expect(@p2).to be_nil
  end

  it "stores the productions" do
    expect(@n.productions.count).to eq(2)
  end

  it "stores the first one added first" do
    expect(@n.productions[0]).to eq(['a', 'b', 'c'])
  end

  it "stores the second one added last" do
    expect(@n.productions[1]).to eq(['x', 'y', 'z'])
  end

end


text:
"""Contain abstract VTGate gateway flavor."""

import logging

class VTGateGateway(object):
  """Base class that defines the required interface."""

  def flags(self, cell=None, tablets=None):
    """Return a list of args that tell a VTGate process to start with."""
    raise NotImplementedError()

  def connection_count_vars(self):
    """Return the vars name containing the number of serving connections."""
    raise NotImplementedError()

  def no_tablet_found_message(self):
    """Return the text message that appears in the gateway.

    When we ask a gateway implementation to perform an operation and
    there is no available tablet for it, this string will appear in
    the error message.
    """
    raise NotImplementedError()

  def flavor(self):
    """Return the name of this topo server flavor."""
    return self.flavor_name

flavor_map = {}

_gateway = None

def vtgate_gateway_flavor():
  """Return the VTGate gateway flavor instance."""
  return _gateway

def set_vtgate_gateway_flavor(flavor):
  """Set the VTGate gateway flavor to be used."""
  global _gateway

  if not flavor:
    flavor = "discoverygateway"

  cls = flavor_map.get(flavor, None)
  if not cls:
    logging.error("Unknown VTGate gateway flavor %s", flavor)
    exit(1)

  _gateway = cls()
  _gateway.flavor_name = flavor
  logging.debug("Using VTGate gateway flavor '%s'", flavor)

def register_flavor(key, cls):
  """Register the available VTGate gateway flavors."""
  flavor_map[key] = cls


text:
package com.sutromedia.android.lib.db;

import android.database.sqlite.SQLiteDatabase;
import android.test.AndroidTestCase;

import java.util.List;
import java.util.Set;

import com.sutromedia.android.lib.app.*;
import com.sutromedia.android.lib.db.*;
import com.sutromedia.android.lib.model.*;

public class ModelFactoryEntriesTest extends AndroidTestCase {

    GuideDatabase mGuide;

    protected void setUp() throws Exception {
        super.setUp();
        mGuide= new GuideDatabase(getContext(), "content.sqlite3");
        mGuide.createDataBase();
    }

    protected void tearDown() throws Exception {
        super.tearDown();
        mGuide.close();
    }

    public void testShouldSucceedGettingAllEntries() throws DataException {
        List<IEntrySummary> all = ModelFactory.getEntries(mGuide);
        assertNotNull(all);
        assertEquals(286, all.size());

        IEntrySummary first = all.get(0);
        assertEquals("5806", first.getId());
        assertEquals("About the App", first.getName());
        assertNull(first.getGroup());
        assertNotNull(first.getPrice());
        assertFalse(first.getPrice().hasAmount());
        assertEquals("249594", first.getIconPhoto());
    }

    public void testShouldSucceedGettingApplicationSettings() throws DataException {
        Settings settings = ModelFactory.getSettings(mGuide);
        assertNotNull(settings);
        assertEquals("$", settings.getValue(Settings.Key.CURRENCY_STRING));
        assertEquals("mi", settings.getValue(Settings.Key.DISTANCE_UNITS));
    }

    public void testShouldSucceedGettingInvalidEntryDetails() throws DataException {
        IEntryDetail details = ModelFactory.getEntryDetails(mGuide, "123456789");
        assertNull(details);
    }
    public void testShouldSucceedGettingValidEntryDetails() throws DataException {
        IEntryDetail details = ModelFactory.getEntryDetails(mGuide, "804");
        assertNotNull(details);
        assertEquals("The Met", details.getSubtitle());
        assertEquals("1000 Fifth Av, Manhattan", details.getAddress());
        assertEquals("2125357710", details.getPhoneRaw());
        assertEquals("(212) 535-7710", details.getPhoneFormatted());
        assertEquals("http://www.metmuseum.org", details.getWebUrl());
        assertNull(details.getTwitter());
        assertNull(details.getAudioUrl());
        assertEquals(
            "$20 adult, $15 senior, $10 student is the recommended donation. Includes same-day access to the Cloisters.",
            details.getPriceDetails());
        assertEquals(
            "Tue-Thu, Sun 9:30am-5:30pm; Fri-Sat 9:30am-9pm; closed Mon except on holidays.",
            details.getHours());
        assertNotNull(details.getLocation());
        assertEquals(40.7791544, details.getLocation().getLatitude());
        assertEquals(-73.962697, details.getLocation().getLongitude());
        assertNotNull(details.getAudioPrice());
        assertFalse(details.getAudioPrice().hasAmount());
    }

    public void testShouldSucceedGettingGroupsForEntry() throws DataException {
        List<IGroup> all = ModelFactory.getGroupsForEntry(mGuide, "804");
        assertNotNull(all);
        assertEquals(4, all.size());
        assertEquals("Manhattan", all.get(0).getName());
        assertEquals("Museums", all.get(1).getName());
        assertEquals("Top 25", all.get(2).getName());
        assertEquals("Top 25 Author", all.get(3).getName());
    }

    public void testShouldSucceedGettingGroupsForInvalidEntry() throws DataException {
        List<IGroup> all = ModelFactory.getGroupsForEntry(mGuide, "12345678");
        assertNotNull(all);
        assertEquals(0, all.size());
    }

    public void testShouldSucceedGettingPhotosForEntry() throws DataException {
        List<IPhoto>  all = ModelFactory.getPhotos(mGuide, "804");
        assertNotNull(all);
        assertEquals(10, all.size());
        IPhoto photo = all.get(0);
        assertEquals("83700", photo.getId());
        assertEquals("804", photo.getEntryId());
        assertEquals("Metropolitan Museum of Art", photo.getEntryName());
        assertNull(photo.getCaption());
        assertEquals("Jeffrey Tanenhaus", photo.getAuthor());
        assertNull(photo.getUrl());
        assertEquals(0, photo.getLicense());

        photo = all.get(1);
        assertEquals("4885", photo.getId());
        assertEquals("804", photo.getEntryId());
        assertEquals("Metropolitan Museum of Art", photo.getEntryName());
        assertNull(photo.getCaption());
        assertEquals("Mike Lyncheski", photo.getAuthor());
        assertEquals("http://www.flickr.com/photos/mlyncheski/3306611549/", photo.getUrl());
        assertEquals(4, photo.getLicense());

        //this collection of photos has an entry with a caption
        all = ModelFactory.getPhotos(mGuide, "33308");
        photo = all.get(0);
        assertEquals("236354", photo.getId());
        assertEquals("33308", photo.getEntryId());
        assertEquals("Bus", photo.getEntryName());
        assertEquals("Regular bus $2.25", photo.getCaption());
        assertEquals("Jeffrey Tanenhaus", photo.getAuthor());
        assertNull(photo.getUrl());
        assertEquals(0, photo.getLicense());
   }

    public void testShouldSucceedGettingEtriesForGroup() throws DataException {
        GroupEntries groups = ModelFactory.getGroupEntries(mGuide);
        Set<String> all = groups.getEntries("2415");
        assertNotNull(all);
        assertEquals(9, all.size());
        assertTrue(all.contains("812"));
        assertTrue(all.contains("4508"));
        assertTrue(all.contains("5925"));
        assertTrue(all.contains("5926"));
        assertTrue(all.contains("7768"));
        assertTrue(all.contains("7811"));
        assertTrue(all.contains("35019"));
        assertTrue(all.contains("40436"));
        assertTrue(all.contains("40437"));
    }

}