diff options
| author | Andrew Lee <alee14498@protonmail.com> | 2020-04-20 19:09:33 -0400 |
|---|---|---|
| committer | Andrew Lee <alee14498@protonmail.com> | 2020-04-20 19:09:33 -0400 |
| commit | 7c1e566113d59699af1624186c64eca67f063fc6 (patch) | |
| tree | 5a6850a695986872d5d0b09d7dab8421628fe33e /Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/AllocatingGCMemoryConstraint.cs | |
| parent | dd117b77aae1d8be7563b360d05b842a73b7dab2 (diff) | |
| download | Project-Sandbox-7c1e566113d59699af1624186c64eca67f063fc6.tar.gz Project-Sandbox-7c1e566113d59699af1624186c64eca67f063fc6.tar.bz2 Project-Sandbox-7c1e566113d59699af1624186c64eca67f063fc6.zip | |
Upgraded Unity
Diffstat (limited to 'Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/AllocatingGCMemoryConstraint.cs')
| -rw-r--r-- | Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/AllocatingGCMemoryConstraint.cs | 83 |
1 files changed, 0 insertions, 83 deletions
diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/AllocatingGCMemoryConstraint.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/AllocatingGCMemoryConstraint.cs deleted file mode 100644 index d765cdb..0000000 --- a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/AllocatingGCMemoryConstraint.cs +++ /dev/null @@ -1,83 +0,0 @@ -using System;
-using NUnit.Framework;
-using NUnit.Framework.Constraints;
-using UnityEngine.Profiling;
-
-namespace UnityEngine.TestTools.Constraints
-{
- public class AllocatingGCMemoryConstraint : Constraint
- {
- private class AllocatingGCMemoryResult : ConstraintResult
- {
- private readonly int diff;
- public AllocatingGCMemoryResult(IConstraint constraint, object actualValue, int diff) : base(constraint, actualValue, diff > 0)
- {
- this.diff = diff;
- }
-
- public override void WriteMessageTo(MessageWriter writer)
- {
- if (diff == 0)
- writer.WriteMessageLine("The provided delegate did not make any GC allocations.");
- else
- writer.WriteMessageLine("The provided delegate made {0} GC allocation(s).", diff);
- }
- }
-
- private ConstraintResult ApplyTo(Action action, object original)
- {
- var recorder = Recorder.Get("GC.Alloc");
-
- // The recorder was created enabled, which means it captured the creation of the Recorder object itself, etc.
- // Disabling it flushes its data, so that we can retrieve the sample block count and have it correctly account
- // for these initial allocations.
- recorder.enabled = false;
-
-#if !UNITY_WEBGL
- recorder.FilterToCurrentThread();
-#endif
-
- recorder.enabled = true;
-
- try
- {
- action();
- }
- finally
- {
- recorder.enabled = false;
-#if !UNITY_WEBGL
- recorder.CollectFromAllThreads();
-#endif
- }
-
- return new AllocatingGCMemoryResult(this, original, recorder.sampleBlockCount);
- }
-
- public override ConstraintResult ApplyTo(object obj)
- {
- if (obj == null)
- throw new ArgumentNullException();
-
- TestDelegate d = obj as TestDelegate;
- if (d == null)
- throw new ArgumentException(string.Format("The actual value must be a TestDelegate but was {0}",
- obj.GetType()));
-
- return ApplyTo(() => d.Invoke(), obj);
- }
-
- public override ConstraintResult ApplyTo<TActual>(ActualValueDelegate<TActual> del)
- {
- if (del == null)
- throw new ArgumentNullException();
-
- return ApplyTo(() => del.Invoke(), del);
- }
-
- public override string Description
- {
- get { return "allocates GC memory"; }
- }
- }
-}
|
