Better implementation of GetCalendarInfo{A,W}, not perfect.
[wine] / dlls / kernel / tests / directory.c
1 /*
2  * Unit test suite for directory functions.
3  *
4  * Copyright 2002 Dmitry Timoshkov
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "wine/test.h"
22 #include "winbase.h"
23
24
25 /* If you change something in these tests, please do the same
26  * for GetSystemDirectory tests.
27  */
28 static void test_GetWindowsDirectoryA(void)
29 {
30     UINT len, len_with_null;
31     char buf[MAX_PATH];
32
33     lstrcpyA(buf, "foo");
34     len_with_null = GetWindowsDirectoryA(buf, 1);
35     ok(lstrcmpA(buf, "foo") == 0, "should not touch the buffer");
36     ok(len_with_null <= MAX_PATH, "should fit into MAX_PATH");
37
38     lstrcpyA(buf, "foo");
39     len = GetWindowsDirectoryA(buf, len_with_null - 1);
40     ok(lstrcmpA(buf, "foo") == 0, "should not touch the buffer");
41     ok(len == len_with_null, "should return length with terminating 0");
42
43     lstrcpyA(buf, "foo");
44     len = GetWindowsDirectoryA(buf, len_with_null);
45     ok(lstrcmpA(buf, "foo") != 0, "should touch the buffer");
46     ok(len == lstrlenA(buf), "returned length should be equal to the length of string");
47     ok(len == (len_with_null - 1), "should return length without terminating 0");
48 }
49
50 static void test_GetWindowsDirectoryW(void)
51 {
52     UINT len, len_with_null;
53     WCHAR buf[MAX_PATH];
54     static const WCHAR fooW[] = {'f','o','o',0};
55
56     lstrcpyW(buf, fooW);
57     len_with_null = GetWindowsDirectoryW(buf, 1);
58     ok(lstrcmpW(buf, fooW) == 0, "should not touch the buffer");
59     ok(len_with_null <= MAX_PATH, "should fit into MAX_PATH");
60
61     lstrcpyW(buf, fooW);
62     len = GetWindowsDirectoryW(buf, len_with_null - 1);
63     ok(lstrcmpW(buf, fooW) == 0, "should not touch the buffer");
64     ok(len == len_with_null, "should return length with terminating 0");
65
66     lstrcpyW(buf, fooW);
67     len = GetWindowsDirectoryW(buf, len_with_null);
68     ok(lstrcmpW(buf, fooW) != 0, "should touch the buffer");
69     ok(len == lstrlenW(buf), "returned length should be equal to the length of string");
70     ok(len == (len_with_null - 1), "should return length without terminating 0");
71 }
72
73
74 /* If you change something in these tests, please do the same
75  * for GetWindowsDirectory tests.
76  */
77 static void test_GetSystemDirectoryA(void)
78 {
79     UINT len, len_with_null;
80     char buf[MAX_PATH];
81
82     lstrcpyA(buf, "foo");
83     len_with_null = GetSystemDirectoryA(buf, 1);
84     ok(lstrcmpA(buf, "foo") == 0, "should not touch the buffer");
85     ok(len_with_null <= MAX_PATH, "should fit into MAX_PATH");
86
87     lstrcpyA(buf, "foo");
88     len = GetSystemDirectoryA(buf, len_with_null - 1);
89     ok(lstrcmpA(buf, "foo") == 0, "should not touch the buffer");
90     ok(len == len_with_null, "should return length with terminating 0");
91
92     lstrcpyA(buf, "foo");
93     len = GetSystemDirectoryA(buf, len_with_null);
94     ok(lstrcmpA(buf, "foo") != 0, "should touch the buffer");
95     ok(len == lstrlenA(buf), "returned length should be equal to the length of string");
96     ok(len == (len_with_null - 1), "should return length without terminating 0");
97 }
98
99 static void test_GetSystemDirectoryW(void)
100 {
101     UINT len, len_with_null;
102     WCHAR buf[MAX_PATH];
103     static const WCHAR fooW[] = {'f','o','o',0};
104
105     lstrcpyW(buf, fooW);
106     len_with_null = GetSystemDirectoryW(buf, 1);
107     ok(lstrcmpW(buf, fooW) == 0, "should not touch the buffer");
108     ok(len_with_null <= MAX_PATH, "should fit into MAX_PATH");
109
110     lstrcpyW(buf, fooW);
111     len = GetSystemDirectoryW(buf, len_with_null - 1);
112     ok(lstrcmpW(buf, fooW) == 0, "should not touch the buffer");
113     ok(len == len_with_null, "should return length with terminating 0");
114
115     lstrcpyW(buf, fooW);
116     len = GetSystemDirectoryW(buf, len_with_null);
117     ok(lstrcmpW(buf, fooW) != 0, "should touch the buffer");
118     ok(len == lstrlenW(buf), "returned length should be equal to the length of string");
119     ok(len == (len_with_null - 1), "should return length without terminating 0");
120 }
121
122 START_TEST(directory)
123 {
124     test_GetWindowsDirectoryA();
125     test_GetWindowsDirectoryW();
126     test_GetSystemDirectoryA();
127     test_GetSystemDirectoryW();
128 }