#include "IOpenCVEngine.h" #include "EngineCommon.h" #include "OpenCVEngine.h" #include "IPackageManager.h" #include "PackageManagerStub.h" #include "PackageInfo.h" #include "HardwareDetector.h" #include #include #include #include #include using namespace android; class ServiceStarter { public: ServiceStarter() { PackageManager = new PackageManagerStub(); Engine = new OpenCVEngine(PackageManager); defaultServiceManager()->addService(IOpenCVEngine::descriptor, Engine); LOGI("OpenCVEngine native service started successfully"); ProcessState::self()->startThreadPool(); } ~ServiceStarter() { delete PackageManager; } PackageManagerStub* PackageManager; sp Engine; }; static ServiceStarter Starter; sp InitConnect() { sp ServiceManager = defaultServiceManager(); sp EngineService; sp Engine; do { EngineService = ServiceManager->getService(IOpenCVEngine::descriptor); if (EngineService != 0) break; usleep(500000); // 0.5 s } while(true); Engine = interface_cast(EngineService); return Engine; } TEST(OpenCVEngineTest, GetVersion) { sp Engine = InitConnect(); EXPECT_FALSE(NULL == Engine.get()); int32_t Version = Engine->GetVersion(); EXPECT_EQ(OPEN_CV_ENGINE_VERSION, Version); } #if defined(__i386__) TEST(OpenCVEngineTest, GetPathForExecHWExistVersion) { sp Engine = InitConnect(); Starter.PackageManager->InstalledPackages.clear(); Starter.PackageManager->InstallVersion("240", PLATFORM_UNKNOWN, ARCH_X86); EXPECT_FALSE(NULL == Engine.get()); String16 result = Engine->GetLibPathByVersion(String16("2.4")); EXPECT_STREQ("/data/data/org.opencv.lib_v24_x86/lib", String8(result).string()); } TEST(OpenCVEngineTest, GetPathForExecHWOldVersion) { sp Engine = InitConnect(); Starter.PackageManager->InstalledPackages.clear(); Starter.PackageManager->InstallVersion("242", PLATFORM_UNKNOWN, ARCH_X86); EXPECT_FALSE(NULL == Engine.get()); String16 result = Engine->GetLibPathByVersion(String16("2.4.1")); EXPECT_STREQ("/data/data/org.opencv.lib_v24_x86/lib", String8(result).string()); } TEST(OpenCVEngineTest, GetPathForExecHWNewVersion) { sp Engine = InitConnect(); Starter.PackageManager->InstalledPackages.clear(); Starter.PackageManager->InstallVersion("241", PLATFORM_UNKNOWN, ARCH_X86); EXPECT_FALSE(NULL == Engine.get()); String16 result = Engine->GetLibPathByVersion(String16("2.4.2")); EXPECT_EQ(0, result.size()); } #elif defined (__mips) TEST(OpenCVEngineTest, GetPathForExecHWExistVersion) { sp Engine = InitConnect(); Starter.PackageManager->InstalledPackages.clear(); Starter.PackageManager->InstallVersion("240", PLATFORM_UNKNOWN, ARCH_MIPS); EXPECT_FALSE(NULL == Engine.get()); String16 result = Engine->GetLibPathByVersion(String16("2.4")); EXPECT_STREQ("/data/data/org.opencv.lib_v24_mips/lib", String8(result).string()); } TEST(OpenCVEngineTest, GetPathForExecHWOldVersion) { sp Engine = InitConnect(); Starter.PackageManager->InstalledPackages.clear(); Starter.PackageManager->InstallVersion("242", PLATFORM_UNKNOWN, ARCH_MIPS); EXPECT_FALSE(NULL == Engine.get()); String16 result = Engine->GetLibPathByVersion(String16("2.4.1")); EXPECT_STREQ("/data/data/org.opencv.lib_v24_mips/lib", String8(result).string()); } TEST(OpenCVEngineTest, GetPathForExecHWNewVersion) { sp Engine = InitConnect(); Starter.PackageManager->InstalledPackages.clear(); Starter.PackageManager->InstallVersion("241", PLATFORM_UNKNOWN, ARCH_MIPS); EXPECT_FALSE(NULL == Engine.get()); String16 result = Engine->GetLibPathByVersion(String16("2.4.2")); EXPECT_EQ(0, result.size()); } #else // armeabi TEST(OpenCVEngineTest, GetPathForExecHWExistVersion) { sp Engine = InitConnect(); Starter.PackageManager->InstalledPackages.clear(); Starter.PackageManager->InstallVersion("240", PLATFORM_TEGRA3, ARCH_ARMv7 | FEATURES_HAS_NEON); EXPECT_FALSE(NULL == Engine.get()); String16 result = Engine->GetLibPathByVersion(String16("2.4")); #ifdef __SUPPORT_TEGRA3 EXPECT_STREQ("/data/data/org.opencv.lib_v24_tegra3/lib", String8(result).string()); #else #ifdef __SUPPORT_ARMEABI_V7A_FEATURES EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv7a_neon/lib", String8(result).string()); #else EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv7a/lib", String8(result).string()); #endif #endif } TEST(OpenCVEngineTest, GetPathForExecHWOldVersion) { sp Engine = InitConnect(); Starter.PackageManager->InstalledPackages.clear(); Starter.PackageManager->InstallVersion("242", PLATFORM_TEGRA3, ARCH_ARMv7 | FEATURES_HAS_NEON); EXPECT_FALSE(NULL == Engine.get()); String16 result = Engine->GetLibPathByVersion(String16("2.4.1")); #ifdef __SUPPORT_TEGRA3 EXPECT_STREQ("/data/data/org.opencv.lib_v24_tegra3/lib", String8(result).string()); #else #ifdef __SUPPORT_ARMEABI_V7A_FEATURES EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv7a_neon/lib", String8(result).string()); #else EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv7a/lib", String8(result).string()); #endif #endif } TEST(OpenCVEngineTest, GetPathForExecHWNewVersion) { sp Engine = InitConnect(); Starter.PackageManager->InstalledPackages.clear(); Starter.PackageManager->InstallVersion("241", PLATFORM_TEGRA3, ARCH_ARMv7 | FEATURES_HAS_NEON); EXPECT_FALSE(NULL == Engine.get()); String16 result = Engine->GetLibPathByVersion(String16("2.4.2")); EXPECT_EQ(0, result.size()); } TEST(OpenCVEngineTest, GetPathForCompatiblePackage1) { sp Engine = InitConnect(); Starter.PackageManager->InstalledPackages.clear(); Starter.PackageManager->InstallVersion("242", PLATFORM_UNKNOWN, ARCH_ARMv5); EXPECT_FALSE(NULL == Engine.get()); String16 result = Engine->GetLibPathByVersion(String16("2.4")); EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv5/lib", String8(result).string()); } TEST(OpenCVEngineTest, GetPathForCompatiblePackage2) { sp Engine = InitConnect(); Starter.PackageManager->InstalledPackages.clear(); Starter.PackageManager->InstallVersion("242", PLATFORM_TEGRA3, ARCH_ARMv7 | FEATURES_HAS_NEON); EXPECT_FALSE(NULL == Engine.get()); String16 result = Engine->GetLibPathByVersion(String16("2.4")); #ifdef __SUPPORT_TEGRA3 EXPECT_STREQ("/data/data/org.opencv.lib_v24_tegra3/lib", String8(result).string()); #else #ifdef __SUPPORT_ARMEABI_V7A_FEATURES EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv7a_neon/lib", String8(result).string()); #else EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv7a/lib", String8(result).string()); #endif #endif } TEST(OpenCVEngineTest, InstallAndGetVersion) { sp Engine = InitConnect(); Starter.PackageManager->InstalledPackages.clear(); EXPECT_FALSE(NULL == Engine.get()); EXPECT_TRUE(Engine->InstallVersion(String16("2.4"))); String16 result = Engine->GetLibPathByVersion(String16("2.4")); #ifdef __SUPPORT_TEGRA3 EXPECT_STREQ("/data/data/org.opencv.lib_v24_tegra3/lib", String8(result).string()); #else #ifdef __SUPPORT_ARMEABI_V7A_FEATURES EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv7a_neon/lib", String8(result).string()); #else EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv7a/lib", String8(result).string()); #endif #endif } #endif #ifndef __i386__ TEST(OpenCVEngineTest, GetPathForInCompatiblePackage1) { sp Engine = InitConnect(); Starter.PackageManager->InstalledPackages.clear(); Starter.PackageManager->InstallVersion("242", PLATFORM_UNKNOWN, ARCH_X64); EXPECT_FALSE(NULL == Engine.get()); String16 result = Engine->GetLibPathByVersion(String16("2.4")); EXPECT_EQ(0, result.size()); } #else TEST(OpenCVEngineTest, GetPathForInCompatiblePackage1) { sp Engine = InitConnect(); Starter.PackageManager->InstalledPackages.clear(); Starter.PackageManager->InstallVersion("242", PLATFORM_UNKNOWN, ARCH_ARMv7); EXPECT_FALSE(NULL == Engine.get()); String16 result = Engine->GetLibPathByVersion(String16("2.4")); EXPECT_EQ(0, result.size()); } #endif TEST(OpenCVEngineTest, GetPathForUnExistVersion) { sp Engine = InitConnect(); EXPECT_FALSE(NULL == Engine.get()); String16 result = Engine->GetLibPathByVersion(String16("2.5")); EXPECT_EQ(0, result.size()); }