I recent wrote a post about testing external pointers with finalization in R using C++. The test package is now available at R-Forge for inspiration.