File: loginshelltest.c

package info (click to toggle)
tinyssh 20250501-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 3,388 kB
  • sloc: ansic: 20,245; sh: 1,582; python: 1,449; makefile: 913
file content (64 lines) | stat: -rw-r--r-- 1,352 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
20140429
Jan Mojzis
Public domain.
*/

#include "str.h"
#include "byte.h"
#include "fail.h"
#include "loginshell.h"

static char buf[10];

static struct vector {
    const char *in;
    const char *out;
} vectors[] = {
    { "",  "-" },
    { "/", "-" },
    { "//", "-" },
    { "///", "-" },
    { "////", "-" },
    { "/////", "-" },
    { "/a/b/c/d/", "-" },
    { "/a///d/", "-" },
    { "//b/c//", "-" },
    { "x/", "-" },
    { "x/x/xx/xxx/", "-" },
    { "sh", "-sh" },
    { "/bin/bash", "-bash" },
    { "///////dash", "-dash" },
    { "///////-ksh", "--ksh" },
    /* truncation */
    { "longlongsh", "-longlong" },
    { 0, 0 }
};

static void testok(void) {

    long long i, len;

    for (i = 0; vectors[i].in; ++i) {
        if (!loginshell(buf, sizeof buf, vectors[i].in)) fail("loginshell failure");
        len = str_len(vectors[i].out);
        if (str_len(buf) != len) fail("loginshell failure");
        if (!byte_isequal(buf, len, vectors[i].out)) fail("loginshell failure");
    }
}

static void testbad(void) {

    if (loginshell(buf, -1, "")) fail("loginshell failure");
    if (loginshell(buf, 0, "")) fail("loginshell failure");
    if (loginshell(buf, 1, "")) fail("loginshell failure");
    if (loginshell(buf, 1, "//")) fail("loginshell failure");
}


int main(void) {

    testok();
    testbad();
    _exit(0);
}