|
| 1 | +#include "fbcunit.bi" |
| 2 | +#include once "uwstring-fixed.bi" |
| 3 | +#include once "chk-wstring.bi" |
| 4 | + |
| 5 | +type UWSTRING_HAS_ID extends UWSTRING_FIXED_MUTABLE |
| 6 | + public: |
| 7 | + id as integer |
| 8 | + declare constructor() |
| 9 | + declare constructor( byval rhs as const wstring const ptr ) |
| 10 | + declare constructor( byval rhs as const zstring const ptr ) |
| 11 | + |
| 12 | + declare operator cast() byref as wstring |
| 13 | +end type |
| 14 | + |
| 15 | +constructor UWSTRING_HAS_ID() |
| 16 | +end constructor |
| 17 | + |
| 18 | +constructor UWSTRING_HAS_ID( byval s as const wstring const ptr ) |
| 19 | + base( s ) |
| 20 | +end constructor |
| 21 | + |
| 22 | +constructor UWSTRING_HAS_ID( byval s as const zstring const ptr ) |
| 23 | + base( s ) |
| 24 | +end constructor |
| 25 | + |
| 26 | +operator UWSTRING_HAS_ID.Cast() byref as wstring |
| 27 | + operator = *cast(wstring ptr, @_data) |
| 28 | +end operator |
| 29 | + |
| 30 | +#define ustring UWSTRING_HAS_ID |
| 31 | + |
| 32 | +SUITE( fbc_tests.udt_wstring_.swap_ ) |
| 33 | + |
| 34 | + #macro check( literal1, literal2 ) |
| 35 | + scope |
| 36 | + dim t1 as wstring * 50 = literal1 |
| 37 | + dim t2 as wstring * 50 = literal2 |
| 38 | + |
| 39 | + dim u1 as ustring = literal1 |
| 40 | + u1.id = 1 |
| 41 | + dim u2 as ustring = literal2 |
| 42 | + u2.id = 2 |
| 43 | + |
| 44 | + '' initial condition check |
| 45 | + scope |
| 46 | + dim r1 as wstring * 50 = u1 |
| 47 | + dim r2 as wstring * 50 = u2 |
| 48 | + CU_ASSERT( u1.id = 1 ) |
| 49 | + CU_ASSERT( u2.id = 2 ) |
| 50 | + CU_ASSERT_WSTRING_EQUAL( r1, t1 ) |
| 51 | + CU_ASSERT_WSTRING_EQUAL( r2, t2 ) |
| 52 | + end scope |
| 53 | + |
| 54 | + '' swap string only |
| 55 | + scope |
| 56 | + swap wstr( u1 ), wstr( u2 ) |
| 57 | + |
| 58 | + dim r1 as wstring * 50 = u1 |
| 59 | + dim r2 as wstring * 50 = u2 |
| 60 | + |
| 61 | + CU_ASSERT( u1.id = 1 ) |
| 62 | + CU_ASSERT( u2.id = 2 ) |
| 63 | + CU_ASSERT_WSTRING_EQUAL( r1, t2 ) |
| 64 | + CU_ASSERT_WSTRING_EQUAL( r2, t1 ) |
| 65 | + end scope |
| 66 | + |
| 67 | + '' swap string only |
| 68 | + scope |
| 69 | + swap wstr( u1 ), u2 |
| 70 | + |
| 71 | + dim r1 as wstring * 50 = u1 |
| 72 | + dim r2 as wstring * 50 = u2 |
| 73 | + |
| 74 | + CU_ASSERT( u1.id = 1 ) |
| 75 | + CU_ASSERT( u2.id = 2 ) |
| 76 | + CU_ASSERT_WSTRING_EQUAL( r1, t1 ) |
| 77 | + CU_ASSERT_WSTRING_EQUAL( r2, t2 ) |
| 78 | + end scope |
| 79 | + |
| 80 | + '' swap string only |
| 81 | + scope |
| 82 | + swap u1, wstr( u2 ) |
| 83 | + |
| 84 | + dim r1 as wstring * 50 = u1 |
| 85 | + dim r2 as wstring * 50 = u2 |
| 86 | + |
| 87 | + CU_ASSERT( u1.id = 1 ) |
| 88 | + CU_ASSERT( u2.id = 2 ) |
| 89 | + CU_ASSERT_WSTRING_EQUAL( r1, t2 ) |
| 90 | + CU_ASSERT_WSTRING_EQUAL( r2, t1 ) |
| 91 | + end scope |
| 92 | + |
| 93 | + '' swap complete UDT |
| 94 | + scope |
| 95 | + swap u1, u2 |
| 96 | + |
| 97 | + dim r1 as wstring * 50 = u1 |
| 98 | + dim r2 as wstring * 50 = u2 |
| 99 | + |
| 100 | + CU_ASSERT( u1.id = 2 ) |
| 101 | + CU_ASSERT( u2.id = 1 ) |
| 102 | + CU_ASSERT_WSTRING_EQUAL( r1, t1 ) |
| 103 | + CU_ASSERT_WSTRING_EQUAL( r2, t2 ) |
| 104 | + end scope |
| 105 | + end scope |
| 106 | + #endmacro |
| 107 | + |
| 108 | + TEST( default ) |
| 109 | + check( "", "" ) |
| 110 | + |
| 111 | + check( "", "a" ) |
| 112 | + check( "a", "a" ) |
| 113 | + check( "a", "abcdefghi" ) |
| 114 | + |
| 115 | + check( "", !"\u3041\u3043\u3045\u3047\u3049" ) |
| 116 | + check( "abc", !"\u3041\u3043\u3045\u3047\u3049" ) |
| 117 | + check( !"\u3045", !"\u3041\u3043\u3047\u3049" ) |
| 118 | + |
| 119 | + END_TEST |
| 120 | + |
| 121 | +END_SUITE |
0 commit comments