Commit f7342535 authored by garciay's avatar garciay
Browse files

Add conversion from char into Hexa

parent 5030ea16
Loading
Loading
Loading
Loading
+24 −3
Original line number Original line Diff line number Diff line
@@ -8,6 +8,14 @@ using System.IO;


namespace TestCastTortureAdapter
namespace TestCastTortureAdapter
{
{
    /**
     * NOTE To build the .dat file, please follow these step:
     *  1. In Wireshark, select the diameter packet
     *  2. Select Diameter Protocol subtree
     *  3. Right click/Copy/Bytes (Hex Stream)
     *  4. Paste the clipboard into the .dat file
     *  5. The .dat file name shall match a testcase name in TortureTest_DIAMETER\TortureTestSolution\DiameterTortureTestCases.ttcn
     */
    class TortureAdapter : ITriCommunicationSA,ITriPlatformPA, IChannelEventHandler
    class TortureAdapter : ITriCommunicationSA,ITriPlatformPA, IChannelEventHandler
    {
    {
        #region ITriCommunicationSA Members
        #region ITriCommunicationSA Members
@@ -56,12 +64,13 @@ namespace TestCastTortureAdapter
            return TriStatus.TriOk;
            return TriStatus.TriOk;
        }
        }


        private static string Hexa = "0123456789abcdef";
        private void SendMessageFor()
        private void SendMessageFor()
        {
        {
            System.Threading.Thread.Sleep(500);
            System.Threading.Thread.Sleep(500);
            try
            try
            {
            {
                string sFilePath = "data\\" + m_sTestCaseName + ".dat";
                string sFilePath = "data\\" + m_sTestCaseName + ".dat";//..\\..\\..\\..\\
                if (!File.Exists(sFilePath))
                if (!File.Exists(sFilePath))
                {
                {
                    Console.WriteLine("Could not find the file: " + sFilePath);
                    Console.WriteLine("Could not find the file: " + sFilePath);
@@ -75,8 +84,17 @@ namespace TestCastTortureAdapter
                while ((nRead = fs.Read(data, (int)fs.Position, nLen)) > 0)
                while ((nRead = fs.Read(data, (int)fs.Position, nLen)) > 0)
                    nLen -= nRead;
                    nLen -= nRead;
                fs.Close();
                fs.Close();

                // Convert into hexadecimal array
                TriMessage msg = new TriMessage(data, nLen * 8);
                byte[] conv = new byte[data.Length / 2];
                byte idx1 = 0x00;
                byte idx2 = 0x00;
                for (int i = 0, j = 0; i < data.Length; i += 2)
                {
                    idx1 = (byte)Hexa.IndexOf((char)data[i]);
                    idx2 = (byte)Hexa.IndexOf((char)data[i + 1]);
                    conv[j++] = (byte)((byte)(idx1 & 0x0f) << 4 | (byte)(idx2 & 0x0f));
                }
                TriMessage msg = new TriMessage(conv, conv.Length * 8);
                if (!m_evExit.WaitOne(0))
                if (!m_evExit.WaitOne(0))
                {
                {
                    TriTciChannel.Instance.EnqueueMessage(m_port, new TriAddress(), m_comp, msg);
                    TriTciChannel.Instance.EnqueueMessage(m_port, new TriAddress(), m_comp, msg);
@@ -175,6 +193,9 @@ namespace TestCastTortureAdapter


        public void run()
        public void run()
        {
        {
            m_sTestCaseName = "Test";
            SendMessageFor();

            TriProvider.Instance.TriPlatformPA = this;
            TriProvider.Instance.TriPlatformPA = this;
            TriProvider.Instance.TriCommunicationSA = this;
            TriProvider.Instance.TriCommunicationSA = this;
            TriTciChannel.Instance.ApplicationName = "TortureTestAdapter";
            TriTciChannel.Instance.ApplicationName = "TortureTestAdapter";