| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,33 +26,46 @@ foreign handler sprintf(in pTarget as Pointer, in pFormat as ZStringNative, ...) | |||
| 26 | 26 | foreign handler MCStringCreateWithCString(in pCString as Pointer, out rString as String) returns CBool binds to "<builtin>" | |
| 27 | 27 | ||
| 28 | 28 | public handler TestForeignInvoke_Varargs() | |
| 29 | - variable tString1 as String | ||
| 30 | - variable tString2 as String | ||
| 29 | + variable tOutputBuffer as Pointer | ||
| 31 | 30 | unsafe | |
| 32 | - variable tOutputBuffer as Pointer | ||
| 33 | 31 | put malloc(4096) into tOutputBuffer | |
| 32 | + end unsafe | ||
| 34 | 33 | ||
| 34 | + variable tString1 as String | ||
| 35 | + unsafe | ||
| 35 | 36 | sprintf(tOutputBuffer, "no formats") | |
| 36 | 37 | MCStringCreateWithCString(tOutputBuffer, tString1) | |
| 38 | + end unsafe | ||
| 39 | + test "sprintf works with no variadic arguments" when tString1 is "no formats" | ||
| 37 | 40 | ||
| 41 | + variable tString2 as String | ||
| 42 | + unsafe | ||
| 38 | 43 | variable tInt as SInt16 | |
| 39 | 44 | variable tLong as SInt32 | |
| 40 | 45 | variable tLongLong as SInt64 | |
| 41 | 46 | variable tFloat as CFloat | |
| 42 | 47 | variable tDouble as CDouble | |
| 43 | - variable tNothing as optional Pointer | ||
| 44 | 48 | put 1000 into tInt | |
| 45 | 49 | put 1000000000 into tLong | |
| 46 | 50 | put tLong * 1000000 into tLongLong | |
| 47 | 51 | put 3.5 into tFloat | |
| 48 | 52 | put 7.5 into tDouble | |
| 49 | - sprintf(tOutputBuffer, "%d %ld %lld %.1f %.1lf %p", tInt, tLong, tLongLong, tFloat, tDouble, tNothing) | ||
| 53 | + sprintf(tOutputBuffer, "%d %ld %lld %.1f %.1lf", tInt, tLong, tLongLong, tFloat, tDouble) | ||
| 50 | 54 | MCStringCreateWithCString(tOutputBuffer, tString2) | |
| 55 | + end unsafe | ||
| 56 | + test "sprintf works with variadic arguments" when tString2 is "1000 1000000000 1000000000000000 3.5 7.5" | ||
| 57 | + | ||
| 58 | + variable tString3 as String | ||
| 59 | + unsafe | ||
| 60 | + variable tNothing as optional Pointer | ||
| 61 | + sprintf(tOutputBuffer, "nullptr %p", tNothing) | ||
| 62 | + MCStringCreateWithCString(tOutputBuffer, tString3) | ||
| 63 | + end unsafe | ||
| 64 | + test "sprintf works with nullptr variadic argument" when tString3 begins with "nullptr " | ||
| 51 | 65 | ||
| 66 | + unsafe | ||
| 52 | 67 | free(tOutputBuffer) | |
| 53 | 68 | end unsafe | |
| 54 | - test "sprintf works with no variadic arguments" when tString1 is "no formats" | ||
| 55 | - test "sprintf works with variadic arguments" when tString2 is "1000 1000000000 1000000000000000 3.5 7.5 0x0" | ||
| 56 | 69 | end handler | |
| 57 | 70 | ||
| 58 | 71 | -------- | |
| Back | FazBrowse Home | New Git URL |
0 commit comments