Skip to content

Commit aefa43e

Browse files
committed
udt-wstring: STR/WSTR function will accept UDT as Z|WSTRING to return a Z|WSTRING
1 parent 2e7d606 commit aefa43e

File tree

6 files changed

+497
-0
lines changed

6 files changed

+497
-0
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Version 1.07.0
1919
- LSET/RSET statements will accept UDT as Z|WSTRING
2020
- MID statement will accept UDT as Z|WSTRING
2121
- ASC function will accept UDT as Z|WSTRING
22+
- STR/WSTR function will accept UDT as Z|WSTRING to return a Z|WSTRING
2223

2324
[fixed]
2425
- sf.net #881: C backend: support for varadic function parameters in gcc using __builtin_va_list type and related macros

src/compiler/rtl-string.bas

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2846,6 +2846,10 @@ function rtlToStr _
28462846
end if
28472847
end if
28482848

2849+
astTryOvlStringCONV( expr )
2850+
2851+
dtype = astGetDataType( expr )
2852+
28492853
''
28502854
select case as const astGetDataClass( expr )
28512855
case FB_DATACLASS_INTEGER
@@ -2946,6 +2950,10 @@ function rtlToWstr _
29462950
end if
29472951
end if
29482952

2953+
astTryOvlStringCONV( expr )
2954+
2955+
dtype = astGetDataType( expr )
2956+
29492957
select case as const astGetDataClass( expr )
29502958
case FB_DATACLASS_INTEGER
29512959
'' Convert pointer to uinteger

tests/udt-wstring/str.bas

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#include "fbcunit.bi"
2+
#include once "uwstring-fixed.bi"
3+
#include once "chk-wstring.bi"
4+
5+
#define ustring UWSTRING_FIXED
6+
7+
SUITE( fbc_tests.udt_wstring_.str_ )
8+
9+
#macro check( dtype, value )
10+
11+
scope
12+
dim t as dtype = value
13+
dim w as wstring * 50 = str( t )
14+
dim u as ustring = str( t )
15+
dim r as wstring * 50 = u
16+
CU_ASSERT_WSTRING_EQUAL( w, r )
17+
end scope
18+
19+
#endmacro
20+
21+
TEST( numeric )
22+
23+
check( byte, -128 )
24+
check( byte, -0 )
25+
check( byte, 127 )
26+
27+
check( ubyte, 0 )
28+
check( ubyte, 128 )
29+
check( ubyte, 255 )
30+
31+
check( short, -32768 )
32+
check( short, 0 )
33+
check( short, 32767 )
34+
35+
check( ushort, 0 )
36+
check( ushort, 32768 )
37+
check( ushort, 65535 )
38+
39+
check( long, -2147483648ll )
40+
check( long, 0 )
41+
check( long, 2147483647ull )
42+
43+
check( ulong, 0 )
44+
check( ulong, 2147483648ull )
45+
check( ulong, 4294967295ull )
46+
47+
check( longint, (-9223372036854775807ll-1ll) )
48+
check( longint, 0 )
49+
check( longint, 9223372036854775807ull )
50+
51+
check( ulongint, 0 )
52+
check( ulongint, 9223372036854775808ull )
53+
check( ulongint, 18446744073709551615ull )
54+
55+
check( single, -1.5 )
56+
check( single, -1.0 )
57+
check( single, -1.0 )
58+
check( single, -0.5 )
59+
check( single, 0.0 )
60+
check( single, 0.5 )
61+
check( single, 1.0)
62+
check( single, 1.5 )
63+
check( single, 2.0 )
64+
check( single, 2.5 )
65+
66+
check( double, -1.5 )
67+
check( double, -1.0 )
68+
check( double, -1.0 )
69+
check( double, -0.5 )
70+
check( double, 0.0 )
71+
check( double, 0.5 )
72+
check( double, 1.0)
73+
check( double, 1.5 )
74+
check( double, 2.0 )
75+
check( double, 2.5 )
76+
77+
END_TEST
78+
79+
TEST( default )
80+
81+
dim s1 as wstring * 10 = chr(65)
82+
dim s2 as wstring * 10 = chr(65)
83+
dim s3 as wstring * 10 = str( s1 )
84+
85+
dim u1 as ustring = chr(65)
86+
dim u2 as ustring = chr(65)
87+
dim u3 as ustring = str( s1 )
88+
dim u4 as ustring = str( u1 )
89+
90+
dim s4 as wstring * 10 = str( u1 )
91+
92+
dim r1 as wstring * 10 = u1
93+
dim r2 as wstring * 10 = u2
94+
dim r3 as wstring * 10 = u3
95+
dim r4 as wstring * 10 = u4
96+
97+
#macro check_group( g )
98+
99+
CU_ASSERT_WSTRING_EQUAL( g, s1 )
100+
CU_ASSERT_WSTRING_EQUAL( g, s2 )
101+
CU_ASSERT_WSTRING_EQUAL( g, s3 )
102+
CU_ASSERT_WSTRING_EQUAL( g, s4 )
103+
104+
CU_ASSERT_WSTRING_EQUAL( g, r1 )
105+
CU_ASSERT_WSTRING_EQUAL( g, r2 )
106+
CU_ASSERT_WSTRING_EQUAL( g, r3 )
107+
CU_ASSERT_WSTRING_EQUAL( g, r4 )
108+
109+
#endmacro
110+
111+
check_group( s1 )
112+
check_group( s2 )
113+
check_group( s3 )
114+
check_group( s4 )
115+
check_group( r1 )
116+
check_group( r2 )
117+
check_group( r3 )
118+
check_group( r4 )
119+
120+
END_TEST
121+
122+
END_SUITE

