| 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 | ** Test to ensure all three possible return values are given under the |
| 11 | ** appropriate circumstance. Also, uses different sizes, to only compare |
| 12 | ** portions of strings, checking to make sure these return the correct value. |
| 13 | ** |
| 14 | ** |
| 15 | **==========================================================================*/ |
| 16 | |
| 17 | #include <palsuite.h> |
| 18 | |
| 19 | typedef struct |
| 20 | { |
| 21 | int result; |
| 22 | char string1[50]; |
| 23 | char string2[50]; |
| 24 | int number; |
| 25 | } testCase; |
| 26 | |
| 27 | testCase testCases[]= |
| 28 | { |
| 29 | {0,"Hello" ,"Hello" ,5}, |
| 30 | {1,"hello" ,"Hello" ,3}, |
| 31 | {-1,"Hello" ,"hello" ,5}, |
| 32 | {0,"heLLo" ,"heLLo" ,5}, |
| 33 | {1,"hello" ,"heLlo" ,5}, |
| 34 | {-1,"heLlo" ,"hello" ,5}, |
| 35 | {0,"0Test" ,"0Test" ,5}, |
| 36 | {0,"***???" ,"***???" ,6}, |
| 37 | {0,"Testing the string for string comparison" ,"Testing the string for " |
| 38 | "string comparison" ,40}, |
| 39 | {-1,"Testing the string for string comparison" ,"Testing the string for " |
| 40 | "string comparsioa" ,40}, |
| 41 | {1,"Testing the string for string comparison" ,"Testing the string for " |
| 42 | "comparison" ,34}, |
| 43 | {0,"aaaabbbbb" ,"aabcdefeccg" ,2}, |
| 44 | {0,"abcd" ,"abcd" ,10} |
| 45 | }; |
| 46 | |
| 47 | |
| 48 | int __cdecl main(int argc, char *argv[]) |
| 49 | { |
| 50 | int i=0; |
| 51 | int iresult=0; |
| 52 | |
| 53 | /* |
| 54 | * Initialize the PAL |
| 55 | */ |
| 56 | if (0 != PAL_Initialize(argc, argv)) |
| 57 | { |
| 58 | return FAIL; |
| 59 | } |
| 60 | |
| 61 | |
| 62 | for (i=0; i< sizeof(testCases)/sizeof(testCase); i++) |
| 63 | { |
| 64 | iresult = strncmp(testCases[i].string1,testCases[i].string2, |
| 65 | testCases[i].number); |
| 66 | |
| 67 | if( ((iresult == 0) && (testCases[i].result !=0)) || |
| 68 | ((iresult <0) && (testCases[i].result !=-1)) || |
| 69 | ((iresult >0) && (testCases[i].result !=1)) ) |
| 70 | |
| 71 | { |
| 72 | Fail("ERROR: strncmp returned %d instead of %d\n" , |
| 73 | iresult, testCases[i].result); |
| 74 | } |
| 75 | |
| 76 | } |
| 77 | |
| 78 | PAL_Terminate(); |
| 79 | return PASS; |
| 80 | } |
| 81 | |