protected override bool PrePerform(PicnicTable obj, bool postLoad) { bool repair = false; if (obj.SeatingGroup != null) { if (obj.mInsideSeats == null) { repair = true; } else { foreach (PartData seat in obj.mInsideSeats) { if (seat == null) { repair = true; break; } } } } if (repair) { obj.OnCreation(); LogCorrection("Picnic Table Seats Repaired: " + ErrorTrap.GetName(obj)); } return(true); }
protected override DereferenceResult Perform(Homework reference, FieldInfo field, List <ReferenceWrapper> objects) { if (Matches(reference, "OwningSimDescription", field, objects)) { if (Performing) { ErrorTrap.AddToBeDeleted(reference, true); Remove(ref reference.OwningSimDescription); } return(DereferenceResult.End); } if (Matches(reference, "HomeworkSoloJig", field, objects)) { if (Performing) { try { reference.HomeworkSoloJig.Destroy(); } catch { } Remove(ref reference.HomeworkSoloJig); } return(DereferenceResult.End); } return(DereferenceResult.Failure); }
public static Module ParseModule(CompileUnit cu, TextReader input, ConverterSettings settings, out IList<ISpecial> specials) { if (cu == null) throw new ArgumentNullException("cu"); if (input == null) throw new ArgumentNullException("input"); if (settings == null) throw new ArgumentNullException("settings"); IParser parser = ParserFactory.CreateParser(settings.IsVisualBasic ? SupportedLanguage.VBNet : SupportedLanguage.CSharp, input); ErrorTrap errorTrap = new ErrorTrap(settings); parser.Errors.SemErr = errorTrap.DefaultCodeError; parser.Errors.SynErr = errorTrap.DefaultCodeError; parser.Errors.Error = errorTrap.DefaultMsgError; parser.Parse(); specials = parser.Lexer.SpecialTracker.CurrentSpecials; if (settings.IsVisualBasic) { PreprocessingDirective.VBToCSharp(specials); } // abort when file has errors if (errorTrap.count > 0) return null; Module m = Converter.Convert(parser.CompilationUnit, settings); if (m != null && cu != null) { cu.Modules.Add(m); if (settings.RemoveRedundantTypeReferences) { cu.Accept(new RemoveRedundantTypeReferencesVisitor()); } } return m; }
protected override void Perform(SimDescription obj, object parent, FieldInfo field) { //if (obj.IsValidDescription) return; if (mSims == null) { mSims = SimListing.AllSims <SimDescription>(null, true); } // All residents, ancestors, and urnstone sims are considered valid if (mSims.ContainsKey(obj.SimDescriptionId)) { return; } GameObjectReference reference = ObjectLookup.GetReference(new ReferenceWrapper(obj)); if (!DereferenceManager.Perform(obj, reference, false, false)) { return; } DereferenceManager.Perform(obj, reference, true, false); string fullName = obj.FullName; if (!string.IsNullOrEmpty(fullName)) { fullName = fullName.Trim(); } if (!string.IsNullOrEmpty(fullName)) { bool found = false; foreach (List <SimDescription> list in mSims.Values) { foreach (SimDescription sim in list) { if (sim.FullName == fullName) { found = true; break; } } } if (!found) { if (reference.Count > 0) { ErrorTrap.LogCorrection("SimDescription Removed: " + fullName); } else { ErrorTrap.DebugLogCorrection("Zero Reference SimDescription Removed: " + fullName); } } } }
protected override void Perform(MapTag obj, object parent, FieldInfo field) { if (!mMapTags.ContainsKey(obj)) { obj.OnRemovedFromManager(); ErrorTrap.DebugLogCorrection("Bogus Map Tag Dropped: " + obj.GetType()); } }
protected override bool PostPerform(IDataDrivenObject obj, bool postLoad) { if (ErrorTrap.Loading) { ErrorTrap.AddObjectOfInterest(obj); } return(true); }
protected override bool PrePerform(MoonDial dial, bool postLoad) { if ((World.GetLunarPhase() < 0) || (World.GetLunarPhase() >= dial.mLunarFXLookUp.Length)) { World.SetLunarPhase(0); ErrorTrap.LogCorrection("LunarPhase Repaired"); } return(true); }
protected override void OnPerform() { if (!object.ReferenceEquals(mSim.CurrentInteraction, mInstance)) { return; } ErrorTrap.DebugLogCorrection("Follow Route Action Reset: " + mSim.FullName); new ResetSimTask(mSim); }
protected override DereferenceResult Perform(AttractionGift reference, FieldInfo field, List <ReferenceWrapper> objects) { if (Matches(reference, "mSimReceivingGift", field, objects)) { //Remove(ref reference.mSimReceivingGift); ErrorTrap.AddToBeDeleted(reference, false); return(DereferenceResult.End); } return(DereferenceResult.Failure); }
public static void MergePlantSeed(HarvestPlant plant, Ingredient ingredient) { plant.Seed = ingredient; plant.PlantDef = PlantHelper.GetPlantDefinition(plant.Seed); plant.mQualityLevel = ingredient.Plantable.QualityLevel; plant.SetGrowthState(plant.GrowthState); sMergedPlants.Add(plant); ErrorTrap.LogCorrection("Plant Seed Merged: " + ErrorTrap.GetName(plant)); }
public void LogReferences() { Dictionary <ReferenceWrapper, bool> processed = new Dictionary <ReferenceWrapper, bool>(); List <StackFrame> references = new List <StackFrame>(); foreach (KeyValuePair <object, FieldInfo> obj in this) { references.Add(new StackFrame(new ReferenceWrapper(obj.Key), obj.Value, "")); } int index = 0; while (index < references.Count) { StackFrame stack = references[index]; index++; bool repeat = false; if (processed.ContainsKey(stack.mReference)) { repeat = true; } else { processed.Add(stack.mReference, true); } GameObjectReference reference = ObjectLookup.GetReference(stack.mReference); ErrorTrap.LogCorrection(" Reference: " + stack.mDepth + stack.mReference.mObject.GetType() + " " + stack.mField + (repeat ? " (Recursion)" : "")); if (stack.mReference.mObject is GameObject) { continue; } if (repeat) { continue; } if (reference != null) { foreach (KeyValuePair <object, FieldInfo> obj in reference) { references.Insert(index, new StackFrame(new ReferenceWrapper(obj.Key), obj.Value, stack.mDepth + " ")); } } } }
protected override DereferenceResult Perform(SculptureFrozenSim reference, FieldInfo field, List <ReferenceWrapper> objects) { if (Matches(reference, "mFrozenSim", field, objects)) { Remove(ref reference.mFrozenSim); if (Performing) { ErrorTrap.AddToBeDeleted(reference, true); } return(DereferenceResult.End); } return(DereferenceResult.Failure); }
protected override DereferenceResult Perform(FireManager reference, FieldInfo field, List <ReferenceWrapper> objects) { if (Matches(reference, "mWindowFires", field, objects)) { Remove(reference.mWindowFires, objects); return(DereferenceResult.End); } if (Matches(reference, "mObjectsToRestore", field, objects)) { if (Performing) { EmergencyFireRestorer obj = FindLast <EmergencyFireRestorer>(objects); if (obj != null) { ErrorTrap.AddToBeDeleted(obj.mObject, true); } Remove(reference.mObjectsToRestore, objects); } return(DereferenceResult.End); } if (Matches(reference, "mSimsReactedToFire", field, objects)) { Remove(reference.mSimsReactedToFire, objects); return(DereferenceResult.End); } ReferenceWrapper result; if (Matches(reference, "mFireSource", field, objects, out result) != MatchResult.Failure) { if (Performing) { if (result.Valid) { Remove(ref reference.mFireSource); } } return(DereferenceResult.End); } return(DereferenceResult.Failure); }
protected override DereferenceResult Perform(Sim.Placeholder reference, FieldInfo field, List <ReferenceWrapper> objects) { if (Matches(reference, "mSimDescription", field, objects)) { if (Performing) { ErrorTrap.AddToBeDeleted(reference, true); Remove(ref reference.mSimDescription); return(DereferenceResult.End); } else { return(DereferenceResult.Found); } } return(DereferenceResult.Failure); }
public static Module ParseModule(CompileUnit cu, TextReader input, ConverterSettings settings, out IList <ISpecial> specials) { if (cu == null) { throw new ArgumentNullException("cu"); } if (input == null) { throw new ArgumentNullException("input"); } if (settings == null) { throw new ArgumentNullException("settings"); } IParser parser = ParserFactory.CreateParser(settings.IsVisualBasic ? SupportedLanguage.VBNet : SupportedLanguage.CSharp, input); ErrorTrap errorTrap = new ErrorTrap(settings); parser.Errors.SemErr = errorTrap.DefaultCodeError; parser.Errors.SynErr = errorTrap.DefaultCodeError; parser.Errors.Error = errorTrap.DefaultMsgError; parser.Parse(); specials = parser.Lexer.SpecialTracker.CurrentSpecials; if (settings.IsVisualBasic) { PreprocessingDirective.VBToCSharp(specials); } // abort when file has errors if (errorTrap.count > 0) { return(null); } Module m = Converter.Convert(parser.CompilationUnit, settings); if (m != null && cu != null) { cu.Modules.Add(m); if (settings.RemoveRedundantTypeReferences) { cu.Accept(new RemoveRedundantTypeReferencesVisitor()); } } return(m); }
protected override void PreProcess(FollowRouteAction obj, object parent, FieldInfo field) { IScriptProxy proxy = Simulator.GetProxy(obj.mRoutingObjectId); if (proxy == null) { return; } Sim sim = proxy.Target as Sim; if (sim == null) { return; } SimRoutingComponent component = sim.RoutingComponent as SimRoutingComponent; if (component == null) { return; } if (component.mRouteActions.Contains(obj)) { return; } if (sSims == null) { sSims = new Dictionary <Sim, InteractionInstance>(); } if (!sSims.ContainsKey(sim)) { sSims.Add(sim, sim.CurrentInteraction); ErrorTrap.DebugLogCorrection("Potential Follow Route Action Reset: " + sim.FullName); } }
protected override bool PrePerform(GameObject obj, bool postLoad) { if (obj.InInventory) { Inventory inventory = Inventory.ParentInventory(obj); if (inventory != null) { if (inventory.Owner == null) { ErrorTrap.AddToBeDeleted(obj, true); LogCorrection("Corrupt Inventory Object Deleted: " + ErrorTrap.GetName(obj)); } } } if (obj.Inventory != null) { Inventories.CheckInventory(LogCorrection, DebugLogCorrection, ErrorTrap.GetName(obj), obj.Inventory, false); } ObjectComponents.Cleanup(obj, DebugLogCorrection); return(true); }
protected override void Perform(GameObject obj, object referenceParent, FieldInfo field) { if (obj is Ocean) { if (LotManager.sOceanObject == obj) { return; } } else if (obj is Terrain) { if (Terrain.sTerrain == obj) { return; } } if (DereferenceManager.HasBeenDestroyed(obj)) { if (obj is Sim) { LotManager.sActorList.Remove(obj as Sim); DereferenceManager.Perform(obj, ObjectLookup.GetReference(new ReferenceWrapper(obj)), true, false); } else { GameObjectReference refObj = ObjectLookup.GetReference(new ReferenceWrapper(obj)); if (DereferenceManager.Perform(obj, refObj, false, false)) { DereferenceManager.Perform(obj, refObj, true, false); ErrorTrap.LogCorrection("Destroyed Object Found: " + obj.GetType()); } } return; } if (kShowFullReferencing) { DereferenceManager.Perform(obj, ObjectLookup.GetReference(new ReferenceWrapper(obj)), false, true); } if (obj.InWorld) { return; } if (obj.InInventory) { if (Inventories.ParentInventory(obj) == null) { if ((obj.Parent != null) || (Consignment.ContainsKey(obj))) { obj.SetFlags(GameObject.FlagField.InInventory, false); ErrorTrap.LogCorrection("Invalid Inventory Object Unflagged: " + obj.GetType()); } else { ErrorTrap.LogCorrection("Invalid Inventory Object Found: " + obj.GetType()); ErrorTrap.AddToBeDeleted(obj, true); } } return; } else { if (SharedInventories.ContainsKey(obj.ObjectId)) { obj.SetFlags(GameObject.FlagField.InInventory, true); ErrorTrap.LogCorrection("Inventory Object Flagged: " + obj.GetType()); return; } } if (EventItems.ContainsKey(obj.ObjectId)) { return; } bool hasParent = false; IGameObject parent = obj.Parent; while (parent != null) { hasParent = true; if (DereferenceManager.HasBeenDestroyed(parent)) { ErrorTrap.LogCorrection("Destroyed Parent Object Found: " + parent.GetType()); ErrorTrap.AddToBeDeleted(obj, true); hasParent = false; break; } parent = parent.Parent; } if (!hasParent) { ReferenceWrapper refObj = new ReferenceWrapper(obj); GameObjectReference reference = ObjectLookup.GetReference(refObj); if ((reference != null) && (reference.HasReferences)) { if (DereferenceManager.Perform(obj, ObjectLookup.GetReference(refObj), false, false)) { IScriptProxy proxy = Simulator.GetProxy(obj.ObjectId); if (proxy != null) { IScriptLogic logic = proxy.Target; if (object.ReferenceEquals(logic, obj)) { bool log = !sSilentDestroy.ContainsKey(obj.GetType()); if (log) { ErrorTrap.LogCorrection("Out of World Object Found 2: " + obj.GetType()); } else { ErrorTrap.DebugLogCorrection("Out of World Object Found 3: " + obj.GetType()); } ErrorTrap.AddToBeDeleted(obj, log); } else { ErrorTrap.DebugLogCorrection("Out of World Object Found 4: " + obj.GetType()); ErrorTrap.DebugLogCorrection("Out of World Object Found 5: " + logic.GetType()); } } else { DereferenceManager.Perform(obj, ObjectLookup.GetReference(refObj), true, false); } } } else { ErrorTrap.LogCorrection("Out of World Object Found 1: " + obj.GetType()); ErrorTrap.AddToBeDeleted(obj, true); } } }
public static bool Perform(object obj, GameObjectReference references, bool perform, bool reportFound) { bool immediate = false; bool report = true; if ((obj is RabbitHoleDoorJig) || (obj is PhoneCell)) { report = ErrorTrap.kDebugging; } else if (obj is Lot) { immediate = true; } else if (obj is Sim) { Sim sim = obj as Sim; if (sim.LotHome != null) { if ((RecoverMissingSimTask.FindPlaceholderForSim(sim.SimDescription) == null) && ((sim.SimDescription.CreatedSim == null) || (sim.SimDescription.CreatedSim == sim))) { immediate = true; } } } ReferenceLog log = null; if (!perform) { log = new ReferenceLog("Potential Object Found: " + ErrorTrap.GetQualifiedName(obj), report, immediate); } if (references == null) { return(false); } if ((!ErrorTrap.kDebugging) && (references.Count == 0)) { return(false); } if (perform) { log = new ReferenceLog("Destroyed Object Found: " + ErrorTrap.GetQualifiedName(obj), report, immediate); } log.Perform = perform; log.ReportFound = reportFound; if ((!ErrorTrap.kDebugging) && (obj is Lot)) { return(false); } List <DereferenceStack> stack = new List <DereferenceStack>(); foreach (KeyValuePair <object, FieldInfo> pair in references) { stack.Add(new DereferenceStack(pair, new Dictionary <ReferenceWrapper, bool>(), new List <ReferenceWrapper>(), new ReferenceWrapper(obj), false, false)); } bool firstFailure = true; int index = 0; while (index < stack.Count) { DereferenceStack stackObject = stack[index]; index++; ReferenceWrapper key = new ReferenceWrapper(stackObject.mReference.Key); bool recursion = false; if (stackObject.ContainsKey(key)) { recursion = true; } if ((perform) && (stackObject.Count == 1)) { log.DumpLog(false); } object reference = stackObject.mReference.Key; string depth = ""; for (int i = 0; i < stackObject.Count - 1; i++) { depth += " "; } bool reset = false, success = false; foreach (IDereference dereference in DereferenceManager.Dereferences) { DereferenceResult result = dereference.IPerform(stackObject.mReference, stackObject.mList, perform); if (result == DereferenceResult.Found) { log.SetFoundSuccess(); } if (result != DereferenceResult.Failure) { stackObject.mResult = depth + " Reference " + result + ": " + reference.GetType() + " " + stackObject.mReference.Value + " (Using " + dereference.GetType().Name + ")"; if (report) { log.Add(stackObject.mResult); } success = true; bool checkSuccess = false; if (reference is GameObject) { stackObject.mEndFound = true; checkSuccess = true; GameObject gameObject = reference as GameObject; if ((perform) && (!HasBeenDestroyed(gameObject)) && (!reset) && (!(reference is Sim))) { try { reset = true; gameObject.SetObjectToReset(); log.Add(depth + " Object Reset: " + ErrorTrap.GetQualifiedName(gameObject)); } catch //(Exception e) { //Common.DebugException(gameObject, e); } } } else { switch (result) { case DereferenceResult.End: case DereferenceResult.Found: stackObject.mEndFound = true; break; case DereferenceResult.Continue: case DereferenceResult.ContinueIfReferenced: case DereferenceResult.Ignore: bool unimportant = stackObject.mUnimportant; switch (result) { case DereferenceResult.ContinueIfReferenced: unimportant = true; break; case DereferenceResult.Ignore: unimportant = true; stackObject.mEndFound = true; break; } if (!recursion) { if (ShouldRecurse(reference)) { bool referenced = false; GameObjectReference gameReference = ObjectLookup.GetReference(key); if (gameReference != null) { foreach (KeyValuePair <object, FieldInfo> pair in gameReference) { stack.Insert(index, new DereferenceStack(pair, stackObject, key, unimportant, stackObject.mEndFound)); referenced = true; } } if (!referenced) { checkSuccess = true; if (result == DereferenceResult.ContinueIfReferenced) { stackObject.mEndFound = true; } } else { stackObject.mBridge = true; } } else { stackObject.mEndFound = true; } } else if (result == DereferenceResult.ContinueIfReferenced) { stackObject.mEndFound = true; } else { checkSuccess = true; } break; default: if (recursion) { checkSuccess = true; } break; } } if (checkSuccess) { switch (result) { case DereferenceResult.End: case DereferenceResult.Ignore: break; default: if (recursion) { if (!object.ReferenceEquals(key.mObject, obj)) { log.SetFailure("A"); } else { stackObject.mEndFound = true; } } else { log.SetFailure("B"); } break; } } } } if (!success) { bool mustRecurse = false; string priority = "UNHANDLED"; if (recursion) { priority = "Recursion"; if (object.ReferenceEquals(key.mObject, obj)) { stackObject.mEndFound = true; } else { stackObject.mBridge = true; } } else if ((reference.GetType().IsArray) || (reference is IList) || (reference is IDictionary) || (reference is ICollection) || (reference.GetType().Name.Contains("ForgetfulList")) || (reference.GetType().Name.Contains("PairedListDictionary"))) { priority = "Bridge"; mustRecurse = true; stackObject.mBridge = true; } else if (stackObject.mUnimportant) { priority = "Ancillary"; if ((reference is GameObject) || (reference is SimDescription)) { recursion = true; } else { mustRecurse = true; } stackObject.mBridge = true; } else { log.ImportantFound(); log.SetFailure("C"); } stackObject.mResult = depth + " " + priority + " Reference: " + ErrorTrap.GetQualifiedName(reference) + " " + stackObject.mReference.Value; if (report) { log.Add(stackObject.mResult); } bool referenced = false; if (!recursion) { if (ShouldRecurse(reference)) { GameObjectReference gameReference = ObjectLookup.GetReference(key); if (gameReference != null) { foreach (KeyValuePair <object, FieldInfo> pair in gameReference) { stack.Insert(index, new DereferenceStack(pair, stackObject, key, stackObject.mUnimportant, stackObject.mEndFound)); referenced = true; } } } else { stackObject.mEndFound = true; mustRecurse = false; } } if (!referenced) { if (mustRecurse) { log.SetFailure("D"); } } else { stackObject.mBridge = true; } } if ((!perform) && (!log.IsTotalSuccess) && (firstFailure)) { firstFailure = false; log.Add(depth + " RETAINED " + log.FailureReason); } } bool first = true; foreach (DereferenceStack stackObject in stack) { if (stackObject.mEndFound) { continue; } if (stackObject.mBridge) { continue; } log.EndMissing(); if (first) { first = false; log.Add(" OPEN ENDED"); } log.Add(stackObject.mResult); } log.DumpLog(false); Logger.ForceRecord(); return(log.IsTotalSuccess); }
public void RunErrorTest(params JSError[] expectedErrorArray) { // open the stack trace for this call StackTrace stackTrace = new StackTrace(); string testClass = null; string testName = null; // save the name of the current method (RunTest) string currentMethodName = MethodInfo.GetCurrentMethod().Name; // loop from the previous frame up until we get a method name that is not the // same as the current method name for (int ndx = 1; ndx < stackTrace.FrameCount; ++ndx) { // get the frame StackFrame stackFrame = stackTrace.GetFrame(ndx); // we have different entry points with the same name -- we're interested // in the first one that ISN'T the same name as our method MethodBase methodBase = stackFrame.GetMethod(); if (methodBase.Name != currentMethodName) { // the calling method's name is the test name - we use this as-is for the output file name // and we use any portion before an underscore as the input file testName = methodBase.Name; // get the method's class - we use this as the subfolder under input/output/expected testClass = methodBase.DeclaringType.Name; break; } } // we definitely should be able to find a function on the stack frame that // has a different name than this function, but just in case... Debug.Assert(testName != null && testClass != null, "Couldn't locate calling stack frame"); // the input file is the portion of the test name before the underscore (if any) string inputFile = testName.Split('_')[0]; // get the input path string inputPath = GetJsPath( m_inputFolder, testClass, inputFile, false ); Assert.IsTrue(File.Exists(inputPath), "Input File does not exist: {0}", inputPath); // read the input JS string jsSource; using (StreamReader reader = new StreamReader(inputPath, true)) { jsSource = reader.ReadToEnd(); } Trace.Write("INPUT FILE: "); Trace.WriteLine(inputPath); Trace.WriteLine(jsSource); /*int expectedErrorCode = (int)(0x800A0000 + (int)expectedError); Trace.WriteLine(string.Empty); Trace.WriteLine(string.Format("Expecting error 0x{0:X}", expectedErrorCode));*/ bool testPassed = true; List<JSError> expectedErrorList = new List<JSError>(expectedErrorArray); ErrorTrap errorTrap = new ErrorTrap(); string crunchedCode = errorTrap.RunTest(jsSource); JScriptException[] errors = errorTrap.Errors; Trace.WriteLine(string.Empty); Trace.WriteLine("---ERRORS---"); Trace.Indent(); foreach (JScriptException ex in errors) { // log the error Trace.WriteLine(string.Empty); Trace.WriteLine(string.Format("Error 0x{0:X} at Line {1}, Column {2}: {3}", ex.Error, ex.Line, ex.Column, ex.ErrorSegment)); Trace.Indent(); Trace.WriteLine(ex.Message); JSError errorCode = (JSError)(ex.Error & 0xffff); int index = expectedErrorList.IndexOf(errorCode); if (index >= 0) { // expected error -- remove it from the list so we can tell what we're missing later expectedErrorList.RemoveAt(index); } else { // unexpected error testPassed = false; Trace.WriteLine("UNEXPECTED"); } Trace.Unindent(); } Trace.Unindent(); // the list should be empty now -- if it isn't, then there was an expected error that didn't happen if (expectedErrorList.Count > 0) { testPassed = false; Trace.WriteLine(string.Empty); Trace.WriteLine("---MISSING ERRORS---"); Trace.Indent(); foreach (JSError jsError in expectedErrorList) { Trace.WriteLine(jsError.ToString()); } Trace.Unindent(); } if (!testPassed) { Trace.WriteLine("UNEXPECTED ERROR RESULTS"); } Trace.WriteLine(string.Empty); Trace.WriteLine("---Resulting Code---"); Trace.WriteLine(crunchedCode); // compute the path to the expected file string expectedPath = GetJsPath( m_expectedFolder, testClass, testName, false ); if (File.Exists(expectedPath)) { string expectedCode; using (StreamReader reader = new StreamReader(expectedPath, true)) { expectedCode = reader.ReadToEnd(); } Trace.WriteLine(string.Empty); Trace.WriteLine("---Expected Code---"); Trace.WriteLine(expectedCode); if (string.CompareOrdinal(expectedCode, crunchedCode) != 0) { Trace.WriteLine("EXPECTED OUTPUT IS DIFFERENT"); testPassed = false; } } Assert.IsTrue(testPassed, "Test failed"); }
protected void LogCorrection(string text) { ErrorTrap.LogCorrection(text); }
protected static Delegate ProcessDuplicates(Delegate del) { Delegate result = del; Delegate[] subs = del.GetInvocationList(); if (subs.Length > 1) { List <Delegate> exists = new List <Delegate>(); bool first = true; foreach (Delegate sub in subs) { if (exists.Contains(sub)) { del = Delegate.Remove(del, sub); // return parameter result = del; bool record = Common.kDebugging; if (record) { // Some objects are written incorrectly and continually add a new delegate each time the game is loaded // without removing the old one. Fix these, but don't record them if (sub.Target is ICanHasTombObjectComponent) { record = false; } else if (sub.Target is CollectionDisplaySingleItem) { record = false; } else if (sub.Target is CookingProcess) { record = false; } } if (record) { if (first) { first = false; ErrorTrap.LogCorrection("Delegate: " + del); } string text = sub.ToString(); text += ": " + sub.Method + " (" + sub.Target + ")"; ErrorTrap.LogCorrection("Duplicate Delegate Call Dropped: " + text); } } else { exists.Add(sub); } } } return(result); }
protected void DebugLogCorrection(string text) { ErrorTrap.DebugLogCorrection(text); }
public void RunErrorTest(params JSError[] expectedErrorArray) { // open the stack trace for this call StackTrace stackTrace = new StackTrace(); string testClass = null; string testName = null; // save the name of the current method (RunTest) string currentMethodName = MethodInfo.GetCurrentMethod().Name; // loop from the previous frame up until we get a method name that is not the // same as the current method name for (int ndx = 1; ndx < stackTrace.FrameCount; ++ndx) { // get the frame StackFrame stackFrame = stackTrace.GetFrame(ndx); // we have different entry points with the same name -- we're interested // in the first one that ISN'T the same name as our method MethodBase methodBase = stackFrame.GetMethod(); if (methodBase.Name != currentMethodName) { // the calling method's name is the test name - we use this as-is for the output file name // and we use any portion before an underscore as the input file testName = methodBase.Name; // get the method's class - we use this as the subfolder under input/output/expected testClass = methodBase.DeclaringType.Name; break; } } // we definitely should be able to find a function on the stack frame that // has a different name than this function, but just in case... Debug.Assert(testName != null && testClass != null, "Couldn't locate calling stack frame"); // the input file is the portion of the test name before the underscore (if any) string inputFile = testName.Split('_')[0]; // get the input path string inputPath = GetJsPath( m_inputFolder, testClass, inputFile, false ); Assert.IsTrue(File.Exists(inputPath), "Input File does not exist: {0}", inputPath); // read the input JS string jsSource; using (StreamReader reader = new StreamReader(inputPath, true)) { jsSource = reader.ReadToEnd(); } Trace.Write("INPUT FILE: "); Trace.WriteLine(inputPath); Trace.WriteLine(jsSource); /*int expectedErrorCode = (int)(0x800A0000 + (int)expectedError); * Trace.WriteLine(string.Empty); * Trace.WriteLine(string.Format("Expecting error 0x{0:X}", expectedErrorCode));*/ bool testPassed = true; List <JSError> expectedErrorList = new List <JSError>(expectedErrorArray); ErrorTrap errorTrap = new ErrorTrap(); string crunchedCode = errorTrap.RunTest(jsSource); JScriptException[] errors = errorTrap.Errors; Trace.WriteLine(string.Empty); Trace.WriteLine("---ERRORS---"); Trace.Indent(); foreach (JScriptException ex in errors) { // log the error Trace.WriteLine(string.Empty); Trace.WriteLine(string.Format("Error 0x{0:X} at Line {1}, Column {2}: {3}", ex.Error, ex.Line, ex.Column, ex.ErrorSegment)); Trace.Indent(); Trace.WriteLine(ex.Message); JSError errorCode = (JSError)(ex.Error & 0xffff); int index = expectedErrorList.IndexOf(errorCode); if (index >= 0) { // expected error -- remove it from the list so we can tell what we're missing later expectedErrorList.RemoveAt(index); } else { // unexpected error testPassed = false; Trace.WriteLine("UNEXPECTED"); } Trace.Unindent(); } Trace.Unindent(); // the list should be empty now -- if it isn't, then there was an expected error that didn't happen if (expectedErrorList.Count > 0) { testPassed = false; Trace.WriteLine(string.Empty); Trace.WriteLine("---MISSING ERRORS---"); Trace.Indent(); foreach (JSError jsError in expectedErrorList) { Trace.WriteLine(jsError.ToString()); } Trace.Unindent(); } if (!testPassed) { Trace.WriteLine("UNEXPECTED ERROR RESULTS"); } Trace.WriteLine(string.Empty); Trace.WriteLine("---Resulting Code---"); Trace.WriteLine(crunchedCode); // compute the path to the expected file string expectedPath = GetJsPath( m_expectedFolder, testClass, testName, false ); if (File.Exists(expectedPath)) { string expectedCode; using (StreamReader reader = new StreamReader(expectedPath, true)) { expectedCode = reader.ReadToEnd(); } Trace.WriteLine(string.Empty); Trace.WriteLine("---Expected Code---"); Trace.WriteLine(expectedCode); if (string.CompareOrdinal(expectedCode, crunchedCode) != 0) { Trace.WriteLine("EXPECTED OUTPUT IS DIFFERENT"); testPassed = false; } } Assert.IsTrue(testPassed, "Test failed"); }
protected override bool PrePerform(Urnstone book, bool postLoad) { ErrorTrap.CheckTravelData(); return(true); }