• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* 	$OpenBSD: tests.c,v 1.1 2019/04/28 22:53:26 dtucker Exp $ */
2 /*
3  * Regress test for misc helper functions.
4  *
5  * Placed in the public domain.
6  */
7 
8 #include <sys/types.h>
9 #include <sys/param.h>
10 #include <stdio.h>
11 #include <stdint.h>
12 #include <stdlib.h>
13 #include <string.h>
14 
15 #include "test_helper.h"
16 
17 #include "misc.h"
18 
19 void
tests(void)20 tests(void)
21 {
22 	int port;
23 	char *user, *host, *path;
24 
25 	TEST_START("misc_parse_user_host_path");
26 	ASSERT_INT_EQ(parse_user_host_path("someuser@some.host:some/path",
27 	    &user, &host, &path), 0);
28 	ASSERT_STRING_EQ(user, "someuser");
29 	ASSERT_STRING_EQ(host, "some.host");
30 	ASSERT_STRING_EQ(path, "some/path");
31 	free(user); free(host); free(path);
32 	TEST_DONE();
33 
34 	TEST_START("misc_parse_user_ipv4_path");
35 	ASSERT_INT_EQ(parse_user_host_path("someuser@1.22.33.144:some/path",
36 	    &user, &host, &path), 0);
37 	ASSERT_STRING_EQ(user, "someuser");
38 	ASSERT_STRING_EQ(host, "1.22.33.144");
39 	ASSERT_STRING_EQ(path, "some/path");
40 	free(user); free(host); free(path);
41 	TEST_DONE();
42 
43 	TEST_START("misc_parse_user_[ipv4]_path");
44 	ASSERT_INT_EQ(parse_user_host_path("someuser@[1.22.33.144]:some/path",
45 	    &user, &host, &path), 0);
46 	ASSERT_STRING_EQ(user, "someuser");
47 	ASSERT_STRING_EQ(host, "1.22.33.144");
48 	ASSERT_STRING_EQ(path, "some/path");
49 	free(user); free(host); free(path);
50 	TEST_DONE();
51 
52 	TEST_START("misc_parse_user_[ipv4]_nopath");
53 	ASSERT_INT_EQ(parse_user_host_path("someuser@[1.22.33.144]:",
54 	    &user, &host, &path), 0);
55 	ASSERT_STRING_EQ(user, "someuser");
56 	ASSERT_STRING_EQ(host, "1.22.33.144");
57 	ASSERT_STRING_EQ(path, ".");
58 	free(user); free(host); free(path);
59 	TEST_DONE();
60 
61 	TEST_START("misc_parse_user_ipv6_path");
62 	ASSERT_INT_EQ(parse_user_host_path("someuser@[::1]:some/path",
63 	    &user, &host, &path), 0);
64 	ASSERT_STRING_EQ(user, "someuser");
65 	ASSERT_STRING_EQ(host, "::1");
66 	ASSERT_STRING_EQ(path, "some/path");
67 	free(user); free(host); free(path);
68 	TEST_DONE();
69 
70 	TEST_START("misc_parse_uri");
71 	ASSERT_INT_EQ(parse_uri("ssh", "ssh://someuser@some.host:22/some/path",
72 	    &user, &host, &port, &path), 0);
73 	ASSERT_STRING_EQ(user, "someuser");
74 	ASSERT_STRING_EQ(host, "some.host");
75 	ASSERT_INT_EQ(port, 22);
76 	ASSERT_STRING_EQ(path, "some/path");
77 	free(user); free(host); free(path);
78 	TEST_DONE();
79 }
80