SQLite4
Check-in [11fd3e7ec4]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add tests for sqlite4_num_to_int64.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 11fd3e7ec4c561c9d0065082615aa1e79dacbfaf
User & Date: peterreid 2013-06-01 23:35:45
Context
2013-06-01
23:42
Handle overflow and rounding cases in sqlite4_num_to_int64. check-in: de7fb192cb user: peterreid tags: trunk
23:35
Add tests for sqlite4_num_to_int64. check-in: 11fd3e7ec4 user: peterreid tags: trunk
22:58
Fix build error from redundant typedefs in test_mem.c introduced by 75b8ccc0a8. check-in: 3ae7214267 user: peterreid tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to test/num.test.

155
156
157
158
159
160
161












162
163
164
165
166
  5.1   1   {sign:0 approx:0 e:0 m:1}
  5.2   1.0 {sign:0 approx:0 e:-1 m:10}
  5.3   1.  {sign:0 approx:0 e:0 m:1}
  5.4   1e0 {sign:0 approx:0 e:0 m:1}
} {
  do_test num-9.1.$tn { sqlite4_num_from_text $in } [list {*}$out]
}













#-------------------------------------------------------------------------
finish_test









>
>
>
>
>
>
>
>
>
>
>
>





155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
  5.1   1   {sign:0 approx:0 e:0 m:1}
  5.2   1.0 {sign:0 approx:0 e:-1 m:10}
  5.3   1.  {sign:0 approx:0 e:0 m:1}
  5.4   1e0 {sign:0 approx:0 e:0 m:1}
} {
  do_test num-9.1.$tn { sqlite4_num_from_text $in } [list {*}$out]
}

foreach {tn in out} {
  0     50                                            50
  1     -94                                           -94
  2     {sign:0 approx:0 e:4 m:2}                     20000
  3     9223372036854775807                           9223372036854775807
  4     -9223372036854775808                          -9223372036854775808
  5     {sign:0 approx:0 e:-1 m:51}                   ~5
} {
  do_test num-10.1.$tn { sqlite4_num_to_int64 $in } [list {*}$out]
}


#-------------------------------------------------------------------------
finish_test


Changes to test/test_num.c.

235
236
237
238
239
240
241
























242
243
244
245
246
247
248
...
253
254
255
256
257
258
259

260
261
262
263
264
265
266

  ret = sqlite4_num_from_double(val);

  Tcl_ResetResult(interp);
  append_num_result(interp, ret);
  return TCL_OK;
}

























/*
** Register commands with the TCL interpreter.
*/
int Sqlitetest_num_init(Tcl_Interp *interp){
  static struct {
     char *zName;
................................................................................
     { "sqlite4_num_to_text",           (Tcl_CmdProc*)test_num_to_text      },
     { "sqlite4_num_add",               (Tcl_CmdProc*)test_num_add          },
     { "sqlite4_num_sub",               (Tcl_CmdProc*)test_num_sub          },
     { "sqlite4_num_mul",               (Tcl_CmdProc*)test_num_mul          },
     { "sqlite4_num_div",               (Tcl_CmdProc*)test_num_div          },
     { "sqlite4_num_isinf",             (Tcl_CmdProc*)test_num_isinf        },
     { "sqlite4_num_isnan",             (Tcl_CmdProc*)test_num_isnan        },

  };

  static struct {
     char *zName;
     Tcl_ObjCmdProc *xProc;
     void *clientData;
  } aObjCmd[] = {







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>







235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
...
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291

  ret = sqlite4_num_from_double(val);

  Tcl_ResetResult(interp);
  append_num_result(interp, ret);
  return TCL_OK;
}


static int test_num_to_int64(
  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 lossy;
  sqlite4_int64 iVal;
  char buf[50];
  if( argc!=2 ){
    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
      " NUM\"", 0);
    return TCL_ERROR;
  }
  A = test_parse_num(argv[1]);
  iVal = sqlite4_num_to_int64(A, &lossy);
  sprintf( buf, "%s%lld", lossy?"~":"", iVal );
  Tcl_AppendResult(interp, buf, 0);
  return TCL_OK;
}


/*
** Register commands with the TCL interpreter.
*/
int Sqlitetest_num_init(Tcl_Interp *interp){
  static struct {
     char *zName;
................................................................................
     { "sqlite4_num_to_text",           (Tcl_CmdProc*)test_num_to_text      },
     { "sqlite4_num_add",               (Tcl_CmdProc*)test_num_add          },
     { "sqlite4_num_sub",               (Tcl_CmdProc*)test_num_sub          },
     { "sqlite4_num_mul",               (Tcl_CmdProc*)test_num_mul          },
     { "sqlite4_num_div",               (Tcl_CmdProc*)test_num_div          },
     { "sqlite4_num_isinf",             (Tcl_CmdProc*)test_num_isinf        },
     { "sqlite4_num_isnan",             (Tcl_CmdProc*)test_num_isnan        },
     { "sqlite4_num_to_int64",          (Tcl_CmdProc*)test_num_to_int64     },
  };

  static struct {
     char *zName;
     Tcl_ObjCmdProc *xProc;
     void *clientData;
  } aObjCmd[] = {