トラッキング コード

3/30/2012

3/11/2012

How to use Google Test on Android-4.0.3_r1

AOSP has Google Test project in extarnal/gtest directory.

I try to use Google Test in my Application.

Create Android.mk for Google Test

I was referring to the existing Android.mk in extarnal/gtest/test.

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

# Gtest depends on STLPort which does not build on host/simulator.

ifeq ($(BUILD_WITH_ASTL),true)
libgtest_test_includes := \
    bionic/libstdc++/include \
    external/astl/include \
    external/gtest/include \
 $(LOCAL_PATH)/../test \
 $(LOCAL_PATH)/..
libgtest_test_static_lib := libgtest_main libgtest libastl
libgtest_test_shared_lib :=
libgtest_test_host_static_lib := libgtest_main_host libgtest_host libastl_host
libgtest_test_host_shared_lib :=
else
# BUILD_WITH_ASTL could be undefined, force it to false (for the guard
# before the test-target call).
BUILD_WITH_ASTL := false
libgtest_test_includes := \
    bionic \
    external/stlport/stlport \
    external/gtest/include \
 $(LOCAL_PATH)/../test \
 $(LOCAL_PATH)/..
libgtest_test_static_lib := libgtest_main libgtest
libgtest_test_shared_lib := libstlport
libgtest_test_host_static_lib :=
libgtest_test_host_shared_lib :=
endif


LOCAL_MODULE_TAGS := TestAppGtest
LOCAL_C_INCLUDES := $(libgtest_test_includes)

LOCAL_SHARED_LIBRARIES := \
    libcutils \
    libutils \
    libandroid_runtime \
    $(libgtest_test_shared_lib) \
    $(libgtest_test_host_shared_lib)

LOCAL_STATIC_LIBRARIES := \
    $(libgtest_test_static_lib) \
    $(libgtest_test_host_static_lib)

# if LOCAL_SRC_FILES is .cc
#LOCAL_CPP_EXTENSION := .cc

# YOUR Source and Test Source
LOCAL_SRC_FILES := \
    sample1.cpp \
    sample1_unittest.cpp

LOCAL_MODULE := gtest_mytest
LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)

include $(BUILD_EXECUTABLE)


Building Google Test

I try to build an apllicaion with google test code.

I uploaded sample project.
https://docs.google.com/open?id=0BwdCdBWuE_7cb2ZzVGt3eHhSOEtEbGVxNnRCSkFJdw

$ cd "YOUR_BUILD_DIRECTORY"
$  . build/envsetup.sh
$ lunch "YOUR_BUILD_LUNCH"
$ make
$ cd packages/apps/
$ cd TestApp
$ mm -B


If building success , executable file is created.
target thumb C++: gtest_mytest <= packages/apps/TestApp/jni/test/sample1.cpp
target thumb C++: gtest_mytest <= packages/apps/TestApp/jni/test/sample1_unittest.cpp
target Executable: gtest_mytest (out/target/product/maguro/obj/EXECUTABLES/gtest_mytest_intermediates/LINKED/gtest_mytest)
target Symbolic: gtest_mytest (out/target/product/maguro/symbols/data/app/gtest_mytest)
target Strip: gtest_mytest (out/target/product/maguro/obj/EXECUTABLES/gtest_mytest_intermediates/gtest_mytest)
Install: out/target/product/maguro/data/app/gtest_mytest

Running Google Test

I try to run Google Test on Galaxy Nexus. My Galaxy Nexus is flashed Android-4.0.3_r1. Copy to executable file.
cd out/target/product/maguro/
$ adb push data/app/gtest_mytest /data/app
2870 KB/s (48728 bytes in 0.016s)
Running test using ADB.
$ adb shell
root@android:/ # cd data/app                                                   
root@android:/data/app # ./gtest_mytest    
Success to run, The test results are displayed.
root@android:/data/app # ./gtest_mytest                                        
Running main() from gtest_main.cc
[==========] Running 6 tests from 2 test cases.
[----------] Global test environment set-up.
[----------] 3 tests from FactorialTest
[ RUN      ] FactorialTest.Negative
[       OK ] FactorialTest.Negative
[ RUN      ] FactorialTest.Zero
[       OK ] FactorialTest.Zero
[ RUN      ] FactorialTest.Positive
[       OK ] FactorialTest.Positive
[----------] 3 tests from IsPrimeTest
[ RUN      ] IsPrimeTest.Negative
[       OK ] IsPrimeTest.Negative
[ RUN      ] IsPrimeTest.Trivial
[       OK ] IsPrimeTest.Trivial
[ RUN      ] IsPrimeTest.Positive
[       OK ] IsPrimeTest.Positive
[----------] Global test environment tear-down
[==========] 6 tests from 2 test cases ran.
[  PASSED  ] 6 tests.

3/10/2012

Create PreferenceActivity with header and Footer.







We can create PreferenceActivity with header and Fotter.

We shoud make following files and call method.
  1. Create Layout with ListView.
  2. Create Preference XML.
  3. Call setContentView() and addPreferencesFromResource() in onCreate().


Create Layout with ListView

Make layout xml file , to set PreferenceActivity#setContentView().
It must have ListView with android:id="@+id/android:list".

you shoud add android:layout_height="0.0dp"and android:layout_weight="1" to ListView, because to show footer in bottom


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <!-- Header  -->

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Header"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    </LinearLayout>

    <!-- Show Preference in ListView  -->

    <ListView
        android:id="@+id/android:list"
        android:layout_width="match_parent"
        android:layout_height="0.0dp"
        android:layout_weight="1" >
    </ListView>

    <!-- Footer -->

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Footer"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    </LinearLayout>

</LinearLayout>


Create Preference XML

Create Preference XML.
Sample.

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >

    <CheckBoxPreference
        android:key="checkbox_preference"
        android:summary="summary_checkbox_preference"
        android:title="checkbox_preference" />

    <EditTextPreference
        android:dialogTitle="dialog_title_edittext_preference"
        android:key="edittext_preference"
        android:summary="summary_edittext_preference"
        android:title="title_edittext_preference" />

    <PreferenceScreen
        android:summary="intent_preference"
        android:title="intent_preference" >
        <intent
            android:action="android.intent.action.VIEW"
            android:data="http://www.android.com" />
    </PreferenceScreen>

</PreferenceScreen>


Call setContentView() and addPreferencesFromResource() in onCreate()

You must call setContentView(YOUR_LAYOUT_WIHT_HEADER_FOOTER_ID).

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        addPreferencesFromResource(R.xml.pref);
    }

3/06/2012

Add WPAN project in AOSP master

When I done "repo sync", added WPAN project in AOSP master.

From https://android.googlesource.com/platform/hardware/ti/wpan
* [new branch]      master     -> master

You need to read Android Building.
wpan project for Panda Bluetooth
http://groups.google.com/group/android-building/browse_thread/thread/b07552678a1829f0?pli=1


Wikipedia:http://en.wikipedia.org/wiki/Personal_area_network

WPAN is "Wireless Personal Area Network".This Network is smaller than WLAN.
Include Bluetooth,WiFi,ZigBee.