forked from cory/tildefriends
Merge branches/quickjs to trunk. This is the way.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3621 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
COPYINGMakefileREADME.mdSConstruct
apps/cory
core
app.jsauth.htmlauth.jsbCrypt.jsclient.jscore.jshttpd.jsindex.htmlisaac.jsnetwork.jsstyle.cssterminal.js
deps
base64c
crypt_blowfish
LINKSMakefilePERFORMANCEREADMEcrypt.3crypt.hcrypt_blowfish.ccrypt_blowfish.hcrypt_gensalt.ccrypt_gensalt.hglibc-2.1.3-crypt.diffglibc-2.14-crypt.diffglibc-2.3.6-crypt.diffow-crypt.hwrapper.cx86.S
libuv
.gitattributes
.github
.gitignore.mailmapAUTHORSCMakeLists.txtCONTRIBUTING.mdChangeLogLICENSELICENSE-docsMAINTAINERS.mdMakefile.amREADME.mdSUPPORTED_PLATFORMS.mdautogen.shconfigure.acdocs
Makefilemake.bat
code
cgi
detach
dns
helloworld
idle-basic
idle-compute
interfaces
locks
multi-echo-server
onchange
pipe-echo-server
plugin
proc-streams
progress
queue-cancel
queue-work
ref-timer
signal
spawn
tcp-echo-server
thread-create
tty-gravity
tty
udp-dhcp
uvcat
uvstop
uvtee
uvwget
src
api.rstasync.rstcheck.rstconf.pydesign.rstdll.rstdns.rsterrors.rstfs.rstfs_event.rstfs_poll.rstguide.rst
guide
about.rstbasics.rsteventloops.rstfilesystem.rstintroduction.rstnetworking.rstprocesses.rstthreads.rstutilities.rst
handle.rstidle.rstindex.rstloop.rstmetrics.rstmigration_010_100.rstmisc.rstpipe.rstpoll.rstprepare.rstprocess.rstrequest.rstsignal.rstsphinx-plugins
static
architecture.png
stream.rsttcp.rstthreading.rstthreadpool.rsttimer.rsttty.rstudp.rstupgrading.rstversion.rstdiagrams.key
favicon.icologo.pngloop_iteration.pngimg
include
uv.h
libuv-static.pc.inlibuv.pc.inuv
m4
src
fs-poll.cheap-inl.hidna.cidna.hinet.cqueue.hrandom.cstrscpy.cstrscpy.hthreadpool.ctimer.c
unix
aix-common.caix.candroid-ifaddrs.casync.catomic-ops.hbsd-ifaddrs.cbsd-proctitle.ccore.ccygwin.cdarwin-proctitle.cdarwin-stub.hdarwin.cdl.cfreebsd.cfs.cfsevents.cgetaddrinfo.cgetnameinfo.chaiku.cibmi.cinternal.hkqueue.clinux-core.clinux-inotify.clinux-syscalls.clinux-syscalls.hloop-watcher.cloop.cnetbsd.cno-fsevents.cno-proctitle.copenbsd.cos390-syscalls.cos390-syscalls.hos390.cpipe.cpoll.cposix-hrtime.cposix-poll.cprocess.cprocfs-exepath.cproctitle.cpthread-fixes.cqnx.crandom-devurandom.crandom-getentropy.crandom-getrandom.crandom-sysctl-linux.csignal.cspinlock.hstream.csunos.csysinfo-loadavg.csysinfo-memory.ctcp.cthread.ctty.cudp.c
uv-common.cuv-common.huv-data-getter-setters.cversion.cwin
async.catomicops-inl.hcore.cdetect-wakeup.cdl.cerror.cfs-event.cfs-fd-hash-inl.hfs.cgetaddrinfo.cgetnameinfo.chandle-inl.hhandle.cinternal.hloop-watcher.cpipe.cpoll.cprocess-stdio.cprocess.creq-inl.hsignal.csnprintf.cstream-inl.hstream.ctcp.cthread.ctty.cudp.cutil.cwinapi.cwinapi.hwinsock.cwinsock.h
test
benchmark-async-pummel.cbenchmark-async.cbenchmark-fs-stat.cbenchmark-getaddrinfo.cbenchmark-list.hbenchmark-loop-count.cbenchmark-million-async.cbenchmark-million-timers.cbenchmark-multi-accept.cbenchmark-ping-pongs.cbenchmark-ping-udp.cbenchmark-pound.cbenchmark-pump.cbenchmark-sizes.cbenchmark-spawn.cbenchmark-tcp-write-batch.cbenchmark-thread.cbenchmark-udp-pummel.cblackhole-server.cdns-server.cecho-server.c
fixtures
run-benchmarks.crun-tests.crunner-unix.crunner-unix.hrunner-win.crunner-win.hrunner.crunner.htask.htest-active.ctest-async-null-cb.ctest-async.ctest-barrier.ctest-callback-order.ctest-callback-stack.ctest-close-fd.ctest-close-order.ctest-condvar.ctest-connect-unspecified.ctest-connection-fail.ctest-cwd-and-chdir.ctest-default-loop-close.ctest-delayed-accept.ctest-dlerror.ctest-eintr-handling.ctest-embed.ctest-emfile.ctest-env-vars.ctest-error.ctest-fail-always.ctest-fork.ctest-fs-copyfile.ctest-fs-event.ctest-fs-fd-hash.ctest-fs-open-flags.ctest-fs-poll.ctest-fs-readdir.ctest-fs.ctest-get-currentexe.ctest-get-loadavg.ctest-get-memory.ctest-get-passwd.ctest-getaddrinfo.ctest-gethostname.ctest-getnameinfo.ctest-getsockname.ctest-getters-setters.ctest-gettimeofday.ctest-handle-fileno.ctest-homedir.ctest-hrtime.ctest-idle.ctest-idna.ctest-ip4-addr.ctest-ip6-addr.ctest-ipc-heavy-traffic-deadlock-bug.ctest-ipc-send-recv.ctest-ipc.ctest-list.htest-loop-alive.ctest-loop-close.ctest-loop-configure.ctest-loop-handles.ctest-loop-stop.ctest-loop-time.ctest-metrics.ctest-multiple-listen.ctest-mutexes.ctest-osx-select.ctest-pass-always.ctest-ping-pong.ctest-pipe-bind-error.ctest-pipe-close-stdout-read-stdin.ctest-pipe-connect-error.ctest-pipe-connect-multiple.ctest-pipe-connect-prepare.ctest-pipe-getsockname.ctest-pipe-pending-instances.ctest-pipe-sendmsg.ctest-pipe-server-close.ctest-pipe-set-fchmod.ctest-pipe-set-non-blocking.ctest-platform-output.ctest-poll-close-doesnt-corrupt-stack.ctest-poll-close.ctest-poll-closesocket.ctest-poll-oob.ctest-poll.ctest-process-priority.ctest-process-title-threadsafe.ctest-process-title.ctest-queue-foreach-delete.ctest-random.ctest-ref.ctest-run-nowait.ctest-run-once.ctest-semaphore.ctest-shutdown-close.ctest-shutdown-eof.ctest-shutdown-twice.ctest-signal-multiple-loops.ctest-signal-pending-on-close.ctest-signal.ctest-socket-buffer-size.ctest-spawn.ctest-stdio-over-pipes.ctest-strscpy.ctest-tcp-alloc-cb-fail.ctest-tcp-bind-error.ctest-tcp-bind6-error.ctest-tcp-close-accept.ctest-tcp-close-reset.ctest-tcp-close-while-connecting.ctest-tcp-close.ctest-tcp-connect-error-after-write.ctest-tcp-connect-error.ctest-tcp-connect-timeout.ctest-tcp-connect6-error.ctest-tcp-create-socket-early.ctest-tcp-flags.ctest-tcp-oob.ctest-tcp-open.ctest-tcp-read-stop-start.ctest-tcp-read-stop.ctest-tcp-shutdown-after-write.ctest-tcp-try-write-error.ctest-tcp-try-write.ctest-tcp-unexpected-read.ctest-tcp-write-after-connect.ctest-tcp-write-fail.ctest-tcp-write-queue-order.ctest-tcp-write-to-half-open-connection.ctest-tcp-writealot.ctest-test-macros.ctest-thread-equal.ctest-thread.ctest-threadpool-cancel.ctest-threadpool.ctest-timer-again.ctest-timer-from-check.ctest-timer.ctest-tmpdir.ctest-tty-duplicate-key.ctest-tty-escape-sequence-processing.ctest-tty.ctest-udp-alloc-cb-fail.ctest-udp-bind.ctest-udp-connect.ctest-udp-create-socket-early.ctest-udp-dgram-too-big.ctest-udp-ipv6.ctest-udp-mmsg.ctest-udp-multicast-interface.ctest-udp-multicast-interface6.ctest-udp-multicast-join.ctest-udp-multicast-join6.ctest-udp-multicast-ttl.ctest-udp-open.ctest-udp-options.ctest-udp-send-and-recv.ctest-udp-send-hang-loop.ctest-udp-send-immediate.ctest-udp-send-unreachable.ctest-udp-sendmmsg-error.ctest-udp-try-send.ctest-uname.ctest-walk-handles.ctest-watcher-cross-stop.ctools
uv_win_longpath.manifestquickjs
ChangelogMakefileTODOVERSIONcutils.ccutils.h
doc
examples
jscompress.clibbf.clibbf.hlibregexp.clibregexp.hlibunicode-table.hlibunicode.cqjs.cqjsc.cqjscalc.jsquickjs-atom.hquickjs-libc.cquickjs-libc.hquickjs-opcode.hquickjs.cquickjs.hrelease.shrepl.jsrun-test262.ctest262.conftest262_errors.txttest262bn.conftest262bn_errors.txttests
bjson.cmicrobench.jstest262.patchtest_bignum.jstest_bjson.jstest_builtin.jstest_language.jstest_op_overloading.jstest_qjscalc.jstest_std.jstest_worker.jstest_worker_module.js
unicode_download.shunicode_gen.cunicode_gen_def.hsqlite
xopt
.circleci
.dockerignore.editorconfig.gitignoreCMakeLists.txtREADME.mdsnprintf.ctest
.gitignoreautohelp-1.outautohelp.cmacro-1.outmacro.cnocondense-1.outnocondense-sloppy-1.outnocondense-sloppy-2.outnocondense-sloppy-3.outnocondense-sloppy.cnocondense.coptional-longarg-1.outoptional-longarg.crequired-1.outrequired.csimple-1.outsimple.csloppyshorts-1.outsloppyshorts.ctest-case.sh
xopt.cxopt.hpackages/cory
about
administration
await
bbs
blink
blog
chat
chattest
contest
db
documentation
emojipush
geolocation
guess
hello
images
index
invite
invite2
ldjam34
libchat
libdocument
libencoding
libhttp
libiframe
libirc
liblist
libunfurl
libxml
libxmpp
meetup
messages
mmoturtle
monitor
news
reminder
sharedwiki
smtp
splits
tanks
test
tmirce
todo
turtle
ui
whatnext
wiki
xmas2016
youtube
src
Database.cppDatabase.hFile.cppFile.hMutex.cppMutex.hPacketStream.cppPacketStream.hSerialize.cppSerialize.hSocket.cppSocket.hTask.cppTask.hTaskStub.cppTaskStub.hTaskTryCatch.cppTaskTryCatch.hTls.hTlsContextWrapper.cppTlsContextWrapper.hbcrypt.cbcrypt.hdatabase.cdatabase.hfile.cfile.hmain.cmain.cpppacketstream.cpacketstream.hquickjstest.cserialize.cserialize.hsocket.csocket.hssb.cssb.connections.cssb.connections.hssb.hssb.qjs.cssb.qjs.hssb.rpc.cssb.rpc.hssb.tests.ctask.ctask.htaskstub.ctaskstub.htls.ctls.htlscontextwrapper.ctlscontextwrapper.htrace.ctrace.h
tests
tools
435
deps/libuv/test/test-fs-open-flags.c
vendored
Normal file
435
deps/libuv/test/test-fs-open-flags.c
vendored
Normal file
@@ -0,0 +1,435 @@
|
||||
/* Copyright libuv project contributors. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#include "uv.h"
|
||||
#include "task.h"
|
||||
|
||||
#if defined(__unix__) || defined(__POSIX__) || \
|
||||
defined(__APPLE__) || defined(__sun) || \
|
||||
defined(_AIX) || defined(__MVS__) || \
|
||||
defined(__HAIKU__)
|
||||
# include <unistd.h> /* unlink, rmdir */
|
||||
#else
|
||||
# include <direct.h>
|
||||
# define rmdir _rmdir
|
||||
# define unlink _unlink
|
||||
#endif
|
||||
|
||||
static int flags;
|
||||
|
||||
static uv_fs_t close_req;
|
||||
static uv_fs_t mkdir_req;
|
||||
static uv_fs_t open_req;
|
||||
static uv_fs_t read_req;
|
||||
static uv_fs_t rmdir_req;
|
||||
static uv_fs_t unlink_req;
|
||||
static uv_fs_t write_req;
|
||||
|
||||
static char buf[32];
|
||||
static uv_buf_t iov;
|
||||
|
||||
/* Opening the same file multiple times quickly can cause uv_fs_open to fail
|
||||
* with EBUSY, so append an identifier to the file name for each operation */
|
||||
static int sid = 0;
|
||||
|
||||
#define FILE_NAME_SIZE 128
|
||||
static char absent_file[FILE_NAME_SIZE];
|
||||
static char empty_file[FILE_NAME_SIZE];
|
||||
static char dummy_file[FILE_NAME_SIZE];
|
||||
static char empty_dir[] = "empty_dir";
|
||||
|
||||
static void setup(void) {
|
||||
int r;
|
||||
|
||||
/* empty_dir */
|
||||
r = uv_fs_rmdir(NULL, &rmdir_req, empty_dir, NULL);
|
||||
ASSERT(r == 0 || r == UV_ENOENT);
|
||||
ASSERT(rmdir_req.result == 0 || rmdir_req.result == UV_ENOENT);
|
||||
uv_fs_req_cleanup(&rmdir_req);
|
||||
|
||||
r = uv_fs_mkdir(NULL, &mkdir_req, empty_dir, 0755, NULL);
|
||||
ASSERT(r == 0);
|
||||
ASSERT(mkdir_req.result == 0);
|
||||
uv_fs_req_cleanup(&mkdir_req);
|
||||
}
|
||||
|
||||
static void refresh(void) {
|
||||
int r;
|
||||
|
||||
/* absent_file */
|
||||
sprintf(absent_file, "test_file_%d", sid++);
|
||||
|
||||
r = uv_fs_unlink(NULL, &unlink_req, absent_file, NULL);
|
||||
ASSERT(r == 0 || r == UV_ENOENT);
|
||||
ASSERT(unlink_req.result == 0 || unlink_req.result == UV_ENOENT);
|
||||
uv_fs_req_cleanup(&unlink_req);
|
||||
|
||||
/* empty_file */
|
||||
sprintf(empty_file, "test_file_%d", sid++);
|
||||
|
||||
r = uv_fs_open(NULL, &open_req, empty_file,
|
||||
UV_FS_O_TRUNC | UV_FS_O_CREAT | UV_FS_O_WRONLY, S_IWUSR | S_IRUSR, NULL);
|
||||
ASSERT(r >= 0);
|
||||
ASSERT(open_req.result >= 0);
|
||||
uv_fs_req_cleanup(&open_req);
|
||||
|
||||
r = uv_fs_close(NULL, &close_req, open_req.result, NULL);
|
||||
ASSERT(r == 0);
|
||||
ASSERT(close_req.result == 0);
|
||||
uv_fs_req_cleanup(&close_req);
|
||||
|
||||
/* dummy_file */
|
||||
sprintf(dummy_file, "test_file_%d", sid++);
|
||||
|
||||
r = uv_fs_open(NULL, &open_req, dummy_file,
|
||||
UV_FS_O_TRUNC | UV_FS_O_CREAT | UV_FS_O_WRONLY, S_IWUSR | S_IRUSR, NULL);
|
||||
ASSERT(r >= 0);
|
||||
ASSERT(open_req.result >= 0);
|
||||
uv_fs_req_cleanup(&open_req);
|
||||
|
||||
iov = uv_buf_init("a", 1);
|
||||
r = uv_fs_write(NULL, &write_req, open_req.result, &iov, 1, -1, NULL);
|
||||
ASSERT(r == 1);
|
||||
ASSERT(write_req.result == 1);
|
||||
uv_fs_req_cleanup(&write_req);
|
||||
|
||||
r = uv_fs_close(NULL, &close_req, open_req.result, NULL);
|
||||
ASSERT(r == 0);
|
||||
ASSERT(close_req.result == 0);
|
||||
uv_fs_req_cleanup(&close_req);
|
||||
}
|
||||
|
||||
static void cleanup(void) {
|
||||
unlink(absent_file);
|
||||
unlink(empty_file);
|
||||
unlink(dummy_file);
|
||||
}
|
||||
|
||||
static void openFail(char *file, int error) {
|
||||
int r;
|
||||
|
||||
refresh();
|
||||
|
||||
r = uv_fs_open(NULL, &open_req, file, flags, S_IWUSR | S_IRUSR, NULL);
|
||||
ASSERT(r == error);
|
||||
ASSERT(open_req.result == error);
|
||||
uv_fs_req_cleanup(&open_req);
|
||||
|
||||
/* Ensure the first call does not create the file */
|
||||
r = uv_fs_open(NULL, &open_req, file, flags, S_IWUSR | S_IRUSR, NULL);
|
||||
ASSERT(r == error);
|
||||
ASSERT(open_req.result == error);
|
||||
uv_fs_req_cleanup(&open_req);
|
||||
|
||||
cleanup();
|
||||
}
|
||||
|
||||
static void refreshOpen(char *file) {
|
||||
int r;
|
||||
|
||||
refresh();
|
||||
|
||||
r = uv_fs_open(NULL, &open_req, file, flags, S_IWUSR | S_IRUSR, NULL);
|
||||
ASSERT(r >= 0);
|
||||
ASSERT(open_req.result >= 0);
|
||||
uv_fs_req_cleanup(&open_req);
|
||||
}
|
||||
|
||||
static void writeExpect(char *file, char *expected, int size) {
|
||||
int r;
|
||||
|
||||
refreshOpen(file);
|
||||
|
||||
iov = uv_buf_init("b", 1);
|
||||
r = uv_fs_write(NULL, &write_req, open_req.result, &iov, 1, -1, NULL);
|
||||
ASSERT(r == 1);
|
||||
ASSERT(write_req.result == 1);
|
||||
uv_fs_req_cleanup(&write_req);
|
||||
|
||||
iov = uv_buf_init("c", 1);
|
||||
r = uv_fs_write(NULL, &write_req, open_req.result, &iov, 1, -1, NULL);
|
||||
ASSERT(r == 1);
|
||||
ASSERT(write_req.result == 1);
|
||||
uv_fs_req_cleanup(&write_req);
|
||||
|
||||
r = uv_fs_close(NULL, &close_req, open_req.result, NULL);
|
||||
ASSERT(r == 0);
|
||||
ASSERT(close_req.result == 0);
|
||||
uv_fs_req_cleanup(&close_req);
|
||||
|
||||
/* Check contents */
|
||||
r = uv_fs_open(NULL, &open_req, file, UV_FS_O_RDONLY, S_IWUSR | S_IRUSR, NULL);
|
||||
ASSERT(r >= 0);
|
||||
ASSERT(open_req.result >= 0);
|
||||
uv_fs_req_cleanup(&open_req);
|
||||
|
||||
iov = uv_buf_init(buf, sizeof(buf));
|
||||
r = uv_fs_read(NULL, &read_req, open_req.result, &iov, 1, -1, NULL);
|
||||
ASSERT(r == size);
|
||||
ASSERT(read_req.result == size);
|
||||
ASSERT(strncmp(buf, expected, size) == 0);
|
||||
uv_fs_req_cleanup(&read_req);
|
||||
|
||||
r = uv_fs_close(NULL, &close_req, open_req.result, NULL);
|
||||
ASSERT(r == 0);
|
||||
ASSERT(close_req.result == 0);
|
||||
uv_fs_req_cleanup(&close_req);
|
||||
|
||||
cleanup();
|
||||
}
|
||||
|
||||
static void writeFail(char *file, int error) {
|
||||
int r;
|
||||
|
||||
refreshOpen(file);
|
||||
|
||||
iov = uv_buf_init("z", 1);
|
||||
r = uv_fs_write(NULL, &write_req, open_req.result, &iov, 1, -1, NULL);
|
||||
ASSERT(r == error);
|
||||
ASSERT(write_req.result == error);
|
||||
uv_fs_req_cleanup(&write_req);
|
||||
|
||||
iov = uv_buf_init("z", 1);
|
||||
r = uv_fs_write(NULL, &write_req, open_req.result, &iov, 1, -1, NULL);
|
||||
ASSERT(r == error);
|
||||
ASSERT(write_req.result == error);
|
||||
uv_fs_req_cleanup(&write_req);
|
||||
|
||||
r = uv_fs_close(NULL, &close_req, open_req.result, NULL);
|
||||
ASSERT(r == 0);
|
||||
ASSERT(close_req.result == 0);
|
||||
uv_fs_req_cleanup(&close_req);
|
||||
|
||||
cleanup();
|
||||
}
|
||||
|
||||
static void readExpect(char *file, char *expected, int size) {
|
||||
int r;
|
||||
|
||||
refreshOpen(file);
|
||||
|
||||
iov = uv_buf_init(buf, sizeof(buf));
|
||||
r = uv_fs_read(NULL, &read_req, open_req.result, &iov, 1, -1, NULL);
|
||||
ASSERT(r == size);
|
||||
ASSERT(read_req.result == size);
|
||||
ASSERT(strncmp(buf, expected, size) == 0);
|
||||
uv_fs_req_cleanup(&read_req);
|
||||
|
||||
r = uv_fs_close(NULL, &close_req, open_req.result, NULL);
|
||||
ASSERT(r == 0);
|
||||
ASSERT(close_req.result == 0);
|
||||
uv_fs_req_cleanup(&close_req);
|
||||
|
||||
cleanup();
|
||||
}
|
||||
|
||||
static void readFail(char *file, int error) {
|
||||
int r;
|
||||
|
||||
refreshOpen(file);
|
||||
|
||||
iov = uv_buf_init(buf, sizeof(buf));
|
||||
r = uv_fs_read(NULL, &read_req, open_req.result, &iov, 1, -1, NULL);
|
||||
ASSERT(r == error);
|
||||
ASSERT(read_req.result == error);
|
||||
uv_fs_req_cleanup(&read_req);
|
||||
|
||||
iov = uv_buf_init(buf, sizeof(buf));
|
||||
r = uv_fs_read(NULL, &read_req, open_req.result, &iov, 1, -1, NULL);
|
||||
ASSERT(r == error);
|
||||
ASSERT(read_req.result == error);
|
||||
uv_fs_req_cleanup(&read_req);
|
||||
|
||||
r = uv_fs_close(NULL, &close_req, open_req.result, NULL);
|
||||
ASSERT(r == 0);
|
||||
ASSERT(close_req.result == 0);
|
||||
uv_fs_req_cleanup(&close_req);
|
||||
|
||||
cleanup();
|
||||
}
|
||||
|
||||
static void fs_open_flags(int add_flags) {
|
||||
/* Follow the order from
|
||||
* https://github.com/nodejs/node/blob/1a96abe849/lib/internal/fs/utils.js#L329-L354
|
||||
*/
|
||||
|
||||
/* r */
|
||||
flags = add_flags | UV_FS_O_RDONLY;
|
||||
openFail(absent_file, UV_ENOENT);
|
||||
writeFail(empty_file, UV_EPERM);
|
||||
readExpect(empty_file, "", 0);
|
||||
writeFail(dummy_file, UV_EPERM);
|
||||
readExpect(dummy_file, "a", 1);
|
||||
writeFail(empty_dir, UV_EPERM);
|
||||
readFail(empty_dir, UV_EISDIR);
|
||||
|
||||
/* rs */
|
||||
flags = add_flags | UV_FS_O_RDONLY | UV_FS_O_SYNC;
|
||||
openFail(absent_file, UV_ENOENT);
|
||||
writeFail(empty_file, UV_EPERM);
|
||||
readExpect(empty_file, "", 0);
|
||||
writeFail(dummy_file, UV_EPERM);
|
||||
readExpect(dummy_file, "a", 1);
|
||||
writeFail(empty_dir, UV_EPERM);
|
||||
readFail(empty_dir, UV_EISDIR);
|
||||
|
||||
/* r+ */
|
||||
flags = add_flags | UV_FS_O_RDWR;
|
||||
openFail(absent_file, UV_ENOENT);
|
||||
writeExpect(empty_file, "bc", 2);
|
||||
readExpect(empty_file, "", 0);
|
||||
writeExpect(dummy_file, "bc", 2);
|
||||
readExpect(dummy_file, "a", 1);
|
||||
writeFail(empty_dir, UV_EISDIR);
|
||||
readFail(empty_dir, UV_EISDIR);
|
||||
|
||||
/* rs+ */
|
||||
flags = add_flags | UV_FS_O_RDWR | UV_FS_O_SYNC;
|
||||
openFail(absent_file, UV_ENOENT);
|
||||
writeExpect(empty_file, "bc", 2);
|
||||
readExpect(empty_file, "", 0);
|
||||
writeExpect(dummy_file, "bc", 2);
|
||||
readExpect(dummy_file, "a", 1);
|
||||
writeFail(empty_dir, UV_EISDIR);
|
||||
readFail(empty_dir, UV_EISDIR);
|
||||
|
||||
/* w */
|
||||
flags = add_flags | UV_FS_O_TRUNC | UV_FS_O_CREAT | UV_FS_O_WRONLY;
|
||||
writeExpect(absent_file, "bc", 2);
|
||||
readFail(absent_file, UV_EPERM);
|
||||
writeExpect(empty_file, "bc", 2);
|
||||
readFail(empty_file, UV_EPERM);
|
||||
writeExpect(dummy_file, "bc", 2);
|
||||
readFail(dummy_file, UV_EPERM);
|
||||
openFail(empty_dir, UV_EISDIR);
|
||||
|
||||
/* wx */
|
||||
flags = add_flags | UV_FS_O_TRUNC | UV_FS_O_CREAT | UV_FS_O_WRONLY |
|
||||
UV_FS_O_EXCL;
|
||||
writeExpect(absent_file, "bc", 2);
|
||||
readFail(absent_file, UV_EPERM);
|
||||
openFail(empty_file, UV_EEXIST);
|
||||
openFail(dummy_file, UV_EEXIST);
|
||||
openFail(empty_dir, UV_EEXIST);
|
||||
|
||||
/* w+ */
|
||||
flags = add_flags | UV_FS_O_TRUNC | UV_FS_O_CREAT | UV_FS_O_RDWR;
|
||||
writeExpect(absent_file, "bc", 2);
|
||||
readExpect(absent_file, "", 0);
|
||||
writeExpect(empty_file, "bc", 2);
|
||||
readExpect(empty_file, "", 0);
|
||||
writeExpect(dummy_file, "bc", 2);
|
||||
readExpect(dummy_file, "", 0);
|
||||
openFail(empty_dir, UV_EISDIR);
|
||||
|
||||
/* wx+ */
|
||||
flags = add_flags | UV_FS_O_TRUNC | UV_FS_O_CREAT | UV_FS_O_RDWR |
|
||||
UV_FS_O_EXCL;
|
||||
writeExpect(absent_file, "bc", 2);
|
||||
readExpect(absent_file, "", 0);
|
||||
openFail(empty_file, UV_EEXIST);
|
||||
openFail(dummy_file, UV_EEXIST);
|
||||
openFail(empty_dir, UV_EEXIST);
|
||||
|
||||
/* a */
|
||||
flags = add_flags | UV_FS_O_APPEND | UV_FS_O_CREAT | UV_FS_O_WRONLY;
|
||||
writeExpect(absent_file, "bc", 2);
|
||||
readFail(absent_file, UV_EPERM);
|
||||
writeExpect(empty_file, "bc", 2);
|
||||
readFail(empty_file, UV_EPERM);
|
||||
writeExpect(dummy_file, "abc", 3);
|
||||
readFail(dummy_file, UV_EPERM);
|
||||
writeFail(empty_dir, UV_EISDIR);
|
||||
readFail(empty_dir, UV_EPERM);
|
||||
|
||||
/* ax */
|
||||
flags = add_flags | UV_FS_O_APPEND | UV_FS_O_CREAT | UV_FS_O_WRONLY |
|
||||
UV_FS_O_EXCL;
|
||||
writeExpect(absent_file, "bc", 2);
|
||||
readFail(absent_file, UV_EPERM);
|
||||
openFail(empty_file, UV_EEXIST);
|
||||
openFail(dummy_file, UV_EEXIST);
|
||||
openFail(empty_dir, UV_EEXIST);
|
||||
|
||||
/* as */
|
||||
flags = add_flags | UV_FS_O_APPEND | UV_FS_O_CREAT | UV_FS_O_WRONLY |
|
||||
UV_FS_O_SYNC;
|
||||
writeExpect(absent_file, "bc", 2);
|
||||
readFail(absent_file, UV_EPERM);
|
||||
writeExpect(empty_file, "bc", 2);
|
||||
readFail(empty_file, UV_EPERM);
|
||||
writeExpect(dummy_file, "abc", 3);
|
||||
readFail(dummy_file, UV_EPERM);
|
||||
writeFail(empty_dir, UV_EISDIR);
|
||||
readFail(empty_dir, UV_EPERM);
|
||||
|
||||
/* a+ */
|
||||
flags = add_flags | UV_FS_O_APPEND | UV_FS_O_CREAT | UV_FS_O_RDWR;
|
||||
writeExpect(absent_file, "bc", 2);
|
||||
readExpect(absent_file, "", 0);
|
||||
writeExpect(empty_file, "bc", 2);
|
||||
readExpect(empty_file, "", 0);
|
||||
writeExpect(dummy_file, "abc", 3);
|
||||
readExpect(dummy_file, "a", 1);
|
||||
writeFail(empty_dir, UV_EISDIR);
|
||||
readFail(empty_dir, UV_EISDIR);
|
||||
|
||||
/* ax+ */
|
||||
flags = add_flags | UV_FS_O_APPEND | UV_FS_O_CREAT | UV_FS_O_RDWR |
|
||||
UV_FS_O_EXCL;
|
||||
writeExpect(absent_file, "bc", 2);
|
||||
readExpect(absent_file, "", 0);
|
||||
openFail(empty_file, UV_EEXIST);
|
||||
openFail(dummy_file, UV_EEXIST);
|
||||
openFail(empty_dir, UV_EEXIST);
|
||||
|
||||
/* as+ */
|
||||
flags = add_flags | UV_FS_O_APPEND | UV_FS_O_CREAT | UV_FS_O_RDWR |
|
||||
UV_FS_O_SYNC;
|
||||
writeExpect(absent_file, "bc", 2);
|
||||
readExpect(absent_file, "", 0);
|
||||
writeExpect(empty_file, "bc", 2);
|
||||
readExpect(empty_file, "", 0);
|
||||
writeExpect(dummy_file, "abc", 3);
|
||||
readExpect(dummy_file, "a", 1);
|
||||
writeFail(empty_dir, UV_EISDIR);
|
||||
readFail(empty_dir, UV_EISDIR);
|
||||
}
|
||||
TEST_IMPL(fs_open_flags) {
|
||||
setup();
|
||||
|
||||
fs_open_flags(0);
|
||||
fs_open_flags(UV_FS_O_FILEMAP);
|
||||
|
||||
/* Cleanup. */
|
||||
rmdir(empty_dir);
|
||||
|
||||
MAKE_VALGRIND_HAPPY();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
typedef int file_has_no_tests; /* ISO C forbids an empty translation unit. */
|
||||
|
||||
#endif /* ifndef _WIN32 */
|
Reference in New Issue
Block a user