A game about forced loneliness, made by TACStudios
1using NUnit.Framework;
2using System;
3using Unity.Jobs;
4using Unity.Collections;
5using Unity.Collections.Tests;
6
7#if ENABLE_UNITY_COLLECTIONS_CHECKS
8internal class NativeParallelMultiHashMapTests_JobDebugger : NativeParallelMultiHashMapTestsFixture
9{
10 [Test]
11 public void NativeParallelMultiHashMap_Read_And_Write_Without_Fences()
12 {
13 var hashMap = new NativeParallelMultiHashMap<int, int>(hashMapSize, CommonRwdAllocator.Handle);
14 var writeStatus = CollectionHelper.CreateNativeArray<int>(hashMapSize, CommonRwdAllocator.Handle);
15 var readValues = CollectionHelper.CreateNativeArray<int>(hashMapSize, CommonRwdAllocator.Handle);
16
17 var writeData = new MultiHashMapWriteParallelForJob()
18 {
19 hashMap = hashMap.AsParallelWriter(),
20 status = writeStatus,
21 keyMod = hashMapSize,
22 };
23
24 var readData = new MultiHashMapReadParallelForJob()
25 {
26 hashMap = hashMap,
27 values = readValues,
28 keyMod = writeData.keyMod,
29 };
30
31 var writeJob = writeData.Schedule(hashMapSize, 1);
32 Assert.Throws<InvalidOperationException>(() => { readData.Schedule(hashMapSize, 1); });
33 writeJob.Complete();
34
35 hashMap.Dispose();
36 writeStatus.Dispose();
37 readValues.Dispose();
38 }
39
40 struct NestedMapJob : IJob
41 {
42 public NativeParallelMultiHashMap<int, NativeParallelMultiHashMap<int, int>> nestedMap;
43
44 public void Execute()
45 {
46 nestedMap.Clear();
47 }
48 }
49
50 [Test]
51 public void NativeParallelMultiHashMap_NestedJob_Error()
52 {
53 var map = new NativeParallelMultiHashMap<int, NativeParallelMultiHashMap<int, int>>(hashMapSize, CommonRwdAllocator.Handle);
54
55 var nestedJob = new NestedMapJob
56 {
57 nestedMap = map
58 };
59
60 JobHandle job = default;
61 Assert.Throws<InvalidOperationException>(() => { job = nestedJob.Schedule(); });
62 job.Complete();
63
64 map.Dispose();
65 }
66}
67#endif