Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Add a few sqlite4_num tests. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | num_work |
Files: | files | file ages | folders |
SHA1: |
6cc07d19e4c2f520d14bd233303039d1 |
User & Date: | peterreid 2013-02-10 04:06:44.501 |
Context
2013-02-10
| ||
04:26 | Add a failing test and supporting functions. When the buffer is ended by a passed-in byte count instead of a trailing 0, sqlite4_num_from_text returns NaN check-in: 2cff3b428a user: peterreid tags: num_work | |
04:06 | Add a few sqlite4_num tests. check-in: 6cc07d19e4 user: peterreid tags: num_work | |
2013-02-09
| ||
05:36 | Create sqlite4_num_isinf check-in: 555cdfbf52 user: peterreid tags: num_work | |
Changes
Added test/num.test.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | # 2001 September 15 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this file is testing the sqlite_*_printf() interface. # # $Id: printf.test,v 1.31 2009/02/01 00:21:10 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl do_test num-equal-1.1.1 { sqlite4_num_compare 20 20 } {equal} do_test num-equal-1.1.2 { sqlite4_num_compare 20 2e1 } {equal} do_test num-equal-1.1.3 { sqlite4_num_compare -00034 -3.4e1 } {equal} # Is +0 > -0? #do_test num-equal-1.1.4 { # sqlite4_num_compare +0 -0 #} {equal} finish_test |
Changes to test/test_main.c.
︙ | ︙ | |||
4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 | Tcl_AppendResult(interp, " ", aOpt[i].zOptName); } return TCL_ERROR; } sqlite4_test_control(SQLITE4_TESTCTRL_OPTIMIZATIONS, db, mask); return TCL_OK; } /* ** Register commands with the TCL interpreter. */ int Sqlitetest1_Init(Tcl_Interp *interp){ extern int sqlite4_search_count; extern int sqlite4_found_count; | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 | Tcl_AppendResult(interp, " ", aOpt[i].zOptName); } return TCL_ERROR; } sqlite4_test_control(SQLITE4_TESTCTRL_OPTIMIZATIONS, db, mask); return TCL_OK; } #define NUM_FORMAT "sign:%d approx:%d e:%d m:%lld" /* Append a return value representing a sqlite4_num. */ static void append_num_result( Tcl_Interp *interp, sqlite4_num A ){ char buf[100]; sprintf( buf, NUM_FORMAT, A.sign, A.approx, A.e, A.m ); Tcl_AppendResult(interp, buf, 0); } /* Convert a string either representing a sqlite4_num (listing its fields as ** returned by append_num_result) or that can be parsed as one. Invalid ** strings become NaN. */ static sqlite4_num test_parse_num( char *arg ){ sqlite4_num A; int sign, approx, e; if( sscanf( arg, NUM_FORMAT, &sign, &approx, &e, &A.m)==4 ){ A.sign = sign; A.approx = approx; A.e = e; return A; } else { return sqlite4_num_from_text(arg, -1, 0); } } /* Convert return values of sqlite4_num to strings that will be readable in ** the tests. */ static char *describe_num_comparison( int code ){ switch( code ){ case 0: return "incomparable"; case 1: return "lesser"; case 2: return "equal"; case 3: return "greater"; default: return "error"; } } /* Compare two numbers A and B. Returns "incomparable", "lesser", "equal", ** "greater", or "error". */ static int test_num_compare( void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ char **argv /* Text of each argument */ ){ sqlite4_num A, B; int cmp; if( argc!=3 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " NUM NUM\"", 0); return TCL_ERROR; } A = test_parse_num( argv[1] ); B = test_parse_num( argv[2] ); cmp = sqlite4_num_compare(A, B); Tcl_AppendResult( interp, describe_num_comparison( cmp ), 0); return TCL_OK; } /* Create a sqlite4_num from a string. The optional second argument specifies ** how many bytes may be read. */ static int test_num_from_text( void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ char **argv /* Text of each argument */ ){ sqlite4_num A; int len; if( argc!=2 && argc!=3 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " STRING\" or \"", argv[0], " STRING INTEGER\"", 0); return TCL_ERROR; } if( argc==3 ){ if ( Tcl_GetInt(interp, argv[2], &len) ) return TCL_ERROR; }else{ len = -1; } A = sqlite4_num_from_text( argv[1], len, 0 ); append_num_result(interp, A); return TCL_OK; } /* ** Register commands with the TCL interpreter. */ int Sqlitetest1_Init(Tcl_Interp *interp){ extern int sqlite4_search_count; extern int sqlite4_found_count; |
︙ | ︙ | |||
4398 4399 4400 4401 4402 4403 4404 | { "sqlite_set_magic", (Tcl_CmdProc*)sqlite_set_magic }, { "sqlite4_interrupt", (Tcl_CmdProc*)test_interrupt }, { "sqlite_delete_function", (Tcl_CmdProc*)delete_function }, { "sqlite_delete_collation", (Tcl_CmdProc*)delete_collation }, { "sqlite4_get_autocommit", (Tcl_CmdProc*)get_autocommit }, { "sqlite4_stack_used", (Tcl_CmdProc*)test_stack_used }, { "printf", (Tcl_CmdProc*)test_printf }, | | > > | 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 | { "sqlite_set_magic", (Tcl_CmdProc*)sqlite_set_magic }, { "sqlite4_interrupt", (Tcl_CmdProc*)test_interrupt }, { "sqlite_delete_function", (Tcl_CmdProc*)delete_function }, { "sqlite_delete_collation", (Tcl_CmdProc*)delete_collation }, { "sqlite4_get_autocommit", (Tcl_CmdProc*)get_autocommit }, { "sqlite4_stack_used", (Tcl_CmdProc*)test_stack_used }, { "printf", (Tcl_CmdProc*)test_printf }, { "sqlite4IoTrace", (Tcl_CmdProc*)test_io_trace }, { "sqlite4_num_compare", (Tcl_CmdProc*)test_num_compare }, { "sqlite4_num_from_text", (Tcl_CmdProc*)test_num_from_text }, }; static struct { char *zName; Tcl_ObjCmdProc *xProc; void *clientData; } aObjCmd[] = { { "sqlite4_connection_pointer", get_sqlite_pointer, 0 }, |
︙ | ︙ |