/// <summary>
        /// Creates a populated instance of a TestValue class to be used in tests.
        /// </summary>
        /// <param name="isRefEnabled">
        /// Flag to indicate if object identity/reference is enabled.
        /// </param>
        /// <returns>
        /// A populated instance of a TestValue class to be used in tests.
        /// </returns>
        public static TestValue CreateTestValue(bool isRefEnabled)
        {
            PortablePerson person = isRefEnabled ? CreatePersonNoChildren() : CreatePerson();

            Object[] aObj = new Object[] { 1, "two", person };
            String[] aStr = new String[] { "one", "two", "three", "four" };

            IList lstObj = new ArrayList();

            lstObj.Add(1);
            lstObj.Add("two");
            lstObj.Add(person);

            IList lstStr = new ArrayList();

            lstStr.Add("one");
            lstStr.Add("two");
            lstStr.Add("three");
            lstStr.Add("four");

            ILongArray oSparseArray = new LongSortedList();

            oSparseArray[2] = "two";
            oSparseArray[4] = 4;
            oSparseArray[5] = person;

            ILongArray oUniformSparseArray = new LongSortedList();

            oUniformSparseArray[2] = "two";
            oUniformSparseArray[4] = "four";

            return(new TestValue(aObj, aStr,
                                 lstObj, lstStr,
                                 oSparseArray, oUniformSparseArray));
        }
Пример #2
0
 /// <summary>
 /// Construct a ComplexPofValue instance wrapping the supplied binary.
 /// </summary>
 /// <param name="valueParent">
 /// Parent value within the POF stream.
 /// </param>
 /// <param name="binValue">
 /// Binary representation of this value.
 /// </param>
 /// <param name="ctx">
 /// POF context to use when reading or writing properties.
 /// </param>
 /// <param name="of">
 /// Offset of this value from the beginning of POF stream.
 /// </param>
 /// <param name="nType">
 /// POF type identifier for this value.
 /// </param>
 /// <param name="ofChildren">
 /// Offset of the first child element within this value.
 /// </param>
 public ComplexPofValue(IPofValue valueParent, Binary binValue,
                        IPofContext ctx, int of, int nType, int ofChildren)
     : base(valueParent, binValue, ctx, of, nType)
 {
     m_aChildren  = new LongSortedList();
     m_ofChildren = ofChildren;
 }
Пример #3
0
        public void TestReadInt32Array()
        {
            la      = new LongSortedList();
            la[1L]  = 0;
            la[3L]  = 1;
            la[30L] = Int32.MaxValue;
            la[31L] = Int32.MinValue;

            LongSortedList la1 = new LongSortedList();

            la1[1L]  = (Single)1.0;
            la1[10L] = (Single)10.0;
            la1[11L] = (Single)11.0;

            DataWriter      writer    = new DataWriter(stream);
            PofStreamWriter pofWriter = new PofStreamWriter(writer, ctx);

            // writting ILongArray
            pofWriter.WriteLongArray(0, la);
            pofWriter.WriteLongArray(0, new LongSortedList());
            // writting uniform ILongArray
            pofWriter.WriteLongArray(0, la, typeof(Int32));
            pofWriter.WriteLongArray(0, la1, typeof(Single));

            stream.Position = 0;
            DataReader      reader    = new DataReader(stream);
            PofStreamReader pofReader = new PofStreamReader(reader, ctx);

            // reading ILongArray
            Int32[] resInt32Array = pofReader.ReadInt32Array(0);
            Assert.AreEqual(la.LastIndex + 1, resInt32Array.Length);

            Assert.AreEqual(la[1L], resInt32Array[1]);
            Assert.AreEqual(la[3L], resInt32Array[3]);
            Assert.AreEqual(la[30L], resInt32Array[30]);
            Assert.AreEqual(la[31L], resInt32Array[31]);

            resInt32Array = pofReader.ReadInt32Array(0);
            Assert.AreEqual(0, resInt32Array.Length);

            // reading  uniform ILongArray
            resInt32Array = pofReader.ReadInt32Array(0);
            Assert.AreEqual(la.LastIndex + 1, resInt32Array.Length);

            Assert.AreEqual(la[1L], resInt32Array[1]);
            Assert.AreEqual(la[3L], resInt32Array[3]);
            Assert.AreEqual(la[30L], resInt32Array[30]);
            Assert.AreEqual(la[31L], resInt32Array[31]);

            resInt32Array = pofReader.ReadInt32Array(0);
            Assert.AreEqual(la1.LastIndex + 1, resInt32Array.Length);

            Assert.AreEqual(la1[1L], resInt32Array[1]);
            Assert.AreEqual(la1[10L], resInt32Array[10]);
            Assert.AreEqual(la1[11L], resInt32Array[11]);
        }
