From 5d8801d4687035ae45143f0f3bc3eeaf75dc17ec Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Mon, 11 Aug 2014 23:26:36 +0200 Subject: Upgrade code to iodine 0.7.0 and improve logging --- jni/iodine/tests/Makefile | 14 ++- jni/iodine/tests/base32.c | 10 ++- jni/iodine/tests/base64.c | 6 +- jni/iodine/tests/common.c | 203 ++++++++++++++++++++++++++++++++++++++++++++ jni/iodine/tests/dns.c | 11 ++- jni/iodine/tests/encoding.c | 5 +- jni/iodine/tests/fw_query.c | 8 +- jni/iodine/tests/login.c | 3 +- jni/iodine/tests/read.c | 20 ++--- jni/iodine/tests/test.c | 6 +- jni/iodine/tests/test.h | 8 +- jni/iodine/tests/user.c | 49 ++++++----- 12 files changed, 284 insertions(+), 59 deletions(-) create mode 100644 jni/iodine/tests/common.c (limited to 'jni/iodine/tests') diff --git a/jni/iodine/tests/Makefile b/jni/iodine/tests/Makefile index 3a7ac01..03eed98 100644 --- a/jni/iodine/tests/Makefile +++ b/jni/iodine/tests/Makefile @@ -1,26 +1,24 @@ -CC = gcc TEST = test -OBJS = test.o base32.o base64.o read.o dns.o encoding.o login.o user.o fw_query.o -SRCOBJS = ../src/base32.o ../src/base64.o ../src/read.o ../src/dns.o ../src/encoding.o ../src/login.o ../src/md5.o ../src/user.o ../src/fw_query.o +OBJS = test.o base32.o base64.o common.o read.o dns.o encoding.o login.o user.o fw_query.o +SRCOBJS = ../src/base32.o ../src/base64.o ../src/common.o ../src/read.o ../src/dns.o ../src/encoding.o ../src/login.o ../src/md5.o ../src/user.o ../src/fw_query.o OS = `uname | tr "a-z" "A-Z"` CHECK_PATH = /usr/local -LDFLAGS = -L$(CHECK_PATH)/lib -lcheck `../src/osflags link` -CFLAGS = -g -Wall -D$(OS) -I../src -I$(CHECK_PATH)/include -pedantic `../src/osflags cflags` +LDFLAGS = -L$(CHECK_PATH)/lib `pkg-config check --libs` -lpthread `sh ../src/osflags $(TARGETOS) link` +CFLAGS = -std=c99 -g -Wall -D$(OS) `pkg-config check --cflags` -I../src -I$(CHECK_PATH)/include -pedantic `sh ../src/osflags $(TARGETOS) cflags` all: $(TEST) @LD_LIBRARY_PATH=${CHECK_PATH}/lib ./$(TEST) $(TEST): $(OBJS) $(SRCOBJS) @echo LD $(TEST) - @$(CC) -o $@ $(SRCOBJS) $(OBJS) $(LDFLAGS) + @$(CC) -o $@ $(SRCOBJS) $(OBJS) $(LDFLAGS) -.c.o: +.c.o: @echo CC $< @$(CC) $(CFLAGS) -c $< - clean: @echo "Cleaning tests/" @rm -f *~ *.core $(TEST) $(OBJS) diff --git a/jni/iodine/tests/base32.c b/jni/iodine/tests/base32.c index 9ff0cf7..419253f 100644 --- a/jni/iodine/tests/base32.c +++ b/jni/iodine/tests/base32.c @@ -1,5 +1,6 @@ /* - * Copyright (c) 2006-2009 Bjorn Andersson , Erik Ekman + * Copyright (c) 2006-2014 Erik Ekman , + * 2006-2009 Bjorn Andersson * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -50,6 +51,7 @@ START_TEST(test_base32_encode) len = sizeof(buf); val = b32->encode(buf, &len, testpairs[_i].a, strlen(testpairs[_i].a)); + fail_unless(val == strlen(testpairs[_i].b)); fail_unless(strcmp(buf, testpairs[_i].b) == 0, "'%s' != '%s'", buf, testpairs[_i].b); } @@ -61,13 +63,13 @@ START_TEST(test_base32_decode) char buf[4096]; struct encoder *b32; int val; - + b32 = get_base32_encoder(); len = sizeof(buf); val = b32->decode(buf, &len, testpairs[_i].b, strlen(testpairs[_i].b)); - fail_unless(buf != NULL, "buf == NULL"); + fail_unless(val == strlen(testpairs[_i].a)); fail_unless(strcmp(buf, testpairs[_i].a) == 0, "'%s' != '%s'", buf, testpairs[_i].a); } @@ -79,7 +81,7 @@ START_TEST(test_base32_5to8_8to5) int c; for (i = 0; i < 32; i++) { - c = b32_5to8(i); + c = b32_5to8(i); fail_unless(b32_8to5(c) == i); } } diff --git a/jni/iodine/tests/base64.c b/jni/iodine/tests/base64.c index bd0e9ce..cd96d21 100644 --- a/jni/iodine/tests/base64.c +++ b/jni/iodine/tests/base64.c @@ -1,5 +1,6 @@ /* - * Copyright (c) 2006-2009 Bjorn Andersson , Erik Ekman + * Copyright (c) 2006-2014 Erik Ekman , + * 2006-2009 Bjorn Andersson * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -76,6 +77,7 @@ START_TEST(test_base64_encode) len = sizeof(buf); val = b64->encode(buf, &len, testpairs[_i].a, strlen(testpairs[_i].a)); + fail_unless(val == strlen(testpairs[_i].b)); fail_unless(strcmp(buf, testpairs[_i].b) == 0, "'%s' != '%s'", buf, testpairs[_i].b); } @@ -93,7 +95,7 @@ START_TEST(test_base64_decode) len = sizeof(buf); val = b64->decode(buf, &len, testpairs[_i].b, strlen(testpairs[_i].b)); - fail_unless(buf != NULL, "buf == NULL"); + fail_unless(val == strlen(testpairs[_i].a)); fail_unless(strcmp(buf, testpairs[_i].a) == 0, "'%s' != '%s'", buf, testpairs[_i].a); } diff --git a/jni/iodine/tests/common.c b/jni/iodine/tests/common.c new file mode 100644 index 0000000..c1bc73f --- /dev/null +++ b/jni/iodine/tests/common.c @@ -0,0 +1,203 @@ +#include +#include +#include +#include +#include + +START_TEST(test_topdomain_ok) +{ + char *error; + + fail_if(check_topdomain("foo.0123456789.qwertyuiop.asdfghjkl.zxcvbnm.com", &error)); + + /* Not allowed to start with dot */ + fail_unless(check_topdomain(".foo.0123456789.qwertyuiop.asdfghjkl.zxcvbnm.com", &error)); + fail_if(strcmp("Starts with a dot", error)); + + /* Test missing error msg ptr */ + fail_unless(check_topdomain(".foo", NULL)); +} +END_TEST + +START_TEST(test_topdomain_length) +{ + char *error; + + /* Test empty and too short */ + fail_unless(check_topdomain("", &error)); + fail_if(strcmp("Too short (< 3)", error)); + fail_unless(check_topdomain("a", &error)); + fail_if(strcmp("Too short (< 3)", error)); + fail_unless(check_topdomain(".a", &error)); + fail_if(strcmp("Too short (< 3)", error)); + fail_unless(check_topdomain("a.", &error)); + fail_if(strcmp("Too short (< 3)", error)); + fail_unless(check_topdomain("ab", &error)); + fail_if(strcmp("Too short (< 3)", error)); + fail_if(check_topdomain("a.b", &error)); + fail_if(strcmp("Too short (< 3)", error)); + + /* Test too long (over 128, need rest of space for data) */ + fail_unless(check_topdomain( + "abcd12345.abcd12345.abcd12345.abcd12345.abcd12345." + "abcd12345.abcd12345.abcd12345.abcd12345.abcd12345." + "abcd12345.abcd12345.foo129xxx", &error)); + fail_if(strcmp("Too long (> 128)", error)); + fail_if(check_topdomain( + "abcd12345.abcd12345.abcd12345.abcd12345.abcd12345." + "abcd12345.abcd12345.abcd12345.abcd12345.abcd12345." + "abcd12345.abcd12345.foo128xx", &error)); +} +END_TEST + +START_TEST(test_topdomain_chunks) +{ + char *error; + + /* Must have at least one dot */ + fail_if(check_topdomain("abcde.gh", &error)); + fail_unless(check_topdomain("abcdefgh", &error)); + fail_if(strcmp("No dots", error)); + + /* Not two consecutive dots */ + fail_unless(check_topdomain("abc..defgh", &error)); + fail_if(strcmp("Consecutive dots", error)); + + /* Not end with a dots */ + fail_unless(check_topdomain("abc.defgh.", &error)); + fail_if(strcmp("Ends with a dot", error)); + + /* No chunk longer than 63 chars */ + fail_if(check_topdomain("123456789012345678901234567890" + "123456789012345678901234567890333.com", &error)); + fail_unless(check_topdomain("123456789012345678901234567890" + "1234567890123456789012345678904444.com", &error)); + fail_if(strcmp("Too long domain part (> 63)", error)); + + fail_if(check_topdomain("abc.123456789012345678901234567890" + "123456789012345678901234567890333.com", &error)); + fail_unless(check_topdomain("abc.123456789012345678901234567890" + "1234567890123456789012345678904444.com", &error)); + fail_if(strcmp("Too long domain part (> 63)", error)); + + fail_if(check_topdomain("abc.123456789012345678901234567890" + "123456789012345678901234567890333", &error)); + fail_unless(check_topdomain("abc.123456789012345678901234567890" + "1234567890123456789012345678904444", &error)); + fail_if(strcmp("Too long domain part (> 63)", error)); +} +END_TEST + +START_TEST(test_parse_format_ipv4) +{ + char *host = "192.168.2.10"; + char *formatted; + struct sockaddr_storage addr; + struct sockaddr_in *v4addr; + int addr_len; + + addr_len = get_addr(host, 53, AF_INET, 0, &addr); + fail_unless(addr_len == sizeof(struct sockaddr_in)); + + v4addr = (struct sockaddr_in *) &addr; + fail_unless(v4addr->sin_addr.s_addr == htonl(0xc0a8020a)); + fail_unless(v4addr->sin_port == htons(53)); + + formatted = format_addr(&addr, addr_len); + fail_if(strcmp(host, formatted)); +} +END_TEST + +START_TEST(test_parse_format_ipv4_listen_all) +{ + char *host = "0.0.0.0"; + char *formatted; + struct sockaddr_storage addr; + struct sockaddr_in *v4addr; + int addr_len; + + addr_len = get_addr(NULL, 53, AF_INET, AI_PASSIVE, &addr); + fail_unless(addr_len == sizeof(struct sockaddr_in)); + + v4addr = (struct sockaddr_in *) &addr; + fail_unless(v4addr->sin_addr.s_addr == htonl(0x00000000)); + fail_unless(v4addr->sin_port == htons(53)); + + formatted = format_addr(&addr, addr_len); + fail_if(strcmp(host, formatted)); +} +END_TEST + +START_TEST(test_parse_format_ipv6) +{ + char *host = "2001:0db8:0505:0::123:0abc"; + char *compact = "2001:db8:505::123:abc"; + unsigned char v6_bits[] = { + 0x20, 0x01, 0x0d, 0xb8, 0x05, 0x05, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x23, 0x0a, 0xbc, + }; + char *formatted; + struct sockaddr_storage addr; + struct sockaddr_in6 *v6addr; + int addr_len; + + addr_len = get_addr(host, 53, AF_UNSPEC, 0, &addr); + fail_unless(addr_len == sizeof(struct sockaddr_in6)); + + v6addr = (struct sockaddr_in6 *) &addr; + fail_if(memcmp(&v6addr->sin6_addr, v6_bits, sizeof(v6_bits))); + fail_unless(v6addr->sin6_port == htons(53)); + + formatted = format_addr(&addr, addr_len); + fail_if(strcmp(compact, formatted)); +} +END_TEST + +START_TEST(test_parse_format_ipv4_mapped_ipv6) +{ + char *v4mapped = "::FFFF:192.168.2.10"; + char *host = "192.168.2.10"; + unsigned char v6_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xff, 0xff, 0xc0, 0xa8, 0x02, 0x0a, + }; + char *formatted; + struct sockaddr_storage addr; + struct sockaddr_in6 *v6addr; + int addr_len; + + addr_len = get_addr(v4mapped, 53, AF_INET6, 0, &addr); + fail_unless(addr_len == sizeof(struct sockaddr_in6)); + + v6addr = (struct sockaddr_in6 *) &addr; + fail_if(memcmp(&v6addr->sin6_addr, v6_bits, sizeof(v6_bits))); + fail_unless(v6addr->sin6_port == htons(53)); + + /* Format as IPv4 address */ + formatted = format_addr(&addr, addr_len); + fail_if(strcmp(host, formatted)); +} +END_TEST + +TCase * +test_common_create_tests() +{ + TCase *tc; + int sock; + + tc = tcase_create("Common"); + tcase_add_test(tc, test_topdomain_ok); + tcase_add_test(tc, test_topdomain_length); + tcase_add_test(tc, test_topdomain_chunks); + tcase_add_test(tc, test_parse_format_ipv4); + tcase_add_test(tc, test_parse_format_ipv4_listen_all); + + /* Tests require IPv6 support */ + sock = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP); + if (sock >= 0) { + close(sock); + tcase_add_test(tc, test_parse_format_ipv6); + tcase_add_test(tc, test_parse_format_ipv4_mapped_ipv6); + } + return tc; +} diff --git a/jni/iodine/tests/dns.c b/jni/iodine/tests/dns.c index 3d21e4c..cdd3378 100644 --- a/jni/iodine/tests/dns.c +++ b/jni/iodine/tests/dns.c @@ -1,5 +1,6 @@ /* - * Copyright (c) 2006-2009 Bjorn Andersson , Erik Ekman + * Copyright (c) 2006-2014 Erik Ekman , + * 2006-2009 Bjorn Andersson * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -24,6 +25,10 @@ #include #include #include +#ifdef DARWIN +#define BIND_8_COMPAT +#include +#endif #include "common.h" #include "dns.h" @@ -159,8 +164,8 @@ START_TEST(test_decode_response) memset(&buf, 0, sizeof(buf)); ret = dns_decode(buf, len, &q, QR_ANSWER, answer_packet, sizeof(answer_packet)-1); - fail_unless(strncmp(msgData, buf, sizeof(msgData)) == 0, "Did not extract expected data"); fail_unless(ret == strlen(msgData), "Bad data length: %d, expected %d", ret, strlen(msgData)); + fail_unless(strncmp(msgData, buf, strlen(msgData)) == 0, "Did not extract expected data"); fail_unless(q.id == 0x0539); } END_TEST @@ -176,8 +181,8 @@ START_TEST(test_decode_response_with_high_trans_id) memset(&buf, 0, sizeof(buf)); ret = dns_decode(buf, len, &q, QR_ANSWER, answer_packet_high_trans_id, sizeof(answer_packet_high_trans_id)-1); - fail_unless(strncmp(msgData, buf, sizeof(msgData)) == 0, "Did not extract expected data"); fail_unless(ret == strlen(msgData), "Bad data length: %d, expected %d", ret, strlen(msgData)); + fail_unless(strncmp(msgData, buf, strlen(msgData)) == 0, "Did not extract expected data"); fail_unless(q.id == 0x8539, "q.id was %08X instead of %08X!", q.id, 0x8539); } END_TEST diff --git a/jni/iodine/tests/encoding.c b/jni/iodine/tests/encoding.c index ac22452..665c4dd 100644 --- a/jni/iodine/tests/encoding.c +++ b/jni/iodine/tests/encoding.c @@ -1,5 +1,6 @@ /* - * Copyright (c) 2006-2009 Bjorn Andersson , Erik Ekman + * Copyright (c) 2006-2014 Erik Ekman , + * 2006-2009 Bjorn Andersson * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -84,7 +85,7 @@ START_TEST(test_build_hostname) } buflen = sizeof(buf); - + for (i = 1; i < sizeof(data); i++) { int len = build_hostname(buf, buflen, data, i, topdomain, get_base32_encoder(), sizeof(buf)); diff --git a/jni/iodine/tests/fw_query.c b/jni/iodine/tests/fw_query.c index 6d23924..c6ed2c7 100644 --- a/jni/iodine/tests/fw_query.c +++ b/jni/iodine/tests/fw_query.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2009 Erik Ekman + * Copyright (c) 2009-2014 Erik Ekman * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -28,7 +28,7 @@ START_TEST(test_fw_query_simple) q.id = 0x848A; fw_query_init(); - + /* Test empty cache */ fw_query_get(0x848A, &qp); fail_unless(qp == NULL); @@ -49,7 +49,7 @@ START_TEST(test_fw_query_edge) int i; fw_query_init(); - + q.addrlen = 33; q.id = 0x848A; fw_query_put(&q); @@ -64,7 +64,7 @@ START_TEST(test_fw_query_edge) fw_query_get(0x848A, &qp); fail_unless(qp->addrlen == 33); fail_unless(qp->id == 0x848A); - + q.addrlen++; q.id++; fw_query_put(&q); diff --git a/jni/iodine/tests/login.c b/jni/iodine/tests/login.c index 1ef23f4..e154ee2 100644 --- a/jni/iodine/tests/login.c +++ b/jni/iodine/tests/login.c @@ -1,5 +1,6 @@ /* - * Copyright (c) 2006-2009 Bjorn Andersson , Erik Ekman + * Copyright (c) 2006-2014 Erik Ekman , + * 2006-2009 Bjorn Andersson * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above diff --git a/jni/iodine/tests/read.c b/jni/iodine/tests/read.c index 18cc29c..24a5214 100644 --- a/jni/iodine/tests/read.c +++ b/jni/iodine/tests/read.c @@ -1,5 +1,6 @@ /* - * Copyright (c) 2006-2009 Bjorn Andersson , Erik Ekman + * Copyright (c) 2006-2014 Erik Ekman , + * 2006-2009 Bjorn Andersson * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -20,7 +21,8 @@ #include #include #ifdef DARWIN -#include +#define BIND_8_COMPAT +#include #endif #include #include @@ -49,7 +51,7 @@ START_TEST(test_read_putshort) i, ntohs(k), i); p = (char*)&k; - readshort(NULL, &p, (short *) &l); + readshort(NULL, &p, &l); fail_unless(l == i, "Bad value on readshort for %d: %d != %d", i, l, i); @@ -96,6 +98,7 @@ START_TEST(test_read_name_empty_loop) data = (char*) emptyloop + sizeof(HEADER); buf[1023] = 'A'; rv = readname((char *) emptyloop, sizeof(emptyloop), &data, buf, 1023); + fail_unless(rv == 0); fail_unless(buf[1023] == 'A'); } END_TEST @@ -113,6 +116,7 @@ START_TEST(test_read_name_inf_loop) data = (char*) infloop + sizeof(HEADER); buf[4] = '\a'; rv = readname((char*) infloop, sizeof(infloop), &data, buf, 4); + fail_unless(rv == 3); fail_unless(buf[4] == '\a'); } END_TEST @@ -136,6 +140,7 @@ START_TEST(test_read_name_longname) data = (char*) longname + sizeof(HEADER); buf[256] = '\a'; rv = readname((char*) longname, sizeof(longname), &data, buf, 256); + fail_unless(rv == 256); fail_unless(buf[256] == '\a'); } END_TEST @@ -213,11 +218,8 @@ START_TEST(test_putname) char buf[256]; char *domain = "BADGER.BADGER.KRYO.SE"; char *b; - int len; int ret; - len = 256; - memset(buf, 0, 256); b = buf; ret = putname(&b, 256, domain); @@ -234,11 +236,8 @@ START_TEST(test_putname_nodot) "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ" "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"; char *b; - int len; int ret; - len = 256; - memset(buf, 0, 256); b = buf; ret = putname(&b, 256, nodot); @@ -259,11 +258,8 @@ START_TEST(test_putname_toolong) "ABCDEFGHIJKLMNOPQRSTUVWXYZ.ABCDEFGHIJKLMNOPQRSTUVWXYZ." "ABCDEFGHIJKLMNOPQRSTUVWXYZ.ABCDEFGHIJKLMNOPQRSTUVWXYZ."; char *b; - int len; int ret; - len = 256; - memset(buf, 0, 256); b = buf; ret = putname(&b, 256, toolong); diff --git a/jni/iodine/tests/test.c b/jni/iodine/tests/test.c index 5bee9d2..cc753d4 100644 --- a/jni/iodine/tests/test.c +++ b/jni/iodine/tests/test.c @@ -1,5 +1,6 @@ /* - * Copyright (c) 2006-2009 Bjorn Andersson , Erik Ekman + * Copyright (c) 2006-2014 Erik Ekman , + * 2006-2009 Bjorn Andersson * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -38,6 +39,9 @@ main() test = test_base64_create_tests(); suite_add_tcase(iodine, test); + test = test_common_create_tests(); + suite_add_tcase(iodine, test); + test = test_dns_create_tests(); suite_add_tcase(iodine, test); diff --git a/jni/iodine/tests/test.h b/jni/iodine/tests/test.h index 1022a9e..511cf31 100644 --- a/jni/iodine/tests/test.h +++ b/jni/iodine/tests/test.h @@ -1,5 +1,6 @@ /* - * Copyright (c) 2006-2009 Bjorn Andersson , Erik Ekman + * Copyright (c) 2006-2014 Erik Ekman , + * 2006-2009 Bjorn Andersson * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -19,6 +20,7 @@ TCase *test_base32_create_tests(); TCase *test_base64_create_tests(); +TCase *test_common_create_tests(); TCase *test_dns_create_tests(); TCase *test_encoding_create_tests(); TCase *test_read_create_tests(); @@ -27,11 +29,11 @@ TCase *test_user_create_tests(); TCase *test_fw_query_create_tests(); char *va_str(const char *, ...); - + #if (CHECK_MAJOR_VERSION == 0 && \ ((CHECK_MINOR_VERSION == 9 && CHECK_MICRO_VERSION < 2) || \ (CHECK_MINOR_VERSION < 9))) -#define tcase_set_timeout(...) +#define tcase_set_timeout(...) #endif #endif diff --git a/jni/iodine/tests/user.c b/jni/iodine/tests/user.c index afd61ca..2e4f36d 100644 --- a/jni/iodine/tests/user.c +++ b/jni/iodine/tests/user.c @@ -1,5 +1,6 @@ /* - * Copyright (c) 2006-2009 Bjorn Andersson , Erik Ekman + * Copyright (c) 2006-2014 Erik Ekman , + * 2006-2009 Bjorn Andersson * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -19,8 +20,8 @@ #include #include #include -#include #include +#include #include "common.h" #include "encoding.h" @@ -32,10 +33,11 @@ START_TEST(test_init_users) in_addr_t ip; char givenip[16]; int i; + int count; ip = inet_addr("127.0.0.1"); - init_users(ip, 27); - for (i = 0; i < USERS; i++) { + count = init_users(ip, 27); + for (i = 0; i < count; i++) { fail_unless(users[i].id == i); fail_unless(users[i].q.id == 0); fail_unless(users[i].inpacket.len == 0); @@ -60,12 +62,12 @@ START_TEST(test_users_waiting) fail_unless(users_waiting_on_reply() == 0); users[3].last_pkt = time(NULL); - + fail_unless(users_waiting_on_reply() == 0); - + users[3].conn = CONN_DNS_NULL; users[3].q.id = 1; - + fail_unless(users_waiting_on_reply() == 1); } END_TEST @@ -81,17 +83,22 @@ START_TEST(test_find_user_by_ip) testip = (unsigned int) inet_addr("10.0.0.1"); fail_unless(find_user_by_ip(testip) == -1); - + testip = (unsigned int) inet_addr("127.0.0.2"); fail_unless(find_user_by_ip(testip) == -1); - + users[0].active = 1; - + testip = (unsigned int) inet_addr("127.0.0.2"); fail_unless(find_user_by_ip(testip) == -1); - + users[0].last_pkt = time(NULL); - + + testip = (unsigned int) inet_addr("127.0.0.2"); + fail_unless(find_user_by_ip(testip) == -1); + + users[0].authenticated = 1; + testip = (unsigned int) inet_addr("127.0.0.2"); fail_unless(find_user_by_ip(testip) == 0); } @@ -105,15 +112,15 @@ START_TEST(test_all_users_waiting_to_send) init_users(ip, 27); fail_unless(all_users_waiting_to_send() == 1); - + users[0].conn = CONN_DNS_NULL; users[0].active = 1; - + fail_unless(all_users_waiting_to_send() == 1); - + users[0].last_pkt = time(NULL); users[0].outpacket.len = 0; - + fail_unless(all_users_waiting_to_send() == 0); #ifdef OUTPACKETQ_LEN @@ -121,7 +128,7 @@ START_TEST(test_all_users_waiting_to_send) #else users[0].outpacket.len = 44; #endif - + fail_unless(all_users_waiting_to_send() == 1); } END_TEST @@ -135,7 +142,11 @@ START_TEST(test_find_available_user) init_users(ip, 27); for (i = 0; i < USERS; i++) { + users[i].authenticated = 1; + users[i].authenticated_raw = 1; fail_unless(find_available_user() == i); + fail_if(users[i].authenticated); + fail_if(users[i].authenticated_raw); } for (i = 0; i < USERS; i++) { @@ -148,7 +159,7 @@ START_TEST(test_find_available_user) fail_unless(find_available_user() == -1); users[3].last_pkt = 55; - + fail_unless(find_available_user() == 3); fail_unless(find_available_user() == -1); } @@ -176,7 +187,7 @@ START_TEST(test_find_available_user_small_net) fail_unless(find_available_user() == -1); users[3].last_pkt = 55; - + fail_unless(find_available_user() == 3); fail_unless(find_available_user() == -1); } -- cgit v1.2.1