/// <summary> /// Initializes a new instance of the <see cref="System.Object" /> /// class. /// </summary> public DefaultObjectIdProvider([NotNull] ObjectIDGenerator generator) { Generator = generator ?? throw new ArgumentNullException(nameof(generator)); _registryById = new ConcurrentDictionary <long, object> ( ); _registry = new ConcurrentDictionary <object, long> ( ); _id = generator.GetId(this, out _); }
/// <summary> /// Saves or updates the entity without its children. /// </summary> /// /// <param name="entity"> /// Entity to save or update. /// </param> /// /// <param name="idGenerator"> /// ObjectIDGenerator instance to generate IDs for objects. /// </param> /// /// <param name="options"> /// Optional options. /// </param> /// /// <returns> /// The number of affected rows. /// </returns> internal int PersistWithChildren(ref VahapYigit.Test.Models.UserRole entity, ObjectIDGenerator idGenerator, SaveOptions options = null) { int rowCount = 0; if (entity.User != null && idGenerator.HasId(entity.User, withForceId: true) == 0) { using (var db = new UserCrud(base.UserContext)) { var child = entity.User; rowCount += db.PersistWithChildren(ref child, idGenerator, options); entity.IdUser = child.Id; } } if (entity.Role != null && idGenerator.HasId(entity.Role, withForceId: true) == 0) { using (var db = new RoleCrud(base.UserContext)) { var child = entity.Role; rowCount += db.PersistWithChildren(ref child, idGenerator, options); entity.IdRole = child.Id; } } rowCount += this.Persist(ref entity, options); return(rowCount); }
private int CreateSsrc(string hostName) { try { ObjectIDGenerator obGen = new ObjectIDGenerator(); MessageDigest md = MessageDigest.GetInstance("MD5"); md.Update(Encoding.GetEncoding("UTF-8").GetBytes(Convert.ToString(new Date().Time).ToCharArray())); md.Update(Encoding.GetEncoding("UTF-8").GetBytes(Convert.ToString(obGen.ToString().ToCharArray()))); md.Update(Encoding.GetEncoding("UTF-8").GetBytes(Paths.Get("").ToAbsolutePath().Normalize().ToString().ToCharArray())); md.Update(Encoding.GetEncoding("UTF-8").GetBytes(hostName.ToCharArray())); byte[] md5 = md.Digest(); int ssrc = 0; ByteBuffer byteBuffer = ByteBuffer.Wrap(md5); for (int i = 0; i < 3; i++) { ssrc ^= byteBuffer.Int; } return(ssrc); } catch (NoSuchAlgorithmException e) { throw new RuntimeException("Could not get MD5 algorithm", e); } }
public XmlSerializerSettings() { converters = new XmlConverterCollection(); converters.CollectionChanged += (sender, ea) => typeContextCache.Clear(); typeContextCache = new ConcurrentDictionary <Type, XmlTypeContext>(); typeResolver = new XmlTypeResolver(); contractResolver = new XmlContractResolver(); cultureInfo = CultureInfo.InvariantCulture; typeAttributeName = new XmlName("type", XmlNamespace.Xsi); nullAttributeName = new XmlName("nil", XmlNamespace.Xsi); encoding = Encoding.UTF8; TypeHandling = XmlTypeHandling.Auto; NullValueHandling = XmlNullValueHandling.Ignore; NoneValueHandling = XmlNoneValueHandling.Ignore; DefaultValueHandling = XmlDefaultValueHandling.Include; ReferenceHandling = XmlReferenceHandling.Throw; ReferenceHandlingIdName = "id"; ReferenceHandlingReferenceName = "ref"; ReferenceHandlingGenerator = new ObjectIDGenerator(); EmptyCollectionHandling = XmlEmptyCollectionHandling.Include; omitXmlDeclaration = false; indentChars = " "; indent = false; namespaces = new List <XmlNamespace> { new XmlNamespace("xsi", XmlNamespace.Xsi) }; }
static void Main(string[] args) { ObjectIDGenerator idGenerator = new ObjectIDGenerator(); bool blStatus = new bool(); //just ignore this blStatus Now. String str = "My first string was "; Console.WriteLine("str = {0}", str); Console.WriteLine("Instance Id : {0}", idGenerator.GetId(str, out blStatus)); //here blStatus get True for new instace otherwise it will be false Console.WriteLine("this instance is new : {0}\n", blStatus); str += "Hello World"; Console.WriteLine("str = {0}", str); Console.WriteLine("Instance Id : {0}", idGenerator.GetId(str, out blStatus)); Console.WriteLine("this instance is new : {0}\n", blStatus); //Now str="My first string was Hello World" StringBuilder sbr = new StringBuilder("My Favourate Programming Font is "); Console.WriteLine("sbr = {0}", sbr); Console.WriteLine("Instance Id : {0}", idGenerator.GetId(sbr, out blStatus)); Console.WriteLine("this instance is new : {0}\n", blStatus); sbr.Append("Inconsolata"); Console.WriteLine("sbr = {0}", sbr); Console.WriteLine("Instance Id : {0}", idGenerator.GetId(sbr, out blStatus)); Console.WriteLine("this instance is new : {0}\n", blStatus); //Now sbr="My Favourate Programming Font is Inconsolata" Console.ReadKey(); }
public ObjectTreeReferenceTracker(ReferenceTrackingType referenceTrackingType, bool useCustomHashCodes) { _objectTree = new Dictionary <long, object>(); _objects = new ObjectIDGenerator(); _referenceTrackingType = referenceTrackingType; _useCustomHashCodes = useCustomHashCodes; }
public FormatSML(Stream stream, List <DocXsdFormat> formats) { this.m_stream = stream; this.m_writer = new StreamWriter(this.m_stream); this.m_gen = new ObjectIDGenerator(); this.m_xsdformats = formats; }
// Test simple object identifier generation. public void TestObjectIDGeneratorSimple() { ObjectIDGenerator gen = new ObjectIDGenerator(); Object obj1 = new Object(); Object obj2 = new Object(); Object obj3 = new Object(); bool firstTime; AssertEquals("Simple (1)", 1, gen.GetId(obj1, out firstTime)); Assert("Simple (2)", firstTime); AssertEquals("Simple (3)", 2, gen.GetId(obj2, out firstTime)); Assert("Simple (4)", firstTime); AssertEquals("Simple (5)", 2, gen.GetId(obj2, out firstTime)); Assert("Simple (6)", !firstTime); AssertEquals("Simple (7)", 1, gen.HasId(obj1, out firstTime)); Assert("Simple (8)", !firstTime); AssertEquals("Simple (9)", 0, gen.HasId(obj3, out firstTime)); Assert("Simple (10)", firstTime); AssertEquals("Simple (11)", 3, gen.GetId(obj3, out firstTime)); Assert("Simple (12)", firstTime); }
private static bool Bug() { ObjectManager objmgr1; StreamingContext sc1; ObjectIDGenerator objid1; TestFixup tstfxp1; Int64 iRootID; Int64 iChildID; String strValue; MemberInfo[] members; Boolean fFirstTime; sc1 = new StreamingContext(StreamingContextStates.All); tstfxp1 = new TestFixup(); strValue = "Hello World"; objid1 = new ObjectIDGenerator(); iRootID = objid1.GetId(tstfxp1, out fFirstTime); iChildID = objid1.GetId(strValue, out fFirstTime); members = FormatterServices.GetSerializableMembers(tstfxp1.GetType()); objmgr1 = new ObjectManager(null, sc1); objmgr1.RecordFixup(iRootID, members[0], iChildID); try { objmgr1.RegisterObject(strValue, iChildID); return(true); } catch (Exception ex) { Console.WriteLine("Bug:Exception thrown, " + ex); return(false); } }
public void Clear(TKey key, Diagnostics.ILog log = null) { ConcurrentBag <TPooledResource> connections; if (!pool.TryRemove(key, out connections)) { return; } // this looks like it should be connections.Count > 0, however setting it to 0 // led to an uptick in users seeing Halibut stacktraces in // in their logs. This may have just uncovered another issue. // We are returning to 1 in Dec 2016 and will monitor. Are // we disposing a connection that is in use somehow? Adding the same connection // twice? var generator = new ObjectIDGenerator(); while (connections.Count > 1) { TPooledResource connection; if (connections.TryTake(out connection)) { if (log != null) { bool firstTime; generator.GetId(connection, out firstTime); if (!firstTime) { log.Write(EventType.Error, "Duplicate connection found in conenction pool"); } } connection.Dispose(); } } }
static void Write(ObjectIDGenerator idgen, object obj) { bool isNew; long id = idgen.GetId(obj, out isNew); System.Console.WriteLine("{0}, {1}", id, isNew); }
public void Serialize(FileStream s) { if (s == null) { throw new ArgumentNullException(nameof(s)); } if (!s.CanWrite) { throw new ArgumentException("FileStream is not writable!"); } var listNodes = new ListNode[Count]; var generator = new ObjectIDGenerator(); var currentNode = Head; while (currentNode != null) { var id = generator.GetId(currentNode, out _); listNodes[id - 1] = currentNode; currentNode = currentNode.Next; } using (TextWriter writer = new StreamWriter(s)) { writer.WriteLine(Count); currentNode = Head; while (currentNode != null) { writer.WriteLine(FindIndex(currentNode.Rand, generator)); writer.WriteLine(currentNode.Data); currentNode = currentNode.Next; } } }
/// <summary> /// Serializes an object, or graph of objects with the given root to the provided stream. /// </summary> /// <param name="serializationStream"> /// The stream where the formatter puts the serialized data. This stream can reference a variety /// of backing stores (such as files, network, memory, and so on). /// </param> /// <param name="graph"> /// The object, or root of the object graph, to serialize. All child objects of this root object /// are automatically serialized. /// </param> /// <exception cref="T:System.ArgumentNullException">The <para>serializationStream</para> cannot be null.</exception> /// <exception cref="T:System.ArgumentNullException">The <para>graph</para> cannot be null.</exception> public void Serialize(Stream serializationStream, object graph) { if (null == serializationStream) { throw new ArgumentNullException("serializationStream", "Stream serializationStream cannot be null."); } if (null == graph) { throw new ArgumentNullException("graph", "Object graph cannot be null."); } XmlWriter xmlWriter = null; try { xmlWriter = XmlWriter.Create(serializationStream, this.createXmlWriterSettings()); this.registeredReferenceObjects.Clear(); this.idGenerator = new ObjectIDGenerator(); IFormatterConverter converter = new FormatterConverter(); SerializationEntry graphEntry = this.createSerializationEntry(this.getName(graph.GetType()), graph, converter); this.serializeEntry(xmlWriter, graphEntry, converter); xmlWriter.WriteWhitespace(Environment.NewLine); } finally { if (null != xmlWriter) { xmlWriter.Flush(); } } }
private static bool Bug() { ObjectManager objmgr1; StreamingContext sc1; ObjectIDGenerator objid1; TestFixup tstfxp1; Int64 iRootID; Int64 iChildID; String strValue; MemberInfo[] members; Boolean fFirstTime; sc1 = new StreamingContext(StreamingContextStates.All); tstfxp1 = new TestFixup(); strValue = "Hello World"; objid1 = new ObjectIDGenerator(); iRootID = objid1.GetId(tstfxp1, out fFirstTime); iChildID = objid1.GetId(strValue, out fFirstTime); members = FormatterServices.GetSerializableMembers(tstfxp1.GetType()); objmgr1 = new ObjectManager(null, sc1); objmgr1.RecordFixup(iRootID, members[0], iChildID); try { objmgr1.RegisterObject(strValue, iChildID); return true; } catch(Exception ex){ Console.WriteLine("Bug:Exception thrown, " + ex); return false; } }
public virtual 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"; try { do { strLoc = "Loc_028tg"; iCountTestcases++; ObjectIDGenerator obGen = new ObjectIDGenerator(); if(obGen==null){ iCountErrors++; Console.WriteLine ("Err_745dsf! Unexpeted result returned!"); } } while (false); } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy! strLoc=="+ strLoc +", exc_general=="+exc_general); } 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; } }
public static void Serialize(DataContext dataContext, string filename) { string data = ""; ObjectIDGenerator idGenerator = new ObjectIDGenerator(); bool firstTime = false; foreach (Person person in dataContext.PeopleCatalog) { data += person.Serialize(idGenerator) + "\n"; } foreach (Item item in dataContext.ItemsCatalog.Values) { data += item.Serialize(idGenerator) + "\n"; } foreach (StateDescription state in dataContext.StatesCatalog) { data += state.Serialize(idGenerator) + "\n"; } foreach (Event ev in dataContext.EventsCatalog) { data += ev.Serialize(idGenerator) + "\n"; } System.IO.File.WriteAllText(filename, data); }
public virtual 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"; try { do { strLoc = "Loc_028tg"; iCountTestcases++; ObjectIDGenerator obGen = new ObjectIDGenerator(); if (obGen == null) { iCountErrors++; Console.WriteLine("Err_745dsf! Unexpeted result returned!"); } } while (false); } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(s_strTFAbbrev + " : Error Err_8888yyy! strLoc==" + strLoc + ", exc_general==" + exc_general); } 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); } }
internal void Serialize(object graph, BinaryFormatterWriter serWriter, bool fCheck) { if (graph == null) { throw new ArgumentNullException(nameof(graph)); } if (serWriter == null) { throw new ArgumentNullException(nameof(serWriter)); } _serWriter = serWriter; serWriter.WriteBegin(); long headerId = 0; object obj; long objectId; bool isNew; // allocations if methodCall or methodResponse and no graph _idGenerator = new ObjectIDGenerator(); _objectQueue = new Queue<object>(); _formatterConverter = new FormatterConverter(); _serObjectInfoInit = new SerObjectInfoInit(); _topId = InternalGetId(graph, false, null, out isNew); headerId = -1; WriteSerializedStreamHeader(_topId, headerId); _objectQueue.Enqueue(graph); while ((obj = GetNext(out objectId)) != null) { WriteObjectInfo objectInfo = null; // GetNext will return either an object or a WriteObjectInfo. // A WriteObjectInfo is returned if this object was member of another object if (obj is WriteObjectInfo) { objectInfo = (WriteObjectInfo)obj; } else { objectInfo = WriteObjectInfo.Serialize(obj, _surrogates, _context, _serObjectInfoInit, _formatterConverter, this, _binder); objectInfo._assemId = GetAssemblyId(objectInfo); } objectInfo._objectId = objectId; NameInfo typeNameInfo = TypeToNameInfo(objectInfo); Write(objectInfo, typeNameInfo, typeNameInfo); PutNameInfo(typeNameInfo); objectInfo.ObjectEnd(); } serWriter.WriteSerializationHeaderEnd(); serWriter.WriteEnd(); // Invoke OnSerialized Event _objectManager.RaiseOnSerializedEvent(); }
internal void Serialize(object graph, BinaryFormatterWriter serWriter, bool fCheck) { if (graph == null) { throw new ArgumentNullException(nameof(graph)); } if (serWriter == null) { throw new ArgumentNullException(nameof(serWriter)); } _serWriter = serWriter; serWriter.WriteBegin(); long headerId = 0; object obj; long objectId; bool isNew; // allocations if methodCall or methodResponse and no graph _idGenerator = new ObjectIDGenerator(); _objectQueue = new Queue <object>(); _formatterConverter = new FormatterConverter(); _serObjectInfoInit = new SerObjectInfoInit(); _topId = InternalGetId(graph, false, null, out isNew); headerId = -1; WriteSerializedStreamHeader(_topId, headerId); _objectQueue.Enqueue(graph); while ((obj = GetNext(out objectId)) != null) { WriteObjectInfo objectInfo = null; // GetNext will return either an object or a WriteObjectInfo. // A WriteObjectInfo is returned if this object was member of another object if (obj is WriteObjectInfo) { objectInfo = (WriteObjectInfo)obj; } else { objectInfo = WriteObjectInfo.Serialize(obj, _surrogates, _context, _serObjectInfoInit, _formatterConverter, this, _binder); objectInfo._assemId = GetAssemblyId(objectInfo); } objectInfo._objectId = objectId; NameInfo typeNameInfo = TypeToNameInfo(objectInfo); Write(objectInfo, typeNameInfo, typeNameInfo); PutNameInfo(typeNameInfo); objectInfo.ObjectEnd(); } serWriter.WriteSerializationHeaderEnd(); serWriter.WriteEnd(); // Invoke OnSerialized Event _objectManager.RaiseOnSerializedEvent(); }
public static IDisplayActual Create(object value, int depth = 0, ObjectIDGenerator graph = null) { if (value is null) { return(Null); } if (value is string stringValue) { if (stringValue.Length == 0) { return(EmptyString); } return(new StringDisplayActual(stringValue, depth > 0)); } if (value is Type typeValue) { return(new BasicDisplayActual(TextUtility.ConvertToSimpleTypeName(typeValue), typeof(Type))); } if (value is Exception exceptionValue) { return(Exception(exceptionValue)); } if (value is StringComparer) { return(new BasicDisplayActual(GetStringComparerText(value), value.GetType())); } if (depth > 3) { return(Ellipsis); } if (graph == null) { graph = new ObjectIDGenerator(); } graph.GetId(value, out bool first); if (!first) { return(Ellipsis); } if (value is IDisplayActual da) { return(da); } if (value is IEnumerable enumerableValue) { return(new EnumerableDisplayActual(enumerableValue, depth + 1)); } if (HasToStringOverride(value.GetType())) { return(new BasicDisplayActual(value.ToString(), value.GetType())); } return(new DefaultDisplayActual(value, depth, graph)); }
public void RunTest () { ObjectIDGenerator IDGen = new ObjectIDGenerator(); int i; for (i = 0; i < 100; i++) GetID(IDGen); }
public ObjectComparisonData() { ObjectIdGenerator1 = new ObjectIDGenerator(); ObjectIdGenerator2 = new ObjectIDGenerator(); VisitedObjectList1 = new List <long>(); VisitedObjectList2 = new List <long>(); WhereAmI = Expression.Parameter(typeof(T)); }
/// <summary> /// Sets up aspects and interceptors to enable call sequence logging. /// </summary> public virtual void SetupCallSequenceLogging(List <IInterceptor> apiAspects) { var traceLogger = GetCallSequenceLogger(); var objectIdGenerator = new ObjectIDGenerator(); var tracingAspect = new CallSequenceLoggingAspect(objectIdGenerator, traceLogger); apiAspects.Add(tracingAspect); }
public long GetID( ObjectIDGenerator IDGen ) { PlaceHolder p = new PlaceHolder(); p.holder = 0; bool temp; lock (p) { return IDGen.GetId(p, out temp); } }
static void Main() { var idgen = new ObjectIDGenerator(); object foo = new object(), bar = new object(), blap = foo; Write(idgen, foo); Write(idgen, bar); Write(idgen, blap); // note this is the same object as foo }
public virtual string Serialize(ObjectIDGenerator idGenerator) { string data = ""; data += this.GetType().FullName + ","; data += idGenerator.GetId(this, out bool firstTime) + ","; data += Id; return(data); }
public CGraphManager(Form1 parent, CLog log) { m_log = log; m_parentForm = parent; m_idGen = new ObjectIDGenerator(); m_serializer = new JsonSerializer(); m_itemMap = new Dictionary <String, NodeItem>(); m_idNameMap = new Dictionary <String, String>(); }
public MockInvocationAuditor() { _arrangementCallsMade = new Dictionary <long, IDictionary <int, int> >(); _arrangementQueue = new Dictionary <long, IDictionary <int, Queue <IArrangement> > >(); _compareLogic = new CompareLogic(); _invocationCallsMade = new Dictionary <long, IDictionary <int, int> >(); _invocationQueue = new Dictionary <long, IDictionary <int, Queue <IInvocation> > >(); _mockFailureMessageFactory = new MockFailureMessageFactory(); _objectIdGenerator = new ObjectIDGenerator(); }
public PropertyTreeObjectReader(object graph) { if (graph == null) { throw new ArgumentNullException("graph"); } this.generator = new ObjectIDGenerator(); this.graph = graph; }
public void RunTest() { ObjectIDGenerator IDGen = new ObjectIDGenerator(); int i; for (i = 0; i < 100; i++) { GetID(IDGen); } }
public long GetID(ObjectIDGenerator IDGen) { PlaceHolder p = new PlaceHolder(); p.holder = 0; bool temp; lock (p) { return(IDGen.GetId(p, out temp)); } }
public string Serialize(ObjectIDGenerator idGenerator) { StringBuilder sb = new StringBuilder(); sb.Append(GetType().FullName.ToString() + ","); sb.Append(idGenerator.GetId(Katalog, out bool firstTime) + ","); sb.Append(RokWydania + ","); sb.Append(IdOpisuStanu + ","); sb.Append(idGenerator.GetId(this, out firstTime)); return(sb.ToString()); }
public CharParserContext(string text) { if (text == null) { throw new ArgumentNullException("text"); } this.text = text; this.idgen = new ObjectIDGenerator(); this.memoTable = ImmutableSortedDictionary <PosLenId, object> .Empty; }
public override string Serialize(ObjectIDGenerator idGenerator) { string data = ""; data += this.GetType().FullName + ","; data += idGenerator.GetId(this, out bool firstTime) + ","; data += this.FirstName + ","; data += this.LastName + ","; data += this.Age.ToString() + ","; data += this.Address; return(data); }
private string GetId(object o, bool addToReferencesList) { if (idGenerator == null) { idGenerator = new ObjectIDGenerator(); } bool firstTime; long lid = idGenerator.GetId(o, out firstTime); return(String.Format(CultureInfo.InvariantCulture, "id{0}", lid)); }
// Add large numbers of objects to an ObjectIDGenerator. public void TestObjectIDGeneratorMany() { ObjectIDGenerator gen = new ObjectIDGenerator(); Object[] list = new Object [1024]; bool firstTime; int posn; for(posn = 0; posn < 1024; ++posn) { list[posn] = new Object(); AssertEquals("Many (1)", posn + 1, gen.GetId(list[posn], out firstTime)); Assert("Many (2)", firstTime); AssertEquals("Many (3)", (posn / 2) + 1, gen.GetId(list[posn / 2], out firstTime)); Assert("Many (4)", !firstTime); AssertEquals("Many (5)", (posn / 2) + 1, gen.HasId(list[posn / 2], out firstTime)); Assert("Many (6)", !firstTime); } }
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; } }
// Test exception cases. public void TestObjectIDGeneratorExceptions() { ObjectIDGenerator gen = new ObjectIDGenerator(); bool firstTime; try { gen.GetId(null, out firstTime); Fail("Exceptions (1)"); } catch(ArgumentNullException) { // Success. } try { gen.HasId(null, out firstTime); Fail("Exceptions (1)"); } catch(ArgumentNullException) { // Success. } }
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"; ObjectManager objmgr1 = null; ISurrogateSelector isur = null; StreamingContext sc1 = new StreamingContext(StreamingContextStates.All); ObjectIDGenerator objid1 = null; TestFixup tstfxp1; Int64 iRootID; Int64 iChildID; String strValue; bool fFirstTime; MemberInfo[] members = null; TestReference tst1; ThisImplementsIObjectReference tst2; try { do { strLoc="Loc_174cds"; tstfxp1 = new TestFixup(); objid1 = new ObjectIDGenerator(); iRootID = objid1.GetId(tstfxp1, out fFirstTime); strValue = "Hello World"; iChildID = objid1.GetId(strValue, out fFirstTime); members = FormatterServices.GetSerializableMembers(tstfxp1.GetType()); objmgr1 = new ObjectManager(isur, sc1); objmgr1.RecordFixup(iRootID, members[0], iChildID); objmgr1.RegisterObject(tstfxp1, iRootID); objmgr1.RegisterObject(strValue, iChildID); iCountTestcases++; if(!tstfxp1.strFixupValue.Equals(strValue)) { iCountErrors++; Console.WriteLine("Err_753cd! Expected value not returned, " + tstfxp1.strFixupValue + ", expected, " + strValue); } objmgr1.DoFixups(); iCountTestcases++; if(!tstfxp1.strFixupValue.Equals(strValue)) { iCountErrors++; Console.WriteLine("Err_90342ddvs! Expected value not returned, " + tstfxp1.strFixupValue + ", expected, " + strValue); } strLoc="Loc_5720xs"; tst1 = new TestReference(); tst2 = new ThisImplementsIObjectReference(); objid1 = new ObjectIDGenerator(); iRootID = objid1.GetId(tst1, out fFirstTime); iChildID = objid1.GetId(tst2, out fFirstTime); members = FormatterServices.GetSerializableMembers(typeof(TestReference)); Console.WriteLine("<<" + members[0].Name + ">>"); objmgr1 = new ObjectManager(isur, sc1); objmgr1.RecordFixup(iRootID, members[0], iChildID); objmgr1.RegisterObject(tst1, iRootID); objmgr1.RegisterObject(tst2, iChildID); try{ iCountTestcases++; objmgr1.DoFixups(); iCountErrors++; Console.WriteLine("Err_753fvdf! exception not thrown!!"); }catch(SerializationException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_04523cd! Unexpected exception, " + ex.ToString()); } } while (false); } 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; } }
// Check that value-equal objects are given distinct object identifiers. public void TestObjectIDGeneratorDistinct() { ObjectIDGenerator gen = new ObjectIDGenerator(); Object obj1 = (Object)3; Object obj2 = (Object)3; long id1; long id2; bool firstTime; id1 = gen.GetId(obj1, out firstTime); id2 = gen.GetId(obj2, out firstTime); Assert("Distinct (1)", (id1 != id2)); }
public virtual 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"; try { do { ObjectIDGenerator objIDGen; Object obj; long objId1, objId2; bool firstTime; Object boo2, cur2, dt2, dec2, dbl2, gui2, i16, i32, i64, sgl2, ts2; strLoc = "Loc_100aa"; objIDGen = new ObjectIDGenerator(); obj = null; iCountTestcases++; try { objIDGen.HasId(null, out firstTime); iCountErrors++; printerr("Error_289t2! Expected Exception not thrown"); } catch (ArgumentException aExc) {} catch (Exception exc) { iCountErrors++; printerr("Error_t2gsa! Incorrect Exception thrown : exc=="+exc.ToString()); } strLoc = "Loc_150aa"; objIDGen = new ObjectIDGenerator(); obj = new Decimal(10); iCountTestcases++; objId1 = objIDGen.HasId(obj, out firstTime); iCountTestcases++; if(!firstTime) { iCountErrors++; printerr("Error_209ts"); } objId1 = objIDGen.HasId(obj, out firstTime); if(!firstTime) { iCountErrors++; printerr("Error_209ts"); } if(objId1 != 0) { iCountErrors++; printerr("Error_150bb! Did not return null for non-existent object"); } strLoc = "Loc_200aa"; objIDGen = new ObjectIDGenerator(); obj = new Decimal(10); objId1 = objIDGen.GetId(obj, out firstTime); iCountTestcases++; if(!firstTime) { iCountErrors++; printerr("Error_200bb! Whoa, This object haven't been searched for before."); } strLoc = "Loc_300aa"; objIDGen = new ObjectIDGenerator(); obj = new Decimal(10); objId1 = objIDGen.GetId(obj, out firstTime); iCountTestcases++; if(!firstTime) { iCountErrors++; printerr("Error_300bb! Whoa, This object haven't been searched for before."); } objId2 = objIDGen.HasId(obj, out firstTime); iCountTestcases++; if(objId1 != objId2) { iCountErrors++; printerr("Error_300cc! Different object id's returned for the same object"); } iCountTestcases++; if(firstTime) { iCountErrors++; printerr("Error_300ee! This object has already been queried, firsttime should be false"); } strLoc = "Loc_400aa"; boo2 = false; dt2 = DateTime.Now; dec2 = new Decimal(15.2); dbl2 = ((Double)12.2); gui2 = Guid.NewGuid(); i16 = ((Int16)18); i32 = ((Int32)42); i64 = ((Int64)11); sgl2 = ((Single)(Single)3.4); ts2 = new TimeSpan(12, 12, 12); objIDGen = new ObjectIDGenerator(); strLoc = "Loc_32948"; objId1 = objIDGen.GetId(boo2, out firstTime); iCountTestcases++; if(!firstTime) { iCountErrors++; printerr("Error_400bb! FirstTime is incorrectly false"); } objId2 = objIDGen.HasId(boo2, out firstTime); iCountTestcases++; if(objId1 != objId2) { iCountErrors++; printerr("Error_400cc! Object id's not same for same object"); } iCountTestcases++; if(firstTime) { iCountErrors++; printerr("Error_400dd! FirstTime is incorrectly false"); } strLoc = "Loc_600aa"; objId1 = objIDGen.GetId(dt2, out firstTime); iCountTestcases++; if(!firstTime) { iCountErrors++; printerr("Error_600bb! FirstTime is incorrectly false"); } objId2 = objIDGen.HasId(dt2, out firstTime); iCountTestcases++; if(firstTime) { iCountErrors++; printerr("Error_600cc! FirstTime is incorrectl true"); } iCountTestcases++; if(objId2 != objId1) { iCountErrors++; printerr("Error_600dd! Object Id's different for same object"); } strLoc = "Loc_700aa"; objId1 = objIDGen.GetId(dec2, out firstTime); iCountTestcases++; if(!firstTime) { iCountErrors++; printerr("Error_700bb! FirstTime is incorrectly false"); } objId2 = objIDGen.HasId(dec2, out firstTime); iCountTestcases++; if(firstTime) { iCountErrors++; printerr("Error_700cc! FirstTime is incorrecly true"); } iCountTestcases++; if(objId2 != objId1) { iCountErrors++; printerr("Error_700dd! Object id's different for same object"); } strLoc = "Loc_800aa"; objId1 = objIDGen.GetId(dbl2, out firstTime); iCountTestcases++; if(!firstTime) { iCountErrors++; printerr("Error_800bb! FirstTime is incorrectly false"); } objId2 = objIDGen.HasId(dbl2, out firstTime); iCountTestcases++; if(firstTime) { iCountErrors++; printerr("Error_800cc! FirstTime is incorrecly true"); } iCountTestcases++; if(objId2 != objId1) { iCountErrors++; printerr("Error_800dd! Object id's different for same object"); } strLoc = "Loc_900aa"; objId1 = objIDGen.GetId(gui2, out firstTime); iCountTestcases++; if(!firstTime) { iCountErrors++; printerr("Error_800bb! FirstTime is incorrectly false"); } objId2 = objIDGen.HasId(gui2, out firstTime); iCountTestcases++; if(firstTime) { iCountErrors++; printerr("Error_800cc! FirstTime is incorrecly true"); } iCountTestcases++; if(objId2 != objId1) { iCountErrors++; printerr("Error_800dd! Object id's different for same object"); } strLoc = "Loc_1000a"; objId1 = objIDGen.GetId(i16, out firstTime); iCountTestcases++; if(!firstTime) { iCountErrors++; printerr("Error_1000b! FirstTime is incorrectly false"); } objId2 = objIDGen.HasId(i16, out firstTime); iCountTestcases++; if(firstTime) { iCountErrors++; printerr("Error_1000c! FirstTime is incorrecly true"); } iCountTestcases++; if(objId2 != objId1) { iCountErrors++; printerr("Error_1000d! Object id's different for same object"); } strLoc = "Loc_2805fe"; objIDGen = new ObjectIDGenerator(); dec2 = new Decimal(10); dbl2 = ((Double)10); objId1 = objIDGen.GetId(dec2, out firstTime); objId2 = objIDGen.HasId(dbl2, out firstTime); iCountTestcases++; if(objId1 == objId2) { iCountErrors++; printerr("Error_98532! Id's of two different objects are equal"); } } while (false); } 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; } }
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"; ObjectManager objmgr1 = null; StreamingContext sc1 = new StreamingContext(StreamingContextStates.All); ObjectIDGenerator objid1 = null; TestFixup tstfxp1; Int64 iRootID; Int64 iChildID; String strValue; bool fFirstTime; MemberInfo[] members = null; try { do { strLoc="Loc_174cds"; tstfxp1 = new TestFixup(); objid1 = new ObjectIDGenerator(); iRootID = objid1.GetId(tstfxp1, out fFirstTime); strValue = "Hello Universe"; iChildID = objid1.GetId(strValue, out fFirstTime); members = FormatterServices.GetSerializableMembers(tstfxp1.GetType()); objmgr1 = new ObjectManager(null, sc1); iCountTestcases++; if(objmgr1.GetObject(iRootID)!=null) { iCountErrors++; Console.WriteLine("Err_753cd! Expected value not returned, " + objmgr1.GetObject(iRootID)); } objmgr1.RecordFixup(iRootID, members[0], iChildID); iCountTestcases++; if(objmgr1.GetObject(iRootID)!=null) { iCountErrors++; Console.WriteLine("Err_048fd! Expected value not returned, " + objmgr1.GetObject(iRootID)); } objmgr1.RegisterObject(tstfxp1, iRootID); iCountTestcases++; if(objmgr1.GetObject(iRootID)==null) { iCountErrors++; Console.WriteLine("Err_0943fd! Null returned"); } iCountTestcases++; if(!((TestFixup)(objmgr1.GetObject(iRootID))).strFixupValue.Equals("Hello World")) { iCountErrors++; Console.WriteLine("Err_047fe! wrong value returned returned, " + ((TestFixup)(objmgr1.GetObject(iRootID))).strFixupValue); } objmgr1.RegisterObject(strValue, iChildID); iCountTestcases++; if(objmgr1.GetObject(iChildID)==null) { iCountErrors++; Console.WriteLine("Err_90853vdf! Null returned"); } iCountTestcases++; if(!objmgr1.GetObject(iChildID).Equals("Hello Universe")) { iCountErrors++; Console.WriteLine("Err_1084cs! wrong value returned returned, " + objmgr1.GetObject(iChildID)); } try{ iCountTestcases++; objmgr1.GetObject(-5); iCountErrors++; Console.WriteLine("Err_04872d! Exception not thrown"); }catch(ArgumentOutOfRangeException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_1083xs! Wrong Exception thrown, " + ex); } } while (false); } 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; } }
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"; ObjectManager objmgr1 = null; ISurrogateSelector isur = null; StreamingContext sc1 = new StreamingContext(StreamingContextStates.All); ObjectIDGenerator objid1 = null; TestFixup tstfxp1; Int64 iRootID; Int64 iChildID; Int32 iValue; bool fFirstTime; MemberInfo[] members = null; SerializationInfo serInfo1; try { do { strLoc = "Loc_8345vdfv"; tstfxp1 = new TestFixup(); iValue = 10; objid1 = new ObjectIDGenerator(); iRootID = objid1.GetId(tstfxp1, out fFirstTime); iChildID = objid1.GetId(iValue, out fFirstTime); members = FormatterServices.GetSerializableMembers(tstfxp1.GetType()); objmgr1 = new ObjectManager(isur, sc1); objmgr1.RecordDelayedFixup(iRootID, "iFixupValue", iChildID); serInfo1 = new SerializationInfo(typeof(TestFixup), new FormatterConverter()); objmgr1.RegisterObject(tstfxp1, iRootID, serInfo1); iCountTestcases++; if(objmgr1.GetObject(iRootID)==null) { iCountErrors++; Console.WriteLine("Err_0943fd! Null returned"); } objmgr1.RegisterObject(iValue, iChildID); objmgr1.DoFixups(); strLoc = "Loc_017ged"; iCountTestcases++; if(tstfxp1.iFixupValue != iValue) { iCountErrors++; Console.WriteLine("Err_753cd! Expected value not returned, " + tstfxp1.iFixupValue.ToString() + ", expected, " + iValue.ToString()); } strLoc = "Loc_0358vdf"; try { iCountTestcases++; objmgr1.RegisterObject(null, iRootID, serInfo1); iCountErrors++; Console.WriteLine("Err_034cd! exception not thrown"); } catch(ArgumentNullException){} catch(Exception ex) { iCountErrors++; Console.WriteLine("Err_03472fd! Unexpected exception, " + ex.ToString()); } try { iCountTestcases++; objmgr1.RegisterObject(tstfxp1, -5, serInfo1); iCountErrors++; Console.WriteLine("Err_037csd! exception not thrown"); } catch(ArgumentOutOfRangeException){} catch(Exception ex) { iCountErrors++; Console.WriteLine("Err_710ca! Unexpected exception, " + ex.ToString()); } try { iCountTestcases++; objmgr1.RegisterObject(tstfxp1, 5, null); Console.WriteLine("Loc_048cs! exception not thrown"); } catch(Exception ex) { iCountErrors++; Console.WriteLine("Err_079cd! Unexpected exception, " + ex.ToString()); } } while (false); } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy! strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString()); } 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; } }
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"; ObjectManager objmgr1 = null; ISurrogateSelector isur = null; StreamingContext sc1 = new StreamingContext(StreamingContextStates.All); ObjectIDGenerator objid1 = null; TestFixup tstfxp1; Int64 iRootID; Int64 iChildID; String strValue; bool fFirstTime; MemberInfo[] members = null; Test1 tst1; A a1; Int32 iOurMan; Boolean fChildFound; Test2 tst2; Test3 tst3; B b1; try { do { tstfxp1 = new TestFixup(); objid1 = new ObjectIDGenerator(); iRootID = objid1.GetId(tstfxp1, out fFirstTime); strValue = "Hello World"; iChildID = objid1.GetId(strValue, out fFirstTime); members = FormatterServices.GetSerializableMembers(tstfxp1.GetType()); objmgr1 = new ObjectManager(isur, sc1); objmgr1.RecordFixup(iRootID, members[0], iChildID); objmgr1.RegisterObject(tstfxp1, iRootID); objmgr1.RegisterObject(strValue, iChildID); iCountTestcases++; if(!tstfxp1.strFixupValue.Equals(strValue)) { iCountErrors++; Console.WriteLine("Err_753cd! Expected value not returned, " + tstfxp1.strFixupValue + ", expected, " + strValue); } objmgr1.DoFixups(); iCountTestcases++; if(!tstfxp1.strFixupValue.Equals(strValue)) { iCountErrors++; Console.WriteLine("Err_90342ddvs! Expected value not returned, " + tstfxp1.strFixupValue + ", expected, " + strValue); } tst1 = new Test1(); a1 = new A(); objid1 = new ObjectIDGenerator(); iRootID = objid1.GetId(tst1, out fFirstTime); iChildID = objid1.GetId(a1, out fFirstTime); members = FormatterServices.GetSerializableMembers(typeof(Test1)); iOurMan = -1; fChildFound=false; for(int i=0; i<members.Length;i++){ if(members[i].Name.Equals("a")){ fChildFound=true; iOurMan=i; break; } } if(!fChildFound) throw new Exception("Loc_342ds! didn't find the member"); objmgr1 = new ObjectManager(isur, sc1); objmgr1.RecordFixup(iRootID, members[iOurMan], iChildID); try{ iCountTestcases++; objmgr1.RegisterObject(a1, iChildID); objmgr1.RegisterObject(tst1, iRootID); objmgr1.DoFixups(); Console.WriteLine("Loc_0283! exception not thrown"); }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_04523cd! Unexpected exception, " + ex.ToString()); } tst1 = new Test1(); objid1 = new ObjectIDGenerator(); iRootID = objid1.GetId(tst1, out fFirstTime); a1 = new A(); iChildID = objid1.GetId(a1, out fFirstTime); members = FormatterServices.GetSerializableMembers(typeof(Test1)); iOurMan = -1; fChildFound=false; for(int i=0; i<members.Length;i++){ if(members[i].Name.Equals("a")){ fChildFound=true; iOurMan=i; break; } } if(!fChildFound) throw new Exception("Loc_342ds! didn't find the member"); objmgr1 = new ObjectManager(isur, sc1); objmgr1.RecordFixup(iRootID, members[iOurMan], iChildID); try{ iCountTestcases++; objmgr1.DoFixups(); iCountErrors++; Console.WriteLine("Err_7453fd! exception not thrown"); }catch(SerializationException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_1204cd! Unexpected exception, " + ex.ToString()); } tst1 = new Test1(); objid1 = new ObjectIDGenerator(); iRootID = objid1.GetId(tst1, out fFirstTime); a1 = new A(); iChildID = objid1.GetId(a1, out fFirstTime); members = FormatterServices.GetSerializableMembers(typeof(Test1)); iOurMan = -1; fChildFound=false; for(int i=0; i<members.Length;i++){ if(members[i].Name.Equals("a")){ fChildFound=true; iOurMan=i; break; } } if(!fChildFound) throw new Exception("Loc_342ds! didn't find the member"); objmgr1 = new ObjectManager(isur, sc1); try{ iCountTestcases++; objmgr1.RegisterObject(a1, iChildID); objmgr1.RegisterObject(tst1, iRootID); objmgr1.RecordFixup(iRootID, members[iOurMan], iChildID); objmgr1.DoFixups(); Console.WriteLine("Loc_02843cd! exception not thrown"); }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_0438fd! Unexpected exception, " + ex.ToString()); } tst1 = new Test1(); objid1 = new ObjectIDGenerator(); iRootID = objid1.GetId(tst1, out fFirstTime); a1 = new A(); iChildID = objid1.GetId(a1, out fFirstTime); members = FormatterServices.GetSerializableMembers(typeof(Test1)); iOurMan = -1; fChildFound=false; for(int i=0; i<members.Length;i++){ if(members[i].Name.Equals("a")){ fChildFound=true; iOurMan=i; break; } } if(!fChildFound) throw new Exception("Loc_342fsd! didn't find the member"); objmgr1 = new ObjectManager(isur, sc1); try{ iCountTestcases++; objmgr1.RegisterObject(a1, iChildID); objmgr1.RegisterObject(tst1, iRootID); objmgr1.DoFixups(); Console.WriteLine("Loc_94523fsd! exception not thrown"); }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_0348dcs! Unexpected exception, " + ex.ToString()); } tst2 = new Test2(); tst3 = new Test3(); b1 = new B(); b1.StrValue = "Hello World"; tst3.Set_B=b1; objid1 = new ObjectIDGenerator(); iRootID = objid1.GetId(tst2, out fFirstTime); iChildID = objid1.GetId(tst3, out fFirstTime); members = FormatterServices.GetSerializableMembers(typeof(Test2)); iOurMan = -1; fChildFound=false; for(int i=0; i<members.Length;i++){ if(members[i].Name.Equals("tst3")){ fChildFound=true; iOurMan=i; break; } } if(!fChildFound) throw new Exception("Loc_024fd! didn't find the member"); objmgr1 = new ObjectManager(isur, sc1); objmgr1.RecordFixup(iRootID, members[iOurMan], iChildID); objmgr1.RegisterObject(tst2, iRootID); objmgr1.RegisterObject(tst3, iChildID); iCountTestcases++; Console.WriteLine("Loc_4523vfd! we hve, " + tst2.StrValue); if(!tst2.StrValue.Equals("Hello World")) { iCountErrors++; Console.WriteLine("Err_038qm! Expected value not returned, " + tst2.StrValue); } tstfxp1 = new TestFixup(); objid1 = new ObjectIDGenerator(); iRootID = objid1.GetId(tstfxp1, out fFirstTime); strValue = "Hello World"; members = FormatterServices.GetSerializableMembers(tstfxp1.GetType()); objmgr1 = new ObjectManager(null, sc1); objmgr1.RecordFixup(iRootID, members[0], iRootID); try{ iCountTestcases++; objmgr1.RegisterObject(tstfxp1, iRootID); iCountErrors++; Console.WriteLine("Err_753cd! exception not thrown"); }catch(ArgumentException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_04523cd! Unexpected exception, " + ex.ToString()); } try { iCountTestcases++; objmgr1.RecordFixup(-1, members[0], iChildID); iCountErrors++; Console.WriteLine("Err_034cd! exception not thrown"); } catch(ArgumentOutOfRangeException){} catch(Exception ex) { iCountErrors++; Console.WriteLine("Err_034cd! Unexpected exception, " + ex.ToString()); } try { iCountTestcases++; objmgr1.RecordFixup(iRootID, members[0], -5); iCountErrors++; Console.WriteLine("Err_037csd! exception not thrown"); } catch(ArgumentOutOfRangeException){} catch(Exception ex) { iCountErrors++; Console.WriteLine("Err_710ca! Unexpected exception, " + ex.ToString()); } try { iCountTestcases++; objmgr1.RecordFixup(iRootID, null, iChildID); iCountErrors++; Console.WriteLine("Err_048cs! exception not thrown"); } catch(ArgumentNullException){} catch(Exception ex) { iCountErrors++; Console.WriteLine("Err_079cd! Unexpected exception, " + ex.ToString()); } } while (false); } 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; } }
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"; ObjectManager objmgr1 = null; StreamingContext sc1 = new StreamingContext(StreamingContextStates.All); ObjectIDGenerator objid1 = null; Int64 iRootID; Int64 iChildID; bool fFirstTime; String[] strArr; String strToBeFixed; TestArrayFixup[] arrTst1; TestArrayFixup tst1; Int32[] indices; String[,] multiArr; String anotherString; Int64 anotherStringId; try { do { strLoc = "Loc_9457and"; strArr = new String[1]; strToBeFixed = "Hello World"; indices = new Int32[1]; indices[0] = 0; objid1 = new ObjectIDGenerator(); iRootID = objid1.GetId(strArr, out fFirstTime); iChildID = objid1.GetId(strToBeFixed, out fFirstTime); objmgr1 = new ObjectManager(null, sc1); objmgr1.RecordArrayElementFixup(iRootID, indices, iChildID); objmgr1.RegisterObject(strArr, iRootID); objmgr1.RegisterObject(strToBeFixed, iChildID); iCountTestcases++; if(!strArr[0].Equals(strToBeFixed)) { iCountErrors++; Console.WriteLine("Err_0452fsd! Expected value not returned, " + strArr[0] + ", expected, " + strToBeFixed); } objmgr1.DoFixups(); strLoc = "Loc_017ged"; iCountTestcases++; if(!strArr[0].Equals(strToBeFixed)) { iCountErrors++; Console.WriteLine("Err_90453vdf! Expected value not returned, " + strArr[0] + ", expected, " + strToBeFixed); } multiArr = new String[5, 10]; indices = new Int32[2]; indices[0] = 1; indices[1] = 5; objid1 = new ObjectIDGenerator(); iRootID = objid1.GetId(multiArr, out fFirstTime); strToBeFixed = "Hello World"; iChildID = objid1.GetId(strToBeFixed, out fFirstTime); objmgr1 = new ObjectManager(null, sc1); objmgr1.RecordArrayElementFixup(iRootID, indices, iChildID); objmgr1.RegisterObject(multiArr, iRootID); objmgr1.RegisterObject(strToBeFixed, iChildID); iCountTestcases++; if(!multiArr[1, 5].Equals(strToBeFixed)){ iCountErrors++; Console.WriteLine("Err_79435sdg_! Expected value not returned, " + multiArr[1,5] + ", expected, " + strToBeFixed); } strLoc = "Loc_1294cd"; arrTst1 = new TestArrayFixup[10]; tst1 = new TestArrayFixup(); indices = new Int32[1]; indices[0] = 5; objid1 = new ObjectIDGenerator(); iRootID = objid1.GetId(arrTst1, out fFirstTime); iChildID = objid1.GetId(tst1, out fFirstTime); objmgr1 = new ObjectManager(null, sc1); objmgr1.RecordArrayElementFixup(iRootID, indices, iChildID); objmgr1.RegisterObject(arrTst1, iRootID); objmgr1.RegisterObject(tst1, iChildID); iCountTestcases++; if(arrTst1[5].iValue != tst1.iValue) { iCountErrors++; Console.WriteLine("Err_112sx! Expected value not returned, " + arrTst1[5].iValue + ", expected, " + tst1.iValue); } objmgr1.DoFixups(); strLoc = "Loc_017ged"; iCountTestcases++; if(arrTst1[5].iValue != tst1.iValue) { iCountErrors++; Console.WriteLine("Err_2048cd! Expected value not returned, " + arrTst1[5].iValue + ", expected, " + tst1.iValue); } strLoc = "Loc_83476tsg"; iCountTestcases++; strArr = new String[1]; strToBeFixed = "Hello World"; indices = new Int32[2]; indices[0] = 0; indices[1] = 0; objid1 = new ObjectIDGenerator(); iRootID = objid1.GetId(strArr, out fFirstTime); iChildID = objid1.GetId(strToBeFixed, out fFirstTime); objmgr1 = new ObjectManager(null, sc1); objmgr1.RecordArrayElementFixup(iRootID, indices, iChildID); objmgr1.RegisterObject(strArr, iRootID); try{ objmgr1.RegisterObject(strToBeFixed, iChildID); iCountErrors++; Console.WriteLine("Err_0452fsd! Exception not thrown"); }catch(ArgumentException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_0452fsd! Wrong Exception thrown, " + ex.GetType().Name); } strLoc = "Loc_9457and"; iCountTestcases++; strArr = new String[5]; strToBeFixed = "Hello World"; indices = new Int32[1]; indices[0] = 0; objid1 = new ObjectIDGenerator(); iRootID = objid1.GetId(strArr, out fFirstTime); iChildID = objid1.GetId(strToBeFixed, out fFirstTime); anotherString = "Another String"; anotherStringId = objid1.GetId(anotherString, out fFirstTime); objmgr1 = new ObjectManager(null, sc1); objmgr1.RecordArrayElementFixup(iRootID, indices, iChildID); objmgr1.RegisterObject(strArr, iRootID); objmgr1.RegisterObject(anotherString, anotherStringId); try{ objmgr1.DoFixups(); iCountErrors++; Console.WriteLine("Err_0452fsd! Exception not thrown"); }catch(SerializationException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_0452fsd! Wrong Exception thrown, " + ex.GetType().Name); } try { iCountTestcases++; objmgr1.RecordArrayElementFixup(-1, indices, iChildID); iCountErrors++; Console.WriteLine("Err_034cd! exception not thrown"); }catch(ArgumentOutOfRangeException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_034cd! Unexpected exception, " + ex.ToString()); } try { iCountTestcases++; objmgr1.RecordArrayElementFixup(2, indices, -5); iCountErrors++; Console.WriteLine("Err_943cdd! exception not thrown"); }catch(ArgumentOutOfRangeException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_0834csd! Unexpected exception, " + ex.ToString()); } try { iCountTestcases++; indices = new Int32[1]; indices[0] = -5; objmgr1.RecordArrayElementFixup(100, indices, 50); Console.WriteLine("Loc_943cdd! exception not thrown"); }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_8321sd! Unexpected exception, " + ex.ToString()); } } while (false); } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy! strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString()); } 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; } }
public bool runTest() { Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer); String strLoc = "Loc_000oo"; String strValue = String.Empty; int iCountErrors = 0; int iCountTestcases = 0; ObjectManager objmgr1 = null; ISurrogateSelector isur = null; StreamingContext sc1 = new StreamingContext(StreamingContextStates.All); ObjectIDGenerator objid1 = null; TestFixup tstfxp1; Int64 iRootID; Int64 iChildID; bool fFirstTime; MemberInfo[] members = null; try { strLoc = "Loc_9347sg"; iCountTestcases++; try{ ConstructOM(); iCountErrors++; Console.WriteLine("Err_7349sg! No exception thrown, "); }catch(SecurityException){ }catch(Exception ex){ iCountErrors++; Console.WriteLine("Err_348tdg! Wrong exception thrown, " + ex.GetType().Name); } strLoc = "Loc_3946tsg"; iCountTestcases++; tstfxp1 = new TestFixup(); objid1 = new ObjectIDGenerator(); iRootID = objid1.GetId(tstfxp1, out fFirstTime); strValue = "Hello World"; iChildID = objid1.GetId(strValue, out fFirstTime); members = FormatterServices.GetSerializableMembers(tstfxp1.GetType()); objmgr1 = new ObjectManager(isur, sc1); objmgr1.RecordFixup(iRootID, members[0], iChildID); objmgr1.RegisterObject(tstfxp1, iRootID); objmgr1.RegisterObject(strValue, iChildID); iCountTestcases++; if(!tstfxp1.strFixupValue.Equals(strValue)) { iCountErrors++; Console.WriteLine("Err_753cd! Expected value not returned, " + tstfxp1.strFixupValue + ", expected, " + strValue); } objmgr1.DoFixups(); iCountTestcases++; if(!tstfxp1.strFixupValue.Equals(strValue)) { iCountErrors++; Console.WriteLine("Err_90342ddvs! Expected value not returned, " + tstfxp1.strFixupValue + ", expected, " + strValue); } } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy! strLoc=="+ strLoc +", exc_general=="+exc_general.ToString()); } if ( iCountErrors == 0 ) { Console.WriteLine( "paSs. "+s_strTFName+" ,iCountTestcases=="+iCountTestcases.ToString()); return true; } else { Console.WriteLine("FAiL! "+s_strTFName+" ,inCountErrors=="+iCountErrors.ToString()+" , BugNums?: "+s_strActiveBugNums ); return false; } }