| 1 | // Licensed to the .NET Foundation under one or more agreements. |
| 2 | // The .NET Foundation licenses this file to you under the MIT license. |
| 3 | // See the LICENSE file in the project root for more information. |
| 4 | |
| 5 | /*============================================================================ |
| 6 | ** |
| 7 | ** Source: test1.c |
| 8 | ** |
| 9 | ** Purpose: |
| 10 | ** Concatenate a few strings together, setting different lengths to be |
| 11 | ** used for each one. Check to ensure the pointers which are returned are |
| 12 | ** correct, and that the final string is what was expected. |
| 13 | ** |
| 14 | ** |
| 15 | **==========================================================================*/ |
| 16 | |
| 17 | #include <palsuite.h> |
| 18 | |
| 19 | |
| 20 | int __cdecl main(int argc, char *argv[]) |
| 21 | { |
| 22 | char dest[80]; |
| 23 | char *test = "foo barbaz" ; |
| 24 | char *str1 = "foo " ; |
| 25 | char *str2 = "bar " ; |
| 26 | char *str3 = "baz" ; |
| 27 | char *ptr; |
| 28 | int i; |
| 29 | |
| 30 | |
| 31 | if (PAL_Initialize(argc, argv)) |
| 32 | { |
| 33 | return FAIL; |
| 34 | } |
| 35 | |
| 36 | |
| 37 | dest[0] = 0; |
| 38 | for (i=1; i<80; i++) |
| 39 | { |
| 40 | dest[i] = 'x'; |
| 41 | } |
| 42 | |
| 43 | ptr = strncat(dest, str1, strlen(str1)); |
| 44 | if (ptr != dest) |
| 45 | { |
| 46 | Fail("ERROR: Expected strncat to return ptr to %p, got %p" , dest, ptr); |
| 47 | } |
| 48 | |
| 49 | ptr = strncat(dest, str2, 3); |
| 50 | if (ptr != dest) |
| 51 | { |
| 52 | Fail("ERROR: Expected strncat to return ptr to %p, got %p" , dest, ptr); |
| 53 | } |
| 54 | if (dest[7] != 0) |
| 55 | { |
| 56 | Fail("ERROR: strncat did not place a terminating NULL!" ); |
| 57 | } |
| 58 | |
| 59 | ptr = strncat(dest, str3, 20); |
| 60 | if (ptr != dest) |
| 61 | { |
| 62 | Fail("ERROR: Expected strncat to return ptr to %p, got %p" , dest, ptr); |
| 63 | } |
| 64 | if (strcmp(dest, test) != 0) |
| 65 | { |
| 66 | Fail("ERROR: Expected strncat to give \"%s\", got \"%s\"\n" , |
| 67 | test, dest); |
| 68 | } |
| 69 | if (dest[strlen(test)+1] != 'x') |
| 70 | { |
| 71 | Fail("strncat went out of bounds!\n" ); |
| 72 | } |
| 73 | |
| 74 | PAL_Terminate(); |
| 75 | |
| 76 | return PASS; |
| 77 | } |
| 78 | |