diff --git a/src/System.Runtime/tests/System/LazyTests.cs b/src/System.Runtime/tests/System/LazyTests.cs index 6badc2072456..91821158294d 100644 --- a/src/System.Runtime/tests/System/LazyTests.cs +++ b/src/System.Runtime/tests/System/LazyTests.cs @@ -3,11 +3,12 @@ // See the LICENSE file in the project root for more information. using System.Collections.Generic; -using System.Threading; -using System.Reflection; using System.IO; +using System.Reflection; using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Serialization.Formatters.Tests; +using System.Threading; +using System.Threading.Tasks; using Xunit; namespace System.Tests @@ -463,6 +464,8 @@ public static void EnsureInitialized_ComplexRefTypes() object aLock = null; Assert.NotNull(LazyInitializer.EnsureInitialized(ref a, ref aInit, ref aLock)); Assert.NotNull(a); + Assert.True(aInit); + Assert.NotNull(aLock); // Activator.CreateInstance (already initialized). HasDefaultCtor b = hdcTemplate; @@ -470,6 +473,8 @@ public static void EnsureInitialized_ComplexRefTypes() object bLock = null; Assert.Equal(hdcTemplate, LazyInitializer.EnsureInitialized(ref b, ref bInit, ref bLock)); Assert.Equal(hdcTemplate, b); + Assert.True(bInit); + Assert.Null(bLock); // Func based initialization (uninitialized). string c = null; @@ -477,6 +482,8 @@ public static void EnsureInitialized_ComplexRefTypes() object cLock = null; Assert.Equal(strTemplate, LazyInitializer.EnsureInitialized(ref c, ref cInit, ref cLock, () => strTemplate)); Assert.Equal(strTemplate, c); + Assert.True(cInit); + Assert.NotNull(cLock); // Func based initialization (already initialized). string d = strTemplate; @@ -484,6 +491,8 @@ public static void EnsureInitialized_ComplexRefTypes() object dLock = null; Assert.Equal(strTemplate, LazyInitializer.EnsureInitialized(ref d, ref dInit, ref dLock, () => strTemplate + "bar")); Assert.Equal(strTemplate, d); + Assert.True(dInit); + Assert.Null(dLock); // Func based initialization (nulls *ARE* permitted). string e = null; @@ -494,7 +503,28 @@ public static void EnsureInitialized_ComplexRefTypes() Assert.Null(LazyInitializer.EnsureInitialized(ref e, ref einit, ref elock, () => { initCount++; return null; })); Assert.Null(e); Assert.Equal(1, initCount); + Assert.True(einit); + Assert.NotNull(elock); Assert.Null(LazyInitializer.EnsureInitialized(ref e, ref einit, ref elock, () => { initCount++; return null; })); + + // Func based initialization without tracking boolean (uninitialized). + string f = null; + object fLock = null; + Assert.Equal(strTemplate, LazyInitializer.EnsureInitialized(ref f, ref fLock, () => strTemplate)); + Assert.Equal(strTemplate, f); + Assert.NotNull(fLock); + + // Func based initialization without tracking boolean (already initialized). + string g = strTemplate; + object gLock = null; + Assert.Equal(strTemplate, LazyInitializer.EnsureInitialized(ref g, ref gLock, () => strTemplate + "bar")); + Assert.Equal(strTemplate, g); + Assert.Null(gLock); + + // Func based initialization without tracking boolean (nulls not permitted). + string h = null; + object hLock = null; + Assert.Throws(() => LazyInitializer.EnsureInitialized(ref h, ref hLock, () => null)); } [Fact] diff --git a/src/System.Threading/ref/System.Threading.cs b/src/System.Threading/ref/System.Threading.cs index eff49cef9121..2347a4f1d824 100644 --- a/src/System.Threading/ref/System.Threading.cs +++ b/src/System.Threading/ref/System.Threading.cs @@ -179,6 +179,7 @@ public static partial class LazyInitializer public static T EnsureInitialized(ref T target, ref bool initialized, ref object syncLock) { throw null; } public static T EnsureInitialized(ref T target, ref bool initialized, ref object syncLock, System.Func valueFactory) { throw null; } public static T EnsureInitialized(ref T target, System.Func valueFactory) where T : class { throw null; } + public static T EnsureInitialized(ref T target, ref object syncLock, System.Func valueFactory) where T : class { throw null; } } public partial struct LockCookie { diff --git a/src/System.Threading/src/ApiCompatBaseline.uapaot.txt b/src/System.Threading/src/ApiCompatBaseline.uapaot.txt index 13352b9859a5..ff26d0f6221f 100644 --- a/src/System.Threading/src/ApiCompatBaseline.uapaot.txt +++ b/src/System.Threading/src/ApiCompatBaseline.uapaot.txt @@ -25,4 +25,5 @@ MembersMustExist : Member 'System.Threading.SynchronizationContext.Wait(System.I MembersMustExist : Member 'System.Threading.SynchronizationContext.WaitHelper(System.IntPtr[], System.Boolean, System.Int32)' does not exist in the implementation but it does exist in the contract. CannotRemoveBaseTypeOrInterface : Type 'System.Threading.SynchronizationLockException' does not inherit from base type 'System.SystemException' in the implementation but it does in the contract. CannotRemoveBaseTypeOrInterface : Type 'System.Threading.WaitHandleCannotBeOpenedException' does not inherit from base type 'System.ApplicationException' in the implementation but it does in the contract. -Total Issues: 26 +MembersMustExist : Member 'System.Threading.LazyInitializer.EnsureInitialized(T, System.Object, System.Func)' does not exist in the implementation but it does exist in the contract. +Total Issues: 27