Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rtlib: ./inc/fbc-int/string.bi - for string descriptor and low level …
…string functions
- Loading branch information
Showing
3 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#ifndef __FBC_INT_STRING_BI__ | ||
#define __FBC_INT_STRING_BI__ | ||
|
||
# if __FB_LANG__ = "qb" | ||
# error not supported in qb dialect | ||
# endif | ||
|
||
'' DISCLAIMER!!! | ||
'' | ||
'' 1) this header documents runtime library internals and is | ||
'' subject to change without notice | ||
'' | ||
'' declarations must follow ./src/rtlib/fb_string.h | ||
|
||
'' fbc won't allow redefinition of these functions in to a namespace due to the | ||
'' internal name lookups and caching in the rtlLookupTB() table - so instead we | ||
'' can keep the global ones and also define our own in a namespace. The global | ||
'' ones will override the ones in our namespace unless we explicitly specify | ||
'' the namespace | ||
'' | ||
'' #undef fb_StrDelete | ||
'' | ||
|
||
namespace FBC | ||
|
||
extern "rtlib" | ||
|
||
type FB_CHAR as ZSTRING | ||
type FB_WCHAR as WSTRING | ||
|
||
'' var-len string descriptor | ||
type FBSTRING | ||
data as FB_CHAR ptr '' pointer to the start of characters | ||
len as integer '' length | ||
size as integer '' size of allocated memory | ||
end type | ||
|
||
'' var-len wstring descriptor (future) | ||
type FBWSTRING | ||
data as FB_WCHAR ptr '' pointer to the start of characters | ||
len as integer '' length | ||
size as integer '' size of allocated memory | ||
end type | ||
|
||
'' VAR-LEN STRING API (STRING) | ||
'' declare sub fb_StrDelete( byref s as const string ) | ||
|
||
declare sub fb_StrDelete alias "fb_StrDelete" ( byval s as const FBSTRING ptr ) | ||
|
||
end extern | ||
|
||
end namespace | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include "fbcunit.bi" | ||
#include "fbc-int/string.bi" | ||
|
||
'' tests for string descriptor internals and low level string functions | ||
|
||
#ifndef NULL | ||
#define NULL cast( const any ptr, 0 ) | ||
#endif | ||
|
||
SUITE( fbc_tests.fbc_int.string_ ) | ||
|
||
|
||
TEST( struct ) | ||
dim sd as fbc.FBSTRING | ||
CU_ASSERT( sizeof(sd.data) = sizeof(any ptr) ) | ||
CU_ASSERT( sizeof(sd.len) = sizeof(integer) ) | ||
CU_ASSERT( sizeof(sd.size) = sizeof(integer) ) | ||
CU_ASSERT( sizeof(fbc.FBSTRING) = sizeof(any ptr) + 2*sizeof(integer) ) | ||
END_TEST | ||
|
||
#macro check_string( s, hasdata, expected_len ) | ||
if( s ) then | ||
if( hasdata ) then | ||
CU_ASSERT( s->data <> 0 ) | ||
CU_ASSERT( s->size > 0 ) | ||
CU_ASSERT( s->len = expected_len ) | ||
else | ||
CU_ASSERT( s->data = 0 ) | ||
CU_ASSERT( s->size = 0 ) | ||
CU_ASSERT( s->len = 0 ) | ||
end if | ||
CU_ASSERT( s->size >= s->len ) | ||
else | ||
CU_FAIL() | ||
end if | ||
#endmacro | ||
|
||
TEST( init ) | ||
dim s as string | ||
var s1 = @s | ||
var s2 = cast( fbc.FBSTRING ptr, @s ) | ||
|
||
CU_ASSERT( s1 = s2 ) | ||
|
||
CU_ASSERT( s2->data = NULL ) | ||
CU_ASSERT( s2->len = 0 ) | ||
CU_ASSERT( s2->size = 0 ) | ||
END_TEST | ||
|
||
TEST( dim_ ) | ||
dim s as string | ||
check_string( cast(fbc.FBSTRING ptr, @s), FALSE, 0 ) | ||
|
||
s = "" | ||
check_string( cast(fbc.FBSTRING ptr, @s), FALSE, 0 ) | ||
|
||
s = "hello" | ||
check_string( cast(fbc.FBSTRING ptr, @s), TRUE, 5 ) | ||
|
||
s = "" | ||
check_string( cast(fbc.FBSTRING ptr, @s), FALSE, 0 ) | ||
|
||
s = "hello" | ||
check_string( cast(fbc.FBSTRING ptr, @s), TRUE, 5 ) | ||
|
||
fbc.fb_strDelete( cast(fbc.FBSTRING ptr, @s) ) | ||
check_string( cast(fbc.FBSTRING ptr, @s), FALSE, 0 ) | ||
|
||
END_TEST | ||
|
||
END_SUITE |