Пример #4
0
        public void TestReadObject()
        {
            la     = new LongSortedList();
            la[1L] = "one";
            la[2L] = "two";
            la.Add("five");
            la.Add("three");
            la[200L] = "twohundred";


            DataWriter      writer    = new DataWriter(stream);
            PofStreamWriter pofWriter = new PofStreamWriter(writer, ctx);

            pofWriter.WriteLongArray(0, la);
            pofWriter.WriteLongArray(0, new LongSortedList());
            pofWriter.WriteLongArray(0, la, typeof(String));

            stream.Position = 0;
            DataReader      reader    = new DataReader(stream);
            PofStreamReader pofReader = new PofStreamReader(reader, ctx);

            LongSortedList resLA = (LongSortedList)pofReader.ReadObject(0);

            Assert.AreEqual(la.Count, resLA.Count);

            IEnumerator e  = resLA.GetEnumerator();
            IEnumerator de = la.GetEnumerator();

            for (; e.MoveNext() && de.MoveNext();)
            {
                Assert.AreEqual(((DictionaryEntry)e.Current).Key, ((DictionaryEntry)de.Current).Key);
                Assert.AreEqual(((DictionaryEntry)e.Current).Value, ((DictionaryEntry)de.Current).Value);
            }

            resLA = (LongSortedList)pofReader.ReadObject(0);
            Assert.AreEqual(0, resLA.Count);

            //uniform sparse array
            resLA = (LongSortedList)pofReader.ReadObject(0);
            Assert.AreEqual(la.Count, resLA.Count);

            e  = resLA.GetEnumerator();
            de = la.GetEnumerator();
            for (; e.MoveNext() && de.MoveNext();)
            {
                Assert.AreEqual(((DictionaryEntry)e.Current).Key, ((DictionaryEntry)de.Current).Key);
                Assert.AreEqual(((DictionaryEntry)e.Current).Value, ((DictionaryEntry)de.Current).Value);
            }
        }
        public void TestInt64Array()
        {
            var        array1   = new Int64[] { 0, Int64.MaxValue, Int64.MinValue, 8888888L };
            var        array2   = new Int64[] { -1, 1, Int64.MinValue, Int64.MaxValue, 88888 };
            var        objArray = new object[] { 1, 2, (Byte)20, null, (Int64)100 };
            var        al       = new ArrayList(0);
            var        dArray   = new double[] { 1.0, 0.0, -1.0 };
            ILongArray aLong    = new LongSortedList();

            initPOFWriter();
            pofWriter.WriteInt64Array(0, array1);
            pofWriter.WriteInt64Array(0, array2);
            pofWriter.WriteInt64Array(0, null);
            pofWriter.WriteArray(0, objArray);
            pofWriter.WriteCollection(0, al);
            pofWriter.WriteDoubleArray(0, dArray);

            aLong.Add("A");
            aLong.Add("B");
            aLong.Add(null);
            aLong.Add("1");
            pofWriter.WriteLongArray(0, aLong, typeof(String));

            initPOFReader();
            Assert.AreEqual(array1, pofReader.ReadInt64Array(0));
            Assert.AreEqual(array2, pofReader.ReadInt64Array(0));
            Assert.AreEqual(null, pofReader.ReadInt64Array(0));
            var objArrayR = new object[5];

            pofReader.ReadArray(0, objArrayR);
            Assert.AreEqual(objArray, objArrayR);
            Assert.AreEqual(al.ToArray(), pofReader.ReadInt64Array(0));
            Assert.AreEqual(dArray, pofReader.ReadInt64Array(0));

            ILongArray aLongResult = new LongSortedList();

            pofReader.ReadLongArray(0, aLongResult);
            Assert.AreEqual(aLongResult.Count, aLong.Count);
            for (int i = 0; i < aLongResult.Count; i++)
            {
                Assert.AreEqual(aLong[i], aLongResult[i]);
            }
        }