Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
test: assert that readdir on file raises UV_ENOTDIR
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Oct 12, 2011
1 parent 197f591 commit 25a177a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
Empty file added test/fixtures/empty_file
Empty file.
33 changes: 33 additions & 0 deletions test/test-fs.c
Expand Up @@ -364,6 +364,17 @@ static void empty_readdir_cb(uv_fs_t* req) {
}


static void file_readdir_cb(uv_fs_t* req) {
ASSERT(req == &readdir_req);
ASSERT(req->fs_type == UV_FS_READDIR);
ASSERT(req->result == -1);
ASSERT(req->ptr == NULL);
ASSERT(uv_last_error(req->loop).code == UV_ENOTDIR);
uv_fs_req_cleanup(req);
readdir_cb_count++;
}


static void stat_cb(uv_fs_t* req) {
ASSERT(req == &stat_req);
ASSERT(req->fs_type == UV_FS_STAT || req->fs_type == UV_FS_LSTAT);
Expand Down Expand Up @@ -1333,3 +1344,25 @@ TEST_IMPL(fs_readdir_empty_dir) {

return 0;
}


TEST_IMPL(fs_readdir_file) {
const char* path;
int r;

path = "test/fixtures/empty_file";
loop = uv_default_loop();

r = uv_fs_readdir(loop, &readdir_req, path, 0, NULL);
ASSERT(r == -1);
ASSERT(uv_last_error(loop).code == UV_ENOTDIR);

r = uv_fs_readdir(loop, &readdir_req, path, 0, file_readdir_cb);
ASSERT(r == 0);

ASSERT(readdir_cb_count == 0);
uv_run(loop);
ASSERT(readdir_cb_count == 1);

return 0;
}
2 changes: 2 additions & 0 deletions test/test-list.h
Expand Up @@ -102,6 +102,7 @@ TEST_DECLARE (fs_event_watch_dir)
TEST_DECLARE (fs_event_watch_file)
TEST_DECLARE (fs_event_watch_file_current_dir)
TEST_DECLARE (fs_readdir_empty_dir)
TEST_DECLARE (fs_readdir_file)
TEST_DECLARE (threadpool_queue_work_simple)
#ifdef _WIN32
TEST_DECLARE (spawn_detect_pipe_name_collisions_on_windows)
Expand Down Expand Up @@ -238,6 +239,7 @@ TASK_LIST_START
TEST_ENTRY (fs_event_watch_file)
TEST_ENTRY (fs_event_watch_file_current_dir)
TEST_ENTRY (fs_readdir_empty_dir)
TEST_ENTRY (fs_readdir_file)

TEST_ENTRY (threadpool_queue_work_simple)

Expand Down

0 comments on commit 25a177a

Please sign in to comment.