Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkQPActivity.java
Go to the documentation of this file.
1package org.skia.skqp;
2
3import android.content.Context;
4import android.content.res.AssetManager;
5import android.os.Bundle;
6import android.support.v7.app.AppCompatActivity;
7import android.support.v7.widget.Toolbar;
8import android.util.Log;
9import java.io.File;
10import java.io.IOException;
11
12public class SkQPActivity extends AppCompatActivity implements Runnable {
13 @Override
14 protected void onCreate(Bundle savedInstanceState) {
15 super.onCreate(savedInstanceState);
16 setContentView(R.layout.activity_skqp);
17 Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
18 setSupportActionBar(toolbar);
19
20 // Start the tests.
21 run();
22 }
23
24 // run implements the Runnable interface.
25 public void run() {
26 // Note: /sdcard/Android/data/<package-name> is a location an app is allowed to write to.
27 // When running tests on Firebase it expects any result files to have a '/sdcard
28 // prefix or it won't trigger tests from the CLI.
29
30 Context context = getApplicationContext();
31 String outputDirPath = "/sdcard/Android/data/" + context.getPackageName();
32 SkQP impl = new SkQP();
33
34 Log.i(SkQP.LOG_PREFIX, "Output Dir: " + outputDirPath);
35 File outputDir = new File(outputDirPath);
36 try {
37 SkQPActivity.ensureEmptyDirectory(outputDir);
38 } catch (IOException e) {
39 Log.e(SkQP.LOG_PREFIX, "ensureEmptyDirectory:" + e.getMessage());
40 }
41
42 // Note: nInit will initialize the mUnitTests field.
43 AssetManager assetManager = context.getResources().getAssets();
44 impl.nInit(assetManager, outputDirPath);
45
46 for (int unitTest = 0; unitTest < impl.mUnitTests.length; unitTest++) {
47 String testName = SkQP.kSkiaUnitTests + "_" + impl.mUnitTests[unitTest];
48 Log.w(SkQP.LOG_PREFIX, "Running: " + testName);
49 String[] errors = impl.nExecuteUnitTest(unitTest);
50 if (errors != null && errors.length > 0) {
51 for (String error : errors) {
52 Log.w(SkQP.LOG_PREFIX, "Error running " + testName + ":" + error);
53 }
54 } else {
55 Log.i(SkQP.LOG_PREFIX, "Test: " + testName + " finished successfully.");
56 }
57 }
58 Log.i(SkQP.LOG_PREFIX, "Finished running all tests.");
59 impl.nMakeReport();
60
61 finish();
62 }
63
64 private static void ensureEmptyDirectory(File f) throws IOException {
65 if (f.exists()) {
66 SkQPActivity.delete(f);
67 }
68 if (!f.mkdirs()) {
69 throw new IOException("Unable to create directory:" + f.getAbsolutePath());
70 }
71 }
72
73 private static void delete(File f) throws IOException {
74 if (f.isDirectory()) {
75 for (File s : f.listFiles()) {
76 SkQPActivity.delete(s);
77 }
78 }
79 if (!f.delete()) {
80 throw new IOException("Unable to delete:" + f.getAbsolutePath());
81 }
82 }
83}
84
void onCreate(Bundle savedInstanceState)
native void nMakeReport()
static final String LOG_PREFIX
Definition SkQP.java:30
String[] mUnitTests
Definition SkQP.java:21
native String[] nExecuteUnitTest(int test)
native void nInit(AssetManager assetManager, String dataDir)
struct MyStruct s
const uint8_t uint32_t uint32_t GError ** error
#define R(r)