summaryrefslogtreecommitdiffstats
path: root/generic/tclTest.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2020-05-06 16:38:45 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2020-05-06 16:38:45 (GMT)
commitda60a1af9f3f57904b13bd79121d88d5e354e7b3 (patch)
tree2ec9fb7223dc074f5a3f7a3b251bc4591bbf51ce /generic/tclTest.c
parent6c9fa195b08a24ca759c7d0e2129a33137bbbccd (diff)
downloadtcl-da60a1af9f3f57904b13bd79121d88d5e354e7b3.zip
tcl-da60a1af9f3f57904b13bd79121d88d5e354e7b3.tar.gz
tcl-da60a1af9f3f57904b13bd79121d88d5e354e7b3.tar.bz2
Backport testutfprev/testutfnex testcase improvements from 8.7. This makes testdescriptions/testresults more equal among branches, so the real differences are more visible.
Diffstat (limited to 'generic/tclTest.c')
-rw-r--r--generic/tclTest.c47
1 files changed, 24 insertions, 23 deletions
diff --git a/generic/tclTest.c b/generic/tclTest.c
index 27e145c..ae2d7bb 100644
--- a/generic/tclTest.c
+++ b/generic/tclTest.c
@@ -5852,7 +5852,6 @@ TestChannelCmd(
chanPtr = statePtr->topChanPtr;
chan = (Tcl_Channel) chanPtr;
} else {
- /* lint */
statePtr = NULL;
chan = NULL;
}
@@ -5907,7 +5906,7 @@ TestChannelCmd(
/* Remember the channel in the pool of detached channels */
- det = (TestChannel *) ckalloc(sizeof(TestChannel));
+ det = (TestChannel *)ckalloc(sizeof(TestChannel));
det->chan = chan;
det->nextPtr = firstDetached;
firstDetached = det;
@@ -6099,7 +6098,7 @@ TestChannelCmd(
for (hPtr = Tcl_FirstHashEntry(hTblPtr, &hSearch);
hPtr != NULL;
hPtr = Tcl_NextHashEntry(&hSearch)) {
- Tcl_AppendElement(interp, Tcl_GetHashKey(hTblPtr, hPtr));
+ Tcl_AppendElement(interp, (char *)Tcl_GetHashKey(hTblPtr, hPtr));
}
return TCL_OK;
}
@@ -6140,7 +6139,7 @@ TestChannelCmd(
chanPtr = (Channel *) Tcl_GetHashValue(hPtr);
statePtr = chanPtr->state;
if (statePtr->flags & TCL_READABLE) {
- Tcl_AppendElement(interp, Tcl_GetHashKey(hTblPtr, hPtr));
+ Tcl_AppendElement(interp, (char *)Tcl_GetHashKey(hTblPtr, hPtr));
}
}
return TCL_OK;
@@ -6197,7 +6196,7 @@ TestChannelCmd(
chanPtr = (Channel *) Tcl_GetHashValue(hPtr);
statePtr = chanPtr->state;
if (statePtr->flags & TCL_WRITABLE) {
- Tcl_AppendElement(interp, Tcl_GetHashKey(hTblPtr, hPtr));
+ Tcl_AppendElement(interp, (char *)Tcl_GetHashKey(hTblPtr, hPtr));
}
}
return TCL_OK;
@@ -7128,15 +7127,15 @@ TestUtfNextCmd(
char *bytes;
const char *result, *first;
char buffer[32];
- static const char tobetested[] = "\xFF\xFE\xF4\xF2\xF0\xEF\xE8\xE3\xE2\xE1\xE0\xC2\xC1\xC0\x82";
+ static const char tobetested[] = "A\xA0\xC0\xC1\xC2\xD0\xE0\xE8\xF2\xF7\xF8\xFE\xFF";
const char *p = tobetested;
if (objc < 2 || objc > 3) {
- Tcl_WrongNumArgs(interp, 1, objv, "bytes ?numBytes?");
+ Tcl_WrongNumArgs(interp, 1, objv, "string ?numBytes?");
return TCL_ERROR;
}
- bytes = (char *) Tcl_GetByteArrayFromObj(objv[1], &numBytes);
+ bytes = Tcl_GetStringFromObj(objv[1], &numBytes);
offset = numBytes +TCL_UTF_MAX -1; /* If no constraint is given, allow
* the terminating NUL to limit
@@ -7154,15 +7153,15 @@ TestUtfNextCmd(
}
}
- if (numBytes > sizeof(buffer) - 2) {
+ if (numBytes > (int)sizeof(buffer) - 3) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"\"testutfnext\" can only handle %d bytes",
- sizeof(buffer) - 2));
+ sizeof(buffer) - 3));
return TCL_ERROR;
}
memcpy(buffer + 1, bytes, numBytes);
- buffer[0] = buffer[numBytes + 1] = '\x00';
+ buffer[0] = buffer[numBytes + 1] = buffer[numBytes + 2] = '\x00';
if (!Tcl_UtfCharComplete(buffer + 1, offset)) {
/* Cannot scan a complete sequence from the data */
@@ -7171,17 +7170,26 @@ TestUtfNextCmd(
return TCL_OK;
}
- first = result = Tcl_UtfNext(buffer + 1);
+ first = result = TclUtfNext(buffer + 1);
while ((buffer[0] = *p++) != '\0') {
/* Run Tcl_UtfNext with many more possible bytes at src[-1], all should give the same result */
- result = Tcl_UtfNext(buffer + 1);
+ result = TclUtfNext(buffer + 1);
if (first != result) {
Tcl_AppendResult(interp, "Tcl_UtfNext is not supposed to read src[-1]", NULL);
return TCL_ERROR;
}
}
+ p = tobetested;
+ while ((buffer[numBytes + 1] = *p++) != '\0') {
+ /* Run Tcl_UtfNext with many more possible bytes at src[end], all should give the same result */
+ result = TclUtfNext(buffer + 1);
+ if (first != result) {
+ Tcl_AppendResult(interp, "Tcl_UtfNext is not supposed to read src[end]", NULL);
+ return TCL_ERROR;
+ }
+ }
- Tcl_SetObjResult(interp, Tcl_NewIntObj(result - buffer - 1));
+ Tcl_SetObjResult(interp, Tcl_NewIntObj(first - buffer - 1));
return TCL_OK;
}
@@ -7201,14 +7209,13 @@ TestUtfPrevCmd(
int numBytes, offset;
char *bytes;
const char *result;
- Tcl_Obj *copy;
if (objc < 2 || objc > 3) {
Tcl_WrongNumArgs(interp, 1, objv, "bytes ?offset?");
return TCL_ERROR;
}
- bytes = (char *) Tcl_GetByteArrayFromObj(objv[1], &numBytes);
+ bytes = Tcl_GetStringFromObj(objv[1], &numBytes);
if (objc == 3) {
if (TCL_OK != TclGetIntForIndex(interp, objv[2], numBytes, &offset)) {
@@ -7223,14 +7230,8 @@ TestUtfPrevCmd(
} else {
offset = numBytes;
}
- copy = Tcl_DuplicateObj(objv[1]);
- bytes = (char *) Tcl_SetByteArrayLength(copy, numBytes+1);
- bytes[numBytes] = '\0';
-
- result = Tcl_UtfPrev(bytes + offset, bytes);
+ result = TclUtfPrev(bytes + offset, bytes);
Tcl_SetObjResult(interp, Tcl_NewIntObj(result - bytes));
-
- Tcl_DecrRefCount(copy);
return TCL_OK;
}