aboutsummaryrefslogtreecommitdiff
path: root/tests/unittests/torture_misc.c
blob: bcede39bc931c2191d617b27e8edbe02fa59d539 (plain)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <sys/types.h>
#include <pwd.h>

#define LIBSSH_STATIC
#include <libssh/priv.h>

#include "torture.h"
#include "misc.c"
#define DIR "/usr/local/bin/truc/much/.."

START_TEST (torture_get_user_home_dir)
{
    struct passwd *pwd;
    char *user;

    pwd = getpwuid(getuid());

    user = ssh_get_user_home_dir();
    ck_assert_str_eq(user, pwd->pw_dir);

    SAFE_FREE(user);
}
END_TEST

START_TEST (torture_basename)
{
    char *path;
    path=ssh_basename(DIR "/test");
    ck_assert(path != NULL);
    ck_assert_str_eq(path, "test");
    SAFE_FREE(path);
    path=ssh_basename(DIR "/test/");
    ck_assert(path != NULL);
    ck_assert_str_eq(path, "test");
    SAFE_FREE(path);
}
END_TEST

START_TEST (torture_dirname)
{
    char *path;
    path=ssh_dirname(DIR "/test");
    ck_assert(path != NULL);
    ck_assert_str_eq(path, DIR );
    SAFE_FREE(path);
    path=ssh_dirname(DIR "/test/");
    ck_assert(path != NULL);
    ck_assert_str_eq(path, DIR);
    SAFE_FREE(path);
}
END_TEST

static Suite *torture_make_suite(void) {
  Suite *s = suite_create("libssh_misc");

  torture_create_case(s, "torture_get_user_home_dir", torture_get_user_home_dir);
  torture_create_case(s, "torture_basename", torture_basename);
  torture_create_case(s, "torture_dirname", torture_dirname);

  return s;
}

int main(int argc, char **argv) {
  Suite *s = NULL;
  SRunner *sr = NULL;
  struct argument_s arguments;
  int nf;

  ZERO_STRUCT(arguments);

  torture_cmdline_parse(argc, argv, &arguments);

  s = torture_make_suite();

  sr = srunner_create(s);
  if (arguments.nofork) {
    srunner_set_fork_status(sr, CK_NOFORK);
  }
  srunner_run_all(sr, CK_VERBOSE);
  nf = srunner_ntests_failed(sr);
  srunner_free(sr);

  return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}