1 /***
2 * Ambient - A music player for the Android platform
3 Copyright (C) 2007 Martin Vysny
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 package sk.baka.ambient.commons;
20
21 import junit.framework.TestCase;
22
23 /***
24 * Tests the {@link MiscUtils} class.
25 *
26 * @author Martin Vysny
27 */
28 public final class IOUtilsTest extends TestCase {
29 /***
30 */
31 public void testStripExt() {
32 assertEquals("", IOUtils.stripExt(""));
33 assertEquals("huhu", IOUtils.stripExt("huhu"));
34 assertEquals("huhu/haha", IOUtils.stripExt("huhu/haha"));
35 assertEquals("huhu.ext/haha", IOUtils.stripExt("huhu.ext/haha"));
36 assertEquals("huhu.ext/haha", IOUtils.stripExt("huhu.ext/haha.e"));
37 assertEquals("huhu/haha", IOUtils.stripExt("huhu/haha.e"));
38 }
39
40 /***
41 */
42 public void testGetExt() {
43 assertEquals("", IOUtils.getExt(""));
44 assertEquals("", IOUtils.getExt("huhu"));
45 assertEquals(".png", IOUtils.getExt("huhu.png"));
46 assertEquals(".png", IOUtils.getExt("huhu/haha.png"));
47 assertEquals("", IOUtils.getExt("huhu.ext/haha"));
48 assertEquals(".e", IOUtils.getExt("huhu.ext/haha.e"));
49 assertEquals(".e", IOUtils.getExt("huhu/haha.e"));
50 }
51
52 /***
53 * @throws Exception
54 */
55 public void testParseRequest() throws Exception {
56 invalidRequest("");
57 invalidRequest("GET");
58 invalidRequest("GET /huhu");
59 invalidRequest("GET /huhu HTTP20");
60 IOUtils.HttpRequest req = IOUtils
61 .parseRequest("GET /huhu/foo/bar?cica=mica&haha=huhu HTTP/1.1\n");
62 assertEquals("GET", req.method);
63 assertEquals("/huhu/foo/bar?cica=mica&haha=huhu", req.requestPath);
64 assertEquals("/huhu/foo/bar", req.path);
65 assertEquals(1, req.version);
66 assertEquals("mica", req.query.get("cica"));
67 assertEquals("huhu", req.query.get("haha"));
68 }
69
70 private void invalidRequest(String string) {
71 try {
72 IOUtils.parseRequest(string);
73 fail();
74 } catch (ServerHttpException e) {
75
76 }
77 }
78 }