/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* 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/. */
/* * File: sprintf.c * Description: * This is a test program for the PR_snprintf() functions defined * in prprf.c. This test program is based on ns/nspr/tests/sprintf.c, * revision 1.10. * Modification History: * 20-May-1997 AGarcia replaced printf statment to return PASS\n. This is to be *used by the regress tool parsing routine. ** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been *updated to recognize the return code from tha main program.
*/
/* ** Perform a three way test against PR_smprintf, PR_snprintf, and sprintf. ** Make sure the results are identical
*/ staticvoid test_i(char* pattern, int i) { char* s; char buf[200]; int n;
/* try all three routines */
s = PR_smprintf(pattern, i);
PR_ASSERT(s != 0);
n = PR_snprintf(buf, sizeof(buf), pattern, i);
PR_ASSERT(n <= sizeof(buf));
sprintf(sbuf, pattern, i);
/* ** Perform a three way test against PR_smprintf, PR_snprintf, and sprintf. ** Make sure the results are identical
*/ staticvoid test_l(char* pattern, char* spattern, PRInt32 l) { char* s; char buf[200]; int n;
/* try all three routines */
s = PR_smprintf(pattern, l);
PR_ASSERT(s != 0);
n = PR_snprintf(buf, sizeof(buf), pattern, l);
PR_ASSERT(n <= sizeof(buf));
sprintf(sbuf, spattern, l);
/* ** Perform a three way test against PR_smprintf, PR_snprintf, and sprintf. ** Make sure the results are identical
*/ staticvoid test_ll(char* pattern, char* spattern, PRInt64 l) { char* s; char buf[200]; int n;
/* try all three routines */
s = PR_smprintf(pattern, l);
PR_ASSERT(s != 0);
n = PR_snprintf(buf, sizeof(buf), pattern, l);
PR_ASSERT(n <= sizeof(buf)); #ifdefined(HAVE_LONG_LONG)
sprintf(sbuf, spattern, l);
/* ** Perform a three way test against PR_smprintf, PR_snprintf, and sprintf. ** Make sure the results are identical
*/ staticvoid test_s(char* pattern, char* ss) { char* s; unsignedchar before[8]; char buf[200]; unsignedchar after[8]; int n;
memset(before, 0xBB, 8);
memset(after, 0xAA, 8);
/* try all three routines */
s = PR_smprintf(pattern, ss);
PR_ASSERT(s != 0);
n = PR_snprintf(buf, sizeof(buf), pattern, ss);
PR_ASSERT(n <= sizeof(buf));
sprintf(sbuf, pattern, ss);
for (n = 0; n < 8; n++) {
PR_ASSERT(before[n] == 0xBB);
PR_ASSERT(after[n] == 0xAA);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.