Пример #1
0
        /// <summary>
        /// Returns a new value.
        /// </summary>
        private object IncrementValue(TestVariable variable, double counter)
        {
            BuiltInType builtInType = TypeInfo.GetBuiltInType(variable.Variable.DataType, Session.TypeTree);
            
            Range range = variable.EURange;

            if (range == null)
            {
                switch (builtInType)
                {
                    case BuiltInType.SByte:
                    {
                        range = new Range(SByte.MaxValue, 0);
                        break;
                    }

                    case BuiltInType.Byte:
                    {
                        range = new Range(Byte.MaxValue, 0);
                        break;
                    }

                    case BuiltInType.Int16:
                    {
                        range = new Range(Int16.MaxValue, 0);
                        break;
                    }

                    case BuiltInType.UInt16:
                    {
                        range = new Range(UInt16.MaxValue, 0);
                        break;
                    }
                        
                    case BuiltInType.Integer:
                    case BuiltInType.Int32:
                    {
                        range = new Range(Int32.MaxValue, 0);
                        break;
                    }

                    default:
                    {
                        range = new Range(Int32.MaxValue, 0);
                        break;
                    }
                }
            }

            if (counter > range.High)
            {
                counter = 0;
            }

            if (counter < range.Low)
            {
                counter = range.Low;
            }

            object value = TypeInfo.Cast(counter, builtInType);
            
            if (variable.Variable.ValueRank < 0)
            {
                return value;
            }
            
            Array array = TypeInfo.CreateArray(builtInType, 3);

            if (array.GetType().GetElementType() == typeof(Variant))
            {
                array.SetValue(new Variant(value), 0);
                array.SetValue(new Variant(value), 1);
                array.SetValue(new Variant(value), 2);
            }
            else
            {
                array.SetValue(value, 0);
                array.SetValue(value, 1);
                array.SetValue(value, 2);
            }

            return array;
        }
Пример #2
0
        /// <summary>
        /// Recursively collects the child variables.
        /// </summary>
        private void AddVariableToTest(VariableNode variable, List<TestVariable> variables, bool numericOnly)
        {
            if (numericOnly)
            {
                BuiltInType builtInType = TypeInfo.GetBuiltInType(variable.DataType, Session.TypeTree);

                if (!TypeInfo.IsNumericType(builtInType))
                {
                    return;
                }
            }

            TestVariable test = new TestVariable();

            test.Variable = variable;
            test.DataType = TypeInfo.GetBuiltInType(variable.DataType, Session.TypeTree);
            test.Values = new List<DataValue>();
            test.Timestamps = new List<DateTime>();
            
            // look up EU range.
            VariableNode euRange = Session.NodeCache.Find(
                variable.NodeId,
                ReferenceTypeIds.HasProperty,
                false,
                false,
                BrowseNames.EURange) as VariableNode;

            if (euRange != null)
            {
                test.EURangeNode = euRange;
            }

            variables.Add(test);
        }
Пример #3
0
        /// <summary>
        /// Checks the timing for notifications.
        /// </summary>
        private bool CheckNotificationTiming(MonitoredItem monitoredItem, TestVariable variable, IList<Notification> notifications)
        {
            bool success = true;

            for (int ii = 0; ii < notifications.Count; ii++)
            {
                double delta = CalculateInterval(notifications[ii].Timestamp, notifications[ii].Value.SourceTimestamp);

                if (delta > monitoredItem.Status.SamplingInterval + 500)
                {
                    Log(
                        "TIMING: Incorrect time for notificiation {0}. NodeId = {1}, Sample={2}, Actual={3}",
                        variable.Variable,
                        variable.Variable.NodeId,
                        ii,
                        delta);

                    success = false;
                }                
            }

            double minDelta = monitoredItem.Status.SamplingInterval;
            double maxDelta = monitoredItem.Status.SamplingInterval*2 + m_publishingTime + m_writeInterval;

            for (int ii = 0; ii < notifications.Count-2; ii++)
            {
                DateTime firstValue = notifications[ii].Value.SourceTimestamp;
                DateTime nextValue  = notifications[ii+2].Value.SourceTimestamp;

                double delta = CalculateInterval(firstValue, nextValue);

                if (delta < minDelta || delta > maxDelta)
                {
                    /*
                    Log(
                        "TIMING: Incorrect time for notificiation {0}. NodeId = {1}, Sample={2}, Min={3}, Actual={4}, Max={5}",
                        variable.Variable,
                        variable.Variable.NodeId,
                        ii,
                        minDelta,
                        delta,
                        maxDelta);

                    StringBuilder buffer = new StringBuilder();
                    buffer.AppendFormat("{0} ({1}):", variable.Variable, notifications.Count);

                    for (int jj = 0; jj < notifications.Count; jj++)
                    {    
                        double delta1 = 0;
                        double delta2 = 0;
                        
                        if (jj > 0)
                        {
                            delta1 = CalculateInterval(notifications[jj-1].Value.SourceTimestamp, notifications[jj].Value.SourceTimestamp);
                        
                            if (jj < notifications.Count-1)
                            {
                                delta2 = CalculateInterval(notifications[jj-1].Value.SourceTimestamp, notifications[jj+1].Value.SourceTimestamp);
                            }
                        }

                        buffer.AppendFormat(
                            "\r\n{0} - {1:ss.fff} - {2:ss.fff} - {3}ms - {4}ms", 
                            jj,
                            notifications[jj].Value.SourceTimestamp,
                            notifications[jj].Timestamp,
                            delta1,
                            delta2);
                    }
                    
                    Log(buffer.ToString());
                    
                    return false;
                    */

                    break;
                }
            }

            return success;
        }
