libscomp/test/input.c

57 lines
1.1 KiB
C
Raw Normal View History

2021-07-10 15:10:00 -04:00
#include "greatest.h"
#include "../input.h"
TEST one_pass(void) {
struct libscomm_input in;
char s[] = "Arg 1\tArg \r\v\t!\n";
char *p = s;
2021-07-10 15:10:00 -04:00
struct libscomm_line l;
libscomm_reset(&in);
ASSERT_EQ(libscomm_read(&in, &p, &l), LIBSCOMM_COMPLETE);
2021-07-10 15:10:00 -04:00
ASSERT_EQ(l.len, 3);
ASSERT_EQ(l.name, 0);
ASSERT_EQ(*p, 0);
ASSERT_EQ(p, &s[sizeof s - 1]);
2021-07-10 15:10:00 -04:00
ASSERT_STR_EQ(l.buf[0], "Arg 1");
ASSERT_STR_EQ(l.buf[1], "Arg \r\v");
ASSERT_STR_EQ(l.buf[2], "!");
PASS();
}
TEST single_arg_too_large(void) {
struct libscomm_input in;
struct libscomm_line l;
char s[LIBSCOMM_MAXBUF + 12];
2021-07-10 15:28:08 -04:00
char *p;
size_t i;
2021-07-10 15:28:08 -04:00
int ostate;
for (i = 0; i < sizeof s; i++)
s[i] = 'a';
2021-07-10 15:28:08 -04:00
s[sizeof s - 2] = '\n';
s[sizeof s - 1] = 0;
p = s;
libscomm_reset(&in);
ASSERT_EQ(libscomm_read(&in, &p, &l), LIBSCOMM_OVERFLOW);
ASSERT_EQ(in.len, 0);
/* state values are opaque. */
ostate = in.state;
libscomm_reset(&in);
ASSERT_EQ(ostate, in.state);
PASS();
}
2021-07-10 15:10:00 -04:00
GREATEST_MAIN_DEFS();
int main(int argc, char *argv[]) {
GREATEST_MAIN_BEGIN();
RUN_TEST(one_pass);
2021-07-10 15:28:08 -04:00
RUN_TEST(single_arg_too_large);
2021-07-10 15:10:00 -04:00
GREATEST_MAIN_END();
}