tests/udt-wstring/wstr.bas

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#include "fbcunit.bi"
2+
#include once "uwstring-fixed.bi"
3+
#include once "chk-wstring.bi"
4+
5+
#define ustring UWSTRING_FIXED
6+
7+
SUITE( fbc_tests.udt_wstring_.wstr_ )
8+
9+
#macro check( dtype, value )
10+
11+
scope
12+
dim t as dtype = value
13+
dim w as wstring * 50 = wstr( t )
14+
dim u as ustring = wstr( t )
15+
dim r as wstring * 50 = u
16+
CU_ASSERT_WSTRING_EQUAL( w, r )
17+
end scope
18+
19+
#endmacro
20+
21+
TEST( numeric )
22+
23+
check( byte, -128 )
24+
check( byte, -0 )
25+
check( byte, 127 )
26+
27+
check( ubyte, 0 )
28+
check( ubyte, 128 )
29+
check( ubyte, 255 )
30+
31+
check( short, -32768 )
32+
check( short, 0 )
33+
check( short, 32767 )
34+
35+
check( ushort, 0 )
36+
check( ushort, 32768 )
37+
check( ushort, 65535 )
38+
39+
check( long, -2147483648ll )
40+
check( long, 0 )
41+
check( long, 2147483647ull )
42+
43+
check( ulong, 0 )
44+
check( ulong, 2147483648ull )
45+
check( ulong, 4294967295ull )
46+
47+
check( longint, (-9223372036854775807ll-1ll) )
48+
check( longint, 0 )
49+
check( longint, 9223372036854775807ull )
50+
51+
check( ulongint, 0 )
52+
check( ulongint, 9223372036854775808ull )
53+
check( ulongint, 18446744073709551615ull )
54+
55+
check( single, -1.5 )
56+
check( single, -1.0 )
57+
check( single, -1.0 )
58+
check( single, -0.5 )
59+
check( single, 0.0 )
60+
check( single, 0.5 )
61+
check( single, 1.0)
62+
check( single, 1.5 )
63+
check( single, 2.0 )
64+
check( single, 2.5 )
65+
66+
check( double, -1.5 )
67+
check( double, -1.0 )
68+
check( double, -1.0 )
69+
check( double, -0.5 )
70+
check( double, 0.0 )
71+
check( double, 0.5 )
72+
check( double, 1.0)
73+
check( double, 1.5 )
74+
check( double, 2.0 )
75+
check( double, 2.5 )
76+
77+
END_TEST
78+
79+
TEST( default )
80+
81+
dim s1 as wstring * 10 = wchr(1234)
82+
dim s2 as wstring * 10 = wchr(1234)
83+
dim s3 as wstring * 10 = wstr( s1 )
84+
85+
dim u1 as ustring = wchr(1234)
86+
dim u2 as ustring = wchr(1234)
87+
dim u3 as ustring = wstr( s1 )
88+
dim u4 as ustring = wstr( u1 )
89+
90+
dim s4 as wstring * 10 = wstr( u1 )
91+
92+
dim r1 as wstring * 10 = u1
93+
dim r2 as wstring * 10 = u2
94+
dim r3 as wstring * 10 = u3
95+
dim r4 as wstring * 10 = u4
96+
97+
#macro check_group( g )
98+
99+
CU_ASSERT_WSTRING_EQUAL( g, s1 )
100+
CU_ASSERT_WSTRING_EQUAL( g, s2 )
101+
CU_ASSERT_WSTRING_EQUAL( g, s3 )
102+
CU_ASSERT_WSTRING_EQUAL( g, s4 )
103+
104+
CU_ASSERT_WSTRING_EQUAL( g, r1 )
105+
CU_ASSERT_WSTRING_EQUAL( g, r2 )
106+
CU_ASSERT_WSTRING_EQUAL( g, r3 )
107+
CU_ASSERT_WSTRING_EQUAL( g, r4 )
108+
109+
#endmacro
110+
111+
check_group( s1 )
112+
check_group( s2 )
113+
check_group( s3 )
114+
check_group( s4 )
115+
check_group( r1 )
116+
check_group( r2 )
117+
check_group( r3 )
118+
check_group( r4 )
119+
120+
END_TEST
121+
122+
END_SUITE

