Пример #1
0
        public void TestObjectDeserializationQ3()
        {
            var expressions =
                new QExpressions(new Dictionary <string, string> {
                { "q3", "..\\..\\test\\QExpressions.3.out" }
            });

            foreach (var expr in expressions.GetExpressions("q3"))
            {
                var stream     = new MemoryStream();
                var writer     = new BinaryWriter(stream);
                var reader     = new QReader(stream, Encoding.ASCII, QBasicConnection.DefaultMaxReadingChunk);
                var binaryExpr = expressions.GetBinaryExpression("q3", expr);
                writer.Write((byte)1);  // little endian
                writer.Write((byte)0);
                writer.Write((byte)0);
                writer.Write((byte)0);
                writer.Write(binaryExpr.Length + 8);
                writer.Write(binaryExpr);
                writer.Flush();
                stream.Seek(0, SeekOrigin.Begin);

                try
                {
                    var obj = reader.Read().Data;
                    if (obj is QDictionary || obj is QTable || obj is QLambda)
                    {
                        // force usage of Equals method
                        Assert.IsTrue(expressions.GetReferenceObject("q3", expr).Equals(obj),
                                      "Deserialization failed for q expression: " + expr);
                    }
                    else
                    {
                        Assert.AreEqual(expressions.GetReferenceObject("q3", expr), obj,
                                        "Deserialization failed for q expression: " + expr);
                    }
                }
                catch (QException e)
                {
                    Console.WriteLine(e);
                    Assert.AreEqual(((QException)expressions.GetReferenceObject("q3", expr)).Message, e.Message,
                                    "Deserialization failed for q error: " + e.Message);
                }
                finally
                {
                    stream.Close();
                }
            }
        }
Пример #2
0
        public void TestObjectSerializationQ2()
        {
            var expressions = new QExpressions(new Dictionary<string, string> {{"q2", "..\\..\\test\\QExpressions.out"}});
            foreach (string expr in expressions.GetExpressions("q2"))
            {
                var stream = new MemoryStream();
                var reader = new BinaryReader(stream);
                var writer = new QWriter(stream, Encoding.ASCII, 1);
                int dataSize = writer.Write(expressions.GetReferenceObject("q2", expr), MessageType.Sync);
                stream.Seek(8, SeekOrigin.Begin);

                Assert.AreEqual(expressions.GetBinaryExpression("q2", expr), reader.ReadBytes(dataSize),
                                "Serialization failed for q expression: " + expr);

                stream.Close();
            }
        }
Пример #3
0
        public void TestObjectSerializationQ2()
        {
            var expressions = new QExpressions(new Dictionary <string, string> {
                { "q2", "..\\..\\test\\QExpressions.out" }
            });

            foreach (var expr in expressions.GetExpressions("q2"))
            {
                var stream   = new MemoryStream();
                var reader   = new BinaryReader(stream);
                var writer   = new QWriter(stream, Encoding.ASCII, 1);
                var dataSize = writer.Write(expressions.GetReferenceObject("q2", expr), MessageType.Sync);
                stream.Seek(8, SeekOrigin.Begin);

                Assert.AreEqual(expressions.GetBinaryExpression("q2", expr), reader.ReadBytes(dataSize),
                                "Serialization failed for q expression: " + expr);

                stream.Close();
            }
        }
Пример #4
0
        public void TestObjectDeserializationQ3()
        {
            var expressions =
                new QExpressions(new Dictionary<string, string> {{"q3", "..\\..\\test\\QExpressions.3.out"}});
            foreach (string expr in expressions.GetExpressions("q3"))
            {
                var stream = new MemoryStream();
                var writer = new BinaryWriter(stream);
                var reader = new QReader(stream, Encoding.ASCII, QBasicConnection.DefaultMaxReadingChunk);
                byte[] binaryExpr = expressions.GetBinaryExpression("q3", expr);
                writer.Write((byte) 1); // little endian
                writer.Write((byte) 0);
                writer.Write((byte) 0);
                writer.Write((byte) 0);
                writer.Write(binaryExpr.Length + 8);
                writer.Write(binaryExpr);
                writer.Flush();
                stream.Seek(0, SeekOrigin.Begin);

                try
                {
                    object obj = reader.Read().Data;
                    if (obj is QDictionary || obj is QTable || obj is QLambda)
                    {
                        // force usage of Equals method
                        Assert.IsTrue(expressions.GetReferenceObject("q3", expr).Equals(obj),
                                      "Deserialization failed for q expression: " + expr);
                    }
                    else
                    {
                        Assert.AreEqual(expressions.GetReferenceObject("q3", expr), obj,
                                        "Deserialization failed for q expression: " + expr);
                    }
                }
                catch (QException e)
                {
                    System.Console.WriteLine(e);
                    Assert.AreEqual(((QException) expressions.GetReferenceObject("q3", expr)).Message, e.Message,
                                    "Deserialization failed for q error: " + e.Message);
                }
                finally
                {
                    stream.Close();
                }
            }
        }