1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/uconv/tests/plattest.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,46 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 +#include "nsIPlatformCharset.h" 1.9 +#include "nsILocaleService.h" 1.10 +#include "nsCOMPtr.h" 1.11 +#include "nsReadableUtils.h" 1.12 +#include "nsIComponentManager.h" 1.13 +#include <stdio.h> 1.14 + 1.15 +int 1.16 +main(int argc, const char** argv) 1.17 +{ 1.18 + 1.19 + nsCOMPtr<nsIPlatformCharset> platform_charset = 1.20 + do_CreateInstance(NS_PLATFORMCHARSET_CONTRACTID); 1.21 + if (!platform_charset) return -1; 1.22 + 1.23 + nsCOMPtr<nsILocaleService> locale_service = 1.24 + do_CreateInstance(NS_LOCALESERVICE_CONTRACTID); 1.25 + if (!locale_service) return -1; 1.26 + 1.27 + nsCOMPtr<nsILocale> locale; 1.28 + nsAutoCString charset; 1.29 + nsAutoString category; 1.30 + 1.31 + nsresult rv = locale_service->GetSystemLocale(getter_AddRefs(locale)); 1.32 + if (NS_FAILED(rv)) return -1; 1.33 + 1.34 + rv = locale->GetCategory(NS_LITERAL_STRING("NSILOCALE_MESSAGES"), category); 1.35 + if (NS_FAILED(rv)) return -1; 1.36 + 1.37 + rv = platform_charset->GetDefaultCharsetForLocale(category, charset); 1.38 + if (NS_FAILED(rv)) return -1; 1.39 + 1.40 + printf("DefaultCharset for %s is %s\n", NS_LossyConvertUTF16toASCII(category).get(), charset.get()); 1.41 + 1.42 + category.AssignLiteral("en-US"); 1.43 + rv = platform_charset->GetDefaultCharsetForLocale(category, charset); 1.44 + if (NS_FAILED(rv)) return -1; 1.45 + 1.46 + printf("DefaultCharset for %s is %s\n", NS_LossyConvertUTF16toASCII(category).get(), charset.get()); 1.47 + 1.48 + return 0; 1.49 +}