Overview
Comment: | Nicer output for OFString tests. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
70087a1b3b04b2369847915319e71f08 |
User & Date: | js on 2008-12-21 16:06:07 |
Other Links: | manifest | tags |
Context
2008-12-21
| ||
17:50 | A few optimizations for OFString. check-in: fb809020b5 user: js tags: trunk | |
16:06 | Nicer output for OFString tests. check-in: 70087a1b3b user: js tags: trunk | |
15:54 | Nicer exception catching in tests. check-in: 1c77f45484 user: js tags: trunk | |
Changes
Modified tests/OFString/OFString.m from [09c95b9e26] to [cab4bb0f80].
︙ | ︙ | |||
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #import <stdio.h> #import <string.h> #import "OFString.h" #import "OFExceptions.h" int main() { OFString *s1 = [OFString newFromCString: "test"]; OFString *s2 = [OFString newFromCString: ""]; OFString *s3; OFString *s4 = [OFString new]; s3 = [s1 clone]; | > > > > > > > > > > > > > > > > > > > > > > > > > > > | < < < < | < | < < < < < < | < < < < < < | < < < < < < | < < < < < < | < < < < < < | < < < < < < | < < < | < < < < | < < < | < | < | < < < < | > | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 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 | #import <stdio.h> #import <string.h> #import "OFString.h" #import "OFExceptions.h" #define NUM_TESTS 10 #define SUCCESS \ printf("\r\033[1;%dmTests successful: %zd/%d\033[0m", \ (i == NUM_TESTS - 1 ? 32 : 33), i + 1, NUM_TESTS); \ fflush(stdout); #define FAIL \ printf("\r\033[K\033[1;31mTest %zd/%d failed!\033[m\n", \ i + 1, NUM_TESTS); \ return 1; #define CHECK(cond) \ if (cond) { \ SUCCESS \ } else { \ FAIL \ } \ i++; #define CHECK_EXCEPT(code, exception) \ @try { \ code; \ FAIL \ } @catch (exception *e) { \ SUCCESS \ } \ i++; int main() { size_t i = 0; OFString *s1 = [OFString newFromCString: "test"]; OFString *s2 = [OFString newFromCString: ""]; OFString *s3; OFString *s4 = [OFString new]; s3 = [s1 clone]; CHECK(![s1 compareTo: s3]) [s2 appendCString: "123"]; [s4 setTo: s2]; CHECK(![s2 compareTo: s4]) CHECK(!strcmp([[s1 append: s2] cString], "test123")) CHECK(strlen([s1 cString]) == [s1 length] && [s1 length] == 7) CHECK(!strcmp([[s1 reverse] cString], "321tset")) CHECK(!strcmp([[s1 upper] cString], "321TSET")) CHECK(!strcmp([[s1 lower] cString], "321tset")) /* Also clears all the memory of the returned C strings */ [s1 free]; [s2 free]; [s3 free]; [s4 free]; /* UTF-8 tests */ CHECK_EXCEPT(s1 = [OFString newFromCString: "\xE0\x80"], OFInvalidEncodingException) CHECK_EXCEPT(s1 = [OFString newFromCString: "\xF0\x80\x80\xC0"], OFInvalidEncodingException) s1 = [OFString newFromCString: "äöü€𝄞"]; CHECK(!strcmp([[s1 reverse] cString], "𝄞€üöä")) puts(""); return 0; } |