summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/c_runtime/_splitpath/test1/test1.c
blob: e98354c2eeeaf77959d19f761b1b9938e92da7c3 (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// 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: Passes _splitpath() a series of sample paths and checks that it
**          parses them as expected.
**
**
**==========================================================================*/


#include <palsuite.h>

struct testCase
{
    const char path[_MAX_PATH];    /* The path to parse. */
    const char drive[_MAX_DRIVE];  /* The expected values... */
    const char dir[_MAX_DIR];
    const char fname[_MAX_FNAME];
    const char ext[_MAX_EXT];
};


int __cdecl main(int argc, char **argv)
{
    struct testCase testCases[] =
    {
#if WIN32
        {"c:\\foo\\bar\\foo.bar", "c:", "\\foo\\bar\\", "foo", ".bar"},
        {"c:/foo/bar/foo.bar", "c:", "/foo/bar/", "foo", ".bar"},
        {"c:/foo/bar/foo", "c:", "/foo/bar/", "foo", ""},
        {"c:/foo/bar/.bar", "c:", "/foo/bar/", "", ".bar"},
        {"c:/foo/bar/", "c:", "/foo/bar/", "", ""},
        {"/foo/bar/foo.bar", "", "/foo/bar/", "foo", ".bar"},
        {"c:foo.bar", "c:", "", "foo", ".bar"}
#else
        {"c:\\foo\\bar\\foo.bar", "","c:/foo/bar/", "foo", ".bar"},
        {"c:/foo/bar/foo.bar", "", "c:/foo/bar/", "foo", ".bar"},
        {"c:/foo/bar/foo", "", "c:/foo/bar/", "foo", ""},
        {"c:/foo/bar/.bar", "", "c:/foo/bar/", ".bar", ""},
        {"c:/foo/bar/", "", "c:/foo/bar/", "", ""},
        {"/foo/bar/foo.bar", "", "/foo/bar/", "foo", ".bar"},
        {"c:foo.bar", "", "", "c:foo", ".bar"}
#endif
    };
    char drive[_MAX_DRIVE];
    char dir[_MAX_DIR];
    char fname[_MAX_FNAME];
    char ext[_MAX_EXT];

    int i=0;

    /*
     *  Initialize the PAL and return FAIL if this fails
     */
    if (0 != (PAL_Initialize(argc, argv)))
    {
        return FAIL;
    }

    for (i = 0; i < sizeof(testCases)/sizeof(struct testCase); i++)
    {
        _splitpath(testCases[i].path, drive, dir, fname, ext);


        /*on platforms that don't support drive letters, the drive
          returned should always be "" */
        if (strcmp(drive, testCases[i].drive) != 0)
        {
            Fail("_splitpath read the path \"%s\" and thought the drive was "
                   "\"%s\" instead of \"%s\"\n"
                   , testCases[i].path, drive, testCases[i].drive);
        }

        if (strcmp(dir, testCases[i].dir) != 0)
        {
            Fail("_splitpath read the path \"%s\" and thought the directory "
                   "was \"%s\" instead of \"%s\"\n"
                   , testCases[i].path, dir, testCases[i].dir);
        }

        if (strcmp(fname, testCases[i].fname) != 0)
        {
            Fail("_splitpath read the path \"%s\" and thought the filename "
                   "was \"%s\" instead of \"%s\"\n"
                   , testCases[i].path, fname, testCases[i].fname);
        }

        if (strcmp(ext, testCases[i].ext) != 0)
        {
            Fail("_splitpath read the path \"%s\" and thought the file "
                   "extension was \"%s\" instead of \"%s\"\n"
                   , testCases[i].path, ext, testCases[i].ext);
        }
    }
    PAL_Terminate();
    return PASS;
}