Add unittest demo for android platform

This commit is contained in:
zhuling13 2014-05-19 23:19:23 -07:00
parent 3d5990500b
commit 9a33512564
22 changed files with 2411 additions and 1 deletions

View File

@ -108,8 +108,14 @@ gtest-bootstrap:
svn co https://googletest.googlecode.com/svn/trunk/ gtest
ifeq ($(HAVE_GTEST),Yes)
test: codec_unittest$(EXEEXT)
ifeq (android, $(OS))
else
./codec_unittest
endif
else
test:
@echo "./gtest : No such file or directory."
@ -163,11 +169,27 @@ include test/api/targets.mk
include test/decoder/targets.mk
include test/encoder/targets.mk
include test/processing/targets.mk
LIBRARIES +=$(LIBPREFIX)ut.$(SHAREDLIBSUFFIX)
$(LIBPREFIX)ut.$(SHAREDLIBSUFFIX): $(DECODER_UNITTEST_OBJS) $(ENCODER_UNITTEST_OBJS) $(PROCESSING_UNITTEST_OBJS) $(API_TEST_OBJS) $(CODEC_UNITTEST_DEPS)
$(QUIET)rm -f $@
$(QUIET_CXX)$(CXX) $(SHARED) $(LDFLAGS) $(CXX_LINK_O) $+ $(CODEC_UNITTEST_LDFLAGS)
binaries: codec_unittest$(EXEEXT)
BINARIES += codec_unittest$(EXEEXT)
ifeq (android,$(OS))
codec_unittest$(EXEEXT):$(LIBPREFIX)ut.$(SHAREDLIBSUFFIX)
cd ./test/build/android && $(NDKROOT)/ndk-build -B APP_ABI=$(APP_ABI) && android update project -t $(TARGET) -p . && ant debug
else
codec_unittest$(EXEEXT): $(DECODER_UNITTEST_OBJS) $(ENCODER_UNITTEST_OBJS) $(PROCESSING_UNITTEST_OBJS) $(API_TEST_OBJS) $(CODEC_UNITTEST_DEPS)
$(QUIET)rm -f $@
$(QUIET_CXX)$(CXX) $(CXX_LINK_O) $+ $(CODEC_UNITTEST_LDFLAGS) $(LDFLAGS)
endif
else
binaries:
@:

2009
loggtest.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,22 @@
#include <gtest/gtest.h>
#if defined (ANDROID_NDK)
#include <stdio.h>
#endif
#if defined(ANDROID_NDK)
int CodecUtMain(int argc , char** argv ) {
#else
int main (int argc, char** argv) {
testing::InitGoogleTest (&argc, argv);
#endif
#if defined(ANDROID_NDK)
char xmlPath[1024] = "";
sprintf(xmlPath,"xml:%s",argv[1]);
::testing::GTEST_FLAG(output) = xmlPath;
#endif
::testing::InitGoogleTest (&argc, argv);
return RUN_ALL_TESTS();
}

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cisco.codec.unittest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Codec_Unittest"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@ -0,0 +1,40 @@
# Generate the libwelsdecdemo.so file
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libUT
LOCAL_SRC_FILES := ../../../../libut.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
#
# Module Settings
#
LOCAL_MODULE := utDemo
#
# Source Files
#
LOCAL_SRC_FILES := \
codec_unittest.cpp
#
# Header Includes
#
LOCAL_C_INCLUDES := \
#
# Compile Flags and Link Libraries
#
LOCAL_CFLAGS := -O3 -DANDROID_NDK
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
LOCAL_ARM_MODE := arm
endif
LOCAL_LDLIBS := -llog
LOCAL_SHARED_LIBRARIES := libUT
include $(BUILD_SHARED_LIBRARY)

View File

@ -0,0 +1,44 @@
# Generate the libwelsdecdemo.so file
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libUT
LOCAL_SRC_FILES := libut.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := wels
LOCAL_SRC_FILES := libopenh264.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
#
# Module Settings
#
LOCAL_MODULE := UTdemo
#
# Source Files
#
LOCAL_SRC_FILES := \
codec_unittest.cpp
#
# Header Includes
#
LOCAL_C_INCLUDES := \
#
# Compile Flags and Link Libraries
#
LOCAL_CFLAGS := -O3 -DANDROID_NDK
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
LOCAL_ARM_MODE := arm
endif
LOCAL_LDLIBS := -llog
LOCAL_SHARED_LIBRARIES := libUT wels
include $(BUILD_SHARED_LIBRARY)

View File

@ -0,0 +1,20 @@
# debug/release, default is release
ifeq ($(OPTIM_debug),true)
APP_OPTIM := debug
else
APP_OPTIM := release
endif
# x86/armeabi-v7a/armeabi, default is armeabi-v7a
ifeq ($(ABI_x86),true)
APP_ABI := x86
else
ifeq ($(ABI_armeabi),true)
APP_ABI := armeabi
else
APP_ABI := armeabi-v7a
endif
endif
APP_STL := stlport_shared
APP_PLATFORM := android-12

View File

@ -0,0 +1,26 @@
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <jni.h>
#include <android/log.h>
#define LOG_TAG "codec_unittest"
#define LOGI(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
int CodecUtMain(int argc, char** argv);
extern "C"
JNIEXPORT void JNICALL Java_com_cisco_codec_unittest_MainActivity_DoUnittest
(JNIEnv* env, jobject thiz,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));
LOGI ("PATH:",+argv[1]);
LOGI ("Start to run JNI module!+++");
CodecUtMain(argc,argv);
LOGI ("End to run JNI module!+++");
}