tests/udt-zstring/str.bas

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#include "fbcunit.bi"
2+
#include once "uzstring-fixed.bi"
3+
#include once "chk-zstring.bi"
4+
5+
#define ustring UZSTRING_FIXED
6+
7+
SUITE( fbc_tests.udt_zstring_.str_ )
8+
9+
#macro check( dtype, value )
10+
11+
scope
12+
dim t as dtype = value
13+
dim w as zstring * 50 = str( t )
14+
dim u as ustring = str( t )
15+
dim r as zstring * 50 = u
16+
CU_ASSERT_ZSTRING_EQUAL( w, r )
17+
end scope
18+
19+
#endmacro
20+
21+
TEST( numeric )
22+
23+
check( byte, -128 )
24+
check( byte, -0 )
25+
check( byte, 127 )
26+
27+
check( ubyte, 0 )
28+
check( ubyte, 128 )
29+
check( ubyte, 255 )
30+
31+
check( short, -32768 )
32+
check( short, 0 )
33+
check( short, 32767 )
34+
35+
check( ushort, 0 )
36+
check( ushort, 32768 )
37+
check( ushort, 65535 )
38+
39+
check( long, -2147483648ll )
40+
check( long, 0 )
41+
check( long, 2147483647ull )
42+
43+
check( ulong, 0 )
44+
check( ulong, 2147483648ull )
45+
check( ulong, 4294967295ull )
46+
47+
check( longint, (-9223372036854775807ll-1ll) )
48+
check( longint, 0 )
49+
check( longint, 9223372036854775807ull )
50+
51+
check( ulongint, 0 )
52+
check( ulongint, 9223372036854775808ull )
53+
check( ulongint, 18446744073709551615ull )
54+
55+
check( single, -1.5 )
56+
check( single, -1.0 )
57+
check( single, -1.0 )
58+
check( single, -0.5 )
59+
check( single, 0.0 )
60+
check( single, 0.5 )
61+
check( single, 1.0)
62+
check( single, 1.5 )
63+
check( single, 2.0 )
64+
check( single, 2.5 )
65+
66+
check( double, -1.5 )
67+
check( double, -1.0 )
68+
check( double, -1.0 )
69+
check( double, -0.5 )
70+
check( double, 0.0 )
71+
check( double, 0.5 )
72+
check( double, 1.0)
73+
check( double, 1.5 )
74+
check( double, 2.0 )
75+
check( double, 2.5 )
76+
77+
END_TEST
78+
79+
TEST( default )
80+
81+
dim s1 as zstring * 10 = chr(1234)
82+
dim s2 as zstring * 10 = chr(1234)
83+
dim s3 as zstring * 10 = str( s1 )
84+
85+
dim u1 as ustring = chr(1234)
86+
dim u2 as ustring = chr(1234)
87+
dim u3 as ustring = str( s1 )
88+
dim u4 as ustring = wstr( u1 )
89+
90+
dim s4 as zstring * 10 = str( u1 )
91+
92+
dim r1 as zstring * 10 = u1
93+
dim r2 as zstring * 10 = u2
94+
dim r3 as zstring * 10 = u3
95+
dim r4 as zstring * 10 = u4
96+
97+
#macro check_group( g )
98+
99+
CU_ASSERT_ZSTRING_EQUAL( g, s1 )
100+
CU_ASSERT_ZSTRING_EQUAL( g, s2 )
101+
CU_ASSERT_ZSTRING_EQUAL( g, s3 )
102+
CU_ASSERT_ZSTRING_EQUAL( g, s4 )
103+
104+
CU_ASSERT_ZSTRING_EQUAL( g, r1 )
105+
CU_ASSERT_ZSTRING_EQUAL( g, r2 )
106+
CU_ASSERT_ZSTRING_EQUAL( g, r3 )
107+
CU_ASSERT_ZSTRING_EQUAL( g, r4 )
108+
109+
#endmacro
110+
111+
check_group( s1 )
112+
check_group( s2 )
113+
check_group( s3 )
114+
check_group( s4 )
115+
check_group( r1 )
116+
check_group( r2 )
117+
check_group( r3 )
118+
check_group( r4 )
119+
120+
END_TEST
121+
122+
END_SUITE

0 commit comments

Comments
 (0)