Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
package com.tencent.shadow.core.manager.installplugin;

import android.content.Context;
import android.os.Build;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.json.JSONException;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -63,6 +65,11 @@ public class DbCompatibilityTest {

@Before
public void setUp() {
//因为sqlite3本身的bug和版本不一致导致dump结果不一致,这个单元测试只能在Android P上完整正常运行
//Android 4.4系统在init时会出现内部错误
//Android 7.0系统dump出的sql对表名加了额外的双引号,兼容略麻烦
Assume.assumeTrue(Build.VERSION.SDK_INT == Build.VERSION_CODES.P);

context = InstrumentationRegistry.getTargetContext();
databasePath = context.getDatabasePath(
InstalledPluginDBHelper.DB_NAME_PREFIX + TEST_DB_NAME
Expand Down Expand Up @@ -201,6 +208,11 @@ private void initDb(File initSqlFile)
if (timeout) {
throw new TimeoutException("exec超时");
}
int exitValue = p.exitValue();
if (exitValue != 0) {
String errorOutput = IOUtils.toString(p.getErrorStream(), Charset.defaultCharset());
throw new Error("exitValue==" + exitValue + " errorOutput==" + errorOutput);
}
}

/**
Expand Down Expand Up @@ -232,6 +244,12 @@ private void dumpDbToFile(File dumpSqlFile)
throw new TimeoutException("exec超时");
}

int exitValue = p.exitValue();
if (exitValue != 0) {
String errorOutput = IOUtils.toString(p.getErrorStream(), Charset.defaultCharset());
throw new Error("exitValue==" + exitValue + " errorOutput==" + errorOutput);
}

Assert.assertTrue(dumpSqlFile.exists() && dumpSqlFile.length() > 0);
}

Expand Down