Ejemplo n.º 1
0
        protected void AssertMarshalBooleans(int count, GetBooleanValueDelegate valueDelegate)
        {
            BooleanStream bs = new BooleanStream();

            for (int i = 0; i < count; i++)
            {
                bs.WriteBoolean(valueDelegate(i, count));
            }
            MemoryStream buffer = new MemoryStream();
            BinaryWriter ds     = new OpenWireBinaryWriter(buffer);

            bs.Marshal(ds);
            ds.Write(endOfStreamMarker);

            // now lets read from the stream

            MemoryStream ins = new MemoryStream(buffer.ToArray());
            BinaryReader dis = new OpenWireBinaryReader(ins);

            bs = new BooleanStream();
            bs.Unmarshal(dis);

            for (int i = 0; i < count; i++)
            {
                bool expected = valueDelegate(i, count);

                try
                {
                    bool actual = bs.ReadBoolean();
                    Assert.AreEqual(expected, actual);
                }
                catch (Exception e)
                {
                    Assert.Fail(
                        "Failed to parse bool: " + i + " out of: " + count + " due to: " + e);
                }
            }
            int marker = dis.ReadInt32();

            Assert.AreEqual(
                endOfStreamMarker, marker, "did not match: " + endOfStreamMarker + " and " + marker);

            // lets try read and we should get an exception
            try
            {
                dis.ReadByte();
                Assert.Fail("Should have reached the end of the stream");
            }
            catch (IOException)
            {
            }
        }
Ejemplo n.º 2
0
                protected void AssertMarshalBooleans(int count, GetBooleanValueDelegate valueDelegate)
                {
                        BooleanStream bs = new BooleanStream();
                        for (int i = 0; i < count; i++)
                        {
                                bs.WriteBoolean(valueDelegate(i, count));
                        }
                        MemoryStream buffer = new MemoryStream();
                        BinaryWriter ds = new OpenWireBinaryWriter(buffer);
                        bs.Marshal(ds);
                        ds.Write(endOfStreamMarker);

                        // now lets read from the stream

                        MemoryStream ins = new MemoryStream(buffer.ToArray());
                        BinaryReader dis = new OpenWireBinaryReader(ins);
                        bs = new BooleanStream();
                        bs.Unmarshal(dis);

                        for (int i = 0; i < count; i++)
                        {
                                bool expected = valueDelegate(i, count);

                                try
                                {
                                        bool actual = bs.ReadBoolean();
                                        Assert.AreEqual(expected, actual);
                                }
                                catch (Exception e)
                                {
                                        Assert.Fail(
                                                "Failed to parse bool: " + i + " out of: " + count + " due to: " + e);
                                }
                        }
                        int marker = dis.ReadInt32();
                        Assert.AreEqual(
                                endOfStreamMarker, marker, "did not match: " + endOfStreamMarker + " and " + marker);

                        // lets try read and we should get an exception
                        try
                        {
                                dis.ReadByte();
                                Assert.Fail("Should have reached the end of the stream");
                        }
                        catch (IOException)
                        {
                        }
                }