src/test.c
author Tero Marttila <terom@fixme.fi>
Thu, 26 Mar 2009 22:03:20 +0200
changeset 73 2780a73c71f3
parent 72 43084f103c2a
child 74 11ec458d1cbf
permissions -rw-r--r--
add set_log_level function, and add --debug/--quiet options to test
40
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     1
/**
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     2
 * The main test code entry point
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     3
 */
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     4
#include "sock_test.h"
41
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
     5
#include "line_proto.h"
40
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     6
#include "irc_conn.h"
44
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
     7
#include "irc_net.h"
40
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     8
#include "log.h"
41
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
     9
#include "error.h"
40
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    10
41
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    11
#include <stdlib.h>
40
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    12
#include <string.h>
73
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
    13
#include <getopt.h>
40
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    14
#include <assert.h>
50
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    15
#include <ctype.h>
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    16
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    17
#define DUMP_STR_BUF 1024
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    18
#define DUMP_STR_COUNT 8
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    19
#define DUMP_STR_TAIL 10
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    20
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    21
char *dump_str_append (char *buf, const char *str)
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    22
{
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    23
    while (*str)
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    24
        *buf++ = *str++;
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    25
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    26
    return buf;
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    27
}
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    28
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    29
/**
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    30
 * This re-formats the given string to escape values, and returns a pointer to an internal static buffer.
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    31
 *
52
97604efda1ce add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
    32
 * If len is given as >= 0, only the given number of chars will be dumped from str.
50
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    33
 *
52
97604efda1ce add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
    34
 * The buffer cycles a bit, so the returned pointers remain valid across DUMP_STR_COUNT calls.
51
cc61eaa841ef add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents: 50
diff changeset
    35
 *
52
97604efda1ce add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
    36
 * The resulting string is truncated to (DUMP_STR_BUF - DUMP_STR_TAIL) bytes, not including the ending "...'\0".
97604efda1ce add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
    37
 *
97604efda1ce add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
    38
 * @param str the string to dump, should be NUL-terminated unless len is given
97604efda1ce add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
    39
 * @param len if negative, ignored, otherwise, only this many bytes are dumped from str
97604efda1ce add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
    40
 * @param return a pointer to a static buffer that remains valid across DUMP_STR_COUNT calls to this function
50
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    41
 */
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    42
const char *dump_strn (const char *str, ssize_t len)
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    43
{
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    44
    static char dump_buf[DUMP_STR_COUNT][DUMP_STR_BUF];
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    45
    static size_t dump_idx = 0;
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    46
    
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    47
    // pick a buffer to use
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    48
    const char *str_ptr = str;
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    49
    char *buf_ptr = dump_buf[dump_idx++], *buf = buf_ptr;
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    50
    
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    51
    // cycle
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    52
    if (dump_idx >= DUMP_STR_COUNT)
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    53
        dump_idx = 0;
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    54
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    55
    // NULL?
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    56
    if (str == NULL) {
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    57
        buf = dump_str_append(buf, "NULL");
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    58
        *buf = '\0';
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    59
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    60
        return buf_ptr;
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    61
    }
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    62
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    63
    // quote
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    64
    *buf++ = '\'';
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    65
    
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    66
    // dump each char
51
cc61eaa841ef add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents: 50
diff changeset
    67
    for (; (
cc61eaa841ef add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents: 50
diff changeset
    68
            // ...stop on NUL
cc61eaa841ef add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents: 50
diff changeset
    69
                *str 
cc61eaa841ef add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents: 50
diff changeset
    70
cc61eaa841ef add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents: 50
diff changeset
    71
            // ...leave DUMP_STR_TAIL bytes room at the end of buf
cc61eaa841ef add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents: 50
diff changeset
    72
            &&  (size_t) (buf - buf_ptr) < DUMP_STR_BUF - DUMP_STR_TAIL 
cc61eaa841ef add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents: 50
diff changeset
    73
            
cc61eaa841ef add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents: 50
diff changeset
    74
            // ...don't consume more than len bytes of str, unless len < 0
cc61eaa841ef add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents: 50
diff changeset
    75
            &&  (len < 0 || (size_t) (str - str_ptr) < (size_t) len)
cc61eaa841ef add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents: 50
diff changeset
    76
        ); str++
cc61eaa841ef add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents: 50
diff changeset
    77
    ) {
50
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    78
        if (*str == '\'') {
51
cc61eaa841ef add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents: 50
diff changeset
    79
            // escape quotes
cc61eaa841ef add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents: 50
diff changeset
    80
            buf = dump_str_append(buf, "\\'");
cc61eaa841ef add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents: 50
diff changeset
    81
cc61eaa841ef add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents: 50
diff changeset
    82
        } else if (*str == '\\') {
cc61eaa841ef add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents: 50
diff changeset
    83
            // escape escapes
cc61eaa841ef add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents: 50
diff changeset
    84
            buf = dump_str_append(buf, "\\\\");
50
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    85
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    86
        } else if (isprint(*str)) {
51
cc61eaa841ef add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents: 50
diff changeset
    87
            // normal char
50
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    88
            *buf++ = *str;
52
97604efda1ce add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
    89
        
50
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    90
        } else {
51
cc61eaa841ef add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents: 50
diff changeset
    91
            // something more special
50
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    92
            switch (*str) {
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    93
                case '\r':
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    94
                    buf = dump_str_append(buf, "\\r"); break;
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    95
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    96
                case '\n':
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    97
                    buf = dump_str_append(buf, "\\n"); break;
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    98
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    99
                default:
51
cc61eaa841ef add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents: 50
diff changeset
   100
                    // format as "\xFF"
50
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   101
                    buf += snprintf(buf, (DUMP_STR_BUF - (buf - buf_ptr)), "\\x%02x", *str);
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   102
                    break;
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   103
            }
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   104
        }
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   105
    }
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   106
51
cc61eaa841ef add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents: 50
diff changeset
   107
    // end quote
50
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   108
    *buf++ = '\'';
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   109
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   110
    // overflow?
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   111
    if ((size_t)(buf - buf_ptr) == DUMP_STR_BUF - DUMP_STR_TAIL)
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   112
        buf = dump_str_append(buf, "...");
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   113
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   114
    // terminate
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   115
    *buf = '\0';
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   116
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   117
    // ok
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   118
    return buf_ptr;
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   119
}
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   120
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   121
const char *dump_str (const char *str) 
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   122
{
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   123
    return dump_strn(str, -1);
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   124
}
40
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   125
42
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   126
void assert_strcmp (const char *is, const char *should_be)
41
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   127
{
52
97604efda1ce add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
   128
    if (!is || strcmp(is, should_be))
50
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   129
        FATAL("%s != %s", dump_str(is), dump_str(should_be));
41
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   130
}
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   131
42
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   132
void assert_strncmp (const char *is, const char *should_be, size_t n)
50
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   133
{   
52
97604efda1ce add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
   134
    if (!is || strncmp(is, should_be, n))
50
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   135
        FATAL("%s:%u != %s", dump_strn(is, n), (unsigned) n, dump_strn(should_be, n));
41
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   136
}
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   137
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   138
void assert_strlen (const char *str, size_t n)
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   139
{
52
97604efda1ce add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
   140
    if (!str || strlen(str) != n)
50
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   141
        FATAL("strlen(%s) != %u", dump_str(str), (unsigned) n);
41
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   142
}
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   143
42
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   144
void assert_strnull (const char *str)
41
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   145
{
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   146
    if (str != NULL)
50
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   147
        FATAL("%s != NULL", dump_str(str));
41
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   148
}
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   149
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   150
void assert_success (err_t err)
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   151
{
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   152
    if (err != SUCCESS)
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   153
        FATAL("error: %s", error_name(err));
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   154
}
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   155
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   156
void assert_err (err_t err, err_t target)
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   157
{
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   158
    if (err != target)
42
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   159
        FATAL("error: <%s> != <%s>", error_name(err), error_name(target));
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   160
}
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   161
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   162
void assert_error_info (struct error_info *is, struct error_info *should_be)
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   163
{
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   164
    if (ERROR_CODE(is) != ERROR_CODE(should_be) || ERROR_EXTRA(is) != ERROR_EXTRA(should_be))
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   165
        FATAL("error: <%s> != <%s>", error_msg(is), error_msg(should_be));
41
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   166
}
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   167
40
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   168
void assert_sock_read (struct sock_stream *sock, const char *str)
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   169
{
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   170
    char buf[strlen(str)];
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   171
50
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   172
    log_debug("read: %p: %s", sock, dump_str(str));
40
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   173
    
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   174
    // read it
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   175
    assert(sock_stream_read(sock, buf, strlen(str)) == (int) strlen(str));
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   176
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   177
    // cmp
41
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   178
    assert_strncmp(buf, str, strlen(str));
40
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   179
}
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   180
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   181
void assert_sock_write (struct sock_stream *sock, const char *str)
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   182
{
50
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   183
    log_debug("write: %p: %s", sock, dump_str(str));
40
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   184
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   185
    // write it
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   186
    assert(sock_stream_write(sock, str, strlen(str)) == (int) strlen(str));
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   187
}
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   188
41
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   189
void assert_sock_eof (struct sock_stream *sock)
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   190
{
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   191
    char buf;
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   192
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   193
    log_debug("eof: %p", sock);
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   194
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   195
    assert_err(-sock_stream_read(sock, &buf, 1), ERR_READ_EOF);
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   196
}
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   197
44
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   198
void assert_sock_data (struct sock_test *sock, const char *data)
43
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   199
{
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   200
    // get the data out
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   201
    char *buf;
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   202
    size_t len;
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   203
    
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   204
    sock_test_get_send_data(sock, &buf, &len);
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   205
    
50
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   206
    log_debug("get_send_data: %s", dump_strn(buf, len));
43
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   207
    
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   208
    // should be the same
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   209
    assert_strncmp(buf, data, len);
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   210
    assert_strlen(data, len);
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   211
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   212
    // cleanup
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   213
    free(buf);
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   214
}
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   215
52
97604efda1ce add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
   216
