summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/c_runtime/wcstod/test1/test1.cpp
blob: e41e92e961e5c06ffd5ca2bd484867186130c28c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

/*=====================================================================
**
** Source:  test1.c
**
** Purpose: Tests wcstod with a number of sample strings.
**
**
**===================================================================*/

#include <palsuite.h>

struct testCase
{
    double CorrectResult;
    char string[20];
    int stopChar;
};

struct testCase testCases[] = 
{
    {1234,"1234", 4},
    {-1234,"-1234", 5},
    {1234.44,"1234.44", 7},
    {1234e-5,"1234e-5", 7},
    {1234e+5,"1234e+5", 7},
    {1234E5,"1234E5", 6},
    {1234.657e-8,  "1234.657e-8", 11},
    {0,  "1e-800", 6},
    {0,  "-1e-800", 7},
    {1234567e-8,  "   1234567e-8 foo", 13},
    {0,     " foo 32 bar", 0},
};

int __cdecl main(int argc, char **argv)
{
    WCHAR *wideStr;
    WCHAR *endptr;
    double result;  
    int i;
  
    if (PAL_Initialize(argc,argv))
    {
        return FAIL;
    }

    for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++)
    {
        wideStr = convert(testCases[i].string);
        result = wcstod(wideStr, &endptr);
      
        if (testCases[i].CorrectResult != result)
        {
            free(wideStr);
            Fail("ERROR: wcstod misinterpreted \"%s\" as %g instead of "
                   "%g.\n", 
                   testCases[i].string, 
                   result, 
                   testCases[i].CorrectResult);
        }
      
        if (endptr != wideStr + testCases[i].stopChar)
        {
            free(wideStr);
            Fail("ERROR: wcstod stopped scanning \"%s\" at %p, "
                "instead of %p!\n", testCases[i].string, endptr,
                wideStr + testCases[i].stopChar);
        }

        free(wideStr);
    }      
  
  
    PAL_Terminate();
    return PASS;
}