| 219 | } |
| 220 | |
| 221 | static void test_decref_order(int *indexes, void **objects) { |
| 222 | setup(objects); |
| 223 | |
| 224 | // printf("-----------\n"); |
| 225 | for (int i = 0; i < 3; i++) { |
| 226 | int idx = indexes[i]; |
| 227 | void *obj = objects[idx]; |
| 228 | // printf("decreffing %s\n", pn_object_reify(obj)->name); |
| 229 | pn_decref(obj); |
| 230 | for (int j = 0; j <= i; j++) { |
| 231 | // everything we've decreffed already should have a refcount of |
| 232 | // 1 because it has been preserved by its parent |
| 233 | assert_refcount(objects[indexes[j]], 1); |
| 234 | } |
| 235 | for (int j = i + 1; j < 4; j++) { |
| 236 | // everything we haven't decreffed yet should have a refcount of |
| 237 | // 2 unless it has a descendant that has not been decrefed (or |
| 238 | // it has no child) in which case it should have a refcount of 1 |
| 239 | int idx = indexes[j]; |
| 240 | void *obj = objects[idx]; |
| 241 | REQUIRE(!decreffed(indexes, objects, i, obj)); |
| 242 | if (live_descendent(indexes, objects, i, idx)) { |
| 243 | assert_refcount(obj, 2); |
| 244 | } else { |
| 245 | assert_refcount(obj, 1); |
| 246 | } |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | void *last = objects[indexes[3]]; |
| 251 | // printf("decreffing %s\n", pn_object_reify(last)->name); |
| 252 | pn_decref(last); |
| 253 | // all should be gone now, need to run with valgrind to check |
| 254 | } |
| 255 | |
| 256 | static void permute(int n, int *indexes, void **objects) { |
| 257 | int j; |
no test coverage detected