public void TestDifferentLine()
 {
     uint slotId = 0x30000001;
     VariableSlotInfo varSlotInfo1 = new VariableSlotInfo("a", 1, slotId);
     VariableSlotInfo varSlotInfo2 = new VariableSlotInfo("a", 2, slotId);
     Assert.AreNotEqual(varSlotInfo1, varSlotInfo2);
 }
Example #2
0
 private bool WriteVariableSlotInfo(IStorage storage, VariableSlotInfo variableSlotInfo)
 {
     storage.WriteString(FieldCode.VariableSlotInfoVar, variableSlotInfo.Variable);
     storage.WriteInteger(FieldCode.VariableSlotInfoLine, variableSlotInfo.Line);
     storage.WriteUnsignedInteger(FieldCode.VariableSlotInfoSlotId, variableSlotInfo.SlotId);
     return(true);
 }
        public void Test1NullObject()
        {
            //1 null object, not equal
            uint slotId = 0x30000001;

            VariableSlotInfo varSlotInfo1 = new VariableSlotInfo("a", 2, slotId);
            VariableSlotInfo varSlotInfo2 = new VariableSlotInfo();
            Assert.AreNotEqual(varSlotInfo1, varSlotInfo2);
        }
        public void TestArgumentValidation()
        {
            Assert.Throws<ArgumentException>(() =>
            {
                VariableSlotInfo v = new VariableSlotInfo("variable", -100, 0x01);
            });

            Assert.Throws<ArgumentException>(() =>
            {
                VariableSlotInfo v = new VariableSlotInfo("", 100, 0x01);
            });

            // null, invalid slot id
        }
Example #5
0
        public void TestConstructor3()
        {
            string code = "a[1][2] = 1;";
            Dictionary<int, List<VariableLine>> unboundIdentifiers = null;
            List<ProtoCore.AST.Node> astNodes = null;
            GraphUtilities.ParseCodeBlockNodeStatements(code, unboundIdentifiers, out astNodes);

            Ui.Statement statement = new Ui.Statement(astNodes[0]);

            VariableSlotInfo outputExpression = new VariableSlotInfo("a[1][2].x[2].p", 1, uint.MaxValue);
            Assert.AreEqual("a", statement.DefinedVariable);
            Assert.AreEqual(outputExpression, statement.OutputExpression);
            Assert.AreEqual(0, statement.References.Count);
            Assert.AreEqual(0, statement.Children.Count);
            Assert.AreEqual(false, statement.IsSwappable);
            Assert.AreEqual(false, statement.IsComplex);
        }
        public void TestCapitalLetter()
        {
            uint slotId = 0x30000001;

            //diff name, same line not equal
            VariableSlotInfo varSlotInfo1 = new VariableSlotInfo("VARIablE", 123312, slotId);
            VariableSlotInfo varSlotInfo2 = new VariableSlotInfo("variable1", 123312, slotId);
            Assert.AreNotEqual(varSlotInfo1, varSlotInfo2);
            //same name, same line, equal
            varSlotInfo1 = new VariableSlotInfo("VARIablE", 123312, slotId);
            varSlotInfo2 = new VariableSlotInfo("VARIablE", 123312, slotId);
            Assert.AreEqual(varSlotInfo1, varSlotInfo2);
            //same name, diff line, not equal
            varSlotInfo1 = new VariableSlotInfo("VARIablE", 123312, slotId);
            varSlotInfo2 = new VariableSlotInfo("VARIablE", 68678, slotId);
            Assert.AreNotEqual(varSlotInfo1, varSlotInfo2);
        }
Example #7
0
 private bool WriteVariableSlotInfo(IStorage storage, VariableSlotInfo variableSlotInfo)
 {
     storage.WriteString(FieldCode.VariableSlotInfoVar, variableSlotInfo.Variable);
     storage.WriteInteger(FieldCode.VariableSlotInfoLine, variableSlotInfo.Line);
     storage.WriteUnsignedInteger(FieldCode.VariableSlotInfoSlotId, variableSlotInfo.SlotId);
     return true;
 }
Example #8
0
        private void Initialize(BinaryExpressionNode binaryExpressionNode)
        {
            this.definedVariable = GetTopLevelVariable(binaryExpressionNode.LeftNode);
            this.outputExpression = GetOutputExpression(binaryExpressionNode.LeftNode);
            AddReferencesFromAst(binaryExpressionNode.RightNode);

            UpdateSwappableFlag(binaryExpressionNode);
            UpdateComplexFlag(binaryExpressionNode);
        }
Example #9
0
        public void TestDeserialize1()
        {
            string code = "a=1;";
            Dictionary<int, List<VariableLine>> unboundIdentifiers = null;
            List<ProtoCore.AST.Node> astNodes = null;
            GraphUtilities.ParseCodeBlockNodeStatements(code, unboundIdentifiers, out astNodes);

            Ui.Statement statement = new Ui.Statement(astNodes[0]);

            IStorage storage = new BinaryStorage();
            statement.Serialize(storage);
            Ui.Statement newStatement = new Ui.Statement(storage);
            storage.Seek(0, SeekOrigin.Begin);
            newStatement.Deserialize(storage);

            VariableSlotInfo outputExpression = new VariableSlotInfo("a", 1, uint.MaxValue);
            Assert.AreEqual("a", statement.DefinedVariable);
            Assert.AreEqual(outputExpression, statement.OutputExpression);
            Assert.AreEqual(0, statement.References.Count);
            Assert.AreEqual(0, statement.Children.Count);
            Assert.AreEqual(false, statement.IsSwappable);
            Assert.AreEqual(false, statement.IsComplex);
        }
Example #10
0
 private bool Equals(VariableSlotInfo other)
 {
     return((this.variable == other.variable) && (this.line == other.line) && (this.slotId == other.slotId));
 }
        public void TestEqual()
        {
            //same name, same line, equal
            IdGenerator idGenerator = new IdGenerator();
            uint slotId = idGenerator.GetNextId(ComponentType.Slot);

            VariableSlotInfo varSlotInfo1 = new VariableSlotInfo("a", 1, slotId);
            VariableSlotInfo varSlotInfo2 = new VariableSlotInfo("a", 1, slotId);
            Assert.AreEqual(varSlotInfo1, varSlotInfo2);
        }
 public void TestNullObject()
 {
     //2 null object, equal
     VariableSlotInfo varSlotInfo1 = new VariableSlotInfo();
     VariableSlotInfo varSlotInfo2 = new VariableSlotInfo();
     Assert.AreEqual(varSlotInfo1, varSlotInfo2);
 }
        public void TestGetProperties()
        {
            uint slotId = 0x30000001;
            string varName = "a";
            int line = 123;
            VariableSlotInfo varSlotInfo = new VariableSlotInfo(varName, line, slotId);

            Assert.AreEqual(varName, varSlotInfo.Variable);
            Assert.AreEqual(line, varSlotInfo.Line);
            Assert.AreEqual(slotId, varSlotInfo.SlotId);
        }
Example #14
0
        public virtual bool Deserialize(IStorage storage)
        {
            if (storage == null)
                throw new ArgumentNullException("storage (58D0A328653F)"); // @TODO(done): GUID?
            if (storage.ReadUnsignedInteger(FieldCode.StatementSignature) != Configurations.StatementSignature)
                throw new InvalidOperationException("Invalid input data (8404892D29B6)"); // @TODO(done): GUID?

            this.flags = (Flags)storage.ReadInteger(FieldCode.StatementFlag);
            this.definedVariable = storage.ReadString(FieldCode.DefinedVariable);
            this.outputExpression = ReadVariableSlotInfo(storage);

            this.references.Clear();
            int referenceCount = storage.ReadInteger(FieldCode.ReferencesCount);
            for (int i = 0; i < referenceCount; i++)
                this.references.Add(ReadVariableSlotInfo(storage));

            // @TODO(Sean): Write Serialize/Deserialize test cases with and without children.
            this.children.Clear();
            int childrenCount = storage.ReadInteger(FieldCode.ChildrenCount);
            for (int i = 0; i < childrenCount; i++)
                this.children.Add(new Statement(storage));

            return true;
        }
 public void TestDifferentNameLine()
 {
     //diff name, diff line, not equal
     uint slotId = 0x30000001;
     VariableSlotInfo varSlotInfo1 = new VariableSlotInfo("a", 2, slotId);
     VariableSlotInfo varSlotInfo2 = new VariableSlotInfo("b", 1, slotId);
     Assert.AreNotEqual(varSlotInfo1, varSlotInfo2);
 }
Example #16
0
 private bool Equals(VariableSlotInfo other)
 {
     return (this.variable == other.variable) && (this.line == other.line) && (this.slotId == other.slotId);
 }
        public void TestDifferentSlot()
        {
            uint slotId1 = 0x30000001;
            uint slotId2 = 0x30000002;

            VariableSlotInfo varSlotInfo1 = new VariableSlotInfo("a", 1, slotId1);
            VariableSlotInfo varSlotInfo2 = new VariableSlotInfo("a", 1, slotId2);
            Assert.AreNotEqual(varSlotInfo1, varSlotInfo2);
        }