michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "TestCommon.h" michael@0: #include michael@0: #include "nsIIDNService.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsIServiceManager.h" michael@0: #include "nsServiceManagerUtils.h" michael@0: #include "nsNetCID.h" michael@0: #include "nsStringAPI.h" michael@0: michael@0: int main(int argc, char **argv) { michael@0: if (test_common_init(&argc, &argv) != 0) michael@0: return -1; michael@0: michael@0: // Test case from RFC 3492 (7.1 - Simplified Chinese) michael@0: const char plain[] = michael@0: "\xE4\xBB\x96\xE4\xBB\xAC\xE4\xB8\xBA\xE4\xBB\x80\xE4\xB9\x88\xE4\xB8\x8D\xE8\xAF\xB4\xE4\xB8\xAD\xE6\x96\x87"; michael@0: const char encoded[] = "xn--ihqwcrb4cv8a8dqg056pqjye"; michael@0: michael@0: nsCOMPtr converter = do_GetService(NS_IDNSERVICE_CONTRACTID); michael@0: NS_ASSERTION(converter, "idnSDK not installed!"); michael@0: if (converter) { michael@0: nsAutoCString buf; michael@0: nsresult rv = converter->ConvertUTF8toACE(NS_LITERAL_CSTRING(plain), buf); michael@0: NS_ASSERTION(NS_SUCCEEDED(rv), "error ConvertUTF8toACE"); michael@0: NS_ASSERTION(buf.Equals(NS_LITERAL_CSTRING(encoded)), michael@0: "encode result incorrect"); michael@0: printf("encoded = %s\n", buf.get()); michael@0: michael@0: buf.Truncate(); michael@0: rv = converter->ConvertACEtoUTF8(NS_LITERAL_CSTRING(encoded), buf); michael@0: NS_ASSERTION(NS_SUCCEEDED(rv), "error ConvertACEtoUTF8"); michael@0: NS_ASSERTION(buf.Equals(NS_LITERAL_CSTRING(plain)), michael@0: "decode result incorrect"); michael@0: printf("decoded = "); michael@0: NS_ConvertUTF8toUTF16 utf(buf); michael@0: const char16_t *u = utf.get(); michael@0: for (int i = 0; u[i]; i++) { michael@0: printf("U+%.4X ", u[i]); michael@0: } michael@0: printf("\n"); michael@0: michael@0: bool isAce; michael@0: rv = converter->IsACE(NS_LITERAL_CSTRING("www.xn--ihqwcrb4cv8a8dqg056pqjye.com"), &isAce); michael@0: NS_ASSERTION(NS_SUCCEEDED(rv), "error IsACE"); michael@0: NS_ASSERTION(isAce, "IsACE incorrect result"); michael@0: } michael@0: return 0; michael@0: }