• Home
Name Date Size #Lines LOC

..--

googletest/03-May-2024-59,77138,371

patches.ndk/03-May-2024-9882

Android.mkD03-May-20245.5 KiB177111

README.NDKD03-May-20242.2 KiB8559

README.NDK

1This is a working copy of GoogleTest for the Android NDK.
2
3Project: https://code.google.com/p/googletest/
4Checkout: svn checkout http://googletest.googlecode.com/svn/trunk@653
5Patches: See patches.ndk/
6Licensing: 3-clause BSD. See googletest/LICENSE file.
7
8Note that the latest official release to date (1.6.0) doesn't work
9too well with Android. This is based on a more recent revision that
10includes many needed bugfixes.
11
12Usage:
13------
14
15This directory contains several module definitions that can be imported
16into your project by using the following at the end of your Android.mk:
17
18  $(call import-module,third_party/googletest)
19
20The 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
36In your source code, use #include <gtest/gtest.h> as usual after ensuring
37your module depends on one of the modules above.
38
39Here's an fictuous example:
40
41jni/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
56jni/foo.cpp:
57  int foo(int x, int y) {
58    return x + y;
59  }
60
61jni/foo.h:
62  extern int foo(int x, int y);
63
64jni/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
77Invoking '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
79the 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