Пример #4
0
        /// <summary>
        /// Checks that the correct values were returned.
        /// </summary>
        private bool CheckReturnedValues(MonitoredItem monitoredItem, TestVariable variable, IList<Notification> notifications)
        {
            // ignore values if syntax errors occurred.
            if (variable.WriteError)
            {
                return true;
            }

            for (int ii = 0; ii < notifications.Count; ii++)
            {
                bool match = false;

                for (int jj = 0; jj < variable.Values.Count; jj++)
                {
                    // must match any value change during the sampling period.
                    if (variable.Timestamps[jj] < notifications[ii].Timestamp.AddMilliseconds(-monitoredItem.Status.SamplingInterval-(2*m_publishingTime)-m_maximumTimingError))
                    {
                        continue;
                    }
                    
                    // cannot match values after the time of notification.
                    if (variable.Timestamps[jj] >= notifications[ii].Timestamp)
                    {
                        match = false;
                        break;
                    }
                    
                    // check for match.
                    match = m_comparer.CompareVariant(variable.Values[jj].WrappedValue, notifications[ii].Value.WrappedValue);

                    if (match)
                    {
                        break;
                    }
                }

                if (!match)
                {
                    Log(
                        "Value does not match written value for MonitoredItem {0}. NodeId={1}, SamplingInterval={2}, Actual={3}",
                        variable.Variable,
                        variable.Variable.NodeId,
                        monitoredItem.SamplingInterval,
                        notifications[ii].Value.WrappedValue);
                    
                    return false;
                }
            }

            return true;
        }
Пример #5
0
        /// <summary>
        /// Reads an verifies all of the nodes.
        /// </summary>
        private bool DoWriteBadTypeTest()
        {
            // follow tree from each starting node.
            bool success = true;

            // collection writeable variables that don't change during the test.
            List <TestVariable> variables = new List <TestVariable>();

            for (int ii = 0; ii < WriteableVariables.Count; ii++)
            {
                TestVariable test = new TestVariable();

                test.Variable = WriteableVariables[ii];
                test.DataType = TypeInfo.GetBuiltInType(WriteableVariables[ii].DataType, Session.TypeTree);
                test.Values   = new List <DataValue>();

                variables.Add(test);
            }

            Log("Starting WriteBadTypeTest for {0} Nodes", variables.Count);

            double increment = MaxProgress / variables.Count;
            double position  = 0;

            WriteValueCollection nodesToWrite = new WriteValueCollection();

            int nodes      = 0;
            int operations = 0;

            foreach (TestVariable variable in variables)
            {
                nodes++;

                AddWriteBadValues(variable, nodesToWrite);

                // process batch.
                if (nodesToWrite.Count > 100)
                {
                    operations += nodesToWrite.Count;

                    if (!WriteBadValues(nodesToWrite))
                    {
                        success = false;
                        break;
                    }

                    if (nodes > variables.Count / 5)
                    {
                        Log("Wrote {0} attribute values for {1} nodes.", operations, nodes);
                        nodes      = 0;
                        operations = 0;
                    }

                    nodesToWrite.Clear();
                }

                position += increment;
                ReportProgress(position);
            }

            // process final batch.
            if (success)
            {
                if (nodesToWrite.Count > 0)
                {
                    operations += nodesToWrite.Count;

                    if (!WriteBadValues(nodesToWrite))
                    {
                        success = false;
                    }
                    else
                    {
                        Log("Wrote {0} attribute values for {1} nodes.", operations, nodes);
                    }

                    nodesToWrite.Clear();
                }
            }

            return(success);
        }
