Generalized the test for encoding in g.toEncodedString.

Leo build: 20141206102008