From 7c7719677fcc6d900175144b99fecb9ac156e492 Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Mon, 7 Oct 2013 14:16:59 +0200 Subject: [PATCH] fix liblinphone tester --- Makefile | 2 +- liblinphone_tester/.classpath | 7 +++-- liblinphone_tester/.gitignore | 2 ++ liblinphone_tester/.project | 5 ++++ liblinphone_tester/res/raw/.gitignore | 12 -------- .../src/org/linphone/tester/MainActivity.java | 27 ++--------------- .../src/org/linphone/tester/TestRunner.java | 3 ++ .../src/org/linphone/tester/TestUnit.java | 30 +++++++++++++++++-- .../src/org/linphone/tester/Tester.java | 1 + 9 files changed, 46 insertions(+), 43 deletions(-) delete mode 100644 liblinphone_tester/res/raw/.gitignore diff --git a/Makefile b/Makefile index 1b4801064..eacc01d66 100644 --- a/Makefile +++ b/Makefile @@ -259,7 +259,7 @@ $(TOPDIR)/res/raw/rootca.pem: prepare-liblinphone_tester: $(TOPDIR)/submodules/linphone/tester/*_lrc $(TOPDIR)/submodules/linphone/tester/*_rc $(TOPDIR)/submodules/linphone/tester/tester_hosts $(TOPDIR)/submodules/linphone/tester/certificates/* $(TOPDIR)/res/raw/rootca.pem for file in $^; do \ - cp -f $$file $(TOPDIR)/liblinphone_tester/res/raw/. \ + cp -f $$file $(TOPDIR)/liblinphone_tester/assets/rc_files/. \ ;done #SQLite3 diff --git a/liblinphone_tester/.classpath b/liblinphone_tester/.classpath index d48ac0e1b..cfe7064fb 100644 --- a/liblinphone_tester/.classpath +++ b/liblinphone_tester/.classpath @@ -1,10 +1,13 @@ + + + - - + + diff --git a/liblinphone_tester/.gitignore b/liblinphone_tester/.gitignore index 00dfbd2c3..9e04b4e45 100644 --- a/liblinphone_tester/.gitignore +++ b/liblinphone_tester/.gitignore @@ -16,3 +16,5 @@ obj/ # Local configuration file (sdk path, etc) local.properties + +assets diff --git a/liblinphone_tester/.project b/liblinphone_tester/.project index 3b3e60d9e..0877c21b1 100644 --- a/liblinphone_tester/.project +++ b/liblinphone_tester/.project @@ -31,6 +31,11 @@ org.eclipse.jdt.core.javanature + + linphone + 2 + PARENT-1-PROJECT_LOCATION/submodules/linphone/java + mediastreamer2 2 diff --git a/liblinphone_tester/res/raw/.gitignore b/liblinphone_tester/res/raw/.gitignore deleted file mode 100644 index 40abfa847..000000000 --- a/liblinphone_tester/res/raw/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -agent.pem -cacert.pem -empty_rc -laure_rc -marie_early_rc -marie_no_sdp_rc -marie_rc -multi_account_lrc -pauline_rc -rootca.pem -tester_hosts -upnp_rc diff --git a/liblinphone_tester/src/org/linphone/tester/MainActivity.java b/liblinphone_tester/src/org/linphone/tester/MainActivity.java index 9d15fecd9..b0502e59e 100644 --- a/liblinphone_tester/src/org/linphone/tester/MainActivity.java +++ b/liblinphone_tester/src/org/linphone/tester/MainActivity.java @@ -7,7 +7,9 @@ import java.io.InputStream; import android.os.Bundle; import android.app.Activity; +import android.content.Context; import android.content.Intent; +import android.content.res.AssetManager; import android.view.Gravity; import android.view.Menu; import android.view.View; @@ -16,34 +18,9 @@ import android.widget.LinearLayout; public class MainActivity extends Activity { - private void copyFromPackage(int ressourceId,String target) throws IOException{ - FileOutputStream lOutputStream = openFileOutput (target, 0); - InputStream lInputStream = getResources().openRawResource(ressourceId); - int readByte; - byte[] buff = new byte[8048]; - while (( readByte = lInputStream.read(buff)) != -1) { - lOutputStream.write(buff,0, readByte); - } - lOutputStream.flush(); - lOutputStream.close(); - lInputStream.close(); - } - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - try { - copyFromPackage(R.raw.laure_rc, new File("laure_rc").getName()); - copyFromPackage(R.raw.marie_rc, new File("marie_rc").getName()); - copyFromPackage(R.raw.marie_early_rc, new File("marie_early_rc").getName()); - copyFromPackage(R.raw.multi_account_lrc, new File("multi_account_lrc").getName()); - copyFromPackage(R.raw.pauline_rc, new File("pauline_rc").getName()); - copyFromPackage(R.raw.rootca, new File("rootca.pem").getName()); - copyFromPackage(R.raw.cacert, new File("cacert.pem").getName()); - copyFromPackage(R.raw.tester_hosts, new File("tester_hosts").getName()); - } catch (IOException e) { - e.printStackTrace(); - } setContentView(R.layout.activity_main); diff --git a/liblinphone_tester/src/org/linphone/tester/TestRunner.java b/liblinphone_tester/src/org/linphone/tester/TestRunner.java index cfa36f636..c3c726eda 100644 --- a/liblinphone_tester/src/org/linphone/tester/TestRunner.java +++ b/liblinphone_tester/src/org/linphone/tester/TestRunner.java @@ -1,5 +1,7 @@ package org.linphone.tester; +import java.io.IOException; + import junit.framework.TestSuite; import android.os.Bundle; import android.test.InstrumentationTestRunner; @@ -13,6 +15,7 @@ public class TestRunner extends InstrumentationTestRunner { public void onCreate(Bundle arguments) { mSuite = arguments.getString("suite"); mTest = arguments.getString("test"); + super.onCreate(arguments); } diff --git a/liblinphone_tester/src/org/linphone/tester/TestUnit.java b/liblinphone_tester/src/org/linphone/tester/TestUnit.java index 46e959c89..0b5b7f10f 100644 --- a/liblinphone_tester/src/org/linphone/tester/TestUnit.java +++ b/liblinphone_tester/src/org/linphone/tester/TestUnit.java @@ -1,25 +1,49 @@ package org.linphone.tester; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; import java.util.Arrays; import java.util.LinkedList; import java.util.List; import junit.framework.Assert; +import android.content.Context; import android.test.AndroidTestCase; public class TestUnit extends AndroidTestCase { private String mSuite; private String mTest; - + static Boolean isAssetCopied=false; + public TestUnit(String suite, String test) { mSuite = suite; mTest = test; setName(suite + "/" + test); } - + private void copyAssetsFromPackage() throws IOException { + Context ctx= getContext(); + for (String file :ctx.getAssets().list("rc_files")) { + FileOutputStream lOutputStream = ctx.openFileOutput (new File(file).getName(), 0); + InputStream lInputStream = ctx.getAssets().open("rc_files/"+file); + int readByte; + byte[] buff = new byte[8048]; + while (( readByte = lInputStream.read(buff)) != -1) { + lOutputStream.write(buff,0, readByte); + } + lOutputStream.flush(); + lOutputStream.close(); + lInputStream.close(); + } + } @Override protected void setUp() throws Exception { super.setUp(); + if (isAssetCopied ==false) { + copyAssetsFromPackage(); + isAssetCopied=true; + } } @Override @@ -29,7 +53,7 @@ public class TestUnit extends AndroidTestCase { @Override protected void runTest() { - String path = getContext().getFilesDir().getAbsolutePath(); + String path = getContext().getFilesDir().getPath(); Tester tester = new Tester(); List list = new LinkedList(Arrays.asList(new String[]{"tester", "--verbose", "--config", path, "--suite", mSuite, "--test", mTest})); String[] array = list.toArray(new String[list.size()]); diff --git a/liblinphone_tester/src/org/linphone/tester/Tester.java b/liblinphone_tester/src/org/linphone/tester/Tester.java index 095a061c5..7a2d4656d 100644 --- a/liblinphone_tester/src/org/linphone/tester/Tester.java +++ b/liblinphone_tester/src/org/linphone/tester/Tester.java @@ -24,6 +24,7 @@ public class Tester { } static { + LinphoneCoreFactory.instance(); System.loadLibrary("cunit");