1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is i-DNS.net International, Inc. code.
16 * The Initial Developer of the Original Code is
17 * i-DNS.net International.
18 * Portions created by the Initial Developer are Copyright (C) 2001
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s): darin@netscape.com,
23 * william.tan@i-dns.net
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #include "TestCommon.h"
42 #include "nsIIDNService.h"
44 #include "nsIServiceManager.h"
45 #include "nsServiceManagerUtils.h"
47 #include "nsStringAPI.h"
49 int main(int argc
, char **argv
) {
50 if (test_common_init(&argc
, &argv
) != 0)
53 // Test case from RFC 3492 (7.1 - Simplified Chinese)
55 "\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";
56 const char encoded
[] = "xn--ihqwcrb4cv8a8dqg056pqjye";
58 nsCOMPtr
<nsIIDNService
> converter
= do_GetService(NS_IDNSERVICE_CONTRACTID
);
59 NS_ASSERTION(converter
, "idnSDK not installed!");
62 nsresult rv
= converter
->ConvertUTF8toACE(NS_LITERAL_CSTRING(plain
), buf
);
63 NS_ASSERTION(NS_SUCCEEDED(rv
), "error ConvertUTF8toACE");
64 NS_ASSERTION(buf
.Equals(NS_LITERAL_CSTRING(encoded
)),
65 "encode result incorrect");
66 printf("encoded = %s\n", buf
.get());
69 rv
= converter
->ConvertACEtoUTF8(NS_LITERAL_CSTRING(encoded
), buf
);
70 NS_ASSERTION(NS_SUCCEEDED(rv
), "error ConvertACEtoUTF8");
71 NS_ASSERTION(buf
.Equals(NS_LITERAL_CSTRING(plain
)),
72 "decode result incorrect");
74 NS_ConvertUTF8toUTF16
utf(buf
);
75 const PRUnichar
*u
= utf
.get();
76 for (int i
= 0; u
[i
]; i
++) {
77 printf("U+%.4X ", u
[i
]);
82 rv
= converter
->IsACE(NS_LITERAL_CSTRING("www.xn--ihqwcrb4cv8a8dqg056pqjye.com"), &isAce
);
83 NS_ASSERTION(NS_SUCCEEDED(rv
), "error IsACE");
84 NS_ASSERTION(isAce
, "IsACE incorrect result");