public void CheckAPI_ReallocateTracer() { #if ENABLE_UNITY_COLLECTIONS_CHECKS string str = "1234567890--@@"; var NSL = new NativeStringList(Allocator.TempJob); NSL.Add(str); StringEntity entity = NSL[0]; bool effective_ref = true; for (int i = 0; i < 100; i++) { NSL.Add(str); try { Debug.Log($"add: {i}, entity: {entity.ToString()}, NSL [Size/Capacity] = [{NSL.Size}/{NSL.Capacity}]"); } catch (InvalidOperationException e) { effective_ref = false; Debug.Log("the reallocation of NativeStringList is detected by StringEntity. exception: " + e.Message); break; } } Assert.IsFalse(effective_ref); NSL.Dispose(); #else Debug.Log("this feature will be enabled when the macro 'ENABLE_UNITY_COLLECTIONS_CHECKS' is defined."); Debug.Log("it is not tested in current setting."); #endif }
private void CheckCollections() { Assert.AreEqual(str_native.Length, str_list.Count); int elem_len = math.min(str_native.Length, str_list.Count); for (int i = 0; i < elem_len; i++) { StringEntity entity = str_native[i]; string str_e = entity.ToString(); char[] c_arr_e = entity.ToArray(); ReadOnlyStringEntity entity_ro = entity.GetReadOnly(); string str = str_list[i]; char[] c_arr = str.ToCharArray(); Assert.AreEqual(str_e, str); Assert.AreEqual(c_arr_e.ToString(), c_arr.ToString()); Assert.IsTrue(entity.Equals(str)); Assert.IsTrue(entity.Equals(c_arr)); if (str.Length == 1) { Assert.IsTrue(entity.Equals(str[0])); } Assert.IsTrue(entity_ro.Equals(str)); Assert.IsTrue(entity_ro.Equals(c_arr)); if (str.Length == 1) { Assert.IsTrue(entity_ro.Equals(str[0])); } } }