コード例 #1
0
        public void TestReadOnlyBody()
        {
            ActiveMQStreamMessage message = new ActiveMQStreamMessage();

            try
            {
                message.WriteBoolean(true);
                message.WriteByte((byte)1);
                message.WriteBytes(new byte[1]);
                message.WriteBytes(new byte[3], 0, 2);
                message.WriteChar('a');
                message.WriteDouble(1.5);
                message.WriteSingle((float)1.5);
                message.WriteInt32(1);
                message.WriteInt64(1);
                message.WriteObject("stringobj");
                message.WriteInt16((short)1);
                message.WriteString("string");
            }
            catch (MessageNotWriteableException)
            {
                Assert.Fail("Should be writeable");
            }
            message.Reset();
            try
            {
                message.ReadBoolean();
                message.ReadByte();
                Assert.AreEqual(1, message.ReadBytes(new byte[10]));
                Assert.AreEqual(-1, message.ReadBytes(new byte[10]));
                Assert.AreEqual(2, message.ReadBytes(new byte[10]));
                Assert.AreEqual(-1, message.ReadBytes(new byte[10]));
                message.ReadChar();
                message.ReadDouble();
                message.ReadSingle();
                message.ReadInt32();
                message.ReadInt64();
                message.ReadString();
                message.ReadInt16();
                message.ReadString();
            }
            catch (MessageNotReadableException)
            {
                Assert.Fail("Should be readable");
            }
            try
            {
                message.WriteBoolean(true);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageNotWriteableException)
            {
            }
            try
            {
                message.WriteByte((byte)1);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageNotWriteableException)
            {
            }
            try
            {
                message.WriteBytes(new byte[1]);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageNotWriteableException)
            {
            }
            try
            {
                message.WriteBytes(new byte[3], 0, 2);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageNotWriteableException)
            {
            }
            try {
                message.WriteChar('a');
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageNotWriteableException)
            {
            }
            try
            {
                message.WriteDouble(1.5);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageNotWriteableException)
            {
            }
            try
            {
                message.WriteSingle((float)1.5);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageNotWriteableException)
            {
            }
            try
            {
                message.WriteInt32(1);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageNotWriteableException)
            {
            }
            try
            {
                message.WriteInt64(1);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageNotWriteableException)
            {
            }
            try
            {
                message.WriteObject("stringobj");
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageNotWriteableException)
            {
            }
            try
            {
                message.WriteSingle((short)1);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageNotWriteableException)
            {
            }
            try
            {
                message.WriteString("string");
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageNotWriteableException)
            {
            }
        }
コード例 #2
0
        public void TestReadDouble()
        {
            ActiveMQStreamMessage msg = new ActiveMQStreamMessage();

            double test = 4.4;

            msg.WriteDouble(test);
            msg.Reset();
            Assert.IsTrue(msg.ReadDouble() == test);
            msg.Reset();
            Assert.IsTrue(msg.ReadString() == (test).ToString());
            msg.Reset();
            try
            {
                msg.ReadBoolean();
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }
            msg.Reset();
            try
            {
                msg.ReadByte();
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }
            msg.Reset();
            try
            {
                msg.ReadInt16();
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }
            msg.Reset();
            try
            {
                msg.ReadInt32();
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }
            msg.Reset();
            try
            {
                msg.ReadInt64();
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }
            msg.Reset();
            try
            {
                msg.ReadSingle();
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }
            msg.Reset();
            try
            {
                msg.ReadChar();
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }
            msg.Reset();
            try
            {
                msg.ReadBytes(new byte[1]);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }
        }
コード例 #3
0
        public void TestReadString()
        {
            ActiveMQStreamMessage msg = new ActiveMQStreamMessage();

            byte testByte = (byte)2;

            msg.WriteString(((Byte)testByte).ToString());
            msg.Reset();
            Assert.IsTrue(msg.ReadByte() == testByte);
            msg.ClearBody();
            short testShort = 3;

            msg.WriteString(((Int16)testShort).ToString());
            msg.Reset();
            Assert.IsTrue(msg.ReadInt16() == testShort);
            msg.ClearBody();
            int testInt = 4;

            msg.WriteString(((Int32)testInt).ToString());
            msg.Reset();
            Assert.IsTrue(msg.ReadInt32() == testInt);
            msg.ClearBody();
            long testLong = 6L;

            msg.WriteString(((Int64)testLong).ToString());
            msg.Reset();
            Assert.IsTrue(msg.ReadInt64() == testLong);
            msg.ClearBody();
            float testFloat = 6.6f;

            msg.WriteString(((Single)testFloat).ToString());
            msg.Reset();
            Assert.IsTrue(msg.ReadSingle() == testFloat);
            msg.ClearBody();
            double testDouble = 7.7d;

            msg.WriteString(((Double)testDouble).ToString());
            msg.Reset();
            Assert.AreEqual(testDouble, msg.ReadDouble(), 0.05);
            msg.ClearBody();
            msg.WriteString("true");
            msg.Reset();
            Assert.IsTrue(msg.ReadBoolean());
            msg.ClearBody();
            msg.WriteString("a");
            msg.Reset();
            try
            {
                msg.ReadChar();
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }
            msg.ClearBody();
            msg.WriteString("777");
            msg.Reset();
            try
            {
                msg.ReadBytes(new byte[3]);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }
        }
コード例 #4
0
        public void TestReadLong()
        {
            ActiveMQStreamMessage msg = new ActiveMQStreamMessage();

            long test = 4L;

            msg.WriteInt64(test);
            msg.Reset();
            Assert.IsTrue(msg.ReadInt64() == test);
            msg.Reset();
            Assert.IsTrue(msg.ReadString() == (test).ToString());
            msg.Reset();
            try
            {
                msg.ReadBoolean();
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }
            msg.Reset();
            try
            {
                msg.ReadByte();
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }
            msg.Reset();
            try
            {
                msg.ReadInt16();
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }
            msg.Reset();
            try
            {
                msg.ReadInt32();
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }
            msg.Reset();
            try
            {
                msg.ReadSingle();
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }
            msg.Reset();
            try
            {
                msg.ReadDouble();
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }
            msg.Reset();
            try
            {
                msg.ReadChar();
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }
            msg.Reset();
            try
            {
                msg.ReadBytes(new byte[1]);
                Assert.Fail("Should have thrown exception");
            }
            catch (MessageFormatException)
            {
            }
            msg = new ActiveMQStreamMessage();
            msg.WriteObject((Int64)1);
            // Reset so it's readable now
            msg.Reset();
            Assert.AreEqual((Int64)1, msg.ReadObject());
        }