Пример #6
0
        /// <summary>
        /// Reads the attributes, verifies the results and updates the nodes.
        /// </summary>
        private bool Write(WriteValueCollection nodesToWrite)
        {
            bool success = true;

            StatusCodeCollection     results         = null;
            DiagnosticInfoCollection diagnosticInfos = null;

            RequestHeader requestHeader = new RequestHeader();

            requestHeader.ReturnDiagnostics = 0;

            try {
                Session.Write(
                    requestHeader,
                    nodesToWrite,
                    out results,
                    out diagnosticInfos);
            } catch (System.ServiceModel.CommunicationException e) {
                Log("WARNING: Communication error (random data may have resulted in a message that is too large). {0}",
                    e.Message);
                return(true);
            } catch (System.Xml.XmlException e) {
                Log("WARNING: XML parsing error (random data may have resulted in a message that is too large). {0}",
                    e.Message);
                return(true);
            } catch (ServiceResultException e) {
                if (e.StatusCode == StatusCodes.BadEncodingLimitsExceeded)
                {
                    Log(
                        "WARNING: Communication error (random data may have resulted in a message that is too large). {0}",
                        e.Message);
                    return(true);
                }

                throw new ServiceResultException(new ServiceResult(e));
            }

            ClientBase.ValidateResponse(results, nodesToWrite);
            ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToWrite);

            // check diagnostics.
            if (diagnosticInfos != null && diagnosticInfos.Count > 0)
            {
                Log("Returned non-empty DiagnosticInfos array during Write.");
                return(false);
            }

            // check results.
            ReadValueIdCollection nodesToRead = new ReadValueIdCollection();

            for (int ii = 0; ii < nodesToWrite.Count; ii++)
            {
                WriteValue   request  = nodesToWrite[ii];
                TestVariable variable = (TestVariable)request.Handle;

                if (results[ii] == StatusCodes.BadUserAccessDenied)
                {
                    continue;
                }

                if (results[ii] == StatusCodes.BadNotWritable)
                {
                    Log(
                        "Write failed when writing a writeable value '{0}'. NodeId = {1}, Value = {2}, StatusCode = {3}",
                        variable.Variable,
                        variable.Variable.NodeId,
                        request.Value.WrappedValue,
                        results[ii]);

                    success = false;
                    break;
                }

                if (StatusCode.IsBad(results[ii]))
                {
                    if (request.Value.StatusCode != StatusCodes.Good)
                    {
                        if (results[ii] != StatusCodes.BadWriteNotSupported)
                        {
                            Log(
                                "Unexpected error when writing the StatusCode for a Value '{0}'. NodeId = {1}, Value = {2}, StatusCode = {3}",
                                variable.Variable,
                                variable.Variable.NodeId,
                                request.Value.WrappedValue,
                                results[ii]);

                            success = false;
                            break;
                        }

                        continue;
                    }

                    if (request.Value.SourceTimestamp != DateTime.MinValue ||
                        request.Value.ServerTimestamp != DateTime.MinValue)
                    {
                        if (results[ii] != StatusCodes.BadWriteNotSupported)
                        {
                            Log(
                                "Unexpected error when writing the Timestamp for a Value '{0}'. NodeId = {1}, Value = {2}, StatusCode = {3}",
                                variable.Variable,
                                variable.Variable.NodeId,
                                request.Value.WrappedValue,
                                results[ii]);

                            success = false;
                            break;
                        }

                        continue;
                    }

                    if (results[ii] != StatusCodes.BadTypeMismatch && results[ii] != StatusCodes.BadOutOfRange)
                    {
                        Log(
                            "Unexpected error when writing a valid value '{0}'. NodeId = {1}, Value = {2}, StatusCode = {3}",
                            variable.Variable,
                            variable.Variable.NodeId,
                            request.Value.WrappedValue,
                            results[ii]);

                        success = false;
                        break;
                    }

                    continue;
                }

                ReadValueId nodeToRead = new ReadValueId();

                nodeToRead.NodeId      = request.NodeId;
                nodeToRead.AttributeId = request.AttributeId;
                nodeToRead.IndexRange  = request.IndexRange;
                nodeToRead.Handle      = request.Handle;

                nodesToRead.Add(nodeToRead);
            }

            // skip read back on failed.
            if (!success)
            {
                return(success);
            }

            // check if nothing more do to.
            if (nodesToRead.Count == 0)
            {
                return(true);
            }

            requestHeader = new RequestHeader();
            requestHeader.ReturnDiagnostics = 0;

            DataValueCollection values = new DataValueCollection();

            try {
                Session.Read(
                    requestHeader,
                    0,
                    TimestampsToReturn.Both,
                    nodesToRead,
                    out values,
                    out diagnosticInfos);
            } catch (System.ServiceModel.CommunicationException e) {
                Log("WARNING: Communication error (random data may have resulted in a message that is too large). {0}",
                    e.Message);
                return(true);
            } catch (System.Xml.XmlException e) {
                Log("WARNING: XML parsing error (random data may have resulted in a message that is too large). {0}",
                    e.Message);
                return(true);
            } catch (ServiceResultException e) {
                if (e.StatusCode == StatusCodes.BadEncodingLimitsExceeded)
                {
                    Log(
                        "WARNING: Communication error (random data may have resulted in a message that is too large). {0}",
                        e.Message);
                    return(true);
                }

                throw new ServiceResultException(new ServiceResult(e));
            }

            ClientBase.ValidateResponse(values, nodesToRead);
            ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToRead);

            // check diagnostics.
            if (diagnosticInfos != null && diagnosticInfos.Count > 0)
            {
                Log("Returned non-empty DiagnosticInfos array during Read.");
                return(false);
            }

            for (int ii = 0; ii < nodesToRead.Count; ii++)
            {
                ReadValueId  request      = nodesToRead[ii];
                TestVariable variable     = (TestVariable)request.Handle;
                DataValue    valueWritten = variable.Values[variable.Values.Count - 1];

                if (StatusCode.IsBad(values[ii].StatusCode) && StatusCode.IsNotBad(valueWritten.StatusCode))
                {
                    Log(
                        "Could not read back the value written '{0}'. NodeId = {1}, Value = {2}, StatusCode = {3}",
                        variable.Variable,
                        variable.Variable.NodeId,
                        valueWritten.WrappedValue,
                        values[ii].StatusCode);

                    success = false;
                    break;
                }

                Opc.Ua.Test.DataComparer comparer = new Opc.Ua.Test.DataComparer(Session.MessageContext);
                comparer.ThrowOnError = false;

                if (!comparer.CompareVariant(values[ii].WrappedValue, valueWritten.WrappedValue))
                {
                    Log(
                        "Read back value does not match the value written '{0}'. NodeId = {1}, Value = {2}, ReadValue = {3}",
                        variable.Variable,
                        variable.Variable.NodeId,
                        valueWritten.WrappedValue,
                        values[ii].WrappedValue);

                    success = false;
                    break;
                }

                if (valueWritten.StatusCode != StatusCodes.Good)
                {
                    if (values[ii].StatusCode != valueWritten.StatusCode)
                    {
                        Log(
                            "Read back StatusCode does not match the StatusCode written '{0}'. NodeId = {1}, StatusCode = {2}, ReadStatusCode = {3}",
                            variable.Variable,
                            variable.Variable.NodeId,
                            valueWritten.StatusCode,
                            values[ii].StatusCode);

                        success = false;
                        break;
                    }
                }

                if (valueWritten.SourceTimestamp != DateTime.MinValue)
                {
                    if (values[ii].SourceTimestamp != valueWritten.SourceTimestamp)
                    {
                        Log(
                            "Read back ServerTimestamp does not match the ServerTimestamp written '{0}'. NodeId = {1}, Timestamp = {2}, ReadTimestamp = {3}",
                            variable.Variable,
                            variable.Variable.NodeId,
                            valueWritten.SourceTimestamp,
                            values[ii].SourceTimestamp);

                        success = false;
                        break;
                    }
                }
            }

            return(success);
        }
