1/*
2 * Copyright (C) 2011 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.server;
18
19import static com.android.server.NativeDaemonConnector.appendEscaped;
20
21import android.test.AndroidTestCase;
22import android.test.suitebuilder.annotation.MediumTest;
23
24/**
25 * Tests for {@link NativeDaemonConnector}.
26 */
27@MediumTest
28public class NativeDaemonConnectorTest extends AndroidTestCase {
29    private static final String TAG = "NativeDaemonConnectorTest";
30
31    public void testArgumentNormal() throws Exception {
32        final StringBuilder builder = new StringBuilder();
33
34        builder.setLength(0);
35        appendEscaped(builder, "");
36        assertEquals("", builder.toString());
37
38        builder.setLength(0);
39        appendEscaped(builder, "foo");
40        assertEquals("foo", builder.toString());
41
42        builder.setLength(0);
43        appendEscaped(builder, "foo\"bar");
44        assertEquals("foo\\\"bar", builder.toString());
45
46        builder.setLength(0);
47        appendEscaped(builder, "foo\\bar\\\"baz");
48        assertEquals("foo\\\\bar\\\\\\\"baz", builder.toString());
49    }
50
51    public void testArgumentWithSpaces() throws Exception {
52        final StringBuilder builder = new StringBuilder();
53
54        builder.setLength(0);
55        appendEscaped(builder, "foo bar");
56        assertEquals("\"foo bar\"", builder.toString());
57
58        builder.setLength(0);
59        appendEscaped(builder, "foo\"bar\\baz foo");
60        assertEquals("\"foo\\\"bar\\\\baz foo\"", builder.toString());
61    }
62
63    public void testArgumentWithUtf() throws Exception {
64        final StringBuilder builder = new StringBuilder();
65
66        builder.setLength(0);
67        appendEscaped(builder, "caf\u00E9 c\u00F6ffee");
68        assertEquals("\"caf\u00E9 c\u00F6ffee\"", builder.toString());
69    }
70}
71