| 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 | ** Tests stroul with different bases and overflows, as well as valid input. |
| 11 | ** Makes sure that the end pointer is correct. |
| 12 | ** |
| 13 | ** |
| 14 | **==========================================================================*/ |
| 15 | |
| 16 | #include <palsuite.h> |
| 17 | |
| 18 | char teststr1[] = "12345" ; |
| 19 | char teststr2[] = "Z" ; |
| 20 | char teststr3[] = "4294967295" ; |
| 21 | char teststr4[] = "4294967296" ; |
| 22 | |
| 23 | typedef struct |
| 24 | { |
| 25 | char *str; |
| 26 | char *end; |
| 27 | int base; |
| 28 | ULONG result; |
| 29 | } TestCase; |
| 30 | |
| 31 | TestCase TestCases[] = |
| 32 | { |
| 33 | { teststr1, teststr1 + 3, 4, 27}, |
| 34 | { teststr1, teststr1 + 5, 10, 12345}, |
| 35 | { teststr2, teststr2, 10, 0}, |
| 36 | { teststr3, teststr3+10, 10, 4294967295ul}, |
| 37 | { teststr4, teststr4+10, 10, 4294967295ul} |
| 38 | }; |
| 39 | |
| 40 | int NumCases = sizeof(TestCases) / sizeof(TestCases[0]); |
| 41 | |
| 42 | |
| 43 | int __cdecl main(int argc, char *argv[]) |
| 44 | { |
| 45 | char *end; |
| 46 | ULONG l; |
| 47 | int i; |
| 48 | |
| 49 | if (PAL_Initialize(argc, argv)) |
| 50 | { |
| 51 | return FAIL; |
| 52 | } |
| 53 | |
| 54 | |
| 55 | for (i=0; i<NumCases; i++) |
| 56 | { |
| 57 | l = strtoul(TestCases[i].str, &end, TestCases[i].base); |
| 58 | |
| 59 | if (l != TestCases[i].result) |
| 60 | { |
| 61 | Fail("ERROR: Expected strtoul to return %u, got %u\n" , |
| 62 | TestCases[i].result, l); |
| 63 | } |
| 64 | |
| 65 | if (end != TestCases[i].end) |
| 66 | { |
| 67 | Fail("ERROR: Expected strtoul to give an end value of %p, got %p\n" , |
| 68 | TestCases[i].end, end); |
| 69 | } |
| 70 | } |
| 71 | PAL_Terminate(); |
| 72 | return PASS; |
| 73 | } |
| 74 | |