Esempio n. 1
0
        public void TestSkipUniformValue()
        {   //PASSED
            // PLEASE DO NOTE, the method SkipUniformValue should be used only for Uniform_Arrays/Collections
            initPOFWriter();

            pofwriter.WriteInt32(0, 100);
            pofwriter.WriteInt32(0, 200);
            pofwriter.WriteInt32(0, 300);

            initPOFReader();
            PofHelper.SkipUniformValue(reader, PofConstants.T_INT32);
            PofHelper.SkipUniformValue(reader, PofConstants.T_INT32);
            PofHelper.SkipUniformValue(reader, PofConstants.T_INT32);
            PofHelper.SkipUniformValue(reader, PofConstants.T_INT32);
            Assert.AreEqual(PofConstants.T_INT32, PofHelper.ReadAsInt32(reader, PofConstants.T_INT32));
            Assert.AreEqual(300, PofHelper.ReadAsInt32(reader, PofConstants.T_INT32));

            initPOFWriter();
            RawYearMonthInterval ymi = new RawYearMonthInterval(2, 10);

            pofwriter.WriteRawYearMonthInterval(0, ymi);
            pofwriter.WriteString(0, "skipping to string1");
            pofwriter.WriteTimeInterval(0, new TimeSpan(4, 52, 10));
            pofwriter.WriteString(0, "skipping to string2");
            pofwriter.WriteDayTimeInterval(0, new TimeSpan(11, 12, 13, 14, 50));
            pofwriter.WriteString(0, "skipping to string3");
            pofwriter.WriteSingle(0, 120.34f);
            pofwriter.WriteString(0, "skipping to string4");
            pofwriter.WriteDouble(0, 1222.22);
            pofwriter.WriteString(0, "skipping to string5");
            pofwriter.WriteChar(0, 'A');
            pofwriter.WriteString(0, "skipping to string6");

            initPOFReader();
            PofHelper.SkipUniformValue(reader, PofConstants.T_INT32);
            PofHelper.SkipUniformValue(reader, PofConstants.T_YEAR_MONTH_INTERVAL);
            Assert.AreEqual("skipping to string1", pofreader.ReadString(0));

            PofHelper.SkipUniformValue(reader, PofConstants.T_INT32);
            PofHelper.SkipUniformValue(reader, PofConstants.T_TIME_INTERVAL);
            Assert.AreEqual("skipping to string2", pofreader.ReadString(0));

            PofHelper.SkipUniformValue(reader, PofConstants.T_INT32);
            PofHelper.SkipUniformValue(reader, PofConstants.T_DAY_TIME_INTERVAL);
            Assert.AreEqual("skipping to string3", pofreader.ReadString(0));

            PofHelper.SkipUniformValue(reader, PofConstants.T_INT32);
            PofHelper.SkipUniformValue(reader, PofConstants.T_FLOAT32);
            Assert.AreEqual("skipping to string4", pofreader.ReadString(0));

            PofHelper.SkipUniformValue(reader, PofConstants.T_INT32);
            PofHelper.SkipUniformValue(reader, PofConstants.T_FLOAT64);
            Assert.AreEqual("skipping to string5", pofreader.ReadString(0));

            PofHelper.SkipUniformValue(reader, PofConstants.T_INT32);
            PofHelper.SkipUniformValue(reader, PofConstants.T_CHAR);
            Assert.AreEqual("skipping to string6", pofreader.ReadString(0));
        }
        public void TestYearMonthInterval()
        {
            RawYearMonthInterval ymi = new RawYearMonthInterval(30, -1);

            initPOFWriter();
            pofWriter.WriteRawYearMonthInterval(0, ymi);
            pofWriter.WriteObject(0, null);

            initPOFReader();
            RawYearMonthInterval result = pofReader.ReadRawYearMonthInterval(0);

            Assert.AreEqual(ymi, result);

            Assert.AreEqual(new RawYearMonthInterval(), pofReader.ReadRawYearMonthInterval(0));
        }
        public void TestObject()
        {
            initPOFWriter();
            // 1
            pofWriter.WriteObject(0, null);
            pofWriter.WriteObject(0, false);
            pofWriter.WriteBoolean(0, true);
            pofWriter.WriteBoolean(0, false);
            pofWriter.WriteObject(0, 'a');
            pofWriter.WriteObject(0, Byte.MinValue);
            pofWriter.WriteObject(0, Int16.MaxValue);
            pofWriter.WriteObject(0, 0);
            pofWriter.WriteObject(0, -1);
            pofWriter.WriteObject(0, Int32.MaxValue);
            // 11
            pofWriter.WriteObject(0, (Int64)(-1));
            pofWriter.WriteObject(0, Int64.MinValue);
            pofWriter.WriteObject(0, (Single)0);
            pofWriter.WriteObject(0, Single.NaN);
            pofWriter.WriteObject(0, Single.NegativeInfinity);
            pofWriter.WriteObject(0, Double.NaN);
            pofWriter.WriteObject(0, "test ");
            pofWriter.WriteObject(0, String.Empty);
            pofWriter.WriteObject(0, new DateTime(1978, 4, 25, 7, 5, 10, 110));

            DateTime dtUtc    = new DateTime(2006, 8, 18, 11, 28, 10, 100, DateTimeKind.Utc);
            RawTime  rawTime1 = new RawTime(11, 30, 0, 99, true);
            RawTime  rawTime2 = new RawTime(11, 30, 0, 99, 2, 30);

            pofWriter.WriteObject(0, dtUtc);
            // 21
            pofWriter.WriteObject(0, rawTime1);
            pofWriter.WriteObject(0, rawTime2);

            bool[] bArray = new bool[] { true, true };
            pofWriter.WriteObject(0, bArray);
            byte[] byteArray = new byte[] { 1, 2, 3 };
            pofWriter.WriteObject(0, byteArray);
            char[] charArray = new char[] { 'a', 'd', Char.MinValue };
            pofWriter.WriteObject(0, charArray);
            Int16[] i16Array = new Int16[] { 100, 200, Int16.MinValue };
            pofWriter.WriteObject(0, i16Array);
            Int32[] i32Array = new Int32[] { 100, 200, Int32.MinValue };
            pofWriter.WriteObject(0, i32Array);
            Int64[] i64Array = new Int64[] { 100, 200, Int64.MinValue };
            pofWriter.WriteObject(0, i64Array);

            ArrayList al = new ArrayList();

            al.Add(true);
            al.Add(5);
            pofWriter.WriteObject(0, al);

            Single[] fArray = new Single[] { Single.MinValue, Single.NegativeInfinity };
            pofWriter.WriteObject(0, fArray);
            Double[] dArray = new Double[] { Double.MinValue, Double.NegativeInfinity };
            pofWriter.WriteObject(0, dArray);
            object[] objArray = new object[] { true, Double.NaN };
            // 31
            pofWriter.WriteObject(0, objArray);
            RawYearMonthInterval ymi = new RawYearMonthInterval(10, 6);

            pofWriter.WriteObject(0, ymi);
            TimeSpan ts = new TimeSpan(1, 16, 30, 25, 400);

            pofWriter.WriteObject(0, ts);
            TimeSpan ts1 = new TimeSpan(5, 10, 30);

            pofWriter.WriteObject(0, ts1);

            initPOFReader();
            // 1
            Assert.AreEqual(null, pofReader.ReadObject(0));
            Assert.AreEqual(false, pofReader.ReadObject(0));
            Assert.AreEqual(true, pofReader.ReadObject(0));
            Assert.AreEqual(false, pofReader.ReadObject(0));
            Assert.AreEqual('a', pofReader.ReadObject(0));
            Assert.AreEqual(Byte.MinValue, pofReader.ReadObject(0));
            Assert.AreEqual(Int16.MaxValue, pofReader.ReadObject(0));
            Assert.AreEqual(0, pofReader.ReadObject(0));
            Assert.AreEqual(-1, pofReader.ReadObject(0));
            Assert.AreEqual(Int32.MaxValue, pofReader.ReadObject(0));
            // 11
            Assert.AreEqual(-1, pofReader.ReadObject(0));
            Assert.AreEqual(Int64.MinValue, pofReader.ReadObject(0));
            Assert.AreEqual(0, pofReader.ReadObject(0));
            Assert.AreEqual(Single.NaN, pofReader.ReadObject(0));
            Assert.AreEqual(Single.NegativeInfinity, pofReader.ReadObject(0));
            Assert.AreEqual(Double.NaN, pofReader.ReadObject(0));
            Assert.AreEqual("test ", pofReader.ReadObject(0));
            Assert.AreEqual(String.Empty, pofReader.ReadObject(0));
            Assert.AreEqual(new DateTime(1978, 4, 25, 7, 5, 10, 110), pofReader.ReadObject(0));
            Assert.AreEqual(dtUtc, pofReader.ReadObject(0));
            // 21
            Assert.AreEqual(rawTime1, pofReader.ReadObject(0));
            Assert.AreEqual(rawTime2, pofReader.ReadObject(0));
            Assert.AreEqual(bArray, pofReader.ReadObject(0));
            Assert.AreEqual(byteArray, pofReader.ReadObject(0));
            Assert.AreEqual(charArray, pofReader.ReadObject(0));
            Assert.AreEqual(i16Array, pofReader.ReadObject(0));
            Assert.AreEqual(i32Array, pofReader.ReadObject(0));
            Assert.AreEqual(i64Array, pofReader.ReadObject(0));

            Object result = pofReader.ReadObject(0);

            Assert.IsTrue(result is ICollection);
            ArrayList ares = new ArrayList((ICollection)result);

            Assert.AreEqual(ares[0], al[0]);
            Assert.AreEqual(ares[1], al[1]);

            Assert.AreEqual(fArray, pofReader.ReadObject(0));
            Assert.AreEqual(dArray, pofReader.ReadObject(0));
            // 31
            Assert.AreEqual(objArray, pofReader.ReadObject(0));
            Assert.AreEqual(ymi, pofReader.ReadObject(0));
            Assert.AreEqual(ts, pofReader.ReadObject(0));
            Assert.AreEqual(ts1, pofReader.ReadObject(0));
        }