|
4 | 4 |
|
5 | 5 | require 'li_std_auto_ptr'
|
6 | 6 |
|
| 7 | +def gc_check(expected_count) |
| 8 | +# GC.start(full_mark: true, immediate_sweep: true) |
| 9 | + GC.start |
| 10 | +# GC is not reliably run, skip check |
| 11 | +# swig_assert_equal_simple(expected_count, Li_std_auto_ptr::Klass::getTotal_count()) |
| 12 | +end |
| 13 | + |
7 | 14 | k1 = Li_std_auto_ptr::makeKlassAutoPtr("first")
|
8 | 15 | k2 = Li_std_auto_ptr::makeKlassAutoPtr("second")
|
9 |
| -swig_assert_equal_simple(Li_std_auto_ptr::Klass::getTotal_count(), 2) |
| 16 | +swig_assert_equal_simple(2, Li_std_auto_ptr::Klass::getTotal_count()) |
10 | 17 |
|
| 18 | +gc_check(2) |
11 | 19 | k1 = nil
|
12 |
| -GC.start |
13 |
| - |
14 |
| -# GC can need a few runs to actually collect the object. |
15 |
| -100.times do || |
16 |
| - next if Li_std_auto_ptr::Klass::getTotal_count() == 2 |
17 |
| - |
18 |
| - swig_assert_equal_simple(Li_std_auto_ptr::Klass::getTotal_count(), 1) |
19 |
| - break |
20 |
| -end |
| 20 | +gc_check(1) |
21 | 21 |
|
22 | 22 | swig_assert_equal_simple(k2.getLabel(), "second")
|
23 |
| - |
24 |
| -if Li_std_auto_ptr::Klass::getTotal_count() != 1 |
25 |
| - STDERR.puts "GC failed to collect the first object, count still #{Li_std_auto_ptr::Klass::getTotal_count()}" |
26 |
| - |
27 |
| - # Skip the rest of the test as it's not going to work correctly anyhow. |
28 |
| - exit |
29 |
| -end |
| 23 | +gc_check(1) |
30 | 24 |
|
31 | 25 | k2 = nil
|
32 |
| -GC.start |
33 |
| - |
34 |
| -100.times do || |
35 |
| - next if Li_std_auto_ptr::Klass::getTotal_count() == 1 |
| 26 | +gc_check(0) |
36 | 27 |
|
37 |
| - swig_assert_equal_simple(Li_std_auto_ptr::Klass::getTotal_count(), 0) |
38 |
| - break |
39 |
| -end |
40 |
| - |
41 |
| -if Li_std_auto_ptr::Klass::getTotal_count() != 0 |
42 |
| - STDERR.puts "GC failed to collect the second object, count still #{Li_std_auto_ptr::Klass::getTotal_count()}" |
43 |
| -end |
0 commit comments