| 1 |
# Functionality covered: this file contains a collection of tests for the |
| 2 |
# procedures in tclObj.c that implement Tcl's basic type support and the |
| 3 |
# type managers for the types boolean, double, and integer. |
| 4 |
# |
| 5 |
# Sourcing this file into Tcl runs the tests and generates output for |
| 6 |
# errors. No output means no errors were found. |
| 7 |
# |
| 8 |
# Copyright (c) 1995-1996 Sun Microsystems, Inc. |
| 9 |
# Copyright (c) 1998-1999 by Scriptics Corporation. |
| 10 |
# |
| 11 |
# See the file "license.terms" for information on usage and redistribution |
| 12 |
# of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 13 |
|
| 14 |
if {"::tcltest" ni [namespace children]} { |
| 15 |
package require tcltest 2.5 |
| 16 |
namespace import -force ::tcltest::* |
| 17 |
} |
| 18 |
|
| 19 |
::tcltest::loadTestedCommands |
| 20 |
catch [list package require -exact Tcltest [info patchlevel]] |
| 21 |
|
| 22 |
testConstraint testobj [llength [info commands testobj]] |
| 23 |
testConstraint longIs32bit [expr {int(0x80000000) < 0}] |
| 24 |
testConstraint wideBiggerThanInt [expr {wide(0x80000000) != int(0x80000000)}] |
| 25 |
|
| 26 |
test obj-1.1 {Tcl_AppendAllObjTypes, and InitTypeTable, Tcl_RegisterObjType} testobj { |
| 27 |
set r 1 |
| 28 |
foreach {t} { |
| 29 |
{array search} |
| 30 |
bytearray |
| 31 |
bytecode |
| 32 |
cmdName |
| 33 |
dict |
| 34 |
end-offset |
| 35 |
regexp |
| 36 |
string |
| 37 |
} { |
| 38 |
set first [string first $t [testobj types]] |
| 39 |
set r [expr {$r && ($first >= 0)}] |
| 40 |
} |
| 41 |
set result $r |
| 42 |
} {1} |
| 43 |
|
| 44 |
test obj-2.1 {Tcl_GetObjType error} testobj { |
| 45 |
list [testintobj set 1 0] [catch {testobj convert 1 foo} msg] $msg |
| 46 |
} {0 1 {no type foo found}} |
| 47 |
test obj-2.2 {Tcl_GetObjType and Tcl_ConvertToType} testobj { |
| 48 |
set result "" |
| 49 |
lappend result [testobj freeallvars] |
| 50 |
lappend result [testintobj set 1 12] |
| 51 |
lappend result [testobj convert 1 bytearray] |
| 52 |
lappend result [testobj type 1] |
| 53 |
lappend result [testobj refcount 1] |
| 54 |
} {{} 12 12 bytearray 3} |
| 55 |
|
| 56 |
test obj-3.1 {Tcl_ConvertToType error} testobj { |
| 57 |
list [testdoubleobj set 1 12.34] \ |
| 58 |
[catch {testobj convert 1 end-offset} msg] \ |
| 59 |
$msg |
| 60 |
} {12.34 1 {bad index "12.34": must be end?[+-]integer?}} |
| 61 |
test obj-3.2 {Tcl_ConvertToType error, "empty string" object} testobj { |
| 62 |
list [testobj newobj 1] [catch {testobj convert 1 end-offset} msg] $msg |
| 63 |
} {{} 1 {bad index "": must be end?[+-]integer?}} |
| 64 |
|
| 65 |
test obj-4.1 {Tcl_NewObj and AllocateFreeObjects} testobj { |
| 66 |
set result "" |
| 67 |
lappend result [testobj freeallvars] |
| 68 |
lappend result [testobj newobj 1] |
| 69 |
lappend result [testobj type 1] |
| 70 |
lappend result [testobj refcount 1] |
| 71 |
} {{} {} string 2} |
| 72 |
|
| 73 |
test obj-5.1 {Tcl_FreeObj} testobj { |
| 74 |
set result "" |
| 75 |
lappend result [testintobj set 1 12345] |
| 76 |
lappend result [testobj freeallvars] |
| 77 |
lappend result [catch {testintobj get 1} msg] |
| 78 |
lappend result $msg |
| 79 |
} {12345 {} 1 {variable 1 is unset (NULL)}} |
| 80 |
|
| 81 |
test obj-6.1 {Tcl_DuplicateObj, object has internal rep} testobj { |
| 82 |
set result "" |
| 83 |
lappend result [testobj freeallvars] |
| 84 |
lappend result [testintobj set 1 47] |
| 85 |
lappend result [testobj duplicate 1 2] |
| 86 |
lappend result [testintobj get 2] |
| 87 |
lappend result [testobj refcount 1] |
| 88 |
lappend result [testobj refcount 2] |
| 89 |
} {{} 47 47 47 2 3} |
| 90 |
test obj-6.2 {Tcl_DuplicateObj, "empty string" object} testobj { |
| 91 |
set result "" |
| 92 |
lappend result [testobj freeallvars] |
| 93 |
lappend result [testobj newobj 1] |
| 94 |
lappend result [testobj duplicate 1 2] |
| 95 |
lappend result [testintobj get 2] |
| 96 |
lappend result [testobj refcount 1] |
| 97 |
lappend result [testobj refcount 2] |
| 98 |
} {{} {} {} {} 2 3} |
| 99 |
|
| 100 |
# We assume that testobj is an indicator for test*obj as well |
| 101 |
|
| 102 |
test obj-7.1 {Tcl_GetString, return existing string rep} testobj { |
| 103 |
set result "" |
| 104 |
lappend result [testintobj set 1 47] |
| 105 |
lappend result [testintobj get2 1] |
| 106 |
} {47 47} |
| 107 |
test obj-7.2 {Tcl_GetString, "empty string" object} testobj { |
| 108 |
set result "" |
| 109 |
lappend result [testobj newobj 1] |
| 110 |
lappend result [teststringobj append 1 abc -1] |
| 111 |
lappend result [teststringobj get2 1] |
| 112 |
} {{} abc abc} |
| 113 |
test obj-7.3 {Tcl_GetString, returns string internal rep (DString)} testobj { |
| 114 |
set result "" |
| 115 |
lappend result [teststringobj set 1 xyz] |
| 116 |
lappend result [teststringobj append 1 abc -1] |
| 117 |
lappend result [teststringobj get2 1] |
| 118 |
} {xyz xyzabc xyzabc} |
| 119 |
test obj-7.4 {Tcl_GetString, recompute string rep from internal rep} testobj { |
| 120 |
set result "" |
| 121 |
lappend result [testintobj set 1 77] |
| 122 |
lappend result [testintobj mult10 1] |
| 123 |
lappend result [teststringobj get2 1] |
| 124 |
} {77 770 770} |
| 125 |
|
| 126 |
test obj-8.1 {Tcl_GetStringFromObj, return existing string rep} testobj { |
| 127 |
set result "" |
| 128 |
lappend result [testintobj set 1 47] |
| 129 |
lappend result [testintobj get 1] |
| 130 |
} {47 47} |
| 131 |
test obj-8.2 {Tcl_GetStringFromObj, "empty string" object} testobj { |
| 132 |
set result "" |
| 133 |
lappend result [testobj newobj 1] |
| 134 |
lappend result [teststringobj append 1 abc -1] |
| 135 |
lappend result [teststringobj get 1] |
| 136 |
} {{} abc abc} |
| 137 |
test obj-8.3 {Tcl_GetStringFromObj, returns string internal rep (DString)} testobj { |
| 138 |
set result "" |
| 139 |
lappend result [teststringobj set 1 xyz] |
| 140 |
lappend result [teststringobj append 1 abc -1] |
| 141 |
lappend result [teststringobj get 1] |
| 142 |
} {xyz xyzabc xyzabc} |
| 143 |
test obj-8.4 {Tcl_GetStringFromObj, recompute string rep from internal rep} testobj { |
| 144 |
set result "" |
| 145 |
lappend result [testintobj set 1 77] |
| 146 |
lappend result [testintobj mult10 1] |
| 147 |
lappend result [teststringobj get 1] |
| 148 |
} {77 770 770} |
| 149 |
|
| 150 |
test obj-9.1 {Tcl_NewBooleanObj} testobj { |
| 151 |
set result "" |
| 152 |
lappend result [testobj freeallvars] |
| 153 |
lappend result [testbooleanobj set 1 0] |
| 154 |
lappend result [testobj type 1] |
| 155 |
lappend result [testobj refcount 1] |
| 156 |
} {{} 0 int 2} |
| 157 |
|
| 158 |
test obj-10.1 {Tcl_SetBooleanObj, existing "empty string" object} testobj { |
| 159 |
set result "" |
| 160 |
lappend result [testobj freeallvars] |
| 161 |
lappend result [testobj newobj 1] |
| 162 |
lappend result [testbooleanobj set 1 0] ;# makes existing obj boolean |
| 163 |
lappend result [testobj type 1] |
| 164 |
lappend result [testobj refcount 1] |
| 165 |
} {{} {} 0 int 2} |
| 166 |
test obj-10.2 {Tcl_SetBooleanObj, existing non-"empty string" object} testobj { |
| 167 |
set result "" |
| 168 |
lappend result [testobj freeallvars] |
| 169 |
lappend result [testintobj set 1 98765] |
| 170 |
lappend result [testbooleanobj set 1 1] ;# makes existing obj boolean |
| 171 |
lappend result [testobj type 1] |
| 172 |
lappend result [testobj refcount 1] |
| 173 |
} {{} 98765 1 int 2} |
| 174 |
|
| 175 |
test obj-11.1 {Tcl_GetBooleanFromObj, existing boolean object} testobj { |
| 176 |
set result "" |
| 177 |
lappend result [testbooleanobj set 1 1] |
| 178 |
lappend result [testbooleanobj not 1] ;# gets existing boolean rep |
| 179 |
} {1 0} |
| 180 |
test obj-11.2 {Tcl_GetBooleanFromObj, convert to boolean} testobj { |
| 181 |
set result "" |
| 182 |
lappend result [testintobj set 1 47] |
| 183 |
lappend result [testbooleanobj not 1] ;# must convert to bool |
| 184 |
lappend result [testobj type 1] |
| 185 |
} {47 0 int} |
| 186 |
test obj-11.3 {Tcl_GetBooleanFromObj, error converting to boolean} testobj { |
| 187 |
set result "" |
| 188 |
lappend result [teststringobj set 1 abc] |
| 189 |
lappend result [catch {testbooleanobj not 1} msg] |
| 190 |
lappend result $msg |
| 191 |
} {abc 1 {expected boolean value but got "abc"}} |
| 192 |
test obj-11.4 {Tcl_GetBooleanFromObj, error converting from "empty string"} testobj { |
| 193 |
set result "" |
| 194 |
lappend result [testobj newobj 1] |
| 195 |
lappend result [catch {testbooleanobj not 1} msg] |
| 196 |
lappend result $msg |
| 197 |
} {{} 1 {expected boolean value but got ""}} |
| 198 |
test obj-11.5 {Tcl_GetBooleanFromObj, convert hex to boolean} testobj { |
| 199 |
set result "" |
| 200 |
lappend result [teststringobj set 1 0xac] |
| 201 |
lappend result [testbooleanobj not 1] |
| 202 |
lappend result [testobj type 1] |
| 203 |
} {0xac 0 int} |
| 204 |
test obj-11.6 {Tcl_GetBooleanFromObj, convert float to boolean} testobj { |
| 205 |
set result "" |
| 206 |
lappend result [teststringobj set 1 5.42] |
| 207 |
lappend result [testbooleanobj not 1] |
| 208 |
lappend result [testobj type 1] |
| 209 |
} {5.42 0 int} |
| 210 |
|
| 211 |
test obj-12.1 {DupBooleanInternalRep} testobj { |
| 212 |
set result "" |
| 213 |
lappend result [testbooleanobj set 1 1] |
| 214 |
lappend result [testobj duplicate 1 2] ;# uses DupBooleanInternalRep |
| 215 |
lappend result [testbooleanobj get 2] |
| 216 |
} {1 1 1} |
| 217 |
|
| 218 |
test obj-13.1 {SetBooleanFromAny, int to boolean special case} testobj { |
| 219 |
set result "" |
| 220 |
lappend result [testintobj set 1 1234] |
| 221 |
lappend result [testbooleanobj not 1] ;# converts with SetBooleanFromAny |
| 222 |
lappend result [testobj type 1] |
| 223 |
} {1234 0 int} |
| 224 |
test obj-13.2 {SetBooleanFromAny, double to boolean special case} testobj { |
| 225 |
set result "" |
| 226 |
lappend result [testdoubleobj set 1 3.14159] |
| 227 |
lappend result [testbooleanobj not 1] ;# converts with SetBooleanFromAny |
| 228 |
lappend result [testobj type 1] |
| 229 |
} {3.14159 0 int} |
| 230 |
test obj-13.3 {SetBooleanFromAny, special case strings representing booleans} testobj { |
| 231 |
set result "" |
| 232 |
foreach s {yes no true false on off} { |
| 233 |
teststringobj set 1 $s |
| 234 |
lappend result [testbooleanobj not 1] |
| 235 |
} |
| 236 |
lappend result [testobj type 1] |
| 237 |
} {0 1 0 1 0 1 int} |
| 238 |
test obj-13.4 {SetBooleanFromAny, recompute string rep then parse it} testobj { |
| 239 |
set result "" |
| 240 |
lappend result [testintobj set 1 456] |
| 241 |
lappend result [testintobj div10 1] |
| 242 |
lappend result [testbooleanobj not 1] ;# converts with SetBooleanFromAny |
| 243 |
lappend result [testobj type 1] |
| 244 |
} {456 45 0 int} |
| 245 |
test obj-13.5 {SetBooleanFromAny, error parsing string} testobj { |
| 246 |
set result "" |
| 247 |
lappend result [teststringobj set 1 abc] |
| 248 |
lappend result [catch {testbooleanobj not 1} msg] |
| 249 |
lappend result $msg |
| 250 |
} {abc 1 {expected boolean value but got "abc"}} |
| 251 |
test obj-13.6 {SetBooleanFromAny, error parsing string} testobj { |
| 252 |
set result "" |
| 253 |
lappend result [teststringobj set 1 x1.0] |
| 254 |
lappend result [catch {testbooleanobj not 1} msg] |
| 255 |
lappend result $msg |
| 256 |
} {x1.0 1 {expected boolean value but got "x1.0"}} |
| 257 |
test obj-13.7 {SetBooleanFromAny, error converting from "empty string"} testobj { |
| 258 |
set result "" |
| 259 |
lappend result [testobj newobj 1] |
| 260 |
lappend result [catch {testbooleanobj not 1} msg] |
| 261 |
lappend result $msg |
| 262 |
} {{} 1 {expected boolean value but got ""}} |
| 263 |
test obj-13.8 {SetBooleanFromAny, unicode strings} testobj { |
| 264 |
set result "" |
| 265 |
lappend result [teststringobj set 1 1\u7777] |
| 266 |
lappend result [catch {testbooleanobj not 1} msg] |
| 267 |
lappend result $msg |
| 268 |
} "1\u7777 1 {expected boolean value but got \"1\u7777\"}" |
| 269 |
|
| 270 |
test obj-14.1 {UpdateStringOfBoolean} testobj { |
| 271 |
set result "" |
| 272 |
lappend result [testbooleanobj set 1 0] |
| 273 |
lappend result [testbooleanobj not 1] |
| 274 |
lappend result [testbooleanobj get 1] ;# must update string rep |
| 275 |
} {0 1 1} |
| 276 |
|
| 277 |
test obj-15.1 {Tcl_NewDoubleObj} testobj { |
| 278 |
set result "" |
| 279 |
lappend result [testobj freeallvars] |
| 280 |
lappend result [testdoubleobj set 1 3.1459] |
| 281 |
lappend result [testobj type 1] |
| 282 |
lappend result [testobj refcount 1] |
| 283 |
} {{} 3.1459 double 2} |
| 284 |
|
| 285 |
test obj-16.1 {Tcl_SetDoubleObj, existing "empty string" object} testobj { |
| 286 |
set result "" |
| 287 |
lappend result [testobj freeallvars] |
| 288 |
lappend result [testobj newobj 1] |
| 289 |
lappend result [testdoubleobj set 1 0.123] ;# makes existing obj boolean |
| 290 |
lappend result [testobj type 1] |
| 291 |
lappend result [testobj refcount 1] |
| 292 |
} {{} {} 0.123 double 2} |
| 293 |
test obj-16.2 {Tcl_SetDoubleObj, existing non-"empty string" object} testobj { |
| 294 |
set result "" |
| 295 |
lappend result [testobj freeallvars] |
| 296 |
lappend result [testintobj set 1 98765] |
| 297 |
lappend result [testdoubleobj set 1 27.56] ;# makes existing obj double |
| 298 |
lappend result [testobj type 1] |
| 299 |
lappend result [testobj refcount 1] |
| 300 |
} {{} 98765 27.56 double 2} |
| 301 |
|
| 302 |
test obj-17.1 {Tcl_GetDoubleFromObj, existing double object} testobj { |
| 303 |
set result "" |
| 304 |
lappend result [testdoubleobj set 1 16.1] |
| 305 |
lappend result [testdoubleobj mult10 1] ;# gets existing double rep |
| 306 |
} {16.1 161.0} |
| 307 |
test obj-17.2 {Tcl_GetDoubleFromObj, convert to double} testobj { |
| 308 |
set result "" |
| 309 |
lappend result [testintobj set 1 477] |
| 310 |
lappend result [testdoubleobj div10 1] ;# must convert to bool |
| 311 |
lappend result [testobj type 1] |
| 312 |
} {477 47.7 double} |
| 313 |
test obj-17.3 {Tcl_GetDoubleFromObj, error converting to double} testobj { |
| 314 |
set result "" |
| 315 |
lappend result [teststringobj set 1 abc] |
| 316 |
lappend result [catch {testdoubleobj mult10 1} msg] |
| 317 |
lappend result $msg |
| 318 |
} {abc 1 {expected floating-point number but got "abc"}} |
| 319 |
test obj-17.4 {Tcl_GetDoubleFromObj, error converting from "empty string"} testobj { |
| 320 |
set result "" |
| 321 |
lappend result [testobj newobj 1] |
| 322 |
lappend result [catch {testdoubleobj div10 1} msg] |
| 323 |
lappend result $msg |
| 324 |
} {{} 1 {expected floating-point number but got ""}} |
| 325 |
|
| 326 |
test obj-18.1 {DupDoubleInternalRep} testobj { |
| 327 |
set result "" |
| 328 |
lappend result [testdoubleobj set 1 17.1] |
| 329 |
lappend result [testobj duplicate 1 2] ;# uses DupDoubleInternalRep |
| 330 |
lappend result [testdoubleobj get 2] |
| 331 |
} {17.1 17.1 17.1} |
| 332 |
|
| 333 |
test obj-19.1 {SetDoubleFromAny, int to double special case} testobj { |
| 334 |
set result "" |
| 335 |
lappend result [testintobj set 1 1234] |
| 336 |
lappend result [testdoubleobj mult10 1] ;# converts with SetDoubleFromAny |
| 337 |
lappend result [testobj type 1] |
| 338 |
} {1234 12340.0 double} |
| 339 |
test obj-19.2 {SetDoubleFromAny, boolean to double special case} testobj { |
| 340 |
set result "" |
| 341 |
lappend result [testbooleanobj set 1 1] |
| 342 |
lappend result [testdoubleobj mult10 1] ;# converts with SetDoubleFromAny |
| 343 |
lappend result [testobj type 1] |
| 344 |
} {1 10.0 double} |
| 345 |
test obj-19.3 {SetDoubleFromAny, recompute string rep then parse it} testobj { |
| 346 |
set result "" |
| 347 |
lappend result [testintobj set 1 456] |
| 348 |
lappend result [testintobj div10 1] |
| 349 |
lappend result [testdoubleobj mult10 1] ;# converts with SetDoubleFromAny |
| 350 |
lappend result [testobj type 1] |
| 351 |
} {456 45 450.0 double} |
| 352 |
test obj-19.4 {SetDoubleFromAny, error parsing string} testobj { |
| 353 |
set result "" |
| 354 |
lappend result [teststringobj set 1 abc] |
| 355 |
lappend result [catch {testdoubleobj mult10 1} msg] |
| 356 |
lappend result $msg |
| 357 |
} {abc 1 {expected floating-point number but got "abc"}} |
| 358 |
test obj-19.5 {SetDoubleFromAny, error parsing string} testobj { |
| 359 |
set result "" |
| 360 |
lappend result [teststringobj set 1 x1.0] |
| 361 |
lappend result [catch {testdoubleobj mult10 1} msg] |
| 362 |
lappend result $msg |
| 363 |
} {x1.0 1 {expected floating-point number but got "x1.0"}} |
| 364 |
test obj-19.6 {SetDoubleFromAny, error converting from "empty string"} testobj { |
| 365 |
set result "" |
| 366 |
lappend result [testobj newobj 1] |
| 367 |
lappend result [catch {testdoubleobj div10 1} msg] |
| 368 |
lappend result $msg |
| 369 |
} {{} 1 {expected floating-point number but got ""}} |
| 370 |
|
| 371 |
test obj-20.1 {UpdateStringOfDouble} testobj { |
| 372 |
set result "" |
| 373 |
lappend result [testdoubleobj set 1 3.14159] |
| 374 |
lappend result [testdoubleobj mult10 1] |
| 375 |
lappend result [testdoubleobj get 1] ;# must update string rep |
| 376 |
} {3.14159 31.4159 31.4159} |
| 377 |
|
| 378 |
test obj-21.1 {Tcl_NewIntObj} testobj { |
| 379 |
set result "" |
| 380 |
lappend result [testobj freeallvars] |
| 381 |
lappend result [testintobj set 1 55] |
| 382 |
lappend result [testobj type 1] |
| 383 |
lappend result [testobj refcount 1] |
| 384 |
} {{} 55 int 2} |
| 385 |
|
| 386 |
test obj-22.1 {Tcl_SetIntObj, existing "empty string" object} testobj { |
| 387 |
set result "" |
| 388 |
lappend result [testobj freeallvars] |
| 389 |
lappend result [testobj newobj 1] |
| 390 |
lappend result [testintobj set 1 77] ;# makes existing obj int |
| 391 |
lappend result [testobj type 1] |
| 392 |
lappend result [testobj refcount 1] |
| 393 |
} {{} {} 77 int 2} |
| 394 |
test obj-22.2 {Tcl_SetIntObj, existing non-"empty string" object} testobj { |
| 395 |
set result "" |
| 396 |
lappend result [testobj freeallvars] |
| 397 |
lappend result [testdoubleobj set 1 12.34] |
| 398 |
lappend result [testintobj set 1 77] ;# makes existing obj int |
| 399 |
lappend result [testobj type 1] |
| 400 |
lappend result [testobj refcount 1] |
| 401 |
} {{} 12.34 77 int 2} |
| 402 |
|
| 403 |
test obj-23.1 {Tcl_GetIntFromObj, existing int object} testobj { |
| 404 |
set result "" |
| 405 |
lappend result [testintobj set 1 22] |
| 406 |
lappend result [testintobj mult10 1] ;# gets existing int rep |
| 407 |
} {22 220} |
| 408 |
test obj-23.2 {Tcl_GetIntFromObj, convert to int} testobj { |
| 409 |
set result "" |
| 410 |
lappend result [testintobj set 1 477] |
| 411 |
lappend result [testintobj div10 1] ;# must convert to bool |
| 412 |
lappend result [testobj type 1] |
| 413 |
} {477 47 int} |
| 414 |
test obj-23.3 {Tcl_GetIntFromObj, error converting to int} testobj { |
| 415 |
set result "" |
| 416 |
lappend result [teststringobj set 1 abc] |
| 417 |
lappend result [catch {testintobj mult10 1} msg] |
| 418 |
lappend result $msg |
| 419 |
} {abc 1 {expected integer but got "abc"}} |
| 420 |
test obj-23.4 {Tcl_GetIntFromObj, error converting from "empty string"} testobj { |
| 421 |
set result "" |
| 422 |
lappend result [testobj newobj 1] |
| 423 |
lappend result [catch {testintobj div10 1} msg] |
| 424 |
lappend result $msg |
| 425 |
} {{} 1 {expected integer but got ""}} |
| 426 |
test obj-23.5 {Tcl_GetIntFromObj, integer too large to represent as non-long error} {testobj} { |
| 427 |
set result "" |
| 428 |
lappend result [testobj newobj 1] |
| 429 |
lappend result [testintobj inttoobigtest 1] |
| 430 |
} {{} 1} |
| 431 |
|
| 432 |
test obj-24.1 {DupIntInternalRep} testobj { |
| 433 |
set result "" |
| 434 |
lappend result [testintobj set 1 23] |
| 435 |
lappend result [testobj duplicate 1 2] ;# uses DupIntInternalRep |
| 436 |
lappend result [testintobj get 2] |
| 437 |
} {23 23 23} |
| 438 |
|
| 439 |
test obj-25.1 {SetIntFromAny, int to int special case} testobj { |
| 440 |
set result "" |
| 441 |
lappend result [testintobj set 1 1234] |
| 442 |
lappend result [testintobj mult10 1] ;# converts with SetIntFromAny |
| 443 |
lappend result [testobj type 1] |
| 444 |
} {1234 12340 int} |
| 445 |
test obj-25.2 {SetIntFromAny, boolean to int special case} testobj { |
| 446 |
set result "" |
| 447 |
lappend result [testbooleanobj set 1 1] |
| 448 |
lappend result [testintobj mult10 1] ;# converts with SetIntFromAny |
| 449 |
lappend result [testobj type 1] |
| 450 |
} {1 10 int} |
| 451 |
test obj-25.3 {SetIntFromAny, recompute string rep then parse it} testobj { |
| 452 |
set result "" |
| 453 |
lappend result [testintobj set 1 456] |
| 454 |
lappend result [testintobj div10 1] |
| 455 |
lappend result [testintobj mult10 1] ;# converts with SetIntFromAny |
| 456 |
lappend result [testobj type 1] |
| 457 |
} {456 45 450 int} |
| 458 |
test obj-25.4 {SetIntFromAny, error parsing string} testobj { |
| 459 |
set result "" |
| 460 |
lappend result [teststringobj set 1 abc] |
| 461 |
lappend result [catch {testintobj mult10 1} msg] |
| 462 |
lappend result $msg |
| 463 |
} {abc 1 {expected integer but got "abc"}} |
| 464 |
test obj-25.5 {SetIntFromAny, error parsing string} testobj { |
| 465 |
set result "" |
| 466 |
lappend result [teststringobj set 1 x17] |
| 467 |
lappend result [catch {testintobj mult10 1} msg] |
| 468 |
lappend result $msg |
| 469 |
} {x17 1 {expected integer but got "x17"}} |
| 470 |
test obj-25.6 {SetIntFromAny, integer too large} {testobj} { |
| 471 |
set result "" |
| 472 |
lappend result [teststringobj set 1 123456789012345678901] |
| 473 |
lappend result [catch {testintobj mult10 1} msg] |
| 474 |
lappend result $msg |
| 475 |
} {123456789012345678901 1 {integer value too large to represent}} |
| 476 |
test obj-25.7 {SetIntFromAny, error converting from "empty string"} testobj { |
| 477 |
set result "" |
| 478 |
lappend result [testobj newobj 1] |
| 479 |
lappend result [catch {testintobj div10 1} msg] |
| 480 |
lappend result $msg |
| 481 |
} {{} 1 {expected integer but got ""}} |
| 482 |
|
| 483 |
test obj-26.1 {UpdateStringOfInt} testobj { |
| 484 |
set result "" |
| 485 |
lappend result [testintobj set 1 512] |
| 486 |
lappend result [testintobj mult10 1] |
| 487 |
lappend result [testintobj get 1] ;# must update string rep |
| 488 |
} {512 5120 5120} |
| 489 |
|
| 490 |
test obj-27.1 {Tcl_NewLongObj} testobj { |
| 491 |
set result "" |
| 492 |
lappend result [testobj freeallvars] |
| 493 |
testintobj setmaxlong 1 |
| 494 |
lappend result [testintobj ismaxlong 1] |
| 495 |
lappend result [testobj type 1] |
| 496 |
lappend result [testobj refcount 1] |
| 497 |
} {{} 1 int 1} |
| 498 |
|
| 499 |
test obj-28.1 {Tcl_SetLongObj, existing "empty string" object} testobj { |
| 500 |
set result "" |
| 501 |
lappend result [testobj freeallvars] |
| 502 |
lappend result [testobj newobj 1] |
| 503 |
lappend result [testintobj setlong 1 77] ;# makes existing obj long int |
| 504 |
lappend result [testobj type 1] |
| 505 |
lappend result [testobj refcount 1] |
| 506 |
} {{} {} 77 int 2} |
| 507 |
test obj-28.2 {Tcl_SetLongObj, existing non-"empty string" object} testobj { |
| 508 |
set result "" |
| 509 |
lappend result [testobj freeallvars] |
| 510 |
lappend result [testdoubleobj set 1 12.34] |
| 511 |
lappend result [testintobj setlong 1 77] ;# makes existing obj long int |
| 512 |
lappend result [testobj type 1] |
| 513 |
lappend result [testobj refcount 1] |
| 514 |
} {{} 12.34 77 int 2} |
| 515 |
|
| 516 |
test obj-29.1 {Tcl_GetLongFromObj, existing long integer object} testobj { |
| 517 |
set result "" |
| 518 |
lappend result [testintobj setlong 1 22] |
| 519 |
lappend result [testintobj mult10 1] ;# gets existing long int rep |
| 520 |
} {22 220} |
| 521 |
test obj-29.2 {Tcl_GetLongFromObj, convert to long} testobj { |
| 522 |
set result "" |
| 523 |
lappend result [testintobj setlong 1 477] |
| 524 |
lappend result [testintobj div10 1] ;# must convert to bool |
| 525 |
lappend result [testobj type 1] |
| 526 |
} {477 47 int} |
| 527 |
test obj-29.3 {Tcl_GetLongFromObj, error converting to long integer} testobj { |
| 528 |
set result "" |
| 529 |
lappend result [teststringobj set 1 abc] |
| 530 |
lappend result [catch {testintobj ismaxlong 1} msg] ;# cvts to long int |
| 531 |
lappend result $msg |
| 532 |
} {abc 1 {expected integer but got "abc"}} |
| 533 |
test obj-29.4 {Tcl_GetLongFromObj, error converting from "empty string"} testobj { |
| 534 |
set result "" |
| 535 |
lappend result [testobj newobj 1] |
| 536 |
lappend result [catch {testintobj ismaxlong 1} msg] ;# cvts to long int |
| 537 |
lappend result $msg |
| 538 |
} {{} 1 {expected integer but got ""}} |
| 539 |
|
| 540 |
test obj-30.1 {Ref counting and object deletion, simple types} testobj { |
| 541 |
set result "" |
| 542 |
lappend result [testobj freeallvars] |
| 543 |
lappend result [testintobj set 1 1024] |
| 544 |
lappend result [testobj assign 1 2] ;# vars 1 and 2 share the int obj |
| 545 |
lappend result [testobj type 2] |
| 546 |
lappend result [testobj refcount 1] |
| 547 |
lappend result [testobj refcount 2] |
| 548 |
lappend result [testbooleanobj set 2 0] ;# must copy on write, now 2 objs |
| 549 |
lappend result [testobj type 2] |
| 550 |
lappend result [testobj refcount 1] |
| 551 |
lappend result [testobj refcount 2] |
| 552 |
} {{} 1024 1024 int 4 4 0 int 3 2} |
| 553 |
|
| 554 |
|
| 555 |
test obj-31.1 {regenerate string rep of "end"} testobj { |
| 556 |
testobj freeallvars |
| 557 |
teststringobj set 1 end |
| 558 |
testobj convert 1 end-offset |
| 559 |
testobj invalidateStringRep 1 |
| 560 |
} end |
| 561 |
test obj-31.2 {regenerate string rep of "end-1"} testobj { |
| 562 |
testobj freeallvars |
| 563 |
teststringobj set 1 end-0x1 |
| 564 |
testobj convert 1 end-offset |
| 565 |
testobj invalidateStringRep 1 |
| 566 |
} end-1 |
| 567 |
test obj-31.3 {regenerate string rep of "end--1"} testobj { |
| 568 |
testobj freeallvars |
| 569 |
teststringobj set 1 end--0x1 |
| 570 |
testobj convert 1 end-offset |
| 571 |
testobj invalidateStringRep 1 |
| 572 |
} end--1 |
| 573 |
test obj-31.4 {regenerate string rep of "end-bigInteger"} testobj { |
| 574 |
testobj freeallvars |
| 575 |
teststringobj set 1 end-0x7fffffff |
| 576 |
testobj convert 1 end-offset |
| 577 |
testobj invalidateStringRep 1 |
| 578 |
} end-2147483647 |
| 579 |
test obj-31.5 {regenerate string rep of "end--bigInteger"} testobj { |
| 580 |
testobj freeallvars |
| 581 |
teststringobj set 1 end--0x7fffffff |
| 582 |
testobj convert 1 end-offset |
| 583 |
testobj invalidateStringRep 1 |
| 584 |
} end--2147483647 |
| 585 |
test obj-31.6 {regenerate string rep of "end--bigInteger"} {testobj longIs32bit} { |
| 586 |
testobj freeallvars |
| 587 |
teststringobj set 1 end--0x80000000 |
| 588 |
testobj convert 1 end-offset |
| 589 |
testobj invalidateStringRep 1 |
| 590 |
} end--2147483648 |
| 591 |
|
| 592 |
test obj-32.1 {freeing very large object trees} { |
| 593 |
set x {} |
| 594 |
for {set i 0} {$i<100000} {incr i} { |
| 595 |
set x [list $x {}] |
| 596 |
} |
| 597 |
unset x |
| 598 |
} {} |
| 599 |
|
| 600 |
test obj-33.1 {integer overflow on input} {longIs32bit wideBiggerThanInt} { |
| 601 |
set x 0x8000; append x 0000 |
| 602 |
list [string is integer $x] [expr { wide($x) }] |
| 603 |
} {1 2147483648} |
| 604 |
test obj-33.2 {integer overflow on input} {longIs32bit wideBiggerThanInt} { |
| 605 |
set x 0xffff; append x ffff |
| 606 |
list [string is integer $x] [expr { wide($x) }] |
| 607 |
} {1 4294967295} |
| 608 |
test obj-33.3 {integer overflow on input} { |
| 609 |
set x 0x10000; append x 0000 |
| 610 |
list [string is integer $x] [expr { wide($x) }] |
| 611 |
} {0 4294967296} |
| 612 |
test obj-33.4 {integer overflow on input} {longIs32bit wideBiggerThanInt} { |
| 613 |
set x -0x8000; append x 0000 |
| 614 |
list [string is integer $x] [expr { wide($x) }] |
| 615 |
} {1 -2147483648} |
| 616 |
test obj-33.5 {integer overflow on input} {longIs32bit wideBiggerThanInt} { |
| 617 |
set x -0x8000; append x 0001 |
| 618 |
list [string is integer $x] [expr { wide($x) }] |
| 619 |
} {1 -2147483649} |
| 620 |
test obj-33.6 {integer overflow on input} {longIs32bit wideBiggerThanInt} { |
| 621 |
set x -0xffff; append x ffff |
| 622 |
list [string is integer $x] [expr { wide($x) }] |
| 623 |
} {1 -4294967295} |
| 624 |
test obj-33.7 {integer overflow on input} { |
| 625 |
set x -0x10000; append x 0000 |
| 626 |
list [string is integer $x] [expr { wide($x) }] |
| 627 |
} {0 -4294967296} |
| 628 |
|
| 629 |
test obj-34.1 {mp_iseven} testobj { |
| 630 |
set result "" |
| 631 |
lappend result [testbignumobj set 1 0] |
| 632 |
lappend result [testbignumobj iseven 1] ; |
| 633 |
lappend result [testobj type 1] |
| 634 |
} {0 1 int} |
| 635 |
test obj-34.2 {mp_radix_size} testobj { |
| 636 |
set result "" |
| 637 |
lappend result [testbignumobj set 1 9] |
| 638 |
lappend result [testbignumobj radixsize 1] ; |
| 639 |
lappend result [testobj type 1] |
| 640 |
} {9 2 int} |
| 641 |
|
| 642 |
if {[testConstraint testobj]} { |
| 643 |
testobj freeallvars |
| 644 |
} |
| 645 |
|
| 646 |
# cleanup |
| 647 |
::tcltest::cleanupTests |
| 648 |
return |