Inheritance: ISerializationSurrogate
Esempio n. 1
0
    public bool runTest()
    {
        Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver : " + s_strDtTmVer);
        int                      iCountErrors    = 0;
        int                      iCountTestcases = 0;
        String                   strLoc          = "Loc_000oo";
        IFormatter               formatter;
        SurrogateSelector        selector;
        MySerializationSurrogate surrogate;
        StreamingContext         context = new StreamingContext(StreamingContextStates.All);
        MemoryStream             stream;
        Int32                    iValue;
        A                 a;
        ObjectManager     manager;
        ObjectIDGenerator generator;
        Int64             rootId;
        Int64             childId;
        Boolean           firstTime;

        MemberInfo[] members;
        try {
            strLoc = "Loc_29457sdg";
            iCountTestcases++;
            selector  = new SurrogateSelector();
            surrogate = new MySerializationSurrogate();
            selector.AddSurrogate(typeof(A), context, surrogate);
            formatter = new BinaryFormatter();
            formatter.SurrogateSelector = selector;
            stream = new MemoryStream();
            a      = new A();
            a.I    = 10;
            formatter.Serialize(stream, a);
            stream.Position = 0;
            A a1 = (A)formatter.Deserialize(stream);
            if (a1.I != 30)
            {
                iCountErrors++;
                Console.WriteLine("Err_753ffd! Unexpected value returned, Value: <{0}>", a1.I);
            }
            strLoc = "Loc_8394tfsg";
            iCountTestcases++;
            generator = new ObjectIDGenerator();
            a         = new A();
            iValue    = 500;
            rootId    = generator.GetId(a, out firstTime);
            childId   = generator.GetId(iValue, out firstTime);
            selector  = new SurrogateSelector();
            surrogate = new MySerializationSurrogate();
            selector.AddSurrogate(typeof(A), context, surrogate);
            manager = new ObjectManager(selector, context);
            members = FormatterServices.GetSerializableMembers(typeof(A));
            manager.RecordDelayedFixup(rootId, "Int32Twist", childId);
            try{
                SerializationInfo serInfo1 = new SerializationInfo(typeof(A), new FormatterConverter());
                manager.RegisterObject(a, rootId, serInfo1);
                manager.RegisterObject(iValue, childId);
                Console.WriteLine(a.I);
            }catch (Exception ex) {
                iCountErrors++;
                Console.WriteLine(ex);
            }
            strLoc = "Loc_87sgsfd";
            iCountTestcases++;
            generator = new ObjectIDGenerator();
            a         = new A();
            iValue    = 500;
            rootId    = generator.GetId(a, out firstTime);
            childId   = generator.GetId(iValue, out firstTime);
            manager   = new ObjectManager(null, context);
            members   = FormatterServices.GetSerializableMembers(typeof(A));
            manager.RecordFixup(rootId, members[0], childId);
            manager.RegisterObject(a, rootId);
            manager.RegisterObject(iValue, childId);
            if (a.I != 500)
            {
                iCountErrors++;
                Console.WriteLine("Err_93745sg! Unexpected value returned, Value: <{0}>", a1.I);
            }
        } catch (Exception exc_general) {
            ++iCountErrors;
            Console.WriteLine(s_strTFAbbrev + " : Error Err_8888yyy!  strLoc==" + strLoc + ", exc_general==\n" + exc_general.StackTrace);
        }
        if (iCountErrors == 0)
        {
            Console.WriteLine("paSs.   " + s_strTFPath + " " + s_strTFName + " ,iCountTestcases==" + iCountTestcases);
            return(true);
        }
        else
        {
            Console.WriteLine("FAiL!   " + s_strTFPath + " " + s_strTFName + " ,iCountErrors==" + iCountErrors + " , BugNums?: " + s_strActiveBugNums);
            return(false);
        }
    }
Esempio n. 2
0
	public bool runTest()
	{
		Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver : " + s_strDtTmVer);
		int iCountErrors = 0;
		int iCountTestcases = 0;
		String strLoc = "Loc_000oo";
		IFormatter formatter;
		SurrogateSelector selector;
		MySerializationSurrogate surrogate;
		StreamingContext context = new StreamingContext(StreamingContextStates.All);
		MemoryStream stream;
		Int32 iValue;
		A a;
		ObjectManager manager;
		ObjectIDGenerator generator;
		Int64 rootId;
		Int64 childId;
		Boolean firstTime;
		MemberInfo[] members;
		try {
			strLoc = "Loc_29457sdg";
			iCountTestcases++;
			selector = new SurrogateSelector();
			surrogate = new MySerializationSurrogate();
			selector.AddSurrogate(typeof(A), context, surrogate);
			formatter = new BinaryFormatter();
			formatter.SurrogateSelector = selector;
			stream = new MemoryStream();
			a = new A();
			a.I = 10;
			formatter.Serialize(stream, a);
			stream.Position = 0;
			A a1 = (A)formatter.Deserialize(stream);
			if(a1.I != 30){
				iCountErrors++;
				Console.WriteLine("Err_753ffd! Unexpected value returned, Value: <{0}>", a1.I);
			}
			strLoc = "Loc_8394tfsg";
			iCountTestcases++;
			generator = new ObjectIDGenerator();
			a = new A();
			iValue = 500;
			rootId = generator.GetId(a, out firstTime);
			childId = generator.GetId(iValue, out firstTime);
			selector = new SurrogateSelector();
			surrogate = new MySerializationSurrogate();
			selector.AddSurrogate(typeof(A), context, surrogate);
			manager = new ObjectManager(selector, context);
			members = FormatterServices.GetSerializableMembers(typeof(A));
			manager.RecordDelayedFixup(rootId, "Int32Twist", childId);
			try{
				SerializationInfo serInfo1 = new SerializationInfo(typeof(A), new FormatterConverter());
				manager.RegisterObject(a, rootId, serInfo1);
				manager.RegisterObject(iValue, childId);
				Console.WriteLine(a.I);
			}catch(Exception ex){
				iCountErrors++;
				Console.WriteLine(ex);
			}
			strLoc = "Loc_87sgsfd";
			iCountTestcases++;
			generator = new ObjectIDGenerator();
			a = new A();
			iValue = 500;
			rootId = generator.GetId(a, out firstTime);
			childId = generator.GetId(iValue, out firstTime);
			manager = new ObjectManager(null, context);
			members = FormatterServices.GetSerializableMembers(typeof(A));
			manager.RecordFixup(rootId, members[0], childId);
			manager.RegisterObject(a, rootId);
			manager.RegisterObject(iValue, childId);
			if(a.I != 500){
				iCountErrors++;
				Console.WriteLine("Err_93745sg! Unexpected value returned, Value: <{0}>", a1.I);
			}
		} catch (Exception exc_general ) {
			++iCountErrors;
			Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general==\n"+exc_general.StackTrace);
		}
		if ( iCountErrors == 0 )
		{
			Console.WriteLine( "paSs.   "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases);
			return true;
		}
		else
		{
			Console.WriteLine("FAiL!   "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums );
			return false;
		}
	}