1 #include <android/log.h>
2 #include <gtest/gtest.h>
3 
4 #include "dvr_api_test.h"
5 
6 namespace {
7 
8 class DvrTrackingTest : public DvrApiTest {};
9 
10 #if DVR_TRACKING_IMPLEMENTED
11 
TEST_F(DvrTrackingTest,Implemented)12 TEST_F(DvrTrackingTest, Implemented) {
13   ASSERT_TRUE(api_.TrackingCameraCreate != nullptr);
14   ASSERT_TRUE(api_.TrackingCameraStart != nullptr);
15   ASSERT_TRUE(api_.TrackingCameraStop != nullptr);
16 
17   ASSERT_TRUE(api_.TrackingFeatureExtractorCreate != nullptr);
18   ASSERT_TRUE(api_.TrackingFeatureExtractorDestroy != nullptr);
19   ASSERT_TRUE(api_.TrackingFeatureExtractorStart != nullptr);
20   ASSERT_TRUE(api_.TrackingFeatureExtractorStop != nullptr);
21   ASSERT_TRUE(api_.TrackingFeatureExtractorProcessBuffer != nullptr);
22 }
23 
TEST_F(DvrTrackingTest,CameraCreateFailsForInvalidInput)24 TEST_F(DvrTrackingTest, CameraCreateFailsForInvalidInput) {
25   int ret;
26   ret = api_.TrackingCameraCreate(nullptr);
27   EXPECT_EQ(ret, -EINVAL);
28 
29   DvrTrackingCamera* camera = reinterpret_cast<DvrTrackingCamera*>(42);
30   ret = api_.TrackingCameraCreate(&camera);
31   EXPECT_EQ(ret, -EINVAL);
32 }
33 
TEST_F(DvrTrackingTest,CameraCreateDestroy)34 TEST_F(DvrTrackingTest, CameraCreateDestroy) {
35   DvrTrackingCamera* camera = nullptr;
36   int ret = api_.TrackingCameraCreate(&camera);
37 
38   EXPECT_EQ(ret, 0);
39   ASSERT_TRUE(camera != nullptr);
40 
41   api_.TrackingCameraDestroy(camera);
42 }
43 
TEST_F(DvrTrackingTest,FeatureExtractorCreateFailsForInvalidInput)44 TEST_F(DvrTrackingTest, FeatureExtractorCreateFailsForInvalidInput) {
45   int ret;
46   ret = api_.TrackingFeatureExtractorCreate(nullptr);
47   EXPECT_EQ(ret, -EINVAL);
48 
49   DvrTrackingFeatureExtractor* camera =
50       reinterpret_cast<DvrTrackingFeatureExtractor*>(42);
51   ret = api_.TrackingFeatureExtractorCreate(&camera);
52   EXPECT_EQ(ret, -EINVAL);
53 }
54 
TEST_F(DvrTrackingTest,FeatureExtractorCreateDestroy)55 TEST_F(DvrTrackingTest, FeatureExtractorCreateDestroy) {
56   DvrTrackingFeatureExtractor* camera = nullptr;
57   int ret = api_.TrackingFeatureExtractorCreate(&camera);
58 
59   EXPECT_EQ(ret, 0);
60   ASSERT_TRUE(camera != nullptr);
61 
62   api_.TrackingFeatureExtractorDestroy(camera);
63 }
64 
65 #else  // !DVR_TRACKING_IMPLEMENTED
66 
TEST_F(DvrTrackingTest,NotImplemented)67 TEST_F(DvrTrackingTest, NotImplemented) {
68   ASSERT_TRUE(api_.TrackingCameraCreate != nullptr);
69   ASSERT_TRUE(api_.TrackingCameraDestroy != nullptr);
70   ASSERT_TRUE(api_.TrackingCameraStart != nullptr);
71   ASSERT_TRUE(api_.TrackingCameraStop != nullptr);
72 
73   EXPECT_EQ(api_.TrackingCameraCreate(nullptr), -ENOSYS);
74   EXPECT_EQ(api_.TrackingCameraStart(nullptr, nullptr), -ENOSYS);
75   EXPECT_EQ(api_.TrackingCameraStop(nullptr), -ENOSYS);
76 
77   ASSERT_TRUE(api_.TrackingFeatureExtractorCreate != nullptr);
78   ASSERT_TRUE(api_.TrackingFeatureExtractorDestroy != nullptr);
79   ASSERT_TRUE(api_.TrackingFeatureExtractorStart != nullptr);
80   ASSERT_TRUE(api_.TrackingFeatureExtractorStop != nullptr);
81   ASSERT_TRUE(api_.TrackingFeatureExtractorProcessBuffer != nullptr);
82 
83   EXPECT_EQ(api_.TrackingFeatureExtractorCreate(nullptr), -ENOSYS);
84   EXPECT_EQ(api_.TrackingFeatureExtractorStart(nullptr, nullptr, nullptr),
85             -ENOSYS);
86   EXPECT_EQ(api_.TrackingFeatureExtractorStop(nullptr), -ENOSYS);
87   EXPECT_EQ(api_.TrackingFeatureExtractorProcessBuffer(nullptr, nullptr,
88                                                        nullptr, nullptr),
89             -ENOSYS);
90 
91   ASSERT_TRUE(api_.TrackingSensorsCreate != nullptr);
92   ASSERT_TRUE(api_.TrackingSensorsDestroy != nullptr);
93   ASSERT_TRUE(api_.TrackingSensorsStart != nullptr);
94   ASSERT_TRUE(api_.TrackingSensorsStop != nullptr);
95 
96   EXPECT_EQ(api_.TrackingSensorsCreate(nullptr, nullptr), -ENOSYS);
97   EXPECT_EQ(api_.TrackingSensorsStart(nullptr, nullptr, nullptr), -ENOSYS);
98   EXPECT_EQ(api_.TrackingSensorsStop(nullptr), -ENOSYS);
99 }
100 
101 #endif  // DVR_TRACKING_IMPLEMENTED
102 
103 }  // namespace
104