Пример #7
0
        /// <summary>
        /// Adds random values to write.
        /// </summary>
        private void AddWriteValues(
            TestVariable variable, 
            WriteValueCollection nodesToWrite)
        {            
            WriteValue nodeToWrite = new WriteValue();
        
            nodeToWrite.NodeId = variable.Variable.NodeId;
            nodeToWrite.AttributeId = Attributes.Value;

            DataValue value = new DataValue();
            
            value.Value = m_generator.GetRandom(
                variable.Variable.DataType,
                variable.Variable.ValueRank,
                variable.Variable.ArrayDimensions,
                Session.TypeTree);
                
            value.StatusCode = StatusCodes.Good;
            value.ServerTimestamp = DateTime.MinValue;
            value.SourceTimestamp = DateTime.MinValue;

            variable.Values.Add(value);

            nodeToWrite.Value = value;
            nodeToWrite.Handle = variable;

            nodesToWrite.Add(nodeToWrite);
        }
Пример #8
0
        /// <summary>
        /// Adds random values to write.
        /// </summary>
        private void AddWriteBadValues(
            TestVariable variable, 
            WriteValueCollection nodesToWrite)
        {           
            for (BuiltInType ii = BuiltInType.Null; ii < BuiltInType.DataValue; ii++)
            {
                if (variable.DataType != ii || variable.Variable.ValueRank >= 0)
                {
                    // add random scalar.
                    WriteValue nodeToWrite = new WriteValue();
                
                    nodeToWrite.NodeId = variable.Variable.NodeId;
                    nodeToWrite.AttributeId = Attributes.Value;

                    DataValue value = new DataValue();
                    
                    value.Value = m_generator.GetRandom(ii);                        
                    value.StatusCode = StatusCodes.Good;
                    value.ServerTimestamp = DateTime.MinValue;
                    value.SourceTimestamp = DateTime.MinValue;

                    variable.Values.Add(value);

                    nodeToWrite.Value = value;
                    nodeToWrite.Handle = variable;

                    nodesToWrite.Add(nodeToWrite);
                }

                if (variable.DataType != ii || variable.Variable.ValueRank == ValueRanks.Scalar)
                {
                    // add random array.
                    WriteValue nodeToWrite = new WriteValue();
                
                    nodeToWrite.NodeId = variable.Variable.NodeId;
                    nodeToWrite.AttributeId = Attributes.Value;

                    DataValue value = new DataValue();
                    
                    value.Value = m_generator.GetRandomArray(ii, true, 100, false);                        
                    value.StatusCode = StatusCodes.Good;
                    value.ServerTimestamp = DateTime.MinValue;
                    value.SourceTimestamp = DateTime.MinValue;

                    variable.Values.Add(value);

                    nodeToWrite.Value = value;
                    nodeToWrite.Handle = variable;

                    nodesToWrite.Add(nodeToWrite);
                }
            }
        }
