Example #1
0
    public void NativeMultiHashMap_UseAfterFree_UsesCustomOwnerTypeName()
    {
        var container = new NativeMultiHashMap <int, int>(10, Allocator.TempJob);

        container.Add(0, 123);
        container.Dispose();
        Assert.That(() => container.ContainsKey(0),
                    Throws.Exception.TypeOf <ObjectDisposedException>()
                    .With.Message.Contains($"The {container.GetType()} has been deallocated"));
    }
Example #2
0
    public void NativeMultiHashMap_CreateAndUseAfterFreeInBurstJob_UsesCustomOwnerTypeName()
    {
        // Make sure this isn't the first container of this type ever created, so that valid static safety data exists
        var container = new NativeMultiHashMap <int, int>(10, Allocator.TempJob);

        container.Dispose();

        var job = new NativeMultiHashMap_CreateAndUseAfterFreeBurst
        {
        };

        // Two things:
        // 1. This exception is logged, not thrown; thus, we use LogAssert to detect it.
        // 2. Calling write operation after container.Dispose() emits an unintuitive error message. For now, all this test cares about is whether it contains the
        //    expected type name.
        job.Run();
        LogAssert.Expect(LogType.Exception,
                         new Regex($"InvalidOperationException: The {Regex.Escape(container.GetType().ToString())} has been declared as \\[ReadOnly\\] in the job, but you are writing to it"));
    }