Home | History | Annotate | only in /prebuilts/ndk/r16/sources/third_party/googletest
Up to higher level directory
NameDateSize
Android.mk21-Aug-20185.5K
googletest/21-Aug-2018
NOTICE21-Aug-20181.4K
patches.ndk/21-Aug-2018
README.NDK21-Aug-20182.4K
repo.prop21-Aug-20184.4K

README.NDK

      1 This is a working copy of GoogleTest for the Android NDK.
      2 
      3 Project: https://code.google.com/p/googletest/
      4 Checkout: svn checkout http://googletest.googlecode.com/svn/trunk@653
      5 Patches: See patches.ndk/
      6 Licensing: 3-clause BSD. See googletest/LICENSE file.
      7 
      8 Note that the latest official release to date (1.6.0) doesn't work
      9 too well with Android. This is based on a more recent revision that
     10 includes many needed bugfixes.
     11 
     12 Usage:
     13 ------
     14 
     15 This directory contains several module definitions that can be imported
     16 into your project by using the following at the end of your Android.mk:
     17 
     18   $(call import-module,third_party/googletest)
     19 
     20 The GoogleTest modules are the following:
     21 
     22   googletest_static:
     23     GoogleTest as a static library.
     24 
     25   googletest_shared:
     26     GoogleTest as a shared library.
     27 
     28   googletest_main:
     29     A small helper static library that provides a main() implementation
     30     that starts all the GoogleTest tests. This also links against
     31     googletest_static.
     32 
     33   googletest_main_shared:
     34     Same as googletest_main, but links against googletest_shared.
     35 
     36 In your source code, use #include <gtest/gtest.h> as usual after ensuring
     37 your module depends on one of the modules above.
     38 
     39 Here's an fictuous example:
     40 
     41 jni/Android.mk:
     42   LOCAL_PATH := $(call my-dir)
     43 
     44   include $(CLEAR_VARS)
     45   LOCAL_MODULE := foo
     46   LOCAL_SRC_FILES := foo.cpp
     47   include $(BUILD_SHARED_LIBRARY)
     48 
     49   include $(CLEAR_VARS)
     50   LOCAL_MODULE := foo_unittest
     51   LOCAL_SRC_FILES := foo_unittest.cpp
     52   LOCAL_SHARED_LIBRARIES := foo
     53   LOCAL_STATIC_LIBRARIES := googletest_main
     54   include $(BUILD_EXECUTABLE)
     55 
     56   $(call import-module,third_party/googletest)
     57 
     58 jni/Application.mk:
     59   APP_STL := gnustl_shared
     60 
     61 jni/foo.cpp:
     62   int foo(int x, int y) {
     63     return x + y;
     64   }
     65 
     66 jni/foo.h:
     67   extern int foo(int x, int y);
     68 
     69 jni/foo_unittest.cc:
     70   #include <gtest/gtest.h>
     71 
     72   #include "foo.h"
     73 
     74   TEST(FooTest,ZeroZero) {
     75     EXPECT_EQ(0, foo(0, 0));
     76   }
     77 
     78   TEST(FooTest,OneOne) {
     79     EXPECT_EQ(2, foo(1, 1));
     80   }
     81 
     82 Invoking 'ndk-build' will build both 'libfoo.so' and 'foo_unittest' under
     83 $PROJECT/libs/$ABI/. After this, to run the unit test program push it to
     84 the device and execute it with ADB, e.g.:
     85 
     86   adb push libs/armeabi/libfoo.so /data/local/tmp/
     87   adb push libs/armeabi/libgnustl_shared.so /data/local/tmp/
     88   adb push libs/armeabi/foo_unittest /data/local/tmp/
     89   adb shell chmod 775 /data/local/tmp/foo_unittest
     90   adb shell "LD_LIBRARY_PATH=/data/local/tmp /data/local/tmp/foo_unittest"
     91 
     92