Example #1
0
    private void StrContains_NewLine_null()
    {
        using (SerialPort com1 = TCSupport.InitFirstSerialPort())
            using (SerialPort com2 = TCSupport.InitSecondSerialPort(com1))
            {
                Random rndGen = new Random(-55);
                System.Text.StringBuilder strBldrToWrite = TCSupport.GetRandomStringBuilder(NEWLINE_TESTING_STRING_SIZE,
                                                                                            TCSupport.CharacterOptions.None);

                string newLine = "\0";

                Debug.WriteLine(
                    "Verifying write method with a NewLine=\\0 string and writing a string that contains the NewLine");

                com1.NewLine = newLine;
                com1.Open();

                if (!com2.IsOpen) //This is necessary since com1 and com2 might be the same port if we are using a loopback
                {
                    com2.Open();
                }

                strBldrToWrite.Insert(rndGen.Next(0, NEWLINE_TESTING_STRING_SIZE), newLine);

                VerifyWriteLine(com1, com2, strBldrToWrite.ToString());
            }
    }
Example #2
0
    public bool StrContains_NewLine_null()
    {
        SerialPort com1   = TCSupport.InitFirstSerialPort();
        SerialPort com2   = TCSupport.InitSecondSerialPort(com1);
        Random     rndGen = new Random(-55);

        System.Text.StringBuilder strBldrToWrite = TCSupport.GetRandomStringBuilder(NEWLINE_TESTING_STRING_SIZE, TCSupport.CharacterOptions.None);
        bool   retValue = true;
        string newLine  = "\0";

        Console.WriteLine("Verifying write method with a NewLine=\\0 string and writing a string that contains the NewLine");

        com1.NewLine = newLine;
        com1.Open();

        if (!com2.IsOpen) //This is necessary since com1 and com2 might be the same port if we are using a loopback
        {
            com2.Open();
        }

        strBldrToWrite.Insert(rndGen.Next(0, NEWLINE_TESTING_STRING_SIZE), newLine);

        if (!VerifyWriteLine(com1, com2, strBldrToWrite.ToString()))
        {
            Console.Write("Err_011!!! Verifying write method with a NewLine=\\0 string and writing a string that contains the NewLine FAILED");
            retValue = false;
        }

        return(retValue);
    }
Example #3
0
    public bool VerifyRead(System.Text.Encoding encoding, string newLine, int numBytesRead, int numNewLines, ReadDataFromEnum readDataFrom)
    {
        SerialPort com1   = TCSupport.InitFirstSerialPort();
        SerialPort com2   = TCSupport.InitSecondSerialPort(com1);
        Random     rndGen = new Random(-55);

        System.Text.StringBuilder strBldrToWrite;
        int numNewLineChars = newLine.ToCharArray().Length;
        int minLength       = (1 + numNewLineChars) * numNewLines;

        if (minLength < numBytesRead)
        {
            strBldrToWrite = TCSupport.GetRandomStringBuilder(numBytesRead, TCSupport.CharacterOptions.None);
        }
        else
        {
            strBldrToWrite = TCSupport.GetRandomStringBuilder(rndGen.Next(minLength, minLength * 2), TCSupport.CharacterOptions.None);
        }

        //We need place the newLine so that they do not write over eachother
        int divisionLength = strBldrToWrite.Length / numNewLines;
        int range          = divisionLength - numNewLineChars;

        for (int i = 0; i < numNewLines; i++)
        {
            int newLineIndex = rndGen.Next(0, range + 1);

            strBldrToWrite.Insert(newLineIndex + (i * divisionLength) + (i * numNewLineChars), newLine);
        }

        Console.WriteLine("Verifying ReadLine encoding={0}, newLine={1}, numBytesRead={2}, numNewLines={3}", encoding, newLine, numBytesRead, numNewLines);

        com1.ReadTimeout = 500;
        com1.Encoding    = encoding;
        com1.NewLine     = newLine;

        com1.Open();

        if (!com2.IsOpen) //This is necessary since com1 and com2 might be the same port if we are using a loopback
        {
            com2.Open();
        }

        switch (readDataFrom)
        {
        case ReadDataFromEnum.NonBuffered:
            return(VerifyReadNonBuffered(com1, com2, strBldrToWrite.ToString(), newLine));

        case ReadDataFromEnum.Buffered:
            return(VerifyReadBuffered(com1, com2, strBldrToWrite.ToString(), newLine));

        case ReadDataFromEnum.BufferedAndNonBuffered:
            return(VerifyReadBufferedAndNonBuffered(com1, com2, strBldrToWrite.ToString(), newLine));
        }
        return(false);
    }
Example #4
0
        private void VerifyRead(Encoding encoding, string newLine, int numBytesRead, int numNewLines, ReadDataFromEnum readDataFrom)
        {
            using (SerialPort com1 = TCSupport.InitFirstSerialPort())
                using (SerialPort com2 = TCSupport.InitSecondSerialPort(com1))
                {
                    Random        rndGen = new Random(-55);
                    StringBuilder strBldrToWrite;
                    int           numNewLineChars = newLine.ToCharArray().Length;
                    int           minLength       = (1 + numNewLineChars) * numNewLines;

                    if (minLength < numBytesRead)
                    {
                        strBldrToWrite = TCSupport.GetRandomStringBuilder(numBytesRead, TCSupport.CharacterOptions.None);
                    }
                    else
                    {
                        strBldrToWrite = TCSupport.GetRandomStringBuilder(rndGen.Next(minLength, minLength * 2),
                                                                          TCSupport.CharacterOptions.None);
                    }

                    //We need place the newLine so that they do not write over eachother
                    int divisionLength = strBldrToWrite.Length / numNewLines;
                    int range          = divisionLength - numNewLineChars;

                    for (int i = 0; i < numNewLines; i++)
                    {
                        int newLineIndex = rndGen.Next(0, range + 1);

                        strBldrToWrite.Insert(newLineIndex + (i * divisionLength) + (i * numNewLineChars), newLine);
                    }

                    Debug.WriteLine("Verifying ReadTo encoding={0}, newLine={1}, numBytesRead={2}, numNewLines={3}", encoding,
                                    newLine, numBytesRead, numNewLines);

                    com1.ReadTimeout = 500;
                    com1.Encoding    = encoding;

                    TCSupport.SetHighSpeed(com1, com2);

                    com1.Open();

                    if (!com2.IsOpen) //This is necessary since com1 and com2 might be the same port if we are using a loopback
                    {
                        com2.Open();
                    }

                    switch (readDataFrom)
                    {
                    case ReadDataFromEnum.NonBuffered:
                        VerifyReadNonBuffered(com1, com2, strBldrToWrite.ToString(), newLine);
                        break;

                    case ReadDataFromEnum.Buffered:
                        VerifyReadBuffered(com1, com2, strBldrToWrite.ToString(), newLine);
                        break;

                    case ReadDataFromEnum.BufferedAndNonBuffered:
                        VerifyReadBufferedAndNonBuffered(com1, com2, strBldrToWrite.ToString(), newLine);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(readDataFrom), readDataFrom, null);
                    }
                }
        }