michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 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 michael@0: #include michael@0: #include michael@0: michael@0: int main() michael@0: { michael@0: int test_ok = true; michael@0: michael@0: nsAutoString fmt(NS_LITERAL_STRING("%3$s %4$S %1$d %2$d %2$d %3$s")); michael@0: char utf8[] = "Hello"; michael@0: char16_t ucs2[]={'W', 'o', 'r', 'l', 'd', 0x4e00, 0xAc00, 0xFF45, 0x0103, 0x00}; michael@0: int d=3; michael@0: michael@0: char16_t buf[256]; michael@0: nsTextFormatter::snprintf(buf, 256, fmt.get(), d, 333, utf8, ucs2); michael@0: nsAutoString out(buf); michael@0: if(strcmp("Hello World", NS_LossyConvertUTF16toASCII(out).get())) michael@0: test_ok = false; michael@0: michael@0: const char16_t *uout = out.get(); michael@0: const char16_t expected[] = {0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, michael@0: 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x4E00, michael@0: 0xAC00, 0xFF45, 0x0103, 0x20, 0x33, michael@0: 0x20, 0x33, 0x33, 0x33, 0x20, 0x33, michael@0: 0x33, 0x33, 0x20, 0x48, 0x65, 0x6C, michael@0: 0x6C, 0x6F}; michael@0: for(uint32_t i=0;i