FileDocCategorySizeDatePackage
NativeDaemonConnectorTest.javaAPI DocAndroid 5.1 API3582Thu Mar 12 22:22:42 GMT 2015com.android.server

NativeDaemonConnectorTest

public class NativeDaemonConnectorTest extends android.test.AndroidTestCase
Tests for {@link NativeDaemonConnector}.

Fields Summary
private static final String
TAG
Constructors Summary
Methods Summary
public voidtestArgumentNormal()


         
        final StringBuilder builder = new StringBuilder();

        builder.setLength(0);
        appendEscaped(builder, "");
        assertEquals("", builder.toString());

        builder.setLength(0);
        appendEscaped(builder, "foo");
        assertEquals("foo", builder.toString());

        builder.setLength(0);
        appendEscaped(builder, "foo\"bar");
        assertEquals("foo\\\"bar", builder.toString());

        builder.setLength(0);
        appendEscaped(builder, "foo\\bar\\\"baz");
        assertEquals("foo\\\\bar\\\\\\\"baz", builder.toString());
    
public voidtestArgumentWithSpaces()

        final StringBuilder builder = new StringBuilder();

        builder.setLength(0);
        appendEscaped(builder, "foo bar");
        assertEquals("\"foo bar\"", builder.toString());

        builder.setLength(0);
        appendEscaped(builder, "foo\"bar\\baz foo");
        assertEquals("\"foo\\\"bar\\\\baz foo\"", builder.toString());
    
public voidtestArgumentWithUtf()

        final StringBuilder builder = new StringBuilder();

        builder.setLength(0);
        appendEscaped(builder, "caf\u00E9 c\u00F6ffee");
        assertEquals("\"caf\u00E9 c\u00F6ffee\"", builder.toString());
    
public voidtestSensitiveArgs()

        final StringBuilder rawBuilder = new StringBuilder();
        final StringBuilder logBuilder = new StringBuilder();

        rawBuilder.setLength(0);
        logBuilder.setLength(0);
        makeCommand(rawBuilder, logBuilder, 1, "foo", "bar", "baz");
        assertEquals("1 foo bar baz\0", rawBuilder.toString());
        assertEquals("1 foo bar baz", logBuilder.toString());

        rawBuilder.setLength(0);
        logBuilder.setLength(0);
        makeCommand(rawBuilder, logBuilder, 1, "foo", new SensitiveArg("bar"), "baz");
        assertEquals("1 foo bar baz\0", rawBuilder.toString());
        assertEquals("1 foo [scrubbed] baz", logBuilder.toString());

        rawBuilder.setLength(0);
        logBuilder.setLength(0);
        makeCommand(rawBuilder, logBuilder, 1, "foo", new SensitiveArg("foo bar"), "baz baz",
                new SensitiveArg("wat"));
        assertEquals("1 foo \"foo bar\" \"baz baz\" wat\0", rawBuilder.toString());
        assertEquals("1 foo [scrubbed] \"baz baz\" [scrubbed]", logBuilder.toString());