Пример #9
0
        /// <summary>
        /// Reads the attributes, verifies the results and updates the nodes.
        /// </summary>
        private bool WriteBadValues(WriteValueCollection nodesToWrite)
        {
            bool success = true;

            StatusCodeCollection     results;
            DiagnosticInfoCollection diagnosticInfos;

            RequestHeader requestHeader = new RequestHeader();

            requestHeader.ReturnDiagnostics = 0;

            try
            {
                Session.Write(
                    requestHeader,
                    nodesToWrite,
                    out results,
                    out diagnosticInfos);
            }
            catch (System.ServiceModel.CommunicationException e)
            {
                Log("WARNING: Communication error (random data may have resulted in a message that is too large). {0}", e.Message);
                return(true);
            }
            catch (System.Xml.XmlException e)
            {
                Log("WARNING: XML parsing error (random data may have resulted in a message that is too large). {0}", e.Message);
                return(true);
            }
            catch (ServiceResultException e)
            {
                if (e.StatusCode == StatusCodes.BadEncodingLimitsExceeded)
                {
                    Log("WARNING: Communication error (random data may have resulted in a message that is too large). {0}", e.Message);
                    return(true);
                }

                throw new ServiceResultException(new ServiceResult(e));
            }

            ClientBase.ValidateResponse(results, nodesToWrite);
            ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToWrite);

            // check diagnostics.
            if (diagnosticInfos != null && diagnosticInfos.Count > 0)
            {
                Log("Returned non-empty DiagnosticInfos array during Write.");
                return(false);
            }

            // check results.
            ReadValueIdCollection nodesToRead = new ReadValueIdCollection();

            for (int ii = 0; ii < nodesToWrite.Count; ii++)
            {
                WriteValue   request  = nodesToWrite[ii];
                TestVariable variable = (TestVariable)request.Handle;

                // allow access denied even if the node was theorectically writeable.
                if (results[ii] == StatusCodes.BadUserAccessDenied)
                {
                    continue;
                }

                if (results[ii] == StatusCodes.BadNotWritable)
                {
                    Log(
                        "Write failed when writing a writeable value '{0}'. NodeId = {1}, Value = {2}, StatusCode = {3}",
                        variable.Variable,
                        variable.Variable.NodeId,
                        request.Value.WrappedValue,
                        results[ii]);

                    success = false;
                    break;
                }

                TypeInfo typeInfo = TypeInfo.IsInstanceOfDataType(
                    request.Value.Value,
                    variable.Variable.DataType,
                    variable.Variable.ValueRank,
                    Session.NamespaceUris,
                    Session.TypeTree);

                if (typeInfo != null)
                {
                    if (results[ii] != StatusCodes.Good && results[ii] != StatusCodes.BadTypeMismatch && results[ii] != StatusCodes.BadOutOfRange)
                    {
                        Log(
                            "Unexpected error when writing a valid value for a Variable '{0}'. NodeId = {1}, Value = {2}, StatusCode = {3}",
                            variable.Variable,
                            variable.Variable.NodeId,
                            request.Value.WrappedValue,
                            results[ii]);

                        success = false;
                        break;
                    }

                    continue;
                }

                if (results[ii] != StatusCodes.BadTypeMismatch && results[ii] != StatusCodes.BadOutOfRange)
                {
                    Log(
                        "Unexpected error when writing a bad value for a Variable '{0}'. NodeId = {1}, Value = {2}, StatusCode = {3}",
                        variable.Variable,
                        variable.Variable.NodeId,
                        request.Value.WrappedValue,
                        results[ii]);

                    success = false;
                    break;
                }
            }

            return(success);
        }
