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

Overview
Comment:Test sqlite4_num_from_text with UTF16BE and UTF16LE
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 9c4e33cc5b36ff41c24a79743f8eaac6d38578cc
User & Date: peterreid 2013-10-25 01:27:26.466
Context
2013-10-25
01:33
Fix parsing UTF16 nums with multi-digit exponents check-in: 667cfd8694 user: peterreid tags: trunk
01:27
Test sqlite4_num_from_text with UTF16BE and UTF16LE check-in: 9c4e33cc5b user: peterreid tags: trunk
00:33
Add tests for prefix-only and ignore-whitespace flags of sqlite4_num_from_text check-in: 19f7a96631 user: peterreid tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to test/num.test.
216
217
218
219
220
221
222






















223
224
225
226
227
228
229
  8     {   14 z}  -1 w    true
  9     {   14 z}  -1 wp   false
} {
  do_test num-9.2.$tn { 
    sqlite4_num_isnan [sqlite4_num_from_text $in $len $flags]
  } $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







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







216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
  8     {   14 z}  -1 w    true
  9     {   14 z}  -1 wp   false
} {
  do_test num-9.2.$tn { 
    sqlite4_num_isnan [sqlite4_num_from_text $in $len $flags]
  } $out
}

#-------------------------------------------------------------------------
# Test from UTF16BE text
#
foreach {tn in len out} {
  0     274   -1   274
} {
  do_test num-9.3.$tn { 
    sqlite4_num_to_text [sqlite4_num_from_text $in $len b]
  } $out
} 

#-------------------------------------------------------------------------
# Test from UTF16LE text
#
foreach {tn in len out} {
  0     4639   -1   4639
} {
  do_test num-9.3.$tn { 
    sqlite4_num_to_text [sqlite4_num_from_text $in $len l]
  } $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
Changes to test/test_num.c.
87
88
89
90
91
92
93

94




95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111


112
113



















114
115



116
117
118
119
120
121
122
  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;

  int flags;




  if( argc<2 || argc>4 ){
    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
      " STRING\" or \"", argv[0], " STRING INTEGER\" or \"",
      argv[0], " STRING INTEGER STRING\"", 0);
    return TCL_ERROR;
  }

  if( argc>=3 ){
    if ( Tcl_GetInt(interp, argv[2], &len) ) return TCL_ERROR; 
  }else{
    len = -1;
  }

  flags = 0;
  if( argc>=4 ){
    if( strchr(argv[3], 'w') ) flags |= SQLITE4_IGNORE_WHITESPACE;
    if( strchr(argv[3], 'p') ) flags |= SQLITE4_PREFIX_ONLY; 


  }




















  A = sqlite4_num_from_text(argv[1], len, flags, 0);
  append_num_result(interp, A);



  return TCL_OK;
}

static int test_num_text_is_real(
  void *NotUsed,
  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
  int argc,              /* Number of arguments */







>

>
>
>
>

















>
>

|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|

>
>
>







87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
  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;
  int input_len;
  int flags;
  int encoding = 0;
  int i;
  char *utf16_text = 0;
  char *text;
  if( argc<2 || argc>4 ){
    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
      " STRING\" or \"", argv[0], " STRING INTEGER\" or \"",
      argv[0], " STRING INTEGER STRING\"", 0);
    return TCL_ERROR;
  }

  if( argc>=3 ){
    if ( Tcl_GetInt(interp, argv[2], &len) ) return TCL_ERROR; 
  }else{
    len = -1;
  }

  flags = 0;
  if( argc>=4 ){
    if( strchr(argv[3], 'w') ) flags |= SQLITE4_IGNORE_WHITESPACE;
    if( strchr(argv[3], 'p') ) flags |= SQLITE4_PREFIX_ONLY; 
    if( strchr(argv[3], 'b') ) encoding = SQLITE4_UTF16BE; 
    if( strchr(argv[3], 'l') ) encoding = SQLITE4_UTF16LE; 
  }
  
 if( encoding==SQLITE4_UTF16BE || encoding==SQLITE4_UTF16LE ){
    flags |= encoding;
    input_len = strlen(argv[1]); 
    utf16_text = malloc(2*(input_len+1));
    if( !utf16_text ){
      Tcl_AppendResult(interp, "utf16 string allocation failed");
      return TCL_ERROR;
    }
    for( i=0; i<2*(input_len+1); i++ ){
      utf16_text[i] = 0;
    }
    for( i=0; i<input_len; i++ ){
      utf16_text[ i*2+ (encoding==SQLITE4_UTF16BE) ] = argv[1][i];
    }
    text = utf16_text;
  }else{
    text = argv[1];
  }

  A = sqlite4_num_from_text(text, len, flags, 0);
  append_num_result(interp, A);
  if( utf16_text ){
    free(utf16_text);
  }
  return TCL_OK;
}

static int test_num_text_is_real(
  void *NotUsed,
  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
  int argc,              /* Number of arguments */