public virtual void TestMany() { //Write a big set of data, one of each primitive type array foreach (object x in bigSet) { //write each test object two ways //First, transparently via ObjectWritable ObjectWritable.WriteObject(@out, x, x.GetType(), null, true); //Second, explicitly via ArrayPrimitiveWritable (new ArrayPrimitiveWritable(x)).Write(@out); } //Now read the data back in @in.Reset(@out.GetData(), @out.GetLength()); for (int x_1 = 0; x_1 < resultSet.Length;) { //First, transparently resultSet[x_1++] = ObjectWritable.ReadObject(@in, null); //Second, explicitly ArrayPrimitiveWritable apw = new ArrayPrimitiveWritable(); apw.ReadFields(@in); resultSet[x_1++] = apw.Get(); } //validate data structures and values Assert.Equal(expectedResultSet.Length, resultSet.Length); for (int x_2 = 0; x_2 < resultSet.Length; x_2++) { Assert.Equal("ComponentType of array " + x_2, expectedResultSet [x_2].GetType().GetElementType(), resultSet[x_2].GetType().GetElementType()); } Assert.True("In and Out arrays didn't match values", Arrays.DeepEquals (expectedResultSet, resultSet)); }
public virtual void TestObjectLabeling() { //Do a few tricky experiments to make sure things are being written //the way we expect //Write the data array with ObjectWritable //which will indirectly write it using APW.Internal ObjectWritable.WriteObject(@out, i, i.GetType(), null, true); //Write the corresponding APW directly with ObjectWritable ArrayPrimitiveWritable apw = new ArrayPrimitiveWritable(i); ObjectWritable.WriteObject(@out, apw, apw.GetType(), null, true); //Get ready to read it back @in.Reset(@out.GetData(), @out.GetLength()); //Read the int[] object as written by ObjectWritable, but //"going around" ObjectWritable string className = UTF8.ReadString(@in); Assert.Equal("The int[] written by ObjectWritable was not labelled as " + "an ArrayPrimitiveWritable.Internal", typeof(ArrayPrimitiveWritable.Internal) .FullName, className); ArrayPrimitiveWritable.Internal apwi = new ArrayPrimitiveWritable.Internal(); apwi.ReadFields(@in); Assert.Equal("The ArrayPrimitiveWritable.Internal component type was corrupted" , typeof(int), apw.GetComponentType()); Assert.True("The int[] written by ObjectWritable as " + "ArrayPrimitiveWritable.Internal was corrupted" , Arrays.Equals(i, (int[])(apwi.Get()))); //Read the APW object as written by ObjectWritable, but //"going around" ObjectWritable string declaredClassName = UTF8.ReadString(@in); Assert.Equal("The APW written by ObjectWritable was not labelled as " + "declaredClass ArrayPrimitiveWritable", typeof(ArrayPrimitiveWritable).FullName , declaredClassName); className = UTF8.ReadString(@in); Assert.Equal("The APW written by ObjectWritable was not labelled as " + "class ArrayPrimitiveWritable", typeof(ArrayPrimitiveWritable).FullName, className ); ArrayPrimitiveWritable apw2 = new ArrayPrimitiveWritable(); apw2.ReadFields(@in); Assert.Equal("The ArrayPrimitiveWritable component type was corrupted" , typeof(int), apw2.GetComponentType()); Assert.True("The int[] written by ObjectWritable as " + "ArrayPrimitiveWritable was corrupted" , Arrays.Equals(i, (int[])(apw2.Get()))); }