Differences From Artifact [4e0f09b991]:
- File tests/OFStringTests.m — part of check-in [561522ae8c] at 2017-04-06 20:19:26 on branch trunk — Prepare OFStringTests for different string classes (user: js, size: 30804) [annotate] [blame] [check-ins using]
To Artifact [c38d6eca4f]:
- File
tests/OFStringTests.m
— part of check-in
[7926b47265]
at
2017-05-01 13:07:16
on branch trunk
— Add tests for generic OFString / OFMutableString
These are usually not used, as OFString_UTF8 and OFMutableString_UTF8
are used instead. However, they are used if someone creates their own
subclass of OFString / OFMutableString. As they are rarely used in
production, it is important to run all tests on them. (user: js, size: 33312) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
49 50 51 52 53 54 55 56 57 58 59 60 61 62 | static uint16_t utf16str[] = { 0xFEFF, 'f', 0xF6, 0xF6, 'b', 0xE4, 'r', 0xD83C, 0xDC3A, 0 }; static uint16_t sutf16str[] = { 0xFFFE, 0x6600, 0xF600, 0xF600, 0x6200, 0xE400, 0x7200, 0x3CD8, 0x3ADC, 0 }; @interface EntityHandler: OFObject <OFStringXMLUnescapingDelegate> @end @implementation EntityHandler - (OFString*)string: (OFString*)string containsUnknownEntityNamed: (OFString*)entity | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | static uint16_t utf16str[] = { 0xFEFF, 'f', 0xF6, 0xF6, 'b', 0xE4, 'r', 0xD83C, 0xDC3A, 0 }; static uint16_t sutf16str[] = { 0xFFFE, 0x6600, 0xF600, 0xF600, 0x6200, 0xE400, 0x7200, 0x3CD8, 0x3ADC, 0 }; @interface SimpleString: OFString { OFMutableString *_string; } @end @interface SimpleMutableString: OFMutableString { OFMutableString *_string; } @end @implementation SimpleString - init { self = [super init]; @try { _string = [[OFMutableString alloc] init]; } @catch (id e) { [self release]; @throw e; } return self; } - initWithString: (OFString*)string { self = [super init]; @try { _string = [string mutableCopy]; } @catch (id e) { [self release]; @throw e; } return self; } - initWithCString: (const char*)cString encoding: (of_string_encoding_t)encoding length: (size_t)length { self = [super init]; @try { _string = [[OFMutableString alloc] initWithCString: cString encoding: encoding length: length]; } @catch (id e) { [self release]; @throw e; } return self; } - initWithUTF16String: (const of_char16_t*)UTF16String length: (size_t)length byteOrder: (of_byte_order_t)byteOrder { self = [super init]; @try { _string = [[OFMutableString alloc] initWithUTF16String: UTF16String length: length byteOrder: byteOrder]; } @catch (id e) { [self release]; @throw e; } return self; } - initWithUTF32String: (const of_char32_t*)UTF32String length: (size_t)length byteOrder: (of_byte_order_t)byteOrder { self = [super init]; @try { _string = [[OFMutableString alloc] initWithUTF32String: UTF32String length: length byteOrder: byteOrder]; } @catch (id e) { [self release]; @throw e; } return self; } - initWithFormat: (OFConstantString*)format arguments: (va_list)arguments { self = [super init]; @try { _string = [[OFMutableString alloc] initWithFormat: format arguments: arguments]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_string release]; [super dealloc]; } - (of_unichar_t)characterAtIndex: (size_t)index { return [_string characterAtIndex: index]; } - (size_t)length { return [_string length]; } @end @implementation SimpleMutableString + (void)initialize { if (self == [SimpleMutableString class]) [self inheritMethodsFromClass: [SimpleString class]]; } - (void)replaceCharactersInRange: (of_range_t)range withString: (OFString*)string { [_string replaceCharactersInRange: range withString: string]; } @end @interface EntityHandler: OFObject <OFStringXMLUnescapingDelegate> @end @implementation EntityHandler - (OFString*)string: (OFString*)string containsUnknownEntityNamed: (OFString*)entity |
︙ | ︙ | |||
77 78 79 80 81 82 83 84 85 86 | OFString *is; OFArray *a; int i; const of_unichar_t *ua; const uint16_t *u16a; EntityHandler *h; #ifdef OF_HAVE_BLOCKS __block bool ok; #endif | > < < | 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | OFString *is; OFArray *a; int i; const of_unichar_t *ua; const uint16_t *u16a; EntityHandler *h; #ifdef OF_HAVE_BLOCKS __block int j; __block bool ok; #endif #define C(s) [stringClass stringWithString: s] s[0] = [mutableStringClass stringWithString: @"täs€"]; s[1] = [mutableStringClass string]; s[2] = [[s[0] copy] autorelease]; TEST(@"-[isEqual:]", [s[0] isEqual: s[2]] && |
︙ | ︙ | |||
791 792 793 794 795 796 797 798 799 800 | ^ OFString* (OFString *str, OFString *entity) { if ([entity isEqual: @"foo"]) return @"bar"; return nil; }] isEqual: @"xbary"]) ok = true; [C(@"foo\nbar\nbaz") enumerateLinesUsingBlock: ^ (OFString *line, bool *stop) { | > < < | | > > > > > | | | 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 | ^ OFString* (OFString *str, OFString *entity) { if ([entity isEqual: @"foo"]) return @"bar"; return nil; }] isEqual: @"xbary"]) j = 0; ok = true; [C(@"foo\nbar\nbaz") enumerateLinesUsingBlock: ^ (OFString *line, bool *stop) { switch (j) { case 0: if (![line isEqual: @"foo"]) ok = false; break; case 1: if (![line isEqual: @"bar"]) ok = false; break; case 2: if (![line isEqual: @"baz"]) ok = false; break; default: ok = false; } j++; }]; TEST(@"-[enumerateLinesUsingBlock:]", ok) #endif #undef C [pool drain]; } - (void)stringTests { module = @"OFString"; [self stringTestsWithClass: [SimpleString class] mutableClass: [SimpleMutableString class]]; module = @"OFString_UTF8"; [self stringTestsWithClass: [OFString_UTF8 class] mutableClass: [OFMutableString_UTF8 class]]; } @end |