/**
97604efda1ce add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
   217
 * Nicer name for test_sock_add_recv_str
97604efda1ce add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
   218
 */
97604efda1ce add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
   219
void test_sock_push (struct sock_test *sock, const char *str)
97604efda1ce add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
   220
{
97604efda1ce add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
   221
    return sock_test_add_recv_str(sock, str);
97604efda1ce add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
   222
}
97604efda1ce add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
   223
72
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   224
/**
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   225
 * Create an empty sock_test
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   226
 */
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   227
struct sock_test* setup_sock_test (void)
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   228
{
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   229
    struct sock_test *sock;
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   230
   
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   231
    assert ((sock = sock_test_create()) != NULL);
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   232
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   233
    return sock;
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   234
}
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   235
50
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   236
void test_dump_str (void)
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   237
{
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   238
    log_info("dumping example strings on stdout:");
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   239
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   240
    log_debug("normal: %s", dump_str("Hello World"));
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   241
    log_debug("escapes: %s", dump_str("foo\r\nbar\a\001"));
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   242
    log_debug("length: %s", dump_strn("<-->**", 4));
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   243
    log_debug("overflow: %s", dump_str( "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"));
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   244
    log_debug("null: %s", dump_str(NULL));
51
cc61eaa841ef add some comments and quote (' + \) to dump_str
Tero Marttila <terom@fixme.fi>
parents: 50
diff changeset
   245
    log_debug("quote: %s", dump_str("foo\\bar'quux"));
50
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   246
}
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   247
40
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   248
void test_sock_test (void)
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   249
{
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   250
    struct sock_test *sock = sock_test_create();
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   251
    struct io_vec _read_data[] = {
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   252
        {   "foo",      3   },
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   253
        {   "barx",     4   }
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   254
    };
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   255
    const char *_write_data = "test data";
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   256
    
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   257
    // put the read data
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   258
    log_debug("set_recv_buffer: %p, %d", _read_data, 2);
41
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   259
    sock_test_set_recv_buffer(sock, _read_data, 2, true);
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   260
    
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   261
    // read it out
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   262
    log_info("test sock_test_read");
40
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   263
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   264
    assert_sock_read(SOCK_TEST_BASE(sock), "foo");
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   265
    assert_sock_read(SOCK_TEST_BASE(sock), "ba");
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   266
    assert_sock_read(SOCK_TEST_BASE(sock), "rx");
41
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   267
    assert_sock_eof(SOCK_TEST_BASE(sock));
40
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   268
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   269
    // write the data in
41
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   270
    log_info("test sock_test_write");
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   271
40
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   272
    assert_sock_write(SOCK_TEST_BASE(sock), "test ");
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   273
    assert_sock_write(SOCK_TEST_BASE(sock), "data");
43
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   274
    
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   275
    // check output
44
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   276
    assert_sock_data(sock, _write_data);
40
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   277
43
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   278
    // check output
44
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   279
    assert_sock_data(sock, "");
40
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   280
41
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   281
    // cleanup
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   282
    sock_test_destroy(sock);
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   283
}
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   284
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   285
void assert_read_line (struct line_proto *lp, const char *line_str)
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   286
{
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   287
    char *line_buf;
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   288
    
50
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   289
    log_debug("expect: %s", dump_str(line_str));
41
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   290
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   291
    assert_success(line_proto_recv(lp, &line_buf));
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   292
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   293
    if (line_str) {
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   294
        assert_strcmp(line_buf, line_str);
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   295
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   296
    } else {
42
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   297
        assert_strnull(line_buf);
41
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   298
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   299
    }
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   300
}
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   301
42
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   302
/**
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   303
 * Context info for test_line_proto callbacks
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   304
 */
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   305
struct _lp_test_ctx {
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   306
    /** Expected line */
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   307
    const char *line;
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   308
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   309
    /** Expected error */
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   310
    struct error_info err;
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   311
};
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   312
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   313
static void _lp_on_line (char *line, void *arg)
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   314
{
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   315
    struct _lp_test_ctx *ctx = arg;
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   316
50
46c3983638d3 add dump_str function to test
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
   317
    log_debug("%s", dump_str(line));
42
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   318
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   319
    assert_strcmp(line, ctx->line);
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   320
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   321
    ctx->line = NULL;
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   322
}
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   323
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   324
static void _lp_on_error (struct error_info *err, void *arg)
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   325
{
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   326
    struct _lp_test_ctx *ctx = arg;
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   327
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   328
    assert_error_info(err, &ctx->err);
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   329
}
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   330
41
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   331
static struct line_proto_callbacks _lp_callbacks = {
42
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   332
    .on_line        = &_lp_on_line,
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   333
    .on_error       = &_lp_on_error,
41
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   334
};
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   335
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   336
void test_line_proto (void)
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   337
{
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   338
    struct sock_test *sock = sock_test_create();
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   339
    struct io_vec _read_data[] = {
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   340
        {   "hello\r\n",    7   },
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   341
        {   "world\n",      6   },
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   342
        {   "this ",        5   },
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   343
        {   "is a line\r",  10  },
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   344
        {   "\nfragment",   9   },
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   345
    }, _trailing_data = {   "\r\n",     2 };
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   346
    struct line_proto *lp;
42
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   347
    struct _lp_test_ctx ctx;
41
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   348
    struct error_info err;
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   349
    
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   350
    // put the read data
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   351
    log_debug("set_recv_buffer: %p, %d", _read_data, 5);
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   352
    sock_test_set_recv_buffer(sock, _read_data, 5, false);
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   353
    
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   354
    // create the lp
42
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   355
    assert_success(line_proto_create(&lp, SOCK_TEST_BASE(sock), 128, &_lp_callbacks, &ctx, &err));
41
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   356
    
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   357
    log_info("test line_proto_recv");
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   358
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   359
    // then read some lines from it
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   360
    assert_read_line(lp, "hello");
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   361
    assert_read_line(lp, "world");
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   362
    assert_read_line(lp, "this is a line");
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   363
    assert_read_line(lp, NULL);
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   364
42
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   365
    // then add a final bit to trigger on_line
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   366
    log_info("test on_line");
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   367
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   368
    ctx.line = "fragment";
41
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   369
    sock_test_add_recv_vec(sock, _trailing_data);
42
13cfc41f76a7 test async operation
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   370
    assert_strnull(ctx.line);
41
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   371
43
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   372
    // test writing
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   373
    log_info("test line_proto_send");
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   374
    assert_success(-line_proto_send(lp, "foobar\r\n"));
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   375
    assert_success(-line_proto_send(lp, "quux\r\n"));
44
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   376
    assert_sock_data(sock, "foobar\r\nquux\r\n");
43
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   377
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   378
    // XXX: test partial writes
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   379
41
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   380
    // cleanup
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   381
    line_proto_release(lp);
40
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   382
}
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   383
43
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   384
struct _test_irc_conn_ctx {
49
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   385
    bool on_registered, on_TEST, on_error, on_quit;
43
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   386
};
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   387
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   388
static void _conn_on_registered (struct irc_conn *conn, void *arg)
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   389
{
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   390
    struct _test_irc_conn_ctx *ctx = arg;
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   391
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   392
    (void) conn;
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   393
44
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   394
    if (ctx) ctx->on_registered = true;
43
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   395
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   396
    log_debug("registered");
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   397
}
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   398
49
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   399
static void _conn_on_error (struct irc_conn *conn, struct error_info *err, void *arg)
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   400
{
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   401
    struct _test_irc_conn_ctx *ctx = arg;
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   402
    
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   403
    (void) conn;
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   404
    (void) err;
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   405
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   406
    if (ctx) ctx->on_error = true;
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   407
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   408
    log_debug("on_error");
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   409
}
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   410
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   411
static void _conn_on_quit (struct irc_conn *conn, void *arg)
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   412
{
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   413
    struct _test_irc_conn_ctx *ctx = arg;
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   414
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   415
    (void) conn;
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   416
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   417
    if (ctx) ctx->on_quit = true;
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   418
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   419
    log_debug("on_quit");
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   420
}
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   421
43
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   422
static void _conn_on_TEST (const struct irc_line *line, void *arg)
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   423
{
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   424
    struct _test_irc_conn_ctx *ctx = arg;
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   425
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   426
    assert_strcmp(line->prefix, "foobar-prefix");
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   427
    assert_strcmp(line->command, "TEST");
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   428
    assert_strcmp(line->args[0], "arg0");
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   429
    assert_strnull(line->args[1]);
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   430
44
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   431
    if (ctx) ctx->on_TEST = true;
43
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   432
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   433
    log_debug("on_TEST");
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   434
}
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   435
40
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   436
static struct irc_conn_callbacks _conn_callbacks = {
43
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   437
    .on_registered      = &_conn_on_registered,
49
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   438
    .on_error           = &_conn_on_error,
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   439
    .on_quit            = &_conn_on_quit,
43
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   440
};
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   441
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   442
static struct irc_cmd_handler _conn_handlers[] = {
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   443
    {   "TEST",         &_conn_on_TEST  },
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   444
    {   NULL,           NULL            }
40
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   445
};
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   446
44
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   447
struct irc_conn* setup_irc_conn (struct sock_test *sock, bool noisy, struct _test_irc_conn_ctx *ctx)
40
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   448
{
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   449
    struct irc_conn *conn;
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   450
    struct error_info err;
43
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   451
    struct irc_conn_register_info register_info = {
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   452
        "nick", "user", "realname"
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   453
    };
44
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   454
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   455
    // create the irc_conn
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   456
    assert_success(irc_conn_create(&conn, SOCK_TEST_BASE(sock), &_conn_callbacks, ctx, &err));
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   457
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   458
    // test register
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   459
    if (noisy) log_info("test irc_conn_register");
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   460
    assert_success(irc_conn_register(conn, &register_info));
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   461
    assert_sock_data(sock, "NICK nick\r\nUSER user 0 * realname\r\n");
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   462
 
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   463
    // test on_register callback    
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   464
    if (noisy) log_info("test irc_conn_callbacks.on_register");
52
97604efda1ce add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
   465
    test_sock_push(sock, "001 mynick :Blaa blaa blaa\r\n");
44
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   466
    if (ctx) assert(ctx->on_registered);
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   467
    assert_strcmp(conn->nickname, "mynick");
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   468
   
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   469
    // ok
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   470
    return conn;
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   471
}
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   472
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   473
void test_irc_conn (void)
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   474
{
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   475
    struct sock_test *sock;
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   476
    struct irc_conn *conn;
49
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   477
    struct _test_irc_conn_ctx ctx = { false, false, false, false };
40
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   478
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   479
    // create the test socket
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   480
    assert((sock = sock_test_create()));
43
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   481
44
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   482
    // setup the basic irc_conn
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   483
    conn = setup_irc_conn(sock, true, &ctx);
43
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   484
    
44
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   485
    // add our test handlers
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   486
    assert_success(irc_conn_add_cmd_handlers(conn, _conn_handlers, &ctx));
43
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   487
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   488
    // test on_TEST handler
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   489
    log_info("test irc_conn.handlers");
52
97604efda1ce add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
   490
    test_sock_push(sock, ":foobar-prefix TEST arg0\r\n");
43
42f5dc680930 improve irc_conn test
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   491
    assert(ctx.on_TEST);
40
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   492
44
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   493
    // test PING/PONG
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   494
    log_info("test PING/PONG");
52
97604efda1ce add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
   495
    test_sock_push(sock, "PING foo\r\n");
44
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   496
    assert_sock_data(sock, "PONG foo\r\n");
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   497
49
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   498
    // quit nicely
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   499
    log_info("test QUIT");
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   500
    assert_success(irc_conn_QUIT(conn, "bye now"));
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   501
    assert_sock_data(sock, "QUIT :bye now\r\n");
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   502
    assert(conn->quitting);
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   503
52
97604efda1ce add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
   504
    test_sock_push(sock, "ERROR :Closing Link: Quit\r\n");
49
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   505
    sock_test_set_recv_eof(sock);
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   506
    assert(conn->quit && !conn->quitting && !conn->registered);
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   507
    assert(ctx.on_quit);
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   508
    assert(!ctx.on_error);
96e0f703a58c update irc_conn status, and add tests for irc_conn_QUIT
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
   509
40
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   510
    // destroy it
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   511
    irc_conn_destroy(conn);
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   512
}
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   513
72
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   514
struct test_chan_ctx {
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   515
    /** The channel we're supposed to be testing */
44
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   516
    struct irc_chan *chan;
72
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   517
    
73
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   518
    /** Flags for callbacks called*/
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   519
    bool on_chan_self_join, on_chan_join;
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   520
44
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   521
};
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   522
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   523
void _on_chan_self_join (struct irc_chan *chan, void *arg)
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   524
{
72
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   525
    struct test_chan_ctx *ctx = arg;
44
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   526
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   527
    assert(chan == ctx->chan);
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   528
    
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   529
    ctx->on_chan_self_join = true;
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   530
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   531
    log_debug("on_self_join");
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   532
}
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   533
73
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   534
void _on_chan_join (struct irc_chan *chan, const struct irc_nm *source, void *arg)
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   535
{
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   536
    struct test_chan_ctx *ctx = arg;
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   537
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   538
    assert(chan == ctx->chan);
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   539
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   540
    // XXX: verify source
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   541
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   542
    ctx->on_chan_join = true;
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   543
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   544
    log_debug("on_join");
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   545
}
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   546
44
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   547
struct irc_chan_callbacks _chan_callbacks = {
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   548
    .on_self_join       = &_on_chan_self_join,
73
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   549
    .on_join            = &_on_chan_join,
44
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   550
};
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   551
72
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   552
/**
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   553
 * Setup an irc_net using the given socket, and consume the register request output, but do not push the RPL_WELCOME
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   554
 */
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   555
struct irc_net* setup_irc_net_unregistered (struct sock_test *sock)
44
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   556
{
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   557
    struct irc_net *net;
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   558
    struct irc_net_info net_info = {
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   559
        .register_info = {
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   560
            "nick", "user", "realname"
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   561
        },
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   562
    };
72
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   563
    struct error_info err;
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   564
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   565
    // create the irc_net
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   566
    net_info.raw_sock = SOCK_TEST_BASE(sock);
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   567
    assert_success(irc_net_create(&net, &net_info, &err));
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   568
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   569
    // test register output
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   570
    assert_sock_data(sock, "NICK nick\r\nUSER user 0 * realname\r\n");
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   571
    
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   572
    // ok
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   573
    return net; 
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   574
}
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   575
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   576
/**
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   577
 * Push to RPL_WELCOME reply, and test state
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   578
 */
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   579
void do_irc_net_welcome (struct sock_test *sock, struct irc_net *net)
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   580
{
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   581
    // registration reply
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   582
    test_sock_push(sock, "001 mynick :Blaa blaa blaa\r\n");
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   583
    assert(net->conn->registered);
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   584
    assert_strcmp(net->conn->nickname, "mynick");
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   585
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   586
}
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   587
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   588
/**
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   589
 * Creates an irc_net and puts it into the registered state
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   590
 */
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   591
struct irc_net* setup_irc_net (struct sock_test *sock)
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   592
{
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   593
    struct irc_net *net;   
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   594
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   595
    net = setup_irc_net_unregistered(sock);
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   596
    do_irc_net_welcome(sock, net);
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   597
    
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   598
    // ok
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   599
    return net;
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   600
}
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   601
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   602
/**
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   603
 * General test for irc_net to handle startup
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   604
 */
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   605
void test_irc_net (void)
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   606
{
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   607
    struct sock_test *sock = setup_sock_test();
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   608
    
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   609
    // create the network
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   610
    log_info("test irc_net_create");
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   611
    struct irc_net *net = setup_irc_net_unregistered(sock);
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   612
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   613
    // send the registration reply
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   614
    log_info("test irc_conn_on_RPL_WELCOME");
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   615
    do_irc_net_welcome(sock, net);
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   616
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   617
    // test errors by setting EOF
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   618
    log_info("test irc_net_error");
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   619
    sock_test_set_recv_eof(sock);
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   620
    assert(net->conn == NULL);
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   621
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   622
    // cleanup
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   623
    irc_net_destroy(net);
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   624
}
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   625
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   626
/**
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   627
 * Creates an irc_chan on the given irc_net, but does not check any output (useful for testing offline add).
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   628
 *
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   629
 * You must pass a test_chan_ctx for use with later operations, this will be initialized for you.
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   630
 */
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   631
struct irc_chan* setup_irc_chan_raw (struct irc_net *net, struct test_chan_ctx *ctx)
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   632
{
44
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   633
    struct irc_chan *chan;
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   634
    struct irc_chan_info chan_info = {
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   635
        .channel        = "#test",
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   636
    };
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   637
    struct error_info err;
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   638
    
72
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   639
    // initialize the given ctx
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   640
    memset(ctx, 0, sizeof(*ctx));
44
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   641
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   642
    // add a channel
72
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   643
    assert_success(irc_net_add_chan(net, &chan, &chan_info, &err));
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   644
    assert(!chan->joined);
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   645
    assert_success(irc_chan_add_callbacks(chan, &_chan_callbacks, ctx));
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   646
    ctx->chan = chan;
44
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   647
    
72
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   648
    // ok
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   649
    return chan;
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   650
}
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   651
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   652
/**
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   653
 * Checks that the JOIN request for a channel was sent, and sends the basic JOIN reply
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   654
 */
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   655
void do_irc_chan_join (struct sock_test *sock, struct test_chan_ctx *ctx)
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   656
{
44
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   657
    // JOIN request
72
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   658
    assert(ctx->chan->joining);
44
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   659
    assert_sock_data(sock, "JOIN #test\r\n");
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   660
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   661
    // JOIN reply
52
97604efda1ce add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
   662
    test_sock_push(sock, ":mynick!user@host JOIN #test\r\n");
72
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   663
    assert(!ctx->chan->joining && ctx->chan->joined);
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   664
    assert(ctx->on_chan_self_join);
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   665
}
46
0c13bca53ae1 add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents: 45
diff changeset
   666
72
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   667
/**
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   668
 * Creates an irc_chan on the given irc_net, and checks up to the JOIN reply
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   669
 */
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   670
struct irc_chan* setup_irc_chan (struct sock_test *sock, struct irc_net *net, struct test_chan_ctx *ctx)
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   671
{
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   672
    setup_irc_chan_raw(net, ctx);
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   673
    do_irc_chan_join(sock, ctx);
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   674
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   675
    // ok
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   676
    return ctx->chan;
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   677
}
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   678
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   679
/**
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   680
 * Call irc_net_add_chan while offline, and ensure that we send the JOIN request after RPL_WELCOME, and handle the join
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   681
 * reply OK.
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   682
 */
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   683
void test_irc_chan_add_offline (void)
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   684
{
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   685
    struct test_chan_ctx ctx;
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   686
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   687
    struct sock_test *sock = setup_sock_test();
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   688
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   689
    log_info("test irc_net_create");
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   690
    struct irc_net *net = setup_irc_net_unregistered(sock);
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   691
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   692
    // add an offline channel
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   693
    log_info("test offline irc_net_add_chan");
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   694
    struct irc_chan *chan = setup_irc_chan_raw(net, &ctx);
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   695
    assert(!chan->joining && !chan->joined);
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   696
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   697
    // send the registration reply
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   698
    log_info("test irc_conn_on_RPL_WELCOME");
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   699
    do_irc_net_welcome(sock, net);
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   700
    
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   701
    // test the join sequence
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   702
    log_info("test irc_chan_join/irc_chan_on_JOIN");
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   703
    do_irc_chan_join(sock, &ctx);
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   704
    
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   705
    // cleanup
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   706
    irc_net_destroy(net);
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   707
}
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   708
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   709
/**
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   710
 * Ensure that an irc_chan_user exists for the given channel/nickname, and return it
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   711
 */
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   712
struct irc_chan_user* check_chan_user (struct irc_chan *chan, const char *nickname)
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   713
{
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   714
    struct irc_chan_user *chan_user;
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   715
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   716
    if ((chan_user = irc_chan_get_user(chan, nickname)) == NULL)
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   717
        FATAL("user %s not found in channel %s", dump_str(nickname), dump_str(irc_chan_name(chan)));
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   718
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   719
    log_debug("%s -> %p: user=%p, nickname=%s", nickname, chan_user, chan_user->user, chan_user->user->nickname);
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   720
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   721
    assert_strcmp(chan_user->user->nickname, nickname);
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   722
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   723
    return chan_user;
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   724
}
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   725
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   726
void test_irc_chan_namreply (void)
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   727
{
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   728
    struct test_chan_ctx ctx;
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   729
    struct sock_test *sock = setup_sock_test();
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   730
    struct irc_net *net = setup_irc_net(sock);
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   731
    struct irc_chan *chan = setup_irc_chan(sock, net, &ctx);
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   732
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   733
    // RPL_NAMREPLY
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   734
    log_info("test irc_chan_on_RPL_NAMREPLY");
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   735
    test_sock_push(sock, "353 mynick = #test :mynick userA +userB @userC\r\n");
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   736
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   737
    check_chan_user(chan, "mynick");
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   738
    check_chan_user(chan, "userA");
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   739
    check_chan_user(chan, "userB");
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   740
    check_chan_user(chan, "userC");
47
7d4094eb3117 add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
   741
7d4094eb3117 add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
   742
    // cleanup
7d4094eb3117 add irc_net_destroy and fix code to be valgrind-clean on bin/test
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
   743
    irc_net_destroy(net);
44
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   744
}
6bd70113e1ed add irc_net test
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   745
73
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   746
void test_irc_chan_user_join (void)
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   747
{
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   748
    struct test_chan_ctx ctx;
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   749
    struct sock_test *sock = setup_sock_test();
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   750
    struct irc_net *net = setup_irc_net(sock);
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   751
    struct irc_chan *chan = setup_irc_chan(sock, net, &ctx);
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   752
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   753
    // RPL_NAMREPLY
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   754
    test_sock_push(sock, "353 mynick = #test :mynick userA +userB @userC\r\n");
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   755
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   756
    check_chan_user(chan, "mynick");
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   757
    check_chan_user(chan, "userA");
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   758
    check_chan_user(chan, "userB");
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   759
    check_chan_user(chan, "userC");
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   760
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   761
    // have a user join
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   762
    log_info("test irc_chan_on_JOIN");
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   763
    test_sock_push(sock, ":newuser!someone@somewhere JOIN #test\r\n");
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   764
    assert(ctx.on_chan_join);
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   765
    check_chan_user(chan, "newuser");
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   766
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   767
    // cleanup
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   768
    irc_net_destroy(net);
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   769
}
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   770
40
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   771
/**
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   772
 * Test definition
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   773
 */
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   774
static struct test {
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   775
    /** Test name */
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   776
    const char *name;
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   777
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   778
    /** Test func */
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   779
    void (*func) (void);
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   780
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   781
} _tests[] = {
72
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   782
    {   "dump_str",             &test_dump_str              },
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   783
    {   "sock_test",            &test_sock_test             },
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   784
    {   "line_proto",           &test_line_proto            },
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   785
    {   "irc_conn",             &test_irc_conn              },
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   786
    {   "irc_net",              &test_irc_net               },
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   787
    {   "irc_chan_add_offline", &test_irc_chan_add_offline  },
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   788
    {   "irc_chan_namreply",    &test_irc_chan_namreply     },
73
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   789
    {   "irc_chan_user_join",   &test_irc_chan_user_join    },
72
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 52
diff changeset
   790
    {   NULL,                   NULL                        }
40
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   791
};
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   792
73
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   793
/**
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   794
 * Command-line option codes
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   795
 */
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   796
enum option_code {
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   797
    OPT_HELP            = 'h',
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   798
    OPT_DEBUG           = 'd',
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   799
    OPT_QUIET           = 'q',
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   800
    
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   801
    /** Options without short names */
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   802
    _OPT_EXT_BEGIN      = 0x00ff,
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   803
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   804
};
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   805
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   806
/**
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   807
 * Command-line option definitions
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   808
 */
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   809
static struct option options[] = {
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   810
    {"help",            0,  NULL,   OPT_HELP        },
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   811
    {"debug",           0,  NULL,   OPT_DEBUG       },
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   812
    {"quiet",           0,  NULL,   OPT_QUIET       },
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   813
    {0,                 0,  0,      0               },
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   814
};
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   815
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   816
/**
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   817
 * Display --help output on stdout
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   818
 */
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   819
static void usage (const char *exe) 
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   820
{
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   821
    printf("Usage: %s [OPTIONS]\n", exe);
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   822
    printf("\n");
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   823
    printf(" --help / -h            display this message\n");
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   824
    printf(" --debug / -d           display DEBUG log messages\n");
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   825
    printf(" --quiet / -q           supress INFO log messages\n");
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   826
}
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   827
40
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   828
int main (int argc, char **argv)
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   829
{
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   830
    struct test *test;
73
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   831
    size_t test_count = 0;
52
97604efda1ce add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
   832
    
73
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   833
    int opt, option_index;
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   834
    const char *filter = NULL;
40
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   835
73
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   836
    // parse options
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   837
    while ((opt = getopt_long(argc, argv, "hdq", options, &option_index)) != -1) {
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   838
        switch (opt) {
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   839
            case OPT_HELP:
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   840
                usage(argv[0]);
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   841
                exit(EXIT_SUCCESS);
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   842
            
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   843
            case OPT_DEBUG:
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   844
                set_log_level(LOG_DEBUG);
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   845
                break;
52
97604efda1ce add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
   846
73
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   847
            case OPT_QUIET:
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   848
                set_log_level(LOG_WARN);
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   849
                break;
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   850
            
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   851
            case '?':
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   852
                usage(argv[0]);
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   853
                exit(EXIT_FAILURE);
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   854
        }
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   855
    }
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   856
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   857
    if (optind < argc) {
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   858
        if (optind == argc - 1) {
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   859
            // filter
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   860
            filter = argv[optind];
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   861
            
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   862
            log_info("only running tests: %s", filter);
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   863
        } else {
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   864
            FATAL("too many arguments");
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   865
        }
52
97604efda1ce add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
   866
    }
40
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   867
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   868
    // run tests
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   869
    for (test = _tests; test->name; test++) {
52
97604efda1ce add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
   870
        if (filter && strcmp(test->name, filter))
97604efda1ce add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
   871
            continue;
97604efda1ce add test_sock_push, and filter argument to test main()
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
   872
40
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   873
        log_info("Running test: %s", test->name);
73
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   874
        
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   875
        test_count++;
40
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   876
        test->func();
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   877
    }
46
0c13bca53ae1 add irc_net_error, and improve test_irc_net to cover it as well
Tero Marttila <terom@fixme.fi>
parents: 45
diff changeset
   878
73
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   879
    // no tests run?
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   880
    if (test_count == 0)
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   881
        FATAL("no tests run");
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   882
2780a73c71f3 add set_log_level function, and add --debug/--quiet options to test
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   883
    log_info("done, ran %zu tests", test_count);
40
51678c7eae03 add sock_test module and some basic initial tests
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   884
}