libuv-svace-build
72 строки · 2.1 Кб
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 409627#define SMALLPATH 128
29TEST_IMPL(homedir) {30char homedir[PATHMAX];31size_t len;32int r;33
34/* Test the normal case */35len = sizeof homedir;36homedir[0] = '\0';37ASSERT_OK(strlen(homedir));38r = uv_os_homedir(homedir, &len);39ASSERT_OK(r);40ASSERT_EQ(strlen(homedir), len);41ASSERT_GT(len, 0);42ASSERT_EQ(homedir[len], '\0');43
44#ifdef _WIN3245if (len == 3 && homedir[1] == ':')46ASSERT_EQ(homedir[2], '\\');47else48ASSERT_NE(homedir[len - 1], '\\');49#else50if (len == 1)51ASSERT_EQ(homedir[0], '/');52else53ASSERT_NE(homedir[len - 1], '/');54#endif55
56/* Test the case where the buffer is too small */57len = SMALLPATH;58r = uv_os_homedir(homedir, &len);59ASSERT_EQ(r, UV_ENOBUFS);60ASSERT_GT(len, SMALLPATH);61
62/* Test invalid inputs */63r = uv_os_homedir(NULL, &len);64ASSERT_EQ(r, UV_EINVAL);65r = uv_os_homedir(homedir, NULL);66ASSERT_EQ(r, UV_EINVAL);67len = 0;68r = uv_os_homedir(homedir, &len);69ASSERT_EQ(r, UV_EINVAL);70
71return 0;72}
73