Home | History | Annotate | only in /ndk/sources/third_party/googletest
Up to higher level directory
NameDateSize
Android.mk04-Nov-20145.5K
googletest/04-Nov-2014
patches.ndk/04-Nov-2014
README.NDK04-Nov-20142.2K

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_STATIC_LIBRARIES := googletest_main
     53   include $(BUILD_EXECUTABLE)
     54 
     55 
     56 jni/foo.cpp:
     57   int foo(int x, int y) {
     58     return x + y;
     59   }
     60 
     61 jni/foo.h:
     62   extern int foo(int x, int y);
     63 
     64 jni/foo_unittest.cc:
     65   #include <gtest/gtest.h>
     66 
     67   #include "foo.h"
     68 
     69   TEST(FooTest,ZeroZero) {
     70     EXPECT_EQ(0, foo(0, 0));
     71   }
     72 
     73   TEST(FooTest,OneOne) {
     74     EXPECT_EQ(2, foo(1, 1));
     75   }
     76 
     77 Invoking 'ndk-build' will build both 'libfoo.so' and 'foo_unittest' under
     78 $PROJECT/libs/$ABI/. After this, to run the unit test program push it to
     79 the device and execute it with ADB, e.g.:
     80 
     81   adb push libs/armeabi/libfoo.so /data/local/tmp/
     82   adb push libs/armeabi/foo_unittest /data/local/tmp/
     83   adb shell "LD_LIBRARY_PATH=/data/local/tmp /data/local/tmp/foo_unittest"
     84 
     85