2016-10-20 10 views
0

Google Testフレームワークを使用してAndroid NDKコード用の単体テストをコンパイルしようとしています。私のコードは、ほぼそのままREADMEを、次のとおりです。Android NDKでGoogleテストケースをコンパイルしていますか?

Application.mk

APP_STL := gnustl_shared 

Android.mk

# Build module 
LOCAL_PATH := $(call my-dir) 
include $(CLEAR_VARS) 
LOCAL_MODULE := jniLib 
LOCAL_SRC_FILES := jniLib.cpp 
include $(BUILD_SHARED_LIBRARY) 

# Build unit tests 
include $(CLEAR_VARS) 
LOCAL_MODULE := jniLib_unittest 
LOCAL_SRC_FILES := jniLib_unittest.cpp 
LOCAL_SHARED_LIBRARIES := jniLib 
LOCAL_STATIC_LIBRARIES := googletest_main 
include $(BUILD_EXECUTABLE) 
$(call import-module,third_party/googletest) 

jniLib.cpp

jint Java_test_nativetest_MainActivity_add(JNIEnv* env, jobject jThis, jint x, jint y) { 
    return x + y; 
} 

jniLib.h

#pragma once 
#include <jni.h> 
extern "C" { 
    jint Java_test_nativetest_MainActivity_add(JNIEnv* env, jobject jThis, jint x, jint y); 
} 

jniLib_unittest.cpp

私は ndk-buildでビルドしようとすると10
#include <gtest/gtest.h> 
Test(AddTest, FivePlusFive) { 
    EXPECT_EQ(10, add(5, 5)); 
} 

、私は次のコンパイルエラーが表示されます。

jni/jniLib_unittest.cpp:10:9: error: expected constructor, destructor, or type 
conversion before '(' token make.exe: 
*** [obj/local/armeabi/objs/jniLib_unittest/jniLib_unittest.o] Error 1 

は私が間違って何をしているのですか?

答えて

0

私のコードにはいくつかのエラーがありましたが、主な問題は、テストの宣言では大文字と小文字が区別されることです。は、ではなくTESTです。次のように私の修正コードは次のとおりです。

Application.mk

# Set APP_PLATFORM >= 16 to fix: http://stackoverflow.com/q/24818902 
APP_PLATFORM = android-18 
APP_STL := gnustl_shared 

jniLib.cpp

#include "jniLib.h" 
jint Java_test_nativetest_MainActivity_add(JNIEnv* env, jobject jThis, jint x, jint y) { 
    return doAdd(x, y); 
} 

int doAdd(int x, int y) { 
    return x + y; 
} 

jniLib.h

#pragma once 
#include <jni.h> 
extern "C" { 
    jint Java_test_nativetest_MainActivity_add(JNIEnv* env, jobject jThis, jint x, jint y); 
} 

int doAdd(int x, int y); 

jniLib_unittest.cpp

#include <gtest/gtest.h> 
    /** 
    * Unit test the function 'add', not the JNI call 
    * 'Java_test_nativetest_MainActivity_add' 
    */ 
TEST(AddTest, FivePlusFive) { 
    EXPECT_EQ(10, add(5, 5)); 
} 

int main(int argc, char** argv) { 
    testing::InitGoogleTest(&argc, argv); 
    return RUN_ALL_TESTS(); 
} 
関連する問題