• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2006-2013 the original author or authors.
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 
17 package org.objenesis.tck.android;
18 
19 import android.app.Activity;
20 import android.app.Instrumentation;
21 import android.os.Bundle;
22 
23 import org.objenesis.tck.Main;
24 
25 import java.io.ByteArrayOutputStream;
26 import java.io.IOException;
27 import java.io.PrintStream;
28 
29 /**
30  * Wraps the Objenesis TCK so that it can be invoked on Android as an {@link Instrumentation}.
31  *
32  * @author Ian Parkinson (Google Inc.)
33  */
34 public class TckInstrumentation extends Instrumentation {
35 
onCreate(Bundle arguments)36    public void onCreate(Bundle arguments) {
37       ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
38       PrintStream printStream = new PrintStream(outputStream);
39       System.setOut(printStream);
40 
41       try {
42          Main.main(new String[0]);
43       } catch (IOException e) {
44          e.printStackTrace();
45       }
46 
47       Bundle bundle = new Bundle();
48       String fromStdout = outputStream.toString();
49       bundle.putString(Instrumentation.REPORT_KEY_STREAMRESULT, fromStdout);
50       finish(Activity.RESULT_OK, bundle);
51    }
52 }
53 
54