1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.gallery3d.data;
18
19import android.test.AndroidTestCase;
20import android.test.suitebuilder.annotation.SmallTest;
21
22public class PathTest extends AndroidTestCase {
23    @SuppressWarnings("unused")
24    private static final String TAG = "PathTest";
25
26    @SmallTest
27    public void testToString() {
28        Path p = Path.fromString("/hello/world");
29        assertEquals("/hello/world", p.toString());
30
31        p = Path.fromString("/a");
32        assertEquals("/a", p.toString());
33
34        p = Path.fromString("");
35        assertEquals("", p.toString());
36    }
37
38    @SmallTest
39    public void testSplit() {
40        Path p = Path.fromString("/hello/world");
41        String[] s = p.split();
42        assertEquals(2, s.length);
43        assertEquals("hello", s[0]);
44        assertEquals("world", s[1]);
45
46        p = Path.fromString("");
47        assertEquals(0, p.split().length);
48    }
49
50    @SmallTest
51    public void testPrefix() {
52        Path p = Path.fromString("/hello/world");
53        assertEquals("hello", p.getPrefix());
54
55        p = Path.fromString("");
56        assertEquals("", p.getPrefix());
57    }
58
59    @SmallTest
60    public void testGetChild() {
61        Path p = Path.fromString("/hello");
62        Path q = Path.fromString("/hello/world");
63        assertSame(q, p.getChild("world"));
64        Path r = q.getChild(17);
65        assertEquals("/hello/world/17", r.toString());
66    }
67
68    @SmallTest
69    public void testSplitSequence() {
70        String[] s = Path.splitSequence("{a,bb,ccc}");
71        assertEquals(3, s.length);
72        assertEquals("a", s[0]);
73        assertEquals("bb", s[1]);
74        assertEquals("ccc", s[2]);
75
76        s = Path.splitSequence("{a,{bb,ccc},d}");
77        assertEquals(3, s.length);
78        assertEquals("a", s[0]);
79        assertEquals("{bb,ccc}", s[1]);
80        assertEquals("d", s[2]);
81    }
82}
83