Change directory to /sdcard before running the unit tests on android

This allows placing the test files in /sdcard/res before running
the test. Previously, the current directory was /, and writing
data into /res isn't possible on non-rooted phones.
This commit is contained in:
Martin Storsjö 2014-05-30 10:58:19 +03:00
parent a0c9f8c9a0
commit a294cad5c8
2 changed files with 5 additions and 3 deletions

View File

@ -2,6 +2,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <jni.h>
#include <unistd.h>
#include <android/log.h>
#define LOG_TAG "codec_unittest"
@ -10,12 +11,13 @@
int CodecUtMain(int argc, char** argv);
extern "C"
JNIEXPORT void JNICALL Java_com_cisco_codec_unittest_MainActivity_DoUnittest
(JNIEnv* env, jobject thiz,jstring jspath) {
(JNIEnv* env, jobject thiz, jstring directory, jstring jspath) {
/**************** Add the native codes/API *****************/
char* argv[2];
int argc = 2;
argv[0] = (char*) ("codec_unittest.exe");
argv[1] = (char*) ((*env).GetStringUTFChars (jspath,NULL));
chdir((*env).GetStringUTFChars (directory, NULL));
LOGI ("PATH: %s", argv[1]);
LOGI ("Start to run JNI module!+++");
CodecUtMain(argc,argv);

View File

@ -53,7 +53,7 @@ public class MainActivity extends Activity {
// }
String path = "/sdcard/codec_unittest.xml";
Log.i("codec_unittest","codec unittest runing @"+path);
DoUnittest(path);
DoUnittest("/sdcard", path);
Log.i("codec_unittest","codec unittest end");
Process.killProcess(Process.myPid());
finish();
@ -76,6 +76,6 @@ public class MainActivity extends Activity {
}
public native void DoUnittest(String path);
public native void DoUnittest(String directory, String path);
}