Skip to content

Commit 64f4e2f

Browse files
committed
Add test case
1 parent 8776fb1 commit 64f4e2f

File tree

1 file changed

+70
-3
lines changed

1 file changed

+70
-3
lines changed

BTProgressHUDDemo/MainViewModel.cs

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public MainViewModel()
2424
Create("Cancel problem 3", () => BTProgressHUD.Show("Cancel", () => KillAfter(), "Cancel and text"), false),
2525
Create("Cancel problem 2", () => BTProgressHUD.Show("Cancel", () => KillAfter()), false),
2626
Create("Cancel problem", () => BTProgressHUD.Show("Cancel", () => KillAfter(), "This is a multilinetext\nSome more text\n more text\n and again more text"), false),
27-
Create("Show Message", () =>
27+
Create("Show Message", () =>
2828
BTProgressHUD.Show("Processing your image", 10, MaskType.Black), true),
2929
Create("Show Success", () =>
3030
{
@@ -103,7 +103,7 @@ public MainViewModel()
103103
{
104104
ProgressHUDAppearance.RingColor = UIColor.Green;
105105
ProgressHUDAppearance.RingBackgroundColor = UIColor.Brown;
106-
106+
107107
ProgressHUDAppearance.HudBackgroundColor = UIColor.Yellow;
108108
ProgressHUDAppearance.HudTextColor = UIColor.Purple;
109109
ProgressHUDAppearance.HudButtonTextColor = UIColor.Orange;
@@ -112,7 +112,74 @@ public MainViewModel()
112112
ProgressHUDAppearance.HudTextColor = UIColor.Cyan;
113113
ProgressHUDAppearance.HudToastBackgroundColor = UIColor.Blue;
114114
}, false),
115-
Create("Reset Customization", ProgressHUDAppearance.ResetToDefaults, false)
115+
Create("Reset Customization", ProgressHUDAppearance.ResetToDefaults, false),
116+
Create("GH117 ObjectDisposeException", async () => {
117+
try
118+
{
119+
// Test 1: Immediate disposal after show
120+
Console.WriteLine("Test 1: Immediate disposal after show");
121+
var window1 = new UIWindow(UIScreen.MainScreen.Bounds);
122+
window1.RootViewController = new UIViewController();
123+
window1.MakeKeyAndVisible();
124+
BTProgressHUD.Show(window1, "Test 1");
125+
window1.Dispose();
126+
await Task.Delay(100);
127+
BTProgressHUD.Dismiss(window1);
128+
129+
// Test 2: Disposal during dismiss animation
130+
Console.WriteLine("Test 2: Disposal during dismiss animation");
131+
var window2 = new UIWindow(UIScreen.MainScreen.Bounds);
132+
window2.RootViewController = new UIViewController();
133+
window2.MakeKeyAndVisible();
134+
BTProgressHUD.Show(window2, "Test 2");
135+
await Task.Delay(100);
136+
BTProgressHUD.Dismiss(window2);
137+
await Task.Delay(150); // Half way through 0.3s animation
138+
window2.Dispose();
139+
await Task.Delay(200); // Let animation complete
140+
141+
// Test 3: Rapid show/dismiss/dispose cycles
142+
Console.WriteLine("Test 3: Rapid cycles");
143+
for (int i = 0; i < 5; i++)
144+
{
145+
var window = new UIWindow(UIScreen.MainScreen.Bounds);
146+
window.RootViewController = new UIViewController();
147+
window.MakeKeyAndVisible();
148+
BTProgressHUD.Show(window, $"Rapid {i}");
149+
await Task.Delay(25);
150+
BTProgressHUD.Dismiss(window);
151+
await Task.Delay(25);
152+
window.Dispose();
153+
await Task.Delay(25);
154+
}
155+
156+
// Test 4: Force garbage collection
157+
Console.WriteLine("Test 4: Force GC");
158+
var window4 = new UIWindow(UIScreen.MainScreen.Bounds);
159+
window4.RootViewController = new UIViewController();
160+
window4.MakeKeyAndVisible();
161+
BTProgressHUD.Show(window4, "GC Test");
162+
window4 = null; // Remove reference
163+
GC.Collect();
164+
GC.WaitForPendingFinalizers();
165+
GC.Collect();
166+
await Task.Delay(100);
167+
// This might cause issues when dismiss tries to access the collected window
168+
169+
BTProgressHUD.Dismiss();
170+
Console.WriteLine("All tests completed without ObjectDisposedException");
171+
}
172+
catch (ObjectDisposedException ex)
173+
{
174+
Console.WriteLine($"SUCCESS: ObjectDisposedException reproduced! {ex.Message}");
175+
Console.WriteLine($"Stack trace: {ex.StackTrace}");
176+
}
177+
catch (Exception ex)
178+
{
179+
Console.WriteLine($"Other exception: {ex.GetType().Name}: {ex.Message}");
180+
Console.WriteLine($"Stack trace: {ex.StackTrace}");
181+
}
182+
}, false)
116183
];
117184
}
118185

0 commit comments

Comments
 (0)