Make the encoding test meaningful.

The old test was neither effective nor clear. This is better.

Also added a way to change the encoding for a limited scope.