grpc
third_party
libuv
test
test-homedir.c
Go to the documentation of this file.
1
/* Copyright libuv project contributors. All rights reserved.
2
*
3
* Permission is hereby granted, free of charge, to any person obtaining a copy
4
* of this software and associated documentation files (the "Software"), to
5
* deal in the Software without restriction, including without limitation the
6
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
* sell copies of the Software, and to permit persons to whom the Software is
8
* furnished to do so, subject to the following conditions:
9
*
10
* The above copyright notice and this permission notice shall be included in
11
* all copies or substantial portions of the Software.
12
*
13
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19
* IN THE SOFTWARE.
20
*/
21
22
#include "
uv.h
"
23
#include "
task.h
"
24
#include <
string.h
>
25
26
#define PATHMAX 4096
27
#define SMALLPATH 1
28
29
TEST_IMPL
(homedir) {
30
char
homedir[
PATHMAX
];
31
size_t
len
;
32
int
r
;
33
34
/* Test the normal case */
35
len
=
sizeof
homedir;
36
homedir[0] =
'\0'
;
37
ASSERT
(strlen(homedir) == 0);
38
r
=
uv_os_homedir
(homedir, &
len
);
39
ASSERT
(
r
== 0);
40
ASSERT
(strlen(homedir) ==
len
);
41
ASSERT
(
len
> 0);
42
ASSERT
(homedir[
len
] ==
'\0'
);
43
44
#ifdef _WIN32
45
if
(
len
== 3 && homedir[1] ==
':'
)
46
ASSERT
(homedir[2] ==
'\\'
);
47
else
48
ASSERT
(homedir[
len
- 1] !=
'\\'
);
49
#else
50
if
(
len
== 1)
51
ASSERT
(homedir[0] ==
'/'
);
52
else
53
ASSERT
(homedir[
len
- 1] !=
'/'
);
54
#endif
55
56
/* Test the case where the buffer is too small */
57
len
=
SMALLPATH
;
58
r
=
uv_os_homedir
(homedir, &
len
);
59
ASSERT
(
r
== UV_ENOBUFS);
60
ASSERT
(
len
>
SMALLPATH
);
61
62
/* Test invalid inputs */
63
r
=
uv_os_homedir
(NULL, &
len
);
64
ASSERT
(
r
== UV_EINVAL);
65
r
=
uv_os_homedir
(homedir, NULL);
66
ASSERT
(
r
== UV_EINVAL);
67
len
= 0;
68
r
=
uv_os_homedir
(homedir, &
len
);
69
ASSERT
(
r
== UV_EINVAL);
70
71
return
0;
72
}
task.h
string.h
ASSERT
#define ASSERT(expr)
Definition:
task.h:102
TEST_IMPL
TEST_IMPL(homedir)
Definition:
test-homedir.c:29
SMALLPATH
#define SMALLPATH
Definition:
test-homedir.c:27
uv.h
fix_build_deps.r
r
Definition:
fix_build_deps.py:491
uv_os_homedir
UV_EXTERN int uv_os_homedir(char *buffer, size_t *size)
Definition:
unix/core.c:1047
len
int len
Definition:
abseil-cpp/absl/base/internal/low_level_alloc_test.cc:46
PATHMAX
#define PATHMAX
Definition:
test-homedir.c:26
grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:26