Files
apps
core
deps
base64c
codemirror
crypt_blowfish
libsodium
libuv
.github
docs
img
include
m4
src
test
fixtures
benchmark-async-pummel.c
benchmark-async.c
benchmark-fs-stat.c
benchmark-getaddrinfo.c
benchmark-list.h
benchmark-loop-count.c
benchmark-million-async.c
benchmark-million-timers.c
benchmark-multi-accept.c
benchmark-ping-pongs.c
benchmark-ping-udp.c
benchmark-pound.c
benchmark-pump.c
benchmark-queue-work.c
benchmark-sizes.c
benchmark-spawn.c
benchmark-tcp-write-batch.c
benchmark-thread.c
benchmark-udp-pummel.c
blackhole-server.c
echo-server.c
run-benchmarks.c
run-tests.c
runner-unix.c
runner-unix.h
runner-win.c
runner-win.h
runner.c
runner.h
task.h
test-active.c
test-async-null-cb.c
test-async.c
test-barrier.c
test-callback-stack.c
test-close-fd.c
test-close-order.c
test-condvar.c
test-connect-unspecified.c
test-connection-fail.c
test-cwd-and-chdir.c
test-default-loop-close.c
test-delayed-accept.c
test-dlerror.c
test-eintr-handling.c
test-embed.c
test-emfile.c
test-env-vars.c
test-error.c
test-fail-always.c
test-fork.c
test-fs-copyfile.c
test-fs-event.c
test-fs-fd-hash.c
test-fs-open-flags.c
test-fs-poll.c
test-fs-readdir.c
test-fs.c
test-get-currentexe.c
test-get-loadavg.c
test-get-memory.c
test-get-passwd.c
test-getaddrinfo.c
test-gethostname.c
test-getnameinfo.c
test-getsockname.c
test-getters-setters.c
test-gettimeofday.c
test-handle-fileno.c
test-homedir.c
test-hrtime.c
test-idle.c
test-idna.c
test-ip-name.c
test-ip4-addr.c
test-ip6-addr.c
test-ipc-heavy-traffic-deadlock-bug.c
test-ipc-send-recv.c
test-ipc.c
test-list.h
test-loop-alive.c
test-loop-close.c
test-loop-configure.c
test-loop-handles.c
test-loop-stop.c
test-loop-time.c
test-metrics.c
test-multiple-listen.c
test-mutexes.c
test-not-readable-nor-writable-on-read-error.c
test-not-writable-after-shutdown.c
test-osx-select.c
test-pass-always.c
test-ping-pong.c
test-pipe-bind-error.c
test-pipe-close-stdout-read-stdin.c
test-pipe-connect-error.c
test-pipe-connect-multiple.c
test-pipe-connect-prepare.c
test-pipe-getsockname.c
test-pipe-pending-instances.c
test-pipe-sendmsg.c
test-pipe-server-close.c
test-pipe-set-fchmod.c
test-pipe-set-non-blocking.c
test-platform-output.c
test-poll-close-doesnt-corrupt-stack.c
test-poll-close.c
test-poll-closesocket.c
test-poll-multiple-handles.c
test-poll-oob.c
test-poll.c
test-process-priority.c
test-process-title-threadsafe.c
test-process-title.c
test-queue-foreach-delete.c
test-random.c
test-readable-on-eof.c
test-ref.c
test-run-nowait.c
test-run-once.c
test-semaphore.c
test-shutdown-close.c
test-shutdown-eof.c
test-shutdown-simultaneous.c
test-shutdown-twice.c
test-signal-multiple-loops.c
test-signal-pending-on-close.c
test-signal.c
test-socket-buffer-size.c
test-spawn.c
test-stdio-over-pipes.c
test-strscpy.c
test-strtok.c
test-tcp-alloc-cb-fail.c
test-tcp-bind-error.c
test-tcp-bind6-error.c
test-tcp-close-accept.c
test-tcp-close-after-read-timeout.c
test-tcp-close-reset.c
test-tcp-close-while-connecting.c
test-tcp-close.c
test-tcp-connect-error-after-write.c
test-tcp-connect-error.c
test-tcp-connect-timeout.c
test-tcp-connect6-error.c
test-tcp-create-socket-early.c
test-tcp-flags.c
test-tcp-oob.c
test-tcp-open.c
test-tcp-read-stop-start.c
test-tcp-read-stop.c
test-tcp-rst.c
test-tcp-shutdown-after-write.c
test-tcp-try-write-error.c
test-tcp-try-write.c
test-tcp-unexpected-read.c
test-tcp-write-after-connect.c
test-tcp-write-fail.c
test-tcp-write-queue-order.c
test-tcp-write-to-half-open-connection.c
test-tcp-writealot.c
test-test-macros.c
test-thread-equal.c
test-thread.c
test-threadpool-cancel.c
test-threadpool.c
test-timer-again.c
test-timer-from-check.c
test-timer.c
test-tmpdir.c
test-tty-duplicate-key.c
test-tty-escape-sequence-processing.c
test-tty.c
test-udp-alloc-cb-fail.c
test-udp-bind.c
test-udp-connect.c
test-udp-connect6.c
test-udp-create-socket-early.c
test-udp-dgram-too-big.c
test-udp-ipv6.c
test-udp-mmsg.c
test-udp-multicast-interface.c
test-udp-multicast-interface6.c
test-udp-multicast-join.c
test-udp-multicast-join6.c
test-udp-multicast-ttl.c
test-udp-open.c
test-udp-options.c
test-udp-send-and-recv.c
test-udp-send-hang-loop.c
test-udp-send-immediate.c
test-udp-send-unreachable.c
test-udp-sendmmsg-error.c
test-udp-try-send.c
test-uname.c
test-walk-handles.c
test-watcher-cross-stop.c
tools
.gitattributes
.gitignore
.mailmap
.readthedocs.yaml
AUTHORS
CMakeLists.txt
CONTRIBUTING.md
ChangeLog
LICENSE
LICENSE-docs
LINKS.md
MAINTAINERS.md
Makefile.am
README.md
SUPPORTED_PLATFORMS.md
autogen.sh
configure.ac
libuv-static.pc.in
libuv.pc.in
uv_win_longpath.manifest
perfetto
quickjs
smoothie
split
sqlite
valgrind
xopt
docs
src
tools
.dockerignore
Dockerfile
LICENSE
Makefile
README.md
tildefriends/deps/libuv/test/test-strtok.c
2022-07-24 21:25:38 +00:00

91 lines
2.4 KiB
C

/* 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.
*/
#include "uv.h"
#include "task.h"
#include <string.h>
#include "../src/strtok.h"
#include "../src/strtok.c"
struct strtok_test_case {
const char* str;
const char* sep;
};
const char* tokens[] = {
"abc",
NULL,
"abc",
"abf",
NULL,
"This",
"is.a",
"test",
"of",
"the",
"string",
"tokenizer",
"function.",
NULL,
"Hello",
"This-is-a-nice",
"-string",
NULL
};
#define ASSERT_STRCMP(x, y) \
ASSERT((x != NULL && y != NULL && strcmp(x, y) == 0) || (x == y && x == NULL))
TEST_IMPL(strtok) {
struct strtok_test_case tests[] = {
{ "abc", "" },
{ "abc.abf", "." },
{ "This;is.a:test:of=the/string\\tokenizer-function.", "\\/:;=-" },
{ "Hello This-is-a-nice.-string", " ." },
};
size_t tokens_len = ARRAY_SIZE(tokens);
size_t tests_len = ARRAY_SIZE(tests);
size_t i;
size_t j;
char* itr;
char* tok_r;
char current_test[2048];
for (i = 0, j = 0; i < tests_len; i += 1) {
ASSERT(j < tokens_len);
snprintf(current_test, sizeof(current_test), "%s", tests[i].str);
tok_r = uv__strtok(current_test, tests[i].sep, &itr);
ASSERT_STRCMP(tok_r, tokens[j]);
j++;
while (tok_r) {
ASSERT(j < tokens_len);
tok_r = uv__strtok(NULL, tests[i].sep, &itr);
ASSERT_STRCMP(tok_r, tokens[j]);
j++;
}
}
return 0;
}