~ubuntu-branches/debian/stretch/gnome-builder/stretch

« back to all changes in this revision

Viewing changes to tests/test-ide-vcs-uri.c

  • Committer: Package Import Robot
  • Author(s): Andreas Henriksson
  • Date: 2015-10-11 12:38:45 UTC
  • Revision ID: package-import@ubuntu.com-20151011123845-a0hvkz01se0p1p5a
Tags: upstream-3.16.3
ImportĀ upstreamĀ versionĀ 3.16.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <ide.h>
 
2
 
 
3
typedef struct
 
4
{
 
5
  const gchar *uri;
 
6
  const gchar *expected_scheme;
 
7
  const gchar *expected_user;
 
8
  const gchar *expected_host;
 
9
  const gchar *expected_path;
 
10
  guint        expected_port;
 
11
  const gchar *canonical;
 
12
} UriTest;
 
13
 
 
14
static void
 
15
test_sample_uris (void)
 
16
{
 
17
  static const UriTest sample_uris[] = {
 
18
    { "ssh://user@host.xz:22/path/to/repo.git/", "ssh", "user", "host.xz", "/path/to/repo.git/", 22, "ssh://user@host.xz:22/path/to/repo.git/" },
 
19
    { "ssh://user@host.xz/path/to/repo.git/", "ssh", "user", "host.xz", "/path/to/repo.git/", 0, "ssh://user@host.xz/path/to/repo.git/" },
 
20
    { "ssh://host.xz:1234/path/to/repo.git/", "ssh", NULL,"host.xz", "/path/to/repo.git/", 1234, "ssh://host.xz:1234/path/to/repo.git/" },
 
21
    { "ssh://host.xz/path/to/repo.git/", "ssh", NULL,"host.xz", "/path/to/repo.git/", 0, "ssh://host.xz/path/to/repo.git/" },
 
22
    { "ssh://user@host.xz/path/to/repo.git/", "ssh", "user","host.xz", "/path/to/repo.git/", 0, "ssh://user@host.xz/path/to/repo.git/" },
 
23
    { "ssh://host.xz/path/to/repo.git/", "ssh", NULL,"host.xz", "/path/to/repo.git/", 0, "ssh://host.xz/path/to/repo.git/" },
 
24
    { "ssh://user@host.xz/~user/path/to/repo.git/", "ssh", "user", "host.xz", "~user/path/to/repo.git/", 0, "ssh://user@host.xz/~user/path/to/repo.git/" },
 
25
    { "ssh://host.xz/~user/path/to/repo.git/", "ssh", NULL,"host.xz", "~user/path/to/repo.git/", 0, "ssh://host.xz/~user/path/to/repo.git/" },
 
26
    { "ssh://user@host.xz/~/path/to/repo.git", "ssh", "user", "host.xz", "~/path/to/repo.git",0, "ssh://user@host.xz/~/path/to/repo.git" },
 
27
    { "ssh://host.xz/~/path/to/repo.git", "ssh", NULL, "host.xz", "~/path/to/repo.git", 0, "ssh://host.xz/~/path/to/repo.git" },
 
28
    { "user@host.xz:/path/to/repo.git/", "ssh", "user", "host.xz", "/path/to/repo.git/", 0, "ssh://user@host.xz/path/to/repo.git/" },
 
29
    { "host.xz:/path/to/repo.git/", "ssh", NULL, "host.xz", "/path/to/repo.git/", 0, "ssh://host.xz/path/to/repo.git/" },
 
30
    { "user@host.xz:~user/path/to/repo.git/", "ssh", "user", "host.xz", "~user/path/to/repo.git/", 0, "ssh://user@host.xz/~user/path/to/repo.git/" },
 
31
    { "host.xz:~user/path/to/repo.git/", "ssh", NULL, "host.xz", "~user/path/to/repo.git/", 0, "ssh://host.xz/~user/path/to/repo.git/" },
 
32
    { "user@host.xz:path/to/repo.git", "ssh", "user", "host.xz", "path/to/repo.git", 0, "ssh://user@host.xz/path/to/repo.git" },
 
33
    { "host.xz:path/to/repo.git", "ssh", NULL, "host.xz", "path/to/repo.git", 0, "ssh://host.xz/path/to/repo.git" },
 
34
    { "rsync://host.xz/path/to/repo.git/", "rsync", NULL, "host.xz", "/path/to/repo.git/", 0, "rsync://host.xz/path/to/repo.git/" },
 
35
    { "git://host.xz/path/to/repo.git/", "git", NULL, "host.xz", "/path/to/repo.git/", 0, "git://host.xz/path/to/repo.git/" },
 
36
    { "git://host.xz/~user/path/to/repo.git/", "git", NULL, "host.xz", "~user/path/to/repo.git/", 0, "git://host.xz/~user/path/to/repo.git/" },
 
37
    { "http://host.xz/path/to/repo.git/", "http", NULL, "host.xz", "/path/to/repo.git/", 0, "http://host.xz/path/to/repo.git/" },
 
38
    { "https://host.xz/path/to/repo.git/", "https", NULL, "host.xz", "/path/to/repo.git/", 0, "https://host.xz/path/to/repo.git/" },
 
39
    { "/path/to/repo.git/", "file", NULL, NULL, "/path/to/repo.git/", 0, "file:///path/to/repo.git/" },
 
40
    { "path/to/repo.git/", "file", NULL, NULL, "path/to/repo.git/", 0, "file://path/to/repo.git/" },
 
41
    { "~/path/to/repo.git", "file", NULL, NULL, "~/path/to/repo.git", 0, "file://~/path/to/repo.git" },
 
42
    { "file:///path/to/repo.git/", "file", NULL, NULL, "/path/to/repo.git/", 0, "file:///path/to/repo.git/" },
 
43
    { "file://~/path/to/repo.git/", "file", NULL, NULL, "~/path/to/repo.git/", 0, "file://~/path/to/repo.git/" },
 
44
    { NULL }
 
45
  };
 
46
  guint i;
 
47
 
 
48
  for (i = 0; sample_uris [i].uri; i++)
 
49
    {
 
50
      g_autoptr(IdeVcsUri) uri = NULL;
 
51
      g_autofree gchar *to_string = NULL;
 
52
 
 
53
      uri = ide_vcs_uri_new (sample_uris [i].uri);
 
54
 
 
55
      if (uri == NULL)
 
56
        g_error ("Failed to parse %s\n", sample_uris [i].uri);
 
57
 
 
58
#if 0
 
59
      g_print ("\n%s (%u)\n"
 
60
               "  scheme: %s\n"
 
61
               "    user: %s\n"
 
62
               "    host: %s\n"
 
63
               "    port: %u\n"
 
64
               "    path: %s\n",
 
65
               sample_uris [i].uri, i,
 
66
               ide_vcs_uri_get_scheme (uri),
 
67
               ide_vcs_uri_get_user (uri),
 
68
               ide_vcs_uri_get_host (uri),
 
69
               ide_vcs_uri_get_port (uri),
 
70
               ide_vcs_uri_get_path (uri));
 
71
#endif
 
72
 
 
73
      g_assert (uri != NULL);
 
74
      g_assert_cmpstr (sample_uris [i].expected_scheme, ==, ide_vcs_uri_get_scheme (uri));
 
75
      g_assert_cmpstr (sample_uris [i].expected_user, ==, ide_vcs_uri_get_user (uri));
 
76
      g_assert_cmpstr (sample_uris [i].expected_host, ==, ide_vcs_uri_get_host (uri));
 
77
      g_assert_cmpstr (sample_uris [i].expected_path, ==, ide_vcs_uri_get_path (uri));
 
78
      g_assert_cmpint (sample_uris [i].expected_port, ==, ide_vcs_uri_get_port (uri));
 
79
 
 
80
      to_string = ide_vcs_uri_to_string (uri);
 
81
      g_assert_cmpstr (sample_uris [i].canonical, ==, to_string);
 
82
    }
 
83
}
 
84
 
 
85
gint
 
86
main (gint argc,
 
87
      gchar *argv[])
 
88
{
 
89
  g_test_init (&argc, &argv, NULL);
 
90
  g_test_add_func ("/Ide/VcsUri/sample_uris", test_sample_uris);
 
91
  return g_test_run ();
 
92
}