summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/c_runtime/_wfopen/test1/test1.cpp
blob: 81d2502cd505937f912c70022834d2d1fca4e31b (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 the PAL implementation of the _wfopen function. 
**          This test simply attempts to open a number of files with
**          different modes.  It checks to ensure a valid file
**          pointer is returned.  It doesn't do any checking to
**          ensure the mode is really what it claims. 
**  

**
**===================================================================*/


#define UNICODE                                  
#include <palsuite.h>

struct testCase
{
    int CorrectResult;
    WCHAR mode[20];
};

int __cdecl main(int argc, char **argv)
{
  
    FILE *fp;
    WCHAR name[128];
    WCHAR base[] = {'t','e','s','t','f','i','l','e','s','\0'};
    char * PrintResult;
    int i;

    struct testCase testCases[] = 
        {
            {0,  {'r','\0'    }}, {1, {'w','\0'}},     {1,  {'a','\0'}},
            {0,  {'r','+','\0'}}, {1, {'w','+','\0'}}, {1,  {'a','+','\0'}},
            {1,  {'w','t','\0'}}, {1, {'w','b','\0'}}, {1,  {'w','S','\0'}},
            {1,  {'w','c','\0'}}, {1, {'w','n','\0'}}, {1,  {'w', 'R','\0'}}, 
            {1,  {'w','T','\0'}}, {0, {'t','w','\0'}}, {0,  {'.','\0'}}
        };

    if (PAL_Initialize(argc, argv))
    {
        return FAIL;
    }

  
  
    for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++)
    {
        wcscpy(name,base);
        wcscat(name,testCases[i].mode);
      
        fp = _wfopen(name,testCases[i].mode);
      
        if ((fp == 0 && testCases[i].CorrectResult != 0)  ||
            (testCases[i].CorrectResult == 0 && fp != 0) )
        {
            PrintResult = convertC(testCases[i].mode);
            Fail("ERROR: fopen returned incorrectly "
                   "opening a file in %s mode.  Perhaps it opened a "
                   "read only file which didn't exist and returned a correct "
                   "pointer?",PrintResult);
            free(PrintResult);
        }    

        memset(name, '\0', 128);  
    }      
  
    PAL_Terminate();
    return PASS;
}