|
| 1 | +#include "fbcunit.bi" |
| 2 | +#include once "chk-wstring.bi" |
| 3 | + |
| 4 | +#define BUFFERSIZE 50 |
| 5 | + |
| 6 | +'' fixed length strings are not cleared |
| 7 | +'' and the garbage in the buffer will affect the tests |
| 8 | +#macro INIT_FIXED_STRING( s, dtype, size, value ) |
| 9 | + dim s as dtype * size |
| 10 | + clear @s, 0, sizeof(s) |
| 11 | + s = value |
| 12 | +#endmacro |
| 13 | + |
| 14 | +SUITE( fbc_tests.wstring_.midstmt ) |
| 15 | + |
| 16 | + #macro check_mid_start( dst, start, src, length1, length2 ) |
| 17 | + scope |
| 18 | + INIT_FIXED_STRING( w1, wstring, BUFFERSIZE, left( dst, (length1) ) ) |
| 19 | + INIT_FIXED_STRING( w2, wstring, BUFFERSIZE, left( src, (length2) ) ) |
| 20 | + INIT_FIXED_STRING( e1, wstring, BUFFERSIZE, w1 ) |
| 21 | + dim n1 as integer = 50 '' len(w1) |
| 22 | + dim n2 as integer = len(w2) |
| 23 | + dim idx1 as integer = start |
| 24 | + dim idx2 as integer = 1 |
| 25 | + |
| 26 | + '' compute the expected string |
| 27 | + if( (n1 > 0) and (start >= 1) and (start <= n1) ) then |
| 28 | + while( idx1 >= 1 and idx1 <= n1 and idx2 >= 1 and idx2 <= n2 ) |
| 29 | + e1[idx1-1] = w2[idx2-1] |
| 30 | + idx1 += 1 |
| 31 | + idx2 += 1 |
| 32 | + wend |
| 33 | + e1[n1] = 0 |
| 34 | + end if |
| 35 | + |
| 36 | + mid( w1, start ) = w2 |
| 37 | + |
| 38 | + CU_ASSERT_WSTRING_EQUAL( w1, e1 ) |
| 39 | + end scope |
| 40 | + #endmacro |
| 41 | + |
| 42 | + #macro check_mid_start_n( dst, start, length, src, length1, length2 ) |
| 43 | + scope |
| 44 | + INIT_FIXED_STRING( w1, wstring, BUFFERSIZE, left( dst, (length1) ) ) |
| 45 | + INIT_FIXED_STRING( w2, wstring, BUFFERSIZE, left( src, (length2) ) ) |
| 46 | + INIT_FIXED_STRING( e1, wstring, BUFFERSIZE, w1 ) |
| 47 | + dim n1 as integer = BUFFERSIZE '' len(w1) |
| 48 | + dim n2 as integer = len(w2) |
| 49 | + dim idx1 as integer = start |
| 50 | + dim idx2 as integer = 1 |
| 51 | + dim n as integer = 0 |
| 52 | + |
| 53 | + '' compute the expected string |
| 54 | + if( (n1 > 0) and (start >= 1) and (start <= n1) ) then |
| 55 | + while( idx1 >= 1 and idx1 <= n1 and idx2 >= 1 and idx2 <= n2 and (n < length or length < 1) ) |
| 56 | + e1[idx1-1] = w2[idx2-1] |
| 57 | + idx1 += 1 |
| 58 | + idx2 += 1 |
| 59 | + n += 1 |
| 60 | + wend |
| 61 | + e1[n1] = 0 |
| 62 | + end if |
| 63 | + |
| 64 | + mid( w1, start, length ) = w2 |
| 65 | + |
| 66 | + CU_ASSERT_WSTRING_EQUAL( w1, e1 ) |
| 67 | + end scope |
| 68 | + #endmacro |
| 69 | + |
| 70 | + TEST( ascii ) |
| 71 | + const MAX = 8 |
| 72 | + |
| 73 | + #define def_dst "12345678" |
| 74 | + #define def_src "ABCDEFGH" |
| 75 | + |
| 76 | + dim dst as wstring * (MAX*2+1) |
| 77 | + dim src as wstring * (MAX*2+1) |
| 78 | + |
| 79 | + for i1 as integer = 0 to MAX |
| 80 | + for i2 as integer = 0 to MAX |
| 81 | + for istart as integer = -2 to MAX+2 |
| 82 | + |
| 83 | + dst = def_src |
| 84 | + src = def_dst |
| 85 | + |
| 86 | + check_mid_start( dst, istart, src, i1, i2 ) |
| 87 | + |
| 88 | + for length as integer = -2 to MAX+2 |
| 89 | + |
| 90 | + dst = def_src |
| 91 | + src = def_dst |
| 92 | + |
| 93 | + check_mid_start_n( dst, istart, length, src, i1, i2 ) |
| 94 | + next |
| 95 | + |
| 96 | + next |
| 97 | + next i2 |
| 98 | + next i1 |
| 99 | + |
| 100 | + END_TEST |
| 101 | + |
| 102 | + TEST( ucs2 ) |
| 103 | + const MAX = 5 |
| 104 | + |
| 105 | + #define def_dst !"\u3041\u3043\u3045\u3047\u3049" |
| 106 | + #define def_src !"\u3042\u3044\u3046\u3048\u3050" |
| 107 | + |
| 108 | + dim dst as wstring * (MAX*2+1) |
| 109 | + dim src as wstring * (MAX*2+1) |
| 110 | + |
| 111 | + for i1 as integer = 0 to MAX |
| 112 | + for i2 as integer = 0 to MAX |
| 113 | + for istart as integer = -1 to MAX+2 |
| 114 | + |
| 115 | + dst = def_src |
| 116 | + src = def_dst |
| 117 | + |
| 118 | + check_mid_start( dst, istart, src, i1, i2 ) |
| 119 | + |
| 120 | + for length as integer = -2 to MAX+2 |
| 121 | + |
| 122 | + dst = def_src |
| 123 | + src = def_dst |
| 124 | + |
| 125 | + check_mid_start_n( dst, istart, length, src, i1, i2 ) |
| 126 | + next |
| 127 | + |
| 128 | + next |
| 129 | + next i2 |
| 130 | + next i1 |
| 131 | + |
| 132 | + END_TEST |
| 133 | + |
| 134 | +END_SUITE |
0 commit comments