override public void Encode(ByteList bytes) { bytes.Add(ClassId); // Write out this class id first Int16 lengthPos = bytes.CurrentWritePosition; // Get the current write position, so we // can write the length here later bytes.Add((Int16)0); // Write out a place holder for the length base.Encode(bytes); // Encode the part of the object defined // by the base class bytes.AddObjects(ThrowingBrilliantStudentId, Bomb, TowardsSquare, EnablingTick); Int16 length = Convert.ToInt16(bytes.CurrentWritePosition - lengthPos - 2); bytes.WriteInt16To(lengthPos, length); // Write out the length of this object }
override public void Encode(ByteList bytes) { bytes.Add(ClassId); // Write out this class id first Int16 lengthPos = bytes.CurrentWritePosition; // Get the current write position, so we // can write the length here later bytes.Add((Int16)0); // Write out a place holder for the length base.Encode(bytes); // Encode the part of the object defined // by the base class bytes.AddObjects(GameId, Convert.ToByte(GetResourceType), EnablingTick); Int16 length = Convert.ToInt16(bytes.CurrentWritePosition - lengthPos - 2); bytes.WriteInt16To(lengthPos, length); // Write out the length of this object }
public void Bomb_CheckEncodeAndDecode() { Tick t1 = new Tick(); List <Excuse> eList = new List <Excuse> { CreateExcuse(10), CreateExcuse(11), CreateExcuse(12) }; List <WhiningTwine> wtList = new List <WhiningTwine> { CreateTwine(20), CreateTwine(21), CreateTwine(22) }; Bomb b1 = new Bomb(1, eList, wtList, t1); Assert.AreEqual(1, b1.CreatorId); Assert.AreSame(eList, b1.Excuses); Assert.AreSame(wtList, b1.Twine); Assert.AreSame(t1, b1.BuiltOnTick); ByteList bytes = new ByteList(); b1.Encode(bytes); Bomb b2 = Bomb.Create(bytes); Assert.AreEqual(b1.CreatorId, b2.CreatorId); Assert.AreEqual(b1.Excuses.Count, b2.Excuses.Count); Assert.AreEqual(b1.Twine.Count, b2.Twine.Count); Assert.AreEqual(b1.BuiltOnTick.LogicalClock, b2.BuiltOnTick.LogicalClock); Assert.AreEqual(b1.BuiltOnTick.HashCode, b2.BuiltOnTick.HashCode); bytes.Clear(); b1.Encode(bytes); bytes.GetByte(); // Read one byte, which will throw the length off try { b2 = Bomb.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } bytes.Clear(); b1.Encode(bytes); bytes.Add((byte)100); // Add a byte bytes.GetByte(); // Read one byte, which will make the ID wrong try { b2 = Bomb.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } }
override public void Encode(ByteList bytes) { bytes.Add(ClassId); // Write out this class id first Int16 lengthPos = bytes.CurrentWritePosition; // Get the current write position, so we // can write the length here later bytes.Add((Int16)0); // Write out a place holder for the length base.Encode(bytes); // Encode stuff from base class if (Message == null) { Message = string.Empty; } bytes.AddObjects(IntResult, ObjResult, Message); Int16 length = Convert.ToInt16(bytes.CurrentWritePosition - lengthPos - 2); bytes.WriteInt16To(lengthPos, length); // Write out the length of this object }
internal byte[] GetHandshakeBytes() { using (var content = new ByteList()) { // Magic number and packet size (0x20 = 32 bytes since there is no payload) content.Add(0x21, 0x31, 0, 0x20); // Fill up the rest of the 32 bytes with 0xff content.Repeat(0xff, 28, 4); return(content.ToBinaryASCIIArray()); } }
public void TickTester_CheckEncodeDecode() { Tick tick1 = new Tick(10); tick1.LogicalClock = 100; ByteList bytes = new ByteList(); tick1.Encode(bytes); Tick tick2 = Tick.Create(bytes); Assert.AreEqual(10, tick1.ForAgentId); Assert.AreEqual(tick1.LogicalClock, tick2.LogicalClock); tick1.LogicalClock = 0; bytes = new ByteList(); tick1.Encode(bytes); tick2 = Tick.Create(bytes); Assert.AreEqual(tick1.LogicalClock, tick2.LogicalClock); tick1.LogicalClock = Int32.MaxValue; bytes = new ByteList(); tick1.Encode(bytes); tick2 = Tick.Create(bytes); Assert.AreEqual(tick1.ForAgentId, tick1.ForAgentId); Assert.AreEqual(tick1.LogicalClock, tick2.LogicalClock); bytes.Clear(); tick1.Encode(bytes); bytes.GetByte(); // Read one byte, which will throw the length off try { tick2 = Tick.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } bytes.Clear(); tick1.Encode(bytes); bytes.Add((byte)100); // Add a byte bytes.GetByte(); // Read one byte, which will make the ID wrong try { tick2 = Tick.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } }
public void AckNak_CheckEncodeDecode() { Tick t1 = new Tick(); AckNak m1 = new AckNak(Reply.PossibleStatus.Success, 10, t1, "Test Message", "Test Note"); Assert.AreEqual(Reply.PossibleTypes.AckNak, m1.ReplyType); Assert.AreEqual(Reply.PossibleStatus.Success, m1.Status); Assert.AreEqual(10, m1.IntResult); Assert.AreSame(t1, m1.ObjResult); Assert.AreEqual("Test Message", m1.Message); Assert.AreEqual("Test Note", m1.Note); ByteList bytes = new ByteList(); m1.Encode(bytes); AckNak m2 = AckNak.Create(bytes); Assert.AreEqual(m1.Status, m2.Status); Assert.AreEqual(m1.IntResult, m2.IntResult); Assert.AreEqual(((Tick)m1.ObjResult).LogicalClock, ((Tick)m2.ObjResult).LogicalClock); Assert.AreEqual(m1.Message, m2.Message); Assert.AreEqual(m1.Note, m2.Note); bytes.Clear(); m1.Encode(bytes); bytes.GetByte(); // Read one byte, which will throw the length off try { m2 = AckNak.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } bytes.Clear(); m1.Encode(bytes); bytes.Add((byte)100); // Add a byte bytes.GetByte(); // Read one byte, which will make the ID wrong try { m2 = AckNak.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } }
public void AgentList_CheckEncodeAndDecode() { AgentInfo info1 = new AgentInfo(10, AgentInfo.PossibleAgentType.ExcuseGenerator); AgentInfo info2 = new AgentInfo(11, AgentInfo.PossibleAgentType.WhiningSpinner); AgentInfo info3 = new AgentInfo(12, AgentInfo.PossibleAgentType.BrilliantStudent); AgentList list1 = new AgentList(); list1.Add(info1); list1.Add(info2); list1.Add(info3); ByteList bytes = new ByteList(); list1.Encode(bytes); AgentList list2 = AgentList.Create(bytes); Assert.AreEqual(3, list2.Count); Assert.AreEqual(10, list2[0].Id); Assert.AreEqual(11, list2[1].Id); Assert.AreEqual(12, list2[2].Id); bytes.Clear(); list1.Encode(bytes); bytes.GetByte(); // Read one byte, which will throw the length off try { list2 = AgentList.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } bytes.Clear(); list1.Encode(bytes); bytes.Add((byte)100); // Add a byte bytes.GetByte(); // Read one byte, which will make the ID wrong try { list2 = AgentList.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } }
public void JoinGame_EncodingAndDecoding() { AgentInfo agentInfo = new AgentInfo(1001, AgentInfo.PossibleAgentType.BrilliantStudent) { ANumber = "A0001", FirstName = "Joe", LastName = "Jone" }; JoinGame jg1 = new JoinGame(10, agentInfo); Assert.AreEqual(10, jg1.GameId); Assert.AreSame(agentInfo, jg1.AgentInfo); ByteList bytes = new ByteList(); jg1.Encode(bytes); JoinGame jg2 = JoinGame.Create(bytes); Assert.AreEqual(jg1.GameId, jg2.GameId); bytes.Clear(); jg1.Encode(bytes); bytes.GetByte(); // Read one byte, which will throw the length off try { jg2 = JoinGame.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } bytes.Clear(); jg1.Encode(bytes); bytes.Add((byte)100); // Add a byte bytes.GetByte(); // Read one byte, which will make the ID wrong try { jg2 = JoinGame.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } }
internal byte[] GetPayloadBytes() { if (_token == null) { throw new Exception("Token is missing"); } if (_deviceId == null) { throw new Exception("DeviceID is missing"); } // Encrypt the payload using the token var jsonBody = CreateJson(); var encryptedPayload = AESHelper.Encrypt(_token.Key, _token.InitializationVector, jsonBody); using (var content = new ByteList()) { // Create the header content.Add(0x21, 0x31); // Magic number content.WriteUInt16BE(32 + encryptedPayload.Length); // Content+header length content.Repeat(0x00, 4); // Unknown1 content.AddRange(_deviceId); // Device ID (received from handshake) // Add seconds passed to server timestamp var secondsPassed = (DateTime.Now - _serverStamp.ReceivedTime).TotalSeconds; // Write Stamp to payload content.WriteUInt32BE((UInt32)Math.Floor(_serverStamp.Timestamp + secondsPassed)); // Header is done and we have the payload and the token. We can now write the MD5 checksum // Get MD5 checksum of [header, token payload] content.AddRange(ByteList.Join(content.Take(16).ToArray(), _token.Token, encryptedPayload).ToMd5()); // Then add the encrypted payload itself content.AddRange(encryptedPayload); return(content.ToBinaryASCIIArray()); } }
public void EndPoint_CheckEncodeAndDecode() { Common.EndPoint ep1 = new Common.EndPoint(3255420, 3004); Assert.AreEqual(3255420, ep1.Address); Assert.AreEqual(3004, ep1.Port); ByteList bytes = new ByteList(); ep1.Encode(bytes); Common.EndPoint ep2 = Common.EndPoint.Create(bytes); Assert.AreEqual(ep1.Address, ep2.Address); Assert.AreEqual(ep1.Port, ep2.Port); bytes.Clear(); ep1.Encode(bytes); bytes.GetByte(); // Read one byte, which will throw the length off try { ep2 = Common.EndPoint.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } bytes.Clear(); ep1.Encode(bytes); bytes.Add((byte)100); // Add a byte bytes.GetByte(); // Read one byte, which will make the ID wrong try { ep2 = Common.EndPoint.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } }
public void PlayingFieldLayout_CheckEncodeAndDecode() { PlayingFieldLayout pfl1 = new PlayingFieldLayout(20, 30); Assert.AreEqual(20, pfl1.Width); Assert.AreEqual(30, pfl1.Height); Assert.IsNotNull(pfl1.SidewalkSquares); List <FieldLocation> flList = new List <FieldLocation> { new FieldLocation(1, 1), new FieldLocation(2, 1) }; pfl1.SidewalkSquares = flList; Assert.AreSame(flList, pfl1.SidewalkSquares); ByteList bytes = new ByteList(); pfl1.Encode(bytes); PlayingFieldLayout pfl2 = PlayingFieldLayout.Create(bytes); Assert.AreEqual(pfl1.Width, pfl2.Width); Assert.AreEqual(pfl1.Height, pfl2.Height); Assert.IsNotNull(pfl2.SidewalkSquares); Assert.AreEqual(pfl1.SidewalkSquares.Count, pfl1.SidewalkSquares.Count); bytes.Clear(); pfl1.Encode(bytes); bytes.GetByte(); // Read one byte, which will throw the length off try { pfl2 = PlayingFieldLayout.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } bytes.Clear(); pfl1.Encode(bytes); bytes.Add((byte)100); // Add a byte bytes.GetByte(); // Read one byte, which will make the ID wrong try { pfl2 = PlayingFieldLayout.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } pfl1 = new PlayingFieldLayout(100, 100); SetUpSidewalks(pfl1); Assert.AreEqual(100, pfl1.Width); Assert.AreEqual(100, pfl1.Height); Assert.IsNotNull(pfl1.SidewalkSquares); bytes = new ByteList(); pfl1.Encode(bytes); pfl2 = PlayingFieldLayout.Create(bytes); Assert.AreEqual(pfl1.Width, pfl2.Width); Assert.AreEqual(pfl1.Height, pfl2.Height); Assert.IsNotNull(pfl2.SidewalkSquares); Assert.AreEqual(pfl1.SidewalkSquares.Count, pfl1.SidewalkSquares.Count); pfl1 = new PlayingFieldLayout(200, 300); SetUpSidewalks(pfl1); Assert.AreEqual(200, pfl1.Width); Assert.AreEqual(300, pfl1.Height); Assert.IsNotNull(pfl1.SidewalkSquares); bytes = new ByteList(); pfl1.Encode(bytes); pfl2 = PlayingFieldLayout.Create(bytes); Assert.AreEqual(pfl1.Width, pfl2.Width); Assert.AreEqual(pfl1.Height, pfl2.Height); Assert.IsNotNull(pfl2.SidewalkSquares); Assert.AreEqual(pfl1.SidewalkSquares.Count, pfl1.SidewalkSquares.Count); }
/////////////////////////////////////////////////////////////////////////////////////////////// private void TranslateEndOfLine( StreamDirection direction, ByteList inputList, ref ByteList outputList ) { // // NOTE: We require the underlying stream to be valid because we use it to // perform the configured end-of-line transformations. // if (stream != null) { // // NOTE: Is the input list valid? // if (inputList != null) { // // NOTE: How many bytes are in the list? // int inputCount = inputList.Count; if (inputCount > 0) { // // NOTE: Copy the input list to the input buffer because the underlying // stream transform works on buffers, not lists. // byte[] inputBuffer = inputList.ToArray(); // // NOTE: Allocate an output buffer of equal length to the input buffer // because the underlying stream transform works on buffers, not // lists. // byte[] outputBuffer = new byte[inputCount]; // // NOTE: Use the underlying stream to perform the actual end-of-line // transformations via the buffers we have prepared. If the stream // direction is neither Input only nor Output only, we do nothing. // int outputCount = Count.Invalid; if (direction == StreamDirection.Output) { outputCount = stream.TranslateOutputEndOfLine( inputBuffer, outputBuffer, 0, inputCount); } else if (direction == StreamDirection.Input) { outputCount = stream.TranslateInputEndOfLine( inputBuffer, outputBuffer, 0, inputCount); } // // NOTE: Did we transform anything? // if (outputCount != Count.Invalid) { // // NOTE: Finally, set the caller's output list to the contents of the // resulting [transformed] output buffer. We have to manually // copy the bytes into the resulting output list because we may // not need all the bytes in the output buffer. // outputList = new ByteList(outputCount); for (int outputIndex = 0; outputIndex < outputCount; outputIndex++) { outputList.Add(outputBuffer[outputIndex]); } } } else { // // NOTE: Garbage in, garbage out. Empty list to empty list. // outputList = new ByteList(); } } else { // // NOTE: Garbage in, garbage out. Null list to null list. // outputList = null; } } }
public void GameConfiguration_CheckEncodeAndDecode() { GameConfiguration gc1 = new GameConfiguration(); gc1.PlayingFieldWidth = 50; gc1.PlayingFieldHeight = 51; gc1.BrilliantStudentRegistrationMin = 10; gc1.BrilliantStudentRegistrationMax = 11; gc1.BrilliantStudentInitialStrength = 2.1F; gc1.BrilliantStudentBaseSpeed = 2.2F; gc1.BrilliantStudentSidewalkSpeedMultiplier = 2.3F; gc1.BrilliantStudentDeathToZombieDelay = 2.4F; gc1.ExcuseGeneratorRegistrationMin = 12; gc1.ExcuseGeneratorRegistrationMax = 13; gc1.ExcuseGeneratorInitialStrength = 2.5F; gc1.NumberOfTicksRequiredToBuildTwine = 3; gc1.WhiningSpinnerRegistrationMin = 14; gc1.WhiningSpinnerRegistrationMax = 15; gc1.WhiningSpinnerInitialStrength = 2.8F; gc1.NumberOfTicksRequiredToBuildTwine = 2; gc1.ZombieInitialStrengthMin = 16; gc1.ZombieInitialStrengthMax = 17; gc1.ZombieInitialSpeedMax = 3.1F; gc1.ZombieInitialSpeedMin = 3.2F; gc1.ZombieSidewalkSpeedMultiplier = 3.3F; gc1.ZombieCreationRate = 3.4F; gc1.ZombieCreationAcceleration = 3.5F; gc1.ZombieEatingRate = 3.6F; gc1.ZombieStrengthIncreaseForEatingStudent = 3.7F; gc1.ZombieStrengthIncreaseForExcuseGenerator = 3.8F; gc1.ZombieStrengthIncreaseForWhiningSpinner = 3.9F; gc1.MaxEatingDistance = 0.5F; gc1.MaxEatingDistance = 4.5F; gc1.RefereeRegistrationMin = 22; gc1.RefereeRegistrationMax = 23; gc1.BombExcuseDamage = 18; gc1.BombTwinePerSquareOfDistance = 4.0F; gc1.BombDamageDiffusionFactor = 4.1F; gc1.TickLifetime = 19; gc1.TicksToStrengthRatio = 4.2F; ByteList bytes = new ByteList(); gc1.Encode(bytes); GameConfiguration gc2 = GameConfiguration.Create(bytes); Assert.AreEqual(gc1.PlayingFieldWidth, gc2.PlayingFieldWidth); Assert.AreEqual(gc1.PlayingFieldHeight, gc2.PlayingFieldHeight); Assert.AreEqual(gc1.BrilliantStudentRegistrationMin, gc2.BrilliantStudentRegistrationMin); Assert.AreEqual(gc1.BrilliantStudentRegistrationMax, gc2.BrilliantStudentRegistrationMax); Assert.AreEqual(gc1.BrilliantStudentInitialStrength, gc2.BrilliantStudentInitialStrength); Assert.AreEqual(gc1.BrilliantStudentBaseSpeed, gc2.BrilliantStudentBaseSpeed); Assert.AreEqual(gc1.BrilliantStudentSidewalkSpeedMultiplier, gc2.BrilliantStudentSidewalkSpeedMultiplier); Assert.AreEqual(gc1.BrilliantStudentDeathToZombieDelay, gc2.BrilliantStudentDeathToZombieDelay); Assert.AreEqual(gc1.ExcuseGeneratorRegistrationMin, gc2.ExcuseGeneratorRegistrationMin); Assert.AreEqual(gc1.ExcuseGeneratorRegistrationMax, gc2.ExcuseGeneratorRegistrationMax); Assert.AreEqual(gc1.ExcuseGeneratorInitialStrength, gc2.ExcuseGeneratorInitialStrength); Assert.AreEqual(gc1.NumberOfTicksRequiredToBuildAnExcuse, gc2.NumberOfTicksRequiredToBuildAnExcuse); Assert.AreEqual(gc1.WhiningSpinnerRegistrationMin, gc2.WhiningSpinnerRegistrationMin); Assert.AreEqual(gc1.WhiningSpinnerRegistrationMax, gc2.WhiningSpinnerRegistrationMax); Assert.AreEqual(gc1.WhiningSpinnerInitialStrength, gc2.WhiningSpinnerInitialStrength); Assert.AreEqual(gc1.NumberOfTicksRequiredToBuildTwine, gc2.NumberOfTicksRequiredToBuildTwine); Assert.AreEqual(gc1.ZombieInitialStrengthMin, gc2.ZombieInitialStrengthMin); Assert.AreEqual(gc1.ZombieInitialStrengthMax, gc2.ZombieInitialStrengthMax); Assert.AreEqual(gc1.ZombieInitialSpeedMax, gc2.ZombieInitialSpeedMax); Assert.AreEqual(gc1.ZombieInitialSpeedMin, gc2.ZombieInitialSpeedMin); Assert.AreEqual(gc1.ZombieSidewalkSpeedMultiplier, gc2.ZombieSidewalkSpeedMultiplier); Assert.AreEqual(gc1.ZombieCreationRate, gc2.ZombieCreationRate); Assert.AreEqual(gc1.ZombieCreationAcceleration, gc2.ZombieCreationAcceleration); Assert.AreEqual(gc1.ZombieEatingRate, gc2.ZombieEatingRate); Assert.AreEqual(gc1.ZombieStrengthIncreaseForEatingStudent, gc2.ZombieStrengthIncreaseForEatingStudent); Assert.AreEqual(gc1.ZombieStrengthIncreaseForExcuseGenerator, gc2.ZombieStrengthIncreaseForExcuseGenerator); Assert.AreEqual(gc1.ZombieStrengthIncreaseForWhiningSpinner, gc2.ZombieStrengthIncreaseForWhiningSpinner); Assert.AreEqual(gc1.MinEatingDistance, gc2.MinEatingDistance); Assert.AreEqual(gc1.MaxEatingDistance, gc2.MaxEatingDistance); Assert.AreEqual(gc1.RefereeRegistrationMin, gc2.RefereeRegistrationMin); Assert.AreEqual(gc1.RefereeRegistrationMax, gc2.RefereeRegistrationMax); Assert.AreEqual(gc1.BombExcuseDamage, gc2.BombExcuseDamage); Assert.AreEqual(gc1.BombTwinePerSquareOfDistance, gc2.BombTwinePerSquareOfDistance); Assert.AreEqual(gc1.BombDamageDiffusionFactor, gc2.BombDamageDiffusionFactor); Assert.AreEqual(gc1.TickLifetime, gc2.TickLifetime); Assert.AreEqual(gc1.TicksToStrengthRatio, gc2.TicksToStrengthRatio); bytes.Clear(); gc1.Encode(bytes); bytes.GetByte(); // Read one byte, which will throw the length off try { gc2 = GameConfiguration.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } bytes.Clear(); gc1.Encode(bytes); bytes.Add((byte)100); // Add a byte bytes.GetByte(); // Read one byte, which will make the ID wrong try { gc2 = GameConfiguration.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } }
public void ByteList_WriteAndAddMethods() { ByteList myBytes = new ByteList(); // Case: Write out a boolean of True myBytes.Clear(); myBytes.Add(true); Assert.IsNotNull(myBytes); Assert.AreEqual(1, myBytes.Length); Assert.AreEqual(1, myBytes[0]); // Case: Write out a boolean of False myBytes.Clear(); myBytes.Add(false); Assert.IsNotNull(myBytes); Assert.AreEqual(1, myBytes.Length); Assert.AreEqual(0, myBytes[0]); // Case: Write out a Byte myBytes.Clear(); myBytes.Add((byte)4); Assert.IsNotNull(myBytes); Assert.AreEqual(1, myBytes.Length); Assert.AreEqual((byte)4, myBytes[0]); // Case: Write out a Char myBytes.Clear(); myBytes.Add('A'); Assert.IsNotNull(myBytes); Assert.AreEqual(2, myBytes.Length); Assert.AreEqual(65, myBytes[0]); Assert.AreEqual(0, myBytes[1]); // Case: Write out a Int16 myBytes.Clear(); myBytes.Add((Int16)7); Assert.IsNotNull(myBytes); Assert.AreEqual(2, myBytes.Length); Assert.AreEqual(0, myBytes[0]); Assert.AreEqual(7, myBytes[1]); // Case: Write out a Int16 myBytes.Clear(); myBytes.Add(Int16.MaxValue); Assert.IsNotNull(myBytes); Assert.AreEqual(2, myBytes.Length); Assert.AreEqual(127, myBytes[0]); Assert.AreEqual(255, myBytes[1]); // Case: Write out a Int32 myBytes.Clear(); myBytes.Add((Int32)7); Assert.IsNotNull(myBytes); Assert.AreEqual(4, myBytes.Length); for (int i = 0; i < 3; i++) { Assert.AreEqual(0, myBytes[i]); } Assert.AreEqual(7, myBytes[3]); // Case: Write out a Int32 myBytes.Clear(); myBytes.Add(Int32.MaxValue); Assert.IsNotNull(myBytes); Assert.AreEqual(4, myBytes.Length); Assert.AreEqual(127, myBytes[0]); for (int i = 1; i < 4; i++) { Assert.AreEqual(255, myBytes[i]); } // Case: Write out a Int64 myBytes.Clear(); myBytes.Add((Int64)7); Assert.IsNotNull(myBytes); Assert.AreEqual(8, myBytes.Length); for (int i = 0; i < 7; i++) { Assert.AreEqual(0, myBytes[i]); } Assert.AreEqual(7, myBytes[7]); // Case 7: Write out a Int64 myBytes.Clear(); myBytes.Add(Int64.MaxValue); Assert.IsNotNull(myBytes); Assert.AreEqual(8, myBytes.Length); Assert.AreEqual(127, myBytes[0]); for (int i = 1; i < 8; i++) { Assert.AreEqual(255, myBytes[i]); } // Case: Write out a Single Precision Real myBytes.Clear(); myBytes.Add((float)7.7); Assert.IsNotNull(myBytes); Assert.AreEqual(4, myBytes.Length); // Case: Write out a Double Precision Real myBytes.Clear(); myBytes.Add((float)7.7); Assert.IsNotNull(myBytes); Assert.AreEqual(4, myBytes.Length); // Case: Write out a Byte Array myBytes.Clear(); myBytes.Add(new byte[] { 1, 2, 3, 4, 5, 6 }); Assert.AreEqual(6, myBytes.Length); for (int i = 0; i < 6; i++) { Assert.AreEqual(i + 1, myBytes[i]); } // Case: Write out a string myBytes.Clear(); myBytes.Add((string)null); Assert.AreEqual(2, myBytes.Length); Assert.AreEqual(0, myBytes[0]); Assert.AreEqual(0, myBytes[1]); // Case: Write out a string myBytes.Clear(); myBytes.Add(string.Empty); Assert.AreEqual(2, myBytes.Length); Assert.AreEqual(0, myBytes[0]); Assert.AreEqual(0, myBytes[1]); // Case 11: Write out a string myBytes = new ByteList("abc"); Assert.AreEqual(2 + 2 * 3, myBytes.Length); Assert.AreEqual(0, myBytes[0]); Assert.AreEqual(2 * 3, myBytes[1]); // Note AddObjects and AddObject methods were tested with constructors }