Add comprehensive unit tests for Xdr, in preparation for refactorization (rebased)

Rebased onto latest master. Modified this change to just contain additional test cases and TODO's in the code.