diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /js/src/jsapi-tests/testPrintf.cpp | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/jsapi-tests/testPrintf.cpp')
-rw-r--r-- | js/src/jsapi-tests/testPrintf.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/js/src/jsapi-tests/testPrintf.cpp b/js/src/jsapi-tests/testPrintf.cpp new file mode 100644 index 000000000..51486856f --- /dev/null +++ b/js/src/jsapi-tests/testPrintf.cpp @@ -0,0 +1,71 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "mozilla/IntegerPrintfMacros.h" +#include "mozilla/SizePrintfMacros.h" + +#include <stdarg.h> + +#include "jsprf.h" + +#include "jsapi-tests/tests.h" + +static bool +MOZ_FORMAT_PRINTF(2, 3) +print_one (const char *expect, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + char *output = JS_vsmprintf (fmt, ap); + va_end(ap); + + bool result = output && !strcmp(output, expect); + JS_smprintf_free(output); + + return result; +} + +static const char * +zero() +{ + return nullptr; +} + +BEGIN_TEST(testPrintf) +{ + CHECK(print_one("23", "%d", 23)); + CHECK(print_one("-1", "%d", -1)); + CHECK(print_one("23", "%u", 23u)); + CHECK(print_one("0x17", "0x%x", 23u)); + CHECK(print_one("0xFF", "0x%X", 255u)); + CHECK(print_one("027", "0%o", 23u)); + CHECK(print_one("-1", "%hd", (short) -1)); + // This could be expanded if need be, it's just convenient to do + // it this way. + if (sizeof(short) == 2) { + CHECK(print_one("8000", "%hx", (unsigned short) 0x8000)); + } + CHECK(print_one("0xf0f0", "0x%lx", 0xf0f0ul)); + CHECK(print_one("0xF0F0", "0x%llX", 0xf0f0ull)); + CHECK(print_one("27270", "%zu", (size_t) 27270)); + CHECK(print_one("27270", "%" PRIuSIZE, (size_t) 27270)); + CHECK(print_one("hello", "he%so", "ll")); + CHECK(print_one("(null)", "%s", zero())); + CHECK(print_one("0", "%p", (char *) 0)); + CHECK(print_one("h", "%c", 'h')); + CHECK(print_one("1.500000", "%f", 1.5f)); + CHECK(print_one("1.5", "%g", 1.5)); + + CHECK(print_one("2727", "%" PRIu32, (uint32_t) 2727)); + CHECK(print_one("aa7", "%" PRIx32, (uint32_t) 2727)); + CHECK(print_one("2727", "%" PRIu64, (uint64_t) 2727)); + CHECK(print_one("aa7", "%" PRIx64, (uint64_t) 2727)); + + return true; +} +END_TEST(testPrintf) |