Merge lp:~mhr3/unity-lens-files/moar-tests into lp:unity-lens-files

Proposed by Michal Hruby
Status: Merged
Approved by: Mikkel Kamstrup Erlandsen
Approved revision: 221
Merged at revision: 221
Proposed branch: lp:~mhr3/unity-lens-files/moar-tests
Merge into: lp:unity-lens-files
Diff against target: 211 lines (+164/-3)
6 files modified
Makefile.am (+1/-1)
configure.ac (+1/-0)
src/url-checker.vala (+2/-2)
tests/Makefile.am (+27/-0)
tests/assertions.vapi (+23/-0)
tests/test-url-checker.vala (+110/-0)
To merge this branch: bzr merge lp:~mhr3/unity-lens-files/moar-tests
Reviewer Review Type Date Requested Status
Mikkel Kamstrup Erlandsen (community) Approve
Review via email: mp+98373@code.launchpad.net

Commit message

Fix URL checking regressions, add tests

Description of the change

Fixes regressions in UrlChecker, adds unit tests for UrlChecker

To post a comment you must log in.
Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

Loving it!

(have you considered upstreaming assertions.vapi? I think it would be great to have a GLib.Assertions namespace)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile.am'
2--- Makefile.am 2011-08-07 09:01:34 +0000
3+++ Makefile.am 2012-03-20 09:43:20 +0000
4@@ -1,4 +1,4 @@
5-SUBDIRS = src data po
6+SUBDIRS = src data po tests
7
8 #
9 # Install the files.lens file
10
11=== modified file 'configure.ac'
12--- configure.ac 2012-03-12 08:40:35 +0000
13+++ configure.ac 2012-03-20 09:43:20 +0000
14@@ -127,6 +127,7 @@
15 src/Makefile
16 src/config.vala
17 po/Makefile.in
18+ tests/Makefile
19 ])
20 AC_OUTPUT
21
22
23=== modified file 'src/url-checker.vala'
24--- src/url-checker.vala 2012-03-14 16:04:50 +0000
25+++ src/url-checker.vala 2012-03-20 09:43:20 +0000
26@@ -53,8 +53,8 @@
27 mountable_icon = new ThemedIcon ("folder-remote").to_string ();
28
29 try {
30- web_regex = new Regex ("(http[s]{0,1}://.+){0,1}" +
31- "[a-zA-Z0-9\\-\\.]+\\." + TLD_REGEX + "$",
32+ web_regex = new Regex ("(http[s]?://.+)|" +
33+ "([a-zA-Z0-9\\-\\.]+\\." +TLD_REGEX+ "\\b.*)",
34 RegexCompileFlags.OPTIMIZE);
35 mountable_regex = new Regex ("(\\\\|(ftp|ssh|sftp|smb|dav)://).+");
36 } catch (RegexError e) {
37
38=== added file 'tests/Makefile.am'
39--- tests/Makefile.am 1970-01-01 00:00:00 +0000
40+++ tests/Makefile.am 2012-03-20 09:43:20 +0000
41@@ -0,0 +1,27 @@
42+check_PROGRAMS = test-url-checker
43+
44+TESTS = $(check_PROGRAMS)
45+
46+AM_CPPFLAGS = \
47+ -w \
48+ $(LENS_DAEMON_CFLAGS) \
49+ $(NULL)
50+
51+AM_VALAFLAGS = \
52+ --pkg gio-2.0 \
53+ $(srcdir)/assertions.vapi \
54+ $(NULL)
55+
56+test_libs = \
57+ $(LENS_DAEMON_LIBS) \
58+ $(NULL)
59+
60+test_url_checker_LDADD = $(test_libs)
61+
62+test_url_checker_SOURCES = \
63+ test-url-checker.vala \
64+ $(top_srcdir)/src/url-checker.vala \
65+ $(NULL)
66+
67+CLEANFILES = *.stamp
68+
69
70=== added file 'tests/assertions.vapi'
71--- tests/assertions.vapi 1970-01-01 00:00:00 +0000
72+++ tests/assertions.vapi 2012-03-20 09:43:20 +0000
73@@ -0,0 +1,23 @@
74+[CCode (cprefix = "G", lower_case_cprefix = "g_", cheader_filename = "glib.h")]
75+namespace Assertions {
76+ public enum OperatorType {
77+ [CCode (cname = "==")]
78+ EQUAL,
79+ [CCode (cname = "!=")]
80+ NOT_EQUAL,
81+ [CCode (cname = "<")]
82+ LESS_THAN,
83+ [CCode (cname = ">")]
84+ GREATER_THAN,
85+ [CCode (cname = "<=")]
86+ LESS_OR_EQUAL,
87+ [CCode (cname = ">=")]
88+ GREATER_OR_EQUAL
89+ }
90+
91+ public void assert_cmpstr (string? s1, OperatorType op, string? s2);
92+ public void assert_cmpint (int n1, OperatorType op, int n2);
93+ public void assert_cmpuint (uint n1, OperatorType op, uint n2);
94+ public void assert_cmphex (uint n1, OperatorType op, uint n2);
95+ public void assert_cmpfloat (float n1, OperatorType op, float n2);
96+}
97
98=== added file 'tests/test-url-checker.vala'
99--- tests/test-url-checker.vala 1970-01-01 00:00:00 +0000
100+++ tests/test-url-checker.vala 2012-03-20 09:43:20 +0000
101@@ -0,0 +1,110 @@
102+/*
103+ * Copyright (C) 2012 Canonical Ltd
104+ *
105+ * This program is free software: you can redistribute it and/or modify
106+ * it under the terms of the GNU General Public License version 3 as
107+ * published by the Free Software Foundation.
108+ *
109+ * This program is distributed in the hope that it will be useful,
110+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
111+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
112+ * GNU General Public License for more details.
113+ *
114+ * You should have received a copy of the GNU General Public License
115+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
116+ *
117+ * Authored by Michal Hruby <michal.hruby@canonical.com>
118+ *
119+ */
120+
121+using Unity.FilesLens;
122+using Assertions;
123+
124+public class Main
125+{
126+ public static int main (string[] args)
127+ {
128+ Test.init (ref args);
129+
130+ Test.add_data_func ("/Unit/UrlChecker/WebUris", test_web_uris);
131+ Test.add_data_func ("/Unit/UrlChecker/MountableUris", test_mountable_uris);
132+
133+ Test.run ();
134+
135+ return 0;
136+ }
137+
138+ private static void test_web_uris ()
139+ {
140+ string result;
141+ var checker = new UrlChecker ();
142+ UrlType url_type;
143+
144+ result = checker.check_url ("facebook.com", out url_type);
145+ assert_cmpint (url_type, OperatorType.EQUAL, UrlType.WEB);
146+ assert_cmpstr (result, OperatorType.EQUAL, "http://facebook.com");
147+
148+ result = checker.check_url ("google.co.uk", out url_type);
149+ assert_cmpint (url_type, OperatorType.EQUAL, UrlType.WEB);
150+ assert_cmpstr (result, OperatorType.EQUAL, "http://google.co.uk");
151+
152+ result = checker.check_url ("http://www.bbc.co.uk", out url_type);
153+ assert_cmpint (url_type, OperatorType.EQUAL, UrlType.WEB);
154+ assert_cmpstr (result, OperatorType.EQUAL, "http://www.bbc.co.uk");
155+
156+ result = checker.check_url ("https://launchpad.net", out url_type);
157+ assert_cmpint (url_type, OperatorType.EQUAL, UrlType.WEB);
158+ assert_cmpstr (result, OperatorType.EQUAL, "https://launchpad.net");
159+
160+ result = checker.check_url ("https://code.launchpad.net/unity-lens-files", out url_type);
161+ assert_cmpint (url_type, OperatorType.EQUAL, UrlType.WEB);
162+ assert_cmpstr (result, OperatorType.EQUAL, "https://code.launchpad.net/unity-lens-files");
163+
164+ result = checker.check_url ("google.com/?q=unity-lens-files", out url_type);
165+ assert_cmpint (url_type, OperatorType.EQUAL, UrlType.WEB);
166+ assert_cmpstr (result, OperatorType.EQUAL, "http://google.com/?q=unity-lens-files");
167+
168+ result = checker.check_url ("192.168.0.1", out url_type);
169+ assert_cmpint (url_type, OperatorType.EQUAL, UrlType.WEB);
170+ assert_cmpstr (result, OperatorType.EQUAL, "http://192.168.0.1");
171+
172+ result = checker.check_url ("daemon.vala", out url_type);
173+ assert_cmpint (url_type, OperatorType.EQUAL, UrlType.UNKNOWN);
174+ assert_cmpstr (result, OperatorType.EQUAL, null);
175+
176+ result = checker.check_url ("non-existing-tld.qv", out url_type);
177+ assert_cmpint (url_type, OperatorType.EQUAL, UrlType.UNKNOWN);
178+ assert_cmpstr (result, OperatorType.EQUAL, null);
179+ }
180+
181+ private static void test_mountable_uris ()
182+ {
183+ string result;
184+ var checker = new UrlChecker ();
185+ UrlType url_type;
186+
187+ result = checker.check_url ("\\\\smb_share", out url_type);
188+ assert_cmpint (url_type, OperatorType.EQUAL, UrlType.MOUNTABLE);
189+ assert_cmpstr (result, OperatorType.EQUAL, "smb://smb_share");
190+
191+ result = checker.check_url ("smb://another_share", out url_type);
192+ assert_cmpint (url_type, OperatorType.EQUAL, UrlType.MOUNTABLE);
193+ assert_cmpstr (result, OperatorType.EQUAL, "smb://another_share");
194+
195+ result = checker.check_url ("ftp://mozilla.org", out url_type);
196+ assert_cmpint (url_type, OperatorType.EQUAL, UrlType.MOUNTABLE);
197+ assert_cmpstr (result, OperatorType.EQUAL, "ftp://mozilla.org");
198+
199+ result = checker.check_url ("ssh://a.server.somewhere", out url_type);
200+ assert_cmpint (url_type, OperatorType.EQUAL, UrlType.MOUNTABLE);
201+ assert_cmpstr (result, OperatorType.EQUAL, "ssh://a.server.somewhere");
202+
203+ result = checker.check_url ("sftp://secure.mozilla.org", out url_type);
204+ assert_cmpint (url_type, OperatorType.EQUAL, UrlType.MOUNTABLE);
205+ assert_cmpstr (result, OperatorType.EQUAL, "sftp://secure.mozilla.org");
206+
207+ result = checker.check_url ("dav://dav.share.co.uk", out url_type);
208+ assert_cmpint (url_type, OperatorType.EQUAL, UrlType.MOUNTABLE);
209+ assert_cmpstr (result, OperatorType.EQUAL, "dav://dav.share.co.uk");
210+ }
211+}

Subscribers

People subscribed via source and target branches