Пример #10
0
        /// <summary>
        /// Reads an verifies all of the nodes.
        /// </summary>
        private bool DoWriteBadTypeTest()
        {
            // follow tree from each starting node.
            bool success = true;

            // collection writeable variables that don't change during the test.
            List<TestVariable> variables = new List<TestVariable>();

            for (int ii = 0; ii < WriteableVariables.Count; ii++)
            {
                TestVariable test = new TestVariable();

                test.Variable = WriteableVariables[ii];
                test.DataType = TypeInfo.GetBuiltInType(WriteableVariables[ii].DataType, Session.TypeTree);
                test.Values = new List<DataValue>();

                variables.Add(test);
            }

            Log("Starting WriteBadTypeTest for {0} Nodes", variables.Count);
            
            double increment = MaxProgress/variables.Count;
            double position  = 0;

            WriteValueCollection nodesToWrite = new WriteValueCollection();
            
            int nodes = 0;
            int operations = 0;

            foreach (TestVariable variable in variables)
            {               
                nodes++;

                AddWriteBadValues(variable, nodesToWrite);

                // process batch.
                if (nodesToWrite.Count > 100)
                {
                    operations += nodesToWrite.Count;

                    if (!WriteBadValues(nodesToWrite))
                    {
                        success = false;
                        break;
                    }

                    if (nodes > variables.Count/5)
                    {
                        Log("Wrote {0} attribute values for {1} nodes.", operations, nodes);
                        nodes = 0;
                        operations = 0;
                    }

                    nodesToWrite.Clear();
                }

                position += increment;
                ReportProgress(position);
            }   
         
            // process final batch.
            if (success)
            {
                if (nodesToWrite.Count > 0)
                {
                    operations += nodesToWrite.Count;

                    if (!WriteBadValues(nodesToWrite))
                    {
                        success = false;
                    }
                    else
                    {
                        Log("Wrote {0} attribute values for {1} nodes.", operations, nodes);
                    }

                    nodesToWrite.Clear();
                }
            }

            return success;
        }
 public static TestVariableViewModel ToModel(this TestVariable variableViewModel)
 {
     return(Mapper.Map <TestVariableViewModel>(variableViewModel));
 }
        public void PrintFamilyPrintsCorrectly()
        {
            // Extended MSTest
            Person person = new Person()
            {
                FirstName = "Robin",
                LastName  = "Rich",
                Age       = 10,
                Mother    = new Person()
                {
                    FirstName = "Anna",
                    LastName  = "Smith",
                    Age       = 38
                },
                Father = new Person()
                {
                    FirstName = "Warren",
                    LastName  = "Rich",
                    Age       = 36,
                    Mother    = new Person()
                    {
                        FirstName = "Elsa",
                        LastName  = "Johnson",
                        Age       = 65
                    },
                    Father = new Person()
                    {
                        FirstName = "Gustav",
                        LastName  = "Rich",
                        Age       = 66
                    }
                }
            };
            PersonPrinter printer = new PersonPrinter();

            string expectedOutput = string.Join(
                Environment.NewLine,
                "Robin Rich (10)",
                "Warren Rich (36)",
                "Gustav Rich (66)",
                "Elsa Johnson (65)",
                "Anna Smith (38)");

            ConsoleAssert.WritesOut(() => printer.PrintFamily(person), expectedOutput);

            // TestTools Code
            UnitTest test = Factory.CreateTest();
            TestVariable <Person>        _person  = test.CreateVariable <Person>("person");
            TestVariable <PersonPrinter> _printer = test.CreateVariable <PersonPrinter>("printer");

            test.Arrange(_person, Expr(() => new Person()
            {
                FirstName = "Robin",
                LastName  = "Rich",
                Age       = 10,
                Mother    = new Person()
                {
                    FirstName = "Anna",
                    LastName  = "Smith",
                    Age       = 38
                },
                Father = new Person()
                {
                    FirstName = "Warren",
                    LastName  = "Rich",
                    Age       = 36,
                    Mother    = new Person()
                    {
                        FirstName = "Elsa",
                        LastName  = "Johnson",
                        Age       = 65
                    },
                    Father = new Person()
                    {
                        FirstName = "Gustav",
                        LastName  = "Rich",
                        Age       = 66
                    }
                }
            }));
            test.ConsoleAssert.WritesOut(
                Lambda(Expr(_printer, _person, (p1, p2) => p1.PrintFamily(p2))),
                Const(expectedOutput));
            test.Execute();
        }
Пример #13
0
    public static void RunValidationC() {
      // Run the example in section 3.4.3 of Cousot and Halbwachs backwards, that is, from
      // from to constraints.
      IVariable/*!*/ dim1 = new TestVariable("X");
      IVariable/*!*/ dim2 = new TestVariable("Y");
      IVariable/*!*/ dim3 = new TestVariable("Z");
      Contract.Assert(dim1 != null);
      Contract.Assert(dim2 != null);
      Contract.Assert(dim3 != null);

      FrameElement s0 = new FrameElement();
      s0.AddCoordinate(dim1, Rational.ONE);
      s0.AddCoordinate(dim2, Rational.FromInts(1, 2));
      s0.AddCoordinate(dim3, Rational.FromInts(-1, 2));

      FrameElement s1 = new FrameElement();
      s1.AddCoordinate(dim1, Rational.ONE);
      s1.AddCoordinate(dim2, Rational.FromInts(-1, 2));
      s1.AddCoordinate(dim3, Rational.FromInts(1, 2));

      FrameElement s2 = new FrameElement();
      s2.AddCoordinate(dim1, Rational.FromInt(3));
      s2.AddCoordinate(dim2, Rational.FromInts(-3, 2));
      s2.AddCoordinate(dim3, Rational.FromInts(3, 2));

      FrameElement r0 = new FrameElement();
      r0.AddCoordinate(dim1, Rational.ONE);
      r0.AddCoordinate(dim2, Rational.FromInts(1, 2));
      r0.AddCoordinate(dim3, Rational.FromInts(-1, 2));

      FrameElement r1 = new FrameElement();
      r1.AddCoordinate(dim1, Rational.ONE);
      r1.AddCoordinate(dim2, Rational.ZERO);
      r1.AddCoordinate(dim3, Rational.ZERO);

      FrameElement d0 = new FrameElement();
      d0.AddCoordinate(dim1, Rational.ZERO);
      d0.AddCoordinate(dim2, Rational.ONE);
      d0.AddCoordinate(dim3, Rational.ONE);

      LinearConstraintSystem lcs = new LinearConstraintSystem(s0);
      lcs.Dump();

      lcs.AddVertex(s1);
      lcs.Dump();

      lcs.AddVertex(s2);
      lcs.Dump();

      lcs.AddRay(r0);
      lcs.Dump();

      lcs.AddRay(r1);
      lcs.Dump();

      lcs.AddLine(d0);
      lcs.Dump();

      lcs.SimplifyConstraints();
      lcs.Dump();

#if LATER
      lcs.GenerateFrameFromConstraints(); // should give us back the original frame...
#endif
    }
Пример #14
0
    /// <summary>
    /// Tests the example in section 3.4.3 of Cousot and Halbwachs.
    /// </summary>
    public static void RunValidationB() {
      IVariable/*!*/ X = new TestVariable("X");
      IVariable/*!*/ Y = new TestVariable("Y");
      IVariable/*!*/ Z = new TestVariable("Z");
      Contract.Assert(X != null);
      Contract.Assert(Y != null);
      Contract.Assert(Z != null);
      ArrayList /*LinearConstraint*/ cs = new ArrayList /*LinearConstraint*/ ();

      LinearConstraint c = new LinearConstraint(LinearConstraint.ConstraintRelation.LE);
      c.SetCoefficient(X, Rational.MINUS_ONE);
      c.SetCoefficient(Y, Rational.ONE);
      c.SetCoefficient(Z, Rational.MINUS_ONE);
      c.rhs = Rational.ZERO;
      cs.Add(c);

      c = new LinearConstraint(LinearConstraint.ConstraintRelation.LE);
      c.SetCoefficient(X, Rational.MINUS_ONE);
      c.rhs = Rational.MINUS_ONE;
      cs.Add(c);

      c = new LinearConstraint(LinearConstraint.ConstraintRelation.LE);
      c.SetCoefficient(X, Rational.MINUS_ONE);
      c.SetCoefficient(Y, Rational.MINUS_ONE);
      c.SetCoefficient(Z, Rational.ONE);
      c.rhs = Rational.ZERO;
      cs.Add(c);

      c = new LinearConstraint(LinearConstraint.ConstraintRelation.LE);
      c.SetCoefficient(Y, Rational.MINUS_ONE);
      c.SetCoefficient(Z, Rational.ONE);
      c.rhs = Rational.FromInt(3);
      cs.Add(c);

      LinearConstraintSystem lcs = new LinearConstraintSystem(cs);
      Console.WriteLine("==================== The final linear constraint system ====================");
      lcs.Dump();
    }
Пример #15
0
    public static void RunValidationA() {
      IVariable/*!*/ dim1 = new TestVariable("X");
      IVariable/*!*/ dim2 = new TestVariable("Y");
      IVariable/*!*/ dim3 = new TestVariable("Z");
      Contract.Assert(dim1 != null);
      Contract.Assert(dim2 != null);
      Contract.Assert(dim3 != null);

      FrameElement s1 = new FrameElement();
      s1.AddCoordinate(dim1, Rational.ONE);
      s1.AddCoordinate(dim2, Rational.MINUS_ONE);
      s1.AddCoordinate(dim3, Rational.ZERO);
      FrameElement s2 = new FrameElement();
      s2.AddCoordinate(dim1, Rational.MINUS_ONE);
      s2.AddCoordinate(dim2, Rational.ONE);
      s2.AddCoordinate(dim3, Rational.ZERO);
      FrameElement r1 = new FrameElement();
      r1.AddCoordinate(dim1, Rational.ZERO);
      r1.AddCoordinate(dim2, Rational.ZERO);
      r1.AddCoordinate(dim3, Rational.ONE);
      FrameElement d1 = new FrameElement();
      d1.AddCoordinate(dim1, Rational.ONE);
      d1.AddCoordinate(dim2, Rational.ONE);
      d1.AddCoordinate(dim3, Rational.ZERO);

      // create lcs from frame -- cf. Cousot/Halbwachs 1978, section 3.3.1.1
      LinearConstraintSystem lcs = new LinearConstraintSystem(s1);
      lcs.Dump();

      lcs.AddVertex(s2);
      lcs.Dump();

      lcs.AddRay(r1);
      lcs.Dump();

      lcs.AddLine(d1);
      lcs.Dump();

      lcs.SimplifyConstraints();
      lcs.Dump();

#if LATER
      lcs.GenerateFrameFromConstraints(); // should give us back the original frame...
#endif
      Console.WriteLine("IsSubset? {0}", lcs.IsSubset(lcs.Clone()));
      lcs.Dump();
    }