fix spelling error
This commit is contained in:
parent
d5b47632b5
commit
0781b98a37
16
Makefile
16
Makefile
|
@ -2,23 +2,23 @@ OUT=libscomp.a
|
||||||
VERSION=0.1.0
|
VERSION=0.1.0
|
||||||
TESTS=test/input test/exec
|
TESTS=test/input test/exec
|
||||||
|
|
||||||
all: $(OUT) libscomm_amalg.c libscomm_amalg.h
|
all: $(OUT) libscomp_amalg.c libscomp_amalg.h
|
||||||
$(OUT): input.o exec.o
|
$(OUT): input.o exec.o
|
||||||
$(AR) rcs $(OUT) input.o exec.o
|
$(AR) rcs $(OUT) input.o exec.o
|
||||||
tests: $(TESTS)
|
tests: $(TESTS)
|
||||||
for i in $(TESTS); do ./$$i -v; done
|
for i in $(TESTS); do ./$$i -v; done
|
||||||
|
|
||||||
libscomm_amalg.h: exec.h input.h
|
libscomp_amalg.h: exec.h input.h
|
||||||
echo '#pragma once' > libscomm_amalg.h
|
echo '#pragma once' > libscomp_amalg.h
|
||||||
echo '#define LIBSCOMM_VERSION "${VERSION}"' >> libscomm_amalg.h
|
echo '#define LIBSCOMP_VERSION "${VERSION}"' >> libscomp_amalg.h
|
||||||
cat input.h exec.h | \
|
cat input.h exec.h | \
|
||||||
sed 's/#pragma .*//g; s/#include ".*//g' \
|
sed 's/#pragma .*//g; s/#include ".*//g' \
|
||||||
>> libscomm_amalg.h
|
>> libscomp_amalg.h
|
||||||
|
|
||||||
libscomm_amalg.c: exec.c input.c
|
libscomp_amalg.c: exec.c input.c
|
||||||
echo '#include "libscomm_amalg.h"' > libscomm_amalg.c
|
echo '#include "libscomp_amalg.h"' > libscomp_amalg.c
|
||||||
cat exec.c input.c | sed 's/#include ".*//g' \
|
cat exec.c input.c | sed 's/#include ".*//g' \
|
||||||
>> libscomm_amalg.c
|
>> libscomp_amalg.c
|
||||||
|
|
||||||
TEST_EXEC=test/exec.o exec.o
|
TEST_EXEC=test/exec.o exec.o
|
||||||
test/exec: $(TEST_EXEC)
|
test/exec: $(TEST_EXEC)
|
||||||
|
|
14
exec.c
14
exec.c
|
@ -1,6 +1,6 @@
|
||||||
#include "exec.h"
|
#include "exec.h"
|
||||||
|
|
||||||
#ifdef LIBSCOMM_FREESTANDING
|
#ifdef LIBSCOMP_FREESTANDING
|
||||||
int strcmp(const char *s1, const char *s2) {
|
int strcmp(const char *s1, const char *s2) {
|
||||||
while (*s1 == *s2) {
|
while (*s1 == *s2) {
|
||||||
if (!*s1)
|
if (!*s1)
|
||||||
|
@ -15,8 +15,8 @@ int strcmp(const char *s1, const char *s2) {
|
||||||
# include <string.h>
|
# include <string.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct libscomm_cmd *hg_bsearch(const char *name,
|
struct libscomp_cmd *hg_bsearch(const char *name,
|
||||||
const struct libscomm_cmd_store *cmds) {
|
const struct libscomp_cmd_store *cmds) {
|
||||||
size_t lower = 0, upper = cmds->len-1;
|
size_t lower = 0, upper = cmds->len-1;
|
||||||
size_t i;
|
size_t i;
|
||||||
int rel;
|
int rel;
|
||||||
|
@ -36,12 +36,12 @@ struct libscomm_cmd *hg_bsearch(const char *name,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int libscomm_exec(const struct libscomm_cmd_store *cmds,
|
int libscomp_exec(const struct libscomp_cmd_store *cmds,
|
||||||
struct libscomm_line *ln, void *ptr) {
|
struct libscomp_line *ln, void *ptr) {
|
||||||
struct libscomm_cmd *cmd;
|
struct libscomp_cmd *cmd;
|
||||||
|
|
||||||
cmd = hg_bsearch(ln->buf[ln->name], cmds);
|
cmd = hg_bsearch(ln->buf[ln->name], cmds);
|
||||||
if (!cmd)
|
if (!cmd)
|
||||||
return LIBSCOMM_NOT_FOUND;
|
return LIBSCOMP_NOT_FOUND;
|
||||||
return cmd->exec(ln,ptr);
|
return cmd->exec(ln,ptr);
|
||||||
}
|
}
|
||||||
|
|
24
exec.h
24
exec.h
|
@ -1,27 +1,27 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
|
|
||||||
enum libscomm_cmd_r {
|
enum libscomp_cmd_r {
|
||||||
LIBSCOMM_NOT_FOUND = -1,
|
LIBSCOMP_NOT_FOUND = -1,
|
||||||
LIBSCOMM_CMD_OK = 0
|
LIBSCOMP_CMD_OK = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
struct libscomm_cmd {
|
struct libscomp_cmd {
|
||||||
const char *name;
|
const char *name;
|
||||||
int (*exec)(struct libscomm_line *, void *);
|
int (*exec)(struct libscomp_line *, void *);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct libscomm_cmd_store {
|
struct libscomp_cmd_store {
|
||||||
struct libscomm_cmd *arr;
|
struct libscomp_cmd *arr;
|
||||||
size_t len;
|
size_t len;
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined(__STDC_VERSION__)
|
#if defined(__STDC_VERSION__)
|
||||||
#define libscomm_mkcmds(...) {(struct libscomm_cmd []){__VA_ARGS__}, \
|
#define libscomp_mkcmds(...) {(struct libscomp_cmd []){__VA_ARGS__}, \
|
||||||
sizeof((struct libscomm_cmd []){__VA_ARGS__}) / \
|
sizeof((struct libscomp_cmd []){__VA_ARGS__}) / \
|
||||||
sizeof((struct libscomm_cmd []){__VA_ARGS__}[0])}
|
sizeof((struct libscomp_cmd []){__VA_ARGS__}[0])}
|
||||||
#endif
|
#endif
|
||||||
int libscomm_exec(const struct libscomm_cmd_store *cmds,
|
int libscomp_exec(const struct libscomp_cmd_store *cmds,
|
||||||
struct libscomm_line *ln,
|
struct libscomp_line *ln,
|
||||||
void *ptr
|
void *ptr
|
||||||
);
|
);
|
||||||
|
|
36
input.c
36
input.c
|
@ -1,26 +1,26 @@
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
|
|
||||||
enum { LIBSCOMM_READ, LIBSCOMM_DISCARD };
|
enum { LIBSCOMP_READ, LIBSCOMP_DISCARD };
|
||||||
|
|
||||||
void libscomm_reset(struct libscomm_input *in) {
|
void libscomp_reset(struct libscomp_input *in) {
|
||||||
in->state = LIBSCOMM_READ;
|
in->state = LIBSCOMP_READ;
|
||||||
in->len = 0;
|
in->len = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum libscomm_input_r libscomm_parse(
|
static enum libscomp_input_r libscomp_parse(
|
||||||
struct libscomm_input *in, struct libscomm_line *line) {
|
struct libscomp_input *in, struct libscomp_line *line) {
|
||||||
char *s = in->intbuf;
|
char *s = in->intbuf;
|
||||||
enum libscomm_input_r r = LIBSCOMM_ARG_OVERFLOW;
|
enum libscomp_input_r r = LIBSCOMP_ARG_OVERFLOW;
|
||||||
|
|
||||||
line->name = (*s == ':');
|
line->name = (*s == ':');
|
||||||
line->len = 0;
|
line->len = 0;
|
||||||
|
|
||||||
while (line->len < LIBSCOMM_MAXARG) {
|
while (line->len < LIBSCOMP_MAXARG) {
|
||||||
line->buf[line->len++] = s;
|
line->buf[line->len++] = s;
|
||||||
for (; *s && *s != '\t'; s++);
|
for (; *s && *s != '\t'; s++);
|
||||||
|
|
||||||
if (!*s) {
|
if (!*s) {
|
||||||
r = LIBSCOMM_COMPLETE;
|
r = LIBSCOMP_COMPLETE;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
*s = 0;
|
*s = 0;
|
||||||
|
@ -28,35 +28,35 @@ static enum libscomm_input_r libscomm_parse(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
libscomm_reset(in);
|
libscomp_reset(in);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum libscomm_input_r libscomm_read(struct libscomm_input *in,
|
enum libscomp_input_r libscomp_read(struct libscomp_input *in,
|
||||||
char **s,
|
char **s,
|
||||||
struct libscomm_line *line) {
|
struct libscomp_line *line) {
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
while ((c = **s)) {
|
while ((c = **s)) {
|
||||||
(*s)++;
|
(*s)++;
|
||||||
|
|
||||||
if (in->state == LIBSCOMM_DISCARD) {
|
if (in->state == LIBSCOMP_DISCARD) {
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
libscomm_reset(in);
|
libscomp_reset(in);
|
||||||
return LIBSCOMM_OVERFLOW;
|
return LIBSCOMP_OVERFLOW;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case '\n':
|
case '\n':
|
||||||
in->intbuf[in->len] = 0;
|
in->intbuf[in->len] = 0;
|
||||||
return libscomm_parse(in, line);
|
return libscomp_parse(in, line);
|
||||||
default:
|
default:
|
||||||
in->intbuf[in->len++] = c;
|
in->intbuf[in->len++] = c;
|
||||||
if (in->len == LIBSCOMM_MAXBUF)
|
if (in->len == LIBSCOMP_MAXBUF)
|
||||||
in->state = LIBSCOMM_DISCARD;
|
in->state = LIBSCOMP_DISCARD;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return LIBSCOMM_MORE;
|
return LIBSCOMP_MORE;
|
||||||
}
|
}
|
||||||
|
|
28
input.h
28
input.h
|
@ -1,30 +1,30 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
#define LIBSCOMM_MAXARG 32
|
#define LIBSCOMP_MAXARG 32
|
||||||
#define LIBSCOMM_MAXBUF 1024
|
#define LIBSCOMP_MAXBUF 1024
|
||||||
|
|
||||||
struct libscomm_line {
|
struct libscomp_line {
|
||||||
size_t name;
|
size_t name;
|
||||||
char *buf[LIBSCOMM_MAXARG];
|
char *buf[LIBSCOMP_MAXARG];
|
||||||
size_t len;
|
size_t len;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct libscomm_input {
|
struct libscomp_input {
|
||||||
int state;
|
int state;
|
||||||
|
|
||||||
char intbuf[LIBSCOMM_MAXBUF];
|
char intbuf[LIBSCOMP_MAXBUF];
|
||||||
size_t len;
|
size_t len;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum libscomm_input_r {
|
enum libscomp_input_r {
|
||||||
LIBSCOMM_MORE,
|
LIBSCOMP_MORE,
|
||||||
LIBSCOMM_OVERFLOW,
|
LIBSCOMP_OVERFLOW,
|
||||||
LIBSCOMM_ARG_OVERFLOW,
|
LIBSCOMP_ARG_OVERFLOW,
|
||||||
LIBSCOMM_COMPLETE
|
LIBSCOMP_COMPLETE
|
||||||
};
|
};
|
||||||
|
|
||||||
void libscomm_reset(struct libscomm_input *);
|
void libscomp_reset(struct libscomp_input *);
|
||||||
enum libscomm_input_r libscomm_read(struct libscomm_input *,
|
enum libscomp_input_r libscomp_read(struct libscomp_input *,
|
||||||
char **,
|
char **,
|
||||||
struct libscomm_line *);
|
struct libscomp_line *);
|
||||||
|
|
26
test/exec.c
26
test/exec.c
|
@ -2,12 +2,12 @@
|
||||||
#include "../exec.h"
|
#include "../exec.h"
|
||||||
|
|
||||||
#define mkfun(f, n) \
|
#define mkfun(f, n) \
|
||||||
int f(struct libscomm_line *x __attribute__((unused)), \
|
int f(struct libscomp_line *x __attribute__((unused)), \
|
||||||
void *ptr __attribute__((unused))) { \
|
void *ptr __attribute__((unused))) { \
|
||||||
return n; \
|
return n; \
|
||||||
}
|
}
|
||||||
|
|
||||||
mkfun(foo, LIBSCOMM_CMD_OK)
|
mkfun(foo, LIBSCOMP_CMD_OK)
|
||||||
mkfun(bar, 1)
|
mkfun(bar, 1)
|
||||||
mkfun(ocmd, 2)
|
mkfun(ocmd, 2)
|
||||||
mkfun(baz, 3)
|
mkfun(baz, 3)
|
||||||
|
@ -20,32 +20,32 @@ mkfun(yan, 9)
|
||||||
mkfun(val, 10)
|
mkfun(val, 10)
|
||||||
mkfun(cal, 11)
|
mkfun(cal, 11)
|
||||||
|
|
||||||
struct libscomm_cmd cmdarr[] = {
|
struct libscomp_cmd cmdarr[] = {
|
||||||
{"apple", apple}, {"bar", bar}, {"baz", baz}, {"cal", cal},
|
{"apple", apple}, {"bar", bar}, {"baz", baz}, {"cal", cal},
|
||||||
{"foo", foo}, {"ocmd", ocmd}, {"quox", quox}, {"rex", rex},
|
{"foo", foo}, {"ocmd", ocmd}, {"quox", quox}, {"rex", rex},
|
||||||
{"test1", test1}, {"under", under}, {"val", val}, {"yan", yan}
|
{"test1", test1}, {"under", under}, {"val", val}, {"yan", yan}
|
||||||
};
|
};
|
||||||
#define arrlen(x) (sizeof(x) / sizeof((x)[0]))
|
#define arrlen(x) (sizeof(x) / sizeof((x)[0]))
|
||||||
const struct libscomm_cmd_store cmds = {cmdarr, arrlen(cmdarr)};
|
const struct libscomp_cmd_store cmds = {cmdarr, arrlen(cmdarr)};
|
||||||
|
|
||||||
#define doexec(f, n) do{\
|
#define doexec(f, n) do{\
|
||||||
x.buf[0] = f; \
|
x.buf[0] = f; \
|
||||||
ASSERT_EQ(libscomm_exec(&cmds, &x, NULL), n); \
|
ASSERT_EQ(libscomp_exec(&cmds, &x, NULL), n); \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
TEST execute_one(void) {
|
TEST execute_one(void) {
|
||||||
struct libscomm_line x = {0};
|
struct libscomp_line x = {0};
|
||||||
x.len = 1;
|
x.len = 1;
|
||||||
|
|
||||||
doexec("foo", LIBSCOMM_CMD_OK);
|
doexec("foo", LIBSCOMP_CMD_OK);
|
||||||
PASS();
|
PASS();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST execute_multiple(void) {
|
TEST execute_multiple(void) {
|
||||||
struct libscomm_line x = {0};
|
struct libscomp_line x = {0};
|
||||||
x.len = 1;
|
x.len = 1;
|
||||||
|
|
||||||
doexec("foo", LIBSCOMM_CMD_OK);
|
doexec("foo", LIBSCOMP_CMD_OK);
|
||||||
doexec("bar", 1);
|
doexec("bar", 1);
|
||||||
doexec("ocmd", 2);
|
doexec("ocmd", 2);
|
||||||
doexec("baz", 3);
|
doexec("baz", 3);
|
||||||
|
@ -62,12 +62,12 @@ TEST execute_multiple(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST not_in(void) {
|
TEST not_in(void) {
|
||||||
struct libscomm_line x = {0};
|
struct libscomp_line x = {0};
|
||||||
x.len = 1;
|
x.len = 1;
|
||||||
|
|
||||||
doexec("test2", LIBSCOMM_NOT_FOUND);
|
doexec("test2", LIBSCOMP_NOT_FOUND);
|
||||||
doexec("flub", LIBSCOMM_NOT_FOUND);
|
doexec("flub", LIBSCOMP_NOT_FOUND);
|
||||||
doexec("doexec", LIBSCOMM_NOT_FOUND);
|
doexec("doexec", LIBSCOMP_NOT_FOUND);
|
||||||
|
|
||||||
PASS();
|
PASS();
|
||||||
}
|
}
|
||||||
|
|
86
test/input.c
86
test/input.c
|
@ -2,13 +2,13 @@
|
||||||
#include "../input.h"
|
#include "../input.h"
|
||||||
|
|
||||||
TEST one_pass(void) {
|
TEST one_pass(void) {
|
||||||
struct libscomm_input in;
|
struct libscomp_input in;
|
||||||
char s[] = "Arg 1\tArg \r\v\t!\n";
|
char s[] = "Arg 1\tArg \r\v\t!\n";
|
||||||
char *p = s;
|
char *p = s;
|
||||||
struct libscomm_line l;
|
struct libscomp_line l;
|
||||||
|
|
||||||
libscomm_reset(&in);
|
libscomp_reset(&in);
|
||||||
ASSERT_EQ(libscomm_read(&in, &p, &l), LIBSCOMM_COMPLETE);
|
ASSERT_EQ(libscomp_read(&in, &p, &l), LIBSCOMP_COMPLETE);
|
||||||
ASSERT_EQ(l.len, 3);
|
ASSERT_EQ(l.len, 3);
|
||||||
ASSERT_EQ(l.name, 0);
|
ASSERT_EQ(l.name, 0);
|
||||||
ASSERT_EQ(*p, 0);
|
ASSERT_EQ(*p, 0);
|
||||||
|
@ -22,33 +22,33 @@ TEST one_pass(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST line_limit(void) {
|
TEST line_limit(void) {
|
||||||
struct libscomm_input in;
|
struct libscomp_input in;
|
||||||
struct libscomm_line l;
|
struct libscomp_line l;
|
||||||
char s[LIBSCOMM_MAXBUF + 1];
|
char s[LIBSCOMP_MAXBUF + 1];
|
||||||
char *p = s;
|
char *p = s;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < LIBSCOMM_MAXBUF - 1; i++) {
|
for (i = 0; i < LIBSCOMP_MAXBUF - 1; i++) {
|
||||||
s[i] = (i + 1) % 64 ? 'a' : '\t';
|
s[i] = (i + 1) % 64 ? 'a' : '\t';
|
||||||
}
|
}
|
||||||
s[LIBSCOMM_MAXBUF - 1] = '\n';
|
s[LIBSCOMP_MAXBUF - 1] = '\n';
|
||||||
s[LIBSCOMM_MAXBUF] = 0;
|
s[LIBSCOMP_MAXBUF] = 0;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
if (GREATEST_IS_VERBOSE())
|
if (GREATEST_IS_VERBOSE())
|
||||||
fprintf(stderr, "%s", s);
|
fprintf(stderr, "%s", s);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
libscomm_reset(&in);
|
libscomp_reset(&in);
|
||||||
ASSERT_EQ(libscomm_read(&in, &p, &l), LIBSCOMM_COMPLETE);
|
ASSERT_EQ(libscomp_read(&in, &p, &l), LIBSCOMP_COMPLETE);
|
||||||
ASSERT_EQ(p, &s[LIBSCOMM_MAXBUF]);
|
ASSERT_EQ(p, &s[LIBSCOMP_MAXBUF]);
|
||||||
PASS();
|
PASS();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST single_arg_too_large(void) {
|
TEST single_arg_too_large(void) {
|
||||||
struct libscomm_input in;
|
struct libscomp_input in;
|
||||||
struct libscomm_line l;
|
struct libscomp_line l;
|
||||||
char s[LIBSCOMM_MAXBUF + 12];
|
char s[LIBSCOMP_MAXBUF + 12];
|
||||||
char *p;
|
char *p;
|
||||||
size_t i;
|
size_t i;
|
||||||
int ostate;
|
int ostate;
|
||||||
|
@ -59,31 +59,31 @@ TEST single_arg_too_large(void) {
|
||||||
s[sizeof s - 1] = 0;
|
s[sizeof s - 1] = 0;
|
||||||
p = s;
|
p = s;
|
||||||
|
|
||||||
libscomm_reset(&in);
|
libscomp_reset(&in);
|
||||||
ASSERT_EQ(libscomm_read(&in, &p, &l), LIBSCOMM_OVERFLOW);
|
ASSERT_EQ(libscomp_read(&in, &p, &l), LIBSCOMP_OVERFLOW);
|
||||||
ASSERT_EQ(p, &s[sizeof s - 1]);
|
ASSERT_EQ(p, &s[sizeof s - 1]);
|
||||||
|
|
||||||
ASSERT_EQ(in.len, 0);
|
ASSERT_EQ(in.len, 0);
|
||||||
|
|
||||||
/* state values are opaque. */
|
/* state values are opaque. */
|
||||||
ostate = in.state;
|
ostate = in.state;
|
||||||
libscomm_reset(&in);
|
libscomp_reset(&in);
|
||||||
ASSERT_EQ(ostate, in.state);
|
ASSERT_EQ(ostate, in.state);
|
||||||
PASS();
|
PASS();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST arg_limit(void) {
|
TEST arg_limit(void) {
|
||||||
struct libscomm_input in;
|
struct libscomp_input in;
|
||||||
struct libscomm_line l;
|
struct libscomp_line l;
|
||||||
char s[] = " 1\t 2\t 3\t 4\t 5\t 6\t 7\t 8\t 9\t 10\t 11\t 12\t 13\t 14\t 15\t 16\t 17\t 18\t 19\t 20\t 21\t 22\t 23\t 24\t 25\t 26\t 27\t 28\t 29\t 30\t 31\t 32\n";
|
char s[] = " 1\t 2\t 3\t 4\t 5\t 6\t 7\t 8\t 9\t 10\t 11\t 12\t 13\t 14\t 15\t 16\t 17\t 18\t 19\t 20\t 21\t 22\t 23\t 24\t 25\t 26\t 27\t 28\t 29\t 30\t 31\t 32\n";
|
||||||
char *p = s;
|
char *p = s;
|
||||||
char tbuf[10];
|
char tbuf[10];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
libscomm_reset(&in);
|
libscomp_reset(&in);
|
||||||
ASSERT_EQ(libscomm_read(&in, &p, &l), LIBSCOMM_COMPLETE);
|
ASSERT_EQ(libscomp_read(&in, &p, &l), LIBSCOMP_COMPLETE);
|
||||||
ASSERT_EQ(l.name, 0);
|
ASSERT_EQ(l.name, 0);
|
||||||
ASSERT_EQ(l.len, LIBSCOMM_MAXARG);
|
ASSERT_EQ(l.len, LIBSCOMP_MAXARG);
|
||||||
ASSERT_EQ(p, &s[sizeof s - 1]);
|
ASSERT_EQ(p, &s[sizeof s - 1]);
|
||||||
|
|
||||||
for (i = 1; i <= l.len; i++) {
|
for (i = 1; i <= l.len; i++) {
|
||||||
|
@ -95,32 +95,32 @@ TEST arg_limit(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST too_many_arg(void) {
|
TEST too_many_arg(void) {
|
||||||
struct libscomm_input in;
|
struct libscomp_input in;
|
||||||
struct libscomm_line l;
|
struct libscomp_line l;
|
||||||
char s[] = " 1\t 2\t 3\t 4\t 5\t 6\t 7\t 8\t 9\t 10\t 11\t 12\t 13\t 14\t 15\t 16\t 17\t 18\t 19\t 20\t 21\t 22\t 23\t 24\t 25\t 26\t 27\t 28\t 29\t 30\t 31\t 32\t 33\n";
|
char s[] = " 1\t 2\t 3\t 4\t 5\t 6\t 7\t 8\t 9\t 10\t 11\t 12\t 13\t 14\t 15\t 16\t 17\t 18\t 19\t 20\t 21\t 22\t 23\t 24\t 25\t 26\t 27\t 28\t 29\t 30\t 31\t 32\t 33\n";
|
||||||
char *p = s;
|
char *p = s;
|
||||||
|
|
||||||
libscomm_reset(&in);
|
libscomp_reset(&in);
|
||||||
ASSERT_EQ(libscomm_read(&in, &p, &l), LIBSCOMM_ARG_OVERFLOW);
|
ASSERT_EQ(libscomp_read(&in, &p, &l), LIBSCOMP_ARG_OVERFLOW);
|
||||||
ASSERT_EQ(p, &s[sizeof s - 1]);
|
ASSERT_EQ(p, &s[sizeof s - 1]);
|
||||||
PASS();
|
PASS();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST two_in_one(void) {
|
TEST two_in_one(void) {
|
||||||
struct libscomm_input in;
|
struct libscomp_input in;
|
||||||
struct libscomm_line l;
|
struct libscomp_line l;
|
||||||
char s[] = "Arg 1\tArg 2\tArg 3\nArg 4\tArg 5\tArg 6\tArg 7\n";
|
char s[] = "Arg 1\tArg 2\tArg 3\nArg 4\tArg 5\tArg 6\tArg 7\n";
|
||||||
char *p = s;
|
char *p = s;
|
||||||
|
|
||||||
libscomm_reset(&in);
|
libscomp_reset(&in);
|
||||||
ASSERT_EQ(libscomm_read(&in, &p, &l), LIBSCOMM_COMPLETE);
|
ASSERT_EQ(libscomp_read(&in, &p, &l), LIBSCOMP_COMPLETE);
|
||||||
ASSERT_EQ(l.name, 0);
|
ASSERT_EQ(l.name, 0);
|
||||||
ASSERT_EQ(l.len, 3);
|
ASSERT_EQ(l.len, 3);
|
||||||
ASSERT_STR_EQ(l.buf[0], "Arg 1");
|
ASSERT_STR_EQ(l.buf[0], "Arg 1");
|
||||||
ASSERT_STR_EQ(l.buf[1], "Arg 2");
|
ASSERT_STR_EQ(l.buf[1], "Arg 2");
|
||||||
ASSERT_STR_EQ(l.buf[2], "Arg 3");
|
ASSERT_STR_EQ(l.buf[2], "Arg 3");
|
||||||
|
|
||||||
ASSERT_EQ(libscomm_read(&in, &p, &l), LIBSCOMM_COMPLETE);
|
ASSERT_EQ(libscomp_read(&in, &p, &l), LIBSCOMP_COMPLETE);
|
||||||
ASSERT_EQ(l.name, 0);
|
ASSERT_EQ(l.name, 0);
|
||||||
ASSERT_EQ(l.len, 4);
|
ASSERT_EQ(l.len, 4);
|
||||||
ASSERT_STR_EQ(l.buf[0], "Arg 4");
|
ASSERT_STR_EQ(l.buf[0], "Arg 4");
|
||||||
|
@ -132,13 +132,13 @@ TEST two_in_one(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST label(void) {
|
TEST label(void) {
|
||||||
struct libscomm_input in;
|
struct libscomp_input in;
|
||||||
struct libscomm_line l;
|
struct libscomp_line l;
|
||||||
char s[] = ":N a m e\tArg 1\tArg 2\tArg 3\n";
|
char s[] = ":N a m e\tArg 1\tArg 2\tArg 3\n";
|
||||||
char *p = s;
|
char *p = s;
|
||||||
|
|
||||||
libscomm_reset(&in);
|
libscomp_reset(&in);
|
||||||
ASSERT_EQ(libscomm_read(&in, &p, &l), LIBSCOMM_COMPLETE);
|
ASSERT_EQ(libscomp_read(&in, &p, &l), LIBSCOMP_COMPLETE);
|
||||||
ASSERT_EQ(l.name, 1);
|
ASSERT_EQ(l.name, 1);
|
||||||
ASSERT_EQ(l.len, 4);
|
ASSERT_EQ(l.len, 4);
|
||||||
ASSERT_STR_EQ(l.buf[0], ":N a m e");
|
ASSERT_STR_EQ(l.buf[0], ":N a m e");
|
||||||
|
@ -150,23 +150,23 @@ TEST label(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST split(void) {
|
TEST split(void) {
|
||||||
struct libscomm_input in;
|
struct libscomp_input in;
|
||||||
struct libscomm_line l;
|
struct libscomp_line l;
|
||||||
char s1[] = ":123456\tArg 1\tArg 2\tAr";
|
char s1[] = ":123456\tArg 1\tArg 2\tAr";
|
||||||
char s2[] = "g 3\tArg 4\tArg 5\tArg 6";
|
char s2[] = "g 3\tArg 4\tArg 5\tArg 6";
|
||||||
char s3[] = "\n";
|
char s3[] = "\n";
|
||||||
char *p = s1;
|
char *p = s1;
|
||||||
|
|
||||||
libscomm_reset(&in);
|
libscomp_reset(&in);
|
||||||
ASSERT_EQ(libscomm_read(&in, &p, &l), LIBSCOMM_MORE);
|
ASSERT_EQ(libscomp_read(&in, &p, &l), LIBSCOMP_MORE);
|
||||||
ASSERT_EQ(p, &s1[sizeof s1 - 1]);
|
ASSERT_EQ(p, &s1[sizeof s1 - 1]);
|
||||||
|
|
||||||
p = s2;
|
p = s2;
|
||||||
ASSERT_EQ(libscomm_read(&in, &p, &l), LIBSCOMM_MORE);
|
ASSERT_EQ(libscomp_read(&in, &p, &l), LIBSCOMP_MORE);
|
||||||
ASSERT_EQ(p, &s2[sizeof s2 - 1]);
|
ASSERT_EQ(p, &s2[sizeof s2 - 1]);
|
||||||
|
|
||||||
p = s3;
|
p = s3;
|
||||||
ASSERT_EQ(libscomm_read(&in, &p, &l), LIBSCOMM_COMPLETE);
|
ASSERT_EQ(libscomp_read(&in, &p, &l), LIBSCOMP_COMPLETE);
|
||||||
ASSERT_EQ(p, &s3[sizeof s3 - 1]);
|
ASSERT_EQ(p, &s3[sizeof s3 - 1]);
|
||||||
|
|
||||||
ASSERT_EQ(l.name, 1);
|
ASSERT_EQ(l.name, 1);
|
||||||
|
|
Loading…
Reference in New Issue