public void NotEqualOperatorShould_Work_For_Unequal_Protocol_Lines() { ProtocolLine pl1 = new ProtocolLine("Set;tagPath1;tagValue1;192"); ProtocolLine pl2 = new ProtocolLine("Dummy;tagPath1;tagValue1;192"); Assert.IsTrue(pl1 != pl2); }
public void EqualsShould_Work_For_Equal_Protocol_Lines() { ProtocolLine pl1 = new ProtocolLine("Set;tagPath1;tagValue1;192"); ProtocolLine pl2 = new ProtocolLine("Set;tagPath1;tagValue1;192"); Assert.IsTrue(pl1.Equals(pl2)); }
public void EqualityOperatorShould_Work_OK_For_Protocol_Lines() { ProtocolLine pl1 = new ProtocolLine("Set;tagPath1;tagValue1;192"); ProtocolLine pl2 = new ProtocolLine("Set;tagPath1;tagValue1;192"); Assert.IsTrue(pl1 == pl2); }
public void ConstructorShould_Parse_Valid_Protocol_Line_With_Blanks() { ProtocolLine protocolLine = new ProtocolLine("Set; tagPath; tagValue; 192"); Assert.AreEqual(ProtocolLine.Actions.Set, protocolLine.Action); Assert.AreEqual("tagPath", protocolLine.TagPath); Assert.AreEqual("tagValue", protocolLine.TagValue); Assert.AreEqual("192", protocolLine.TagQualityInt); }
public void ProtocolLine_ToString() { ProtocolLine line = ProtocolLine.Parse ( "DBN=IBIS#MFN=2#AUTOIN=#UPDATE=0#STATUS=8#UPDUF=0#" ); Assert.AreEqual ( "DBN=IBIS#MFN=2#AUTOIN=#UPDATE=0#STATUS=8#UPDUF=0#", line.ToString() ); }
public void ProtocolLine_Construction() { ProtocolLine line = new ProtocolLine(); Assert.AreEqual(false, line.Success); Assert.AreEqual(null, line.Database); Assert.AreEqual(0, line.Mfn); Assert.AreEqual(null, line.Update); Assert.AreEqual(null, line.Status); Assert.AreEqual(null, line.Error); Assert.AreEqual(null, line.UpdUf); Assert.AreEqual(null, line.Text); }
public void ProtocolLine_Parse2() { ProtocolLine line = ProtocolLine.Parse ( "DBN=IBIS#MFN=4#GBL_ERROR=-605" ); Assert.AreEqual(false, line.Success); Assert.AreEqual("IBIS", line.Database); Assert.AreEqual(4, line.Mfn); Assert.AreEqual(null, line.Update); Assert.AreEqual(null, line.Status); Assert.AreEqual("-605", line.Error); Assert.AreEqual(null, line.UpdUf); Assert.AreEqual("DBN=IBIS#MFN=4#GBL_ERROR=-605", line.Text); }
public void ProtocolLine_Parse1() { ProtocolLine line = ProtocolLine.Parse ( "DBN=IBIS#MFN=2#AUTOIN=#UPDATE=0#STATUS=8#UPDUF=0#" ); Assert.AreEqual(true, line.Success); Assert.AreEqual("IBIS", line.Database); Assert.AreEqual(2, line.Mfn); Assert.AreEqual("0", line.Update); Assert.AreEqual("8", line.Status); Assert.AreEqual(null, line.Error); Assert.AreEqual("0", line.UpdUf); Assert.AreEqual("DBN=IBIS#MFN=2#AUTOIN=#UPDATE=0#STATUS=8#UPDUF=0#", line.Text); }
public void EqualsShould_Work_For_UnEqual_Protocol_Lines() { ProtocolLine pl1 = new ProtocolLine("Set;tagPath1;tagValue1;192"); ProtocolLine pl2 = new ProtocolLine("Dummy;tagPath1;tagValue1;192"); Assert.IsFalse(pl1.Equals(pl2)); pl2 = new ProtocolLine("Set;tagPath2;tagValue1;192"); Assert.IsFalse(pl1.Equals(pl2)); pl2 = new ProtocolLine("Set;tagPath1;tagValue2;192"); Assert.IsFalse(pl1.Equals(pl2)); pl2 = new ProtocolLine("Set;tagPath1;tagValue1;0"); Assert.IsFalse(pl1.Equals(pl2)); pl2 = new ProtocolLine("Dummy;tagPath1;tagValue1;0"); Assert.IsFalse(pl1.Equals(pl2)); }
public void DummyShould_Be_A_Valid_Contructor_Parameter() { ProtocolLine protocolLine = new ProtocolLine("Dummy"); }
public void InvalidLineShould_Cause_An_IndexOutOfRangeException() { ProtocolLine protocolLine = new ProtocolLine("Set; tagPath; tagValue"); }
public void UnknownActionShould_Cause_A_ProtocolActionException() { ProtocolLine protocolLine = new ProtocolLine("UnSet; tagPath; tagValue; 192"); }
public void EmptyProtocolLineShould_Cause_An_ArgumentExceptionn() { ProtocolLine protocolLine = new ProtocolLine(string.Empty); }
public void WhitespacesOnlyProtocolLineShould_Cause_An_ArgumentException() { ProtocolLine protocolLine = new ProtocolLine(" \t"); }
public void ToStringWithoutParametersShould_Produce_Semicolon_Separated_String() { ProtocolLine protocolLine = new ProtocolLine("Set;tagPath;tagValue;192"); Assert.AreEqual("Set;tagPath;tagValue;192", protocolLine.ToString()); }
static Dictionary <string, object> ReadRecursive(List <ProtocolLine> lines, MessageReader reader) { Dictionary <string, object> result = new Dictionary <string, object>(); Dictionary <string, ushort> offsets = new Dictionary <string, ushort>(); Dictionary <string, ushort> counts = new Dictionary <string, ushort>(); ProtocolLine prevProtoLine = null; if (lines.Count == 0) { return(result); } int baseIndent = lines[0].Indent; //Read meta information for (int lineCounter = 0; lineCounter < lines.Count; lineCounter++) { if (lines[lineCounter].Indent != baseIndent) { continue; } ushort offset, count; switch (lines[lineCounter].Term) { case ProtocolTerm.STRING: offset = reader.ReadUInt16(); offsets.Add(lines[lineCounter].Name, offset); break; case ProtocolTerm.ARRAY: count = reader.ReadUInt16(); counts.Add(lines[lineCounter].Name, count); offset = reader.ReadUInt16(); offsets.Add(lines[lineCounter].Name, offset); break; case ProtocolTerm.BYTES: offset = reader.ReadUInt16(); offsets.Add(lines[lineCounter].Name, offset); count = reader.ReadUInt16(); counts.Add(lines[lineCounter].Name, count); break; } } //Read content for (int lineCounter = 0; lineCounter < lines.Count; lineCounter++) { object value = null; ProtocolLine line = lines[lineCounter]; switch (line.Term) { case ProtocolTerm.INT32: value = reader.ReadInt32(); break; case ProtocolTerm.UINT32: value = reader.ReadUInt32(); break; case ProtocolTerm.INT64: value = reader.ReadInt64(); break; case ProtocolTerm.UINT64: value = reader.ReadUInt64(); break; case ProtocolTerm.INT16: value = reader.ReadInt16(); break; case ProtocolTerm.UINT16: value = reader.ReadUInt16(); break; case ProtocolTerm.FLOAT: value = reader.ReadSingle(); break; case ProtocolTerm.BYTE: value = reader.ReadByte(); break; case ProtocolTerm.BOOL: value = reader.ReadBoolean(); break; case ProtocolTerm.SKILLID: value = new SkillId(reader.ReadUInt64()); break; case ProtocolTerm.VEC3: case ProtocolTerm.VEC3FA: value = reader.ReadVector3f(); break; case ProtocolTerm.ANGLE: value = reader.ReadAngle(); break; case ProtocolTerm.STRING: ushort soffset; if (!offsets.TryGetValue(line.Name, out soffset)) { throw new FormatException(); } if (soffset == 0) { continue; } reader.BaseStream.Position = soffset - 4; value = reader.ReadTeraString(); break; case ProtocolTerm.BYTES: ushort boffset; ushort bcount; if (!offsets.TryGetValue(line.Name, out boffset) || !counts.TryGetValue(line.Name, out bcount)) { throw new FormatException(); } if (boffset == 0 || bcount == 0) { continue; } reader.BaseStream.Position = boffset - 4; value = reader.ReadBytes(bcount); break; case ProtocolTerm.ARRAY: ushort aoffset = 0; ushort acount = 0; if (!offsets.TryGetValue(line.Name, out aoffset) || !counts.TryGetValue(line.Name, out acount)) { throw new FormatException(); } var innerBlock = lines.Skip(lineCounter + 1).TakeWhile(l => l.Indent > line.Indent).ToList(); lineCounter += innerBlock.Count; if (aoffset == 0 || acount == 0) { continue; } value = new List <object>(); for (var arrayCounter = 0; arrayCounter < acount; arrayCounter++) { reader.BaseStream.Position = aoffset - 4; var pointer = reader.ReadUInt16(); if (pointer != aoffset) { throw new FormatException(); } ushort nextOffset = reader.ReadUInt16(); (value as List <object>).Add(ReadRecursive(innerBlock, reader)); ////// aoffset = nextOffset; } break; } if (value != null) { result.Add(line.Name, value); } } return(result); }