ICU-3522 Tracing, incorrect fn number passed to trace data callbacks

X-SVN-Rev: 14384
This commit is contained in:
Andy Heninger 2004-01-22 19:32:42 +00:00
parent fbcd6bdd00
commit adf7b6c0a6
2 changed files with 73 additions and 13 deletions

View File

@ -236,7 +236,7 @@ U_CDECL_END
*/
#define UTRACE_DATA0(level, fmt) \
if(UTRACE_LEVEL(level)) { \
utrace_data(utraceFnNumber, (level), (fmt)); \
utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt)); \
}
/**
@ -249,7 +249,7 @@ U_CDECL_END
*/
#define UTRACE_DATA1(level, fmt, a) \
if(UTRACE_LEVEL(level)) { \
utrace_data(utraceFnNumber, (level), (fmt), (a)); \
utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY , (level), (fmt), (a)); \
}
/**
@ -262,7 +262,7 @@ U_CDECL_END
*/
#define UTRACE_DATA2(level, fmt, a, b) \
if(UTRACE_LEVEL(level)) { \
utrace_data(utraceFnNumber, (level), (fmt), (a), (b)); \
utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY , (level), (fmt), (a), (b)); \
}
/**
@ -275,7 +275,7 @@ U_CDECL_END
*/
#define UTRACE_DATA3(level, fmt, a, b, c) \
if(UTRACE_LEVEL(level)) { \
utrace_data(utraceFnNumber, (level), (fmt), (a), (b), (c)); \
utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c)); \
}
/**
@ -288,7 +288,7 @@ U_CDECL_END
*/
#define UTRACE_DATA4(level, fmt, a, b, c, d) \
if(UTRACE_LEVEL(level)) { \
utrace_data(utraceFnNumber, (level), (fmt), (a), (b), (c), (d)); \
utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c), (d)); \
}
/**
@ -301,7 +301,7 @@ U_CDECL_END
*/
#define UTRACE_DATA5(level, fmt, a, b, c, d, e) \
if(UTRACE_LEVEL(level)) { \
utrace_data(utraceFnNumber, (level), (fmt), (a), (b), (c), (d), (e)); \
utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c), (d), (e)); \
}
/**
@ -314,7 +314,7 @@ U_CDECL_END
*/
#define UTRACE_DATA6(level, fmt, a, b, c, d, e, f) \
if(UTRACE_LEVEL(level)) { \
utrace_data(utraceFnNumber, (level), (fmt), (a), (b), (c), (d), (e), (f)); \
utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c), (d), (e), (f)); \
}
/**
@ -327,7 +327,7 @@ U_CDECL_END
*/
#define UTRACE_DATA7(level, fmt, a, b, c, d, e, f, g) \
if(UTRACE_LEVEL(level)) { \
utrace_data(utraceFnNumber, (level), (fmt), (a), (b), (c), (d), (e), (f), (g)); \
utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c), (d), (e), (f), (g)); \
}
/**
@ -340,7 +340,7 @@ U_CDECL_END
*/
#define UTRACE_DATA8(level, fmt, a, b, c, d, e, f, g, h) \
if(UTRACE_LEVEL(level)) { \
utrace_data(utraceFnNumber, (level), (fmt), (a), (b), (c), (d), (e), (f), (g), (h)); \
utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c), (d), (e), (f), (g), (h)); \
}
/**
@ -353,7 +353,7 @@ U_CDECL_END
*/
#define UTRACE_DATA9(level, fmt, a, b, c, d, e, f, g, h, i) \
if(UTRACE_LEVEL(level)) { \
utrace_data(utraceFnNumber, (level), (fmt), (a), (b), (c), (d), (e), (f), (g), (h), (i)); \
utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c), (d), (e), (f), (g), (h), (i)); \
}
#else

View File

@ -17,6 +17,7 @@
#include "unicode/ucnv.h"
#include "cintltst.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "utracimp.h"
@ -95,22 +96,77 @@ static void test_format(const char *format, int32_t bufCap, int32_t indent,
/*
* define trace functions for use in this test.
*/
static int gTraceEntryCount;
static int gTraceExitCount;
static int gTraceDataCount;
static int gTraceEntryCount;
static int gTraceExitCount;
static int gTraceDataCount;
static UBool gFnNameError = FALSE;
static UBool gFnFormatError = FALSE;
static void testTraceEntry(const void *context, int32_t fnNumber) {
const char *fnName;
const char *bogusFnName;
gTraceEntryCount++;
/* Verify that a name is available for the fnNumber passed to us */
bogusFnName = utrace_functionName(-1);
fnName = utrace_functionName(fnNumber);
if (strcmp(fnName, bogusFnName) == 0) {
gFnNameError = TRUE;
}
/* printf("%s() Enter\n", fnName); */
}
static void testTraceExit(const void *context, int32_t fnNumber,
const char *fmt, va_list args) {
char buf[1000];
const char *fnName;
const char *bogusFnName;
gTraceExitCount++;
/* Verify that a name is available for the fnNumber passed to us */
bogusFnName = utrace_functionName(-1);
fnName = utrace_functionName(fnNumber);
if (strcmp(fnName, bogusFnName) == 0) {
gFnNameError = TRUE;
}
/* Verify that the format can be used. */
buf[0] = 0;
utrace_vformat(buf, sizeof(buf), 0, fmt, args);
if (strlen(buf) == 0) {
gFnFormatError = TRUE;
}
/* printf("%s() %s\n", fnName, buf); */
}
static void testTraceData(const void *context, int32_t fnNumber, int32_t level,
const char *fmt, va_list args) {
char buf[1000];
const char *fnName;
const char *bogusFnName;
gTraceDataCount++;
/* Verify that a name is available for the fnNumber passed to us */
bogusFnName = utrace_functionName(-1);
fnName = utrace_functionName(fnNumber);
if (strcmp(fnName, bogusFnName) == 0) {
gFnNameError = TRUE;
}
/* Verify that the format can be used. */
buf[0] = 0;
utrace_vformat(buf, sizeof(buf), 0, fmt, args);
if (strlen(buf) == 0) {
gFnFormatError = TRUE;
}
/* printf(" %s() %s\n", fnName, buf); */
}
@ -184,6 +240,8 @@ static void TestTraceAPI() {
gTraceEntryCount = 0;
gTraceExitCount = 0;
gTraceDataCount = 0;
gFnNameError = FALSE;
gFnFormatError = FALSE;
utrace_setLevel(UTRACE_OPEN_CLOSE);
cnv = ucnv_open(NULL, &status);
TEST_ASSERT(U_SUCCESS(status));
@ -192,6 +250,8 @@ static void TestTraceAPI() {
TEST_ASSERT(gTraceEntryCount > 0);
TEST_ASSERT(gTraceExitCount > 0);
TEST_ASSERT(gTraceDataCount > 0);
TEST_ASSERT(gFnNameError == FALSE);
TEST_ASSERT(gFnFormatError == FALSE);
#else
log_info("Tracing has been disabled. Testing of this feature has been skipped.\n");
#endif