Writer: check that aggregates are open before closing them
Also add the missing tests for that.
The checks worked, but testing in debug builds triggered assertion
failures in Nesting::endFoo() BEFORE the checks.
The assertions could be safely ignored, doing the other checks
earlier is cleaner, though.