View File

@ -0,0 +1,26 @@
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <jni.h>
#include <android/log.h>
#define LOG_TAG "welsdec"
#define LOGI(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
int CodecUtMain(int argc, char** argv);
extern "C"
JNIEXPORT void JNICALL JNICALL Java_com_cisco_codec_unittest_MainActivity_DoUnittest
(JNIEnv* env, jobject thiz,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));
LOGI ("PATH:\n",argv[1]);
LOGI ("Start to run JNI module!+++");
CodecUtMain(argc,argv);
LOGI ("End to run JNI module!+++");
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View File

@ -0,0 +1,19 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.cisco.codec.unittest.MainActivity" >
<TextView
android:id="@+id/status_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="@string/hello_world" />
</RelativeLayout>

View File

@ -0,0 +1,10 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
android:showAsAction="never"/>
</menu>

View File

@ -0,0 +1,11 @@
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!-- API 11 theme customizations can go here. -->
</style>
</resources>

View File

@ -0,0 +1,12 @@
<resources>
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
</style>
</resources>

View File

@ -0,0 +1,10 @@
<resources>
<!--
Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively).
-->
<dimen name="activity_horizontal_margin">64dp</dimen>
</resources>

View File

@ -0,0 +1,7 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Codec_Unittest</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
</resources>

View File

@ -0,0 +1,20 @@
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>

View File

@ -0,0 +1,81 @@
package com.cisco.codec.unittest;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.util.Log;
import android.widget.TextView;
import android.os.Build;
import android.os.Process;
public class MainActivity extends Activity {
private TextView mStatusView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mStatusView = (TextView)findViewById(R.id.status_view);
runUnitTest();
}
@Override
public void onDestroy()
{
Process.killProcess(Process.myPid());
}
public void runUnitTest()
{
Thread thread = new Thread() {
public void run()
{
Log.i("codec_unittest","codec unittest begin");
CharSequence text = "Running...";
if(mStatusView !=null)
{
mStatusView.setText(text);
}
// String path = getIntent().getStringExtra("path");
// if (path.length() <=0)
// {
// path = "/sdcard/codec_unittest.xml";
// }
String path = "/sdcard/codec_unittest.xml";
Log.i("codec_unittest","codec unittest runing @"+path);
DoUnittest(path);
Log.i("codec_unittest","codec unittest end");
Process.killProcess(Process.myPid());
finish();
}
};
thread.start();
}
static{
try{
System.loadLibrary("stlport_shared");
//System.loadLibrary("openh264");
System.loadLibrary("ut");
System.loadLibrary("utDemo");
}
catch(Exception e){Log.v("codec_unittest","Load library failed");}
}
public native void DoUnittest(String path);
}