test: refactor task manager test case 58/313758/4
authorSeungbae Shin <seungbae.shin@samsung.com>
Mon, 1 Jul 2024 09:04:03 +0000 (18:04 +0900)
committerInki Dae <inki.dae@samsung.com>
Mon, 8 Jul 2024 05:45:06 +0000 (14:45 +0900)
Change-Id: I06f1a57e6f22c4ba31f8b024ed16fa300879311a
Signed-off-by: Seungbae Shin <seungbae.shin@samsung.com>
Fixed conflict and modified member order of Rect structure properly
to be suitable for answer value order.
Signed-off-by: Inki Dae <inki.dae@samsung.com>
common/include/SingleoCommonTypes.h
test/services/test_task_manager.cpp

index b14cacf5a32a238dc71b0c94569db828498d8ecc..d885552ff79fbd1fb8df662780f4b45afc691005 100644 (file)
@@ -27,14 +27,24 @@ namespace singleo
 {
 struct Rect {
        int left {};
-       int right {};
        int top {};
+       int right {};
        int bottom {};
+
+       bool operator==(const Rect &other) const
+       {
+               return (left == other.left && right == other.right && top == other.top && bottom == other.bottom);
+       }
 };
 
 struct Point {
        int x {};
        int y {};
+
+       bool operator==(const Point &other) const
+       {
+               return (x == other.x && y == other.y);
+       }
 };
 
 enum class DataType { NONE, FILE, IMAGE, RAW };
@@ -77,6 +87,15 @@ struct ImageDataType : public BaseDataType {
 
        ImageDataType() : BaseDataType(DataType::IMAGE)
        {}
+       ImageDataType(unsigned char *ptr_, unsigned int width_, unsigned int height_, unsigned int byte_per_pixel_,
+                                 ImagePixelFormat pixel_format_)
+                       : BaseDataType(DataType::IMAGE)
+                       , ptr(ptr_)
+                       , width(width_)
+                       , height(height_)
+                       , byte_per_pixel(byte_per_pixel_)
+                       , pixel_format(pixel_format_)
+       {}
 
        std::shared_ptr<BaseDataType> clone() override
        {
index d16b607e3469c4cbfc2a1789559b7530d30a9654..4a0b4eaa940f7b0fe0cc308dfafab95617c6fb42 100644 (file)
@@ -43,23 +43,20 @@ void BridgeNodeCallbackFD(INode *node)
        auto &inputBuffer = callbackNode->getInputBuffer();
        auto newBaseData = inputBuffer->getInputs()[0]->clone();
        auto newImage = dynamic_pointer_cast<ImageDataType>(newBaseData);
-       const int answer[][4] = { { 553, 87, 583, 129 }, { 397, 110, 427, 149 } };
+       const vector<Rect> answer { { 553, 87, 583, 129 }, { 397, 110, 427, 149 } };
 
        cv::Mat cv_image(cv::Size(newImage->width, newImage->height), CV_MAKETYPE(CV_8U, 3), newImage->ptr);
 
-       auto &results = callbackNode->results();
-       for (auto r : results) {
-               ASSERT_EQ(r->_type, ResultType::FACE_DETECTION);
+       for (auto &result : callbackNode->results()) {
+               ASSERT_EQ(result->_type, ResultType::FACE_DETECTION);
 
-               auto f_r = dynamic_pointer_cast<FdResultType>(r);
-               unsigned int idx = 0;
+               auto f_r = dynamic_pointer_cast<FdResultType>(result);
 
-               for (auto rect : f_r->_rects) {
-                       ASSERT_EQ(rect.left, answer[idx][0]);
-                       ASSERT_EQ(rect.top, answer[idx][1]);
-                       ASSERT_EQ(rect.right, answer[idx][2]);
-                       ASSERT_EQ(rect.bottom, answer[idx++][3]);
-               }
+               ASSERT_EQ(f_r->_rects.size(), answer.size());
+
+               unsigned int idx = 0;
+               for (auto &rect : f_r->_rects)
+                       ASSERT_EQ(rect, answer[idx++]);
        }
 
        auto outputBuffer = make_shared<SharedBuffer>();
@@ -72,7 +69,7 @@ TEST(SingloTaskManager, MultipleNodesBasedGraphAShouldWork)
 {
        cv::Mat cv_image = cv::imread(IMG_FACE, cv::IMREAD_COLOR);
        cv::cvtColor(cv_image, cv_image, cv::COLOR_BGR2RGB);
-       const int answer[][2] = { { 243, 133 }, { 404, 135 }, { 347, 197 }, { 250, 266 }, { 385, 266 } };
+       const vector<Point> answer { { 243, 133 }, { 404, 135 }, { 347, 197 }, { 250, 266 }, { 385, 266 } };
 
        ASSERT_FALSE(cv_image.empty());
 
@@ -107,15 +104,14 @@ TEST(SingloTaskManager, MultipleNodesBasedGraphAShouldWork)
 
                taskManager->run();
 
-               auto results = taskManager->output();
-               for (auto &result : results) {
+               for (auto &result : taskManager->output()) {
                        auto fld_result = dynamic_pointer_cast<FldResultType>(result);
-                       unsigned int idx = 0;
 
-                       for (auto &point : fld_result->_points) {
-                               ASSERT_EQ(point.x, answer[idx][0]);
-                               ASSERT_EQ(point.y, answer[idx++][1]);
-                       }
+                       ASSERT_EQ(fld_result->_points.size(), answer.size());
+
+                       unsigned int idx = 0;
+                       for (auto &point : fld_result->_points)
+                               ASSERT_EQ(point, answer[idx++]);
                }
 
                taskManager->clear();
@@ -130,7 +126,7 @@ TEST(SingloTaskManager, MultipleNodesBasedGraphBShouldWork)
 {
        cv::Mat cv_image = cv::imread(IMG_FACE, cv::IMREAD_COLOR);
        cv::cvtColor(cv_image, cv_image, cv::COLOR_BGR2RGB);
-       const int answer[][2] = { { 243, 133 }, { 404, 135 }, { 347, 197 }, { 250, 266 }, { 385, 266 } };
+       const vector<Point> answer { { 243, 133 }, { 404, 135 }, { 347, 197 }, { 250, 266 }, { 385, 266 } };
 
        ASSERT_FALSE(cv_image.empty());
 
@@ -169,15 +165,14 @@ TEST(SingloTaskManager, MultipleNodesBasedGraphBShouldWork)
 
                taskManager->run();
 
-               auto results = taskManager->output();
-               for (auto &result : results) {
+               for (auto &result : taskManager->output()) {
                        auto fld_result = dynamic_pointer_cast<FldResultType>(result);
-                       unsigned int idx = 0;
 
-                       for (auto &point : fld_result->_points) {
-                               ASSERT_EQ(point.x, answer[idx][0]);
-                               ASSERT_EQ(point.y, answer[idx++][1]);
-                       }
+                       ASSERT_EQ(fld_result->_points.size(), answer.size());
+
+                       unsigned int idx = 0;
+                       for (auto &point : fld_result->_points)
+                               ASSERT_EQ(point, answer[idx++]);
                }
 
                taskManager->clear();
@@ -203,8 +198,8 @@ TEST(SingloTaskManager, MultipleNodesBasedGraphCShouldWork)
 {
        cv::Mat cv_image = cv::imread(IMG_FACE, cv::IMREAD_COLOR);
        cv::cvtColor(cv_image, cv_image, cv::COLOR_BGR2RGB);
-       const int fd_answer[][4] = { { 553, 87, 583, 129 }, { 397, 110, 427, 149 } };
-       const int fld_answer[][2] = { { 243, 133 }, { 404, 135 }, { 347, 197 }, { 250, 266 }, { 385, 266 } };
+       const vector<Rect> fd_answer { { 553, 87, 583, 129 }, { 397, 110, 427, 149 } };
+       const vector<Point> fld_answer { { 243, 133 }, { 404, 135 }, { 347, 197 }, { 250, 266 }, { 385, 266 } };
 
        ASSERT_FALSE(cv_image.empty());
 
@@ -241,26 +236,23 @@ TEST(SingloTaskManager, MultipleNodesBasedGraphCShouldWork)
 
                taskManager->run();
 
-               auto results = taskManager->output();
-               for (auto &result : results) {
+               for (auto &result : taskManager->output()) {
                        if (result->_type == ResultType::FACE_DETECTION) {
                                auto fd_result = dynamic_pointer_cast<FdResultType>(result);
-                               unsigned int idx = 0;
 
-                               for (auto rect : fd_result->_rects) {
-                                       ASSERT_EQ(rect.left, fd_answer[idx][0]);
-                                       ASSERT_EQ(rect.top, fd_answer[idx][1]);
-                                       ASSERT_EQ(rect.right, fd_answer[idx][2]);
-                                       ASSERT_EQ(rect.bottom, fd_answer[idx++][3]);
-                               }
+                               ASSERT_EQ(fd_result->_rects.size(), fd_answer.size());
+
+                               unsigned int idx = 0;
+                               for (auto &rect : fd_result->_rects)
+                                       ASSERT_EQ(rect, fd_answer[idx++]);
                        } else {
                                auto fld_result = dynamic_pointer_cast<FldResultType>(result);
-                               unsigned int idx = 0;
 
-                               for (auto &point : fld_result->_points) {
-                                       ASSERT_EQ(point.x, fld_answer[idx][0]);
-                                       ASSERT_EQ(point.y, fld_answer[idx++][1]);
-                               }
+                               ASSERT_EQ(fld_result->_points.size(), fld_answer.size());
+
+                               unsigned int idx = 0;
+                               for (auto &point : fld_result->_points)
+                                       ASSERT_EQ(point, fld_answer[idx++]);
                        }
                }
 
@@ -276,8 +268,8 @@ TEST(SingloTaskManager, MultipleNodesBasedGraphDShouldWork)
 {
        cv::Mat cv_image = cv::imread(IMG_FACE, cv::IMREAD_COLOR);
        cv::cvtColor(cv_image, cv_image, cv::COLOR_BGR2RGB);
-       const int fd_answer[][4] = { { 553, 87, 583, 129 }, { 397, 110, 427, 149 } };
-       const int fld_answer[][2] = { { 243, 133 }, { 404, 135 }, { 347, 197 }, { 250, 266 }, { 385, 266 } };
+       const vector<Rect> fd_answer { { 553, 87, 583, 129 }, { 397, 110, 427, 149 } };
+       const vector<Point> fld_answer { { 243, 133 }, { 404, 135 }, { 347, 197 }, { 250, 266 }, { 385, 266 } };
 
        ASSERT_FALSE(cv_image.empty());
 
@@ -318,26 +310,23 @@ TEST(SingloTaskManager, MultipleNodesBasedGraphDShouldWork)
 
                taskManager->run();
 
-               auto results = taskManager->output();
-               for (auto &result : results) {
+               for (auto &result : taskManager->output()) {
                        if (result->_type == ResultType::FACE_DETECTION) {
                                auto fd_result = dynamic_pointer_cast<FdResultType>(result);
-                               unsigned int idx = 0;
 
-                               for (auto rect : fd_result->_rects) {
-                                       ASSERT_EQ(rect.left, fd_answer[idx][0]);
-                                       ASSERT_EQ(rect.top, fd_answer[idx][1]);
-                                       ASSERT_EQ(rect.right, fd_answer[idx][2]);
-                                       ASSERT_EQ(rect.bottom, fd_answer[idx++][3]);
-                               }
+                               ASSERT_EQ(fd_result->_rects.size(), fd_answer.size());
+
+                               unsigned int idx = 0;
+                               for (auto &rect : fd_result->_rects)
+                                       ASSERT_EQ(rect, fd_answer[idx++]);
                        } else {
                                auto fld_result = dynamic_pointer_cast<FldResultType>(result);
-                               unsigned int idx = 0;
 
-                               for (auto &point : fld_result->_points) {
-                                       ASSERT_EQ(point.x, fld_answer[idx][0]);
-                                       ASSERT_EQ(point.y, fld_answer[idx++][1]);
-                               }
+                               ASSERT_EQ(fld_result->_points.size(), fld_answer.size());
+
+                               unsigned int idx = 0;
+                               for (auto &point : fld_result->_points)
+                                       ASSERT_EQ(point, fld_answer[idx++]);
                        }
                }
 
@@ -356,13 +345,12 @@ void BridgeNodeCallbackOD(INode *node)
 
        auto outputBuffer = make_shared<SharedBuffer>();
 
-       auto &results = callbackNode->results();
-       for (auto r : results) {
+       for (auto &r : callbackNode->results()) {
                ASSERT_EQ(r->_type, ResultType::OBJECT_DETECTION);
 
                auto obj_r = dynamic_pointer_cast<OdResultType>(r);
 
-               for (auto rect : obj_r->_rects) {
+               for (auto &rect : obj_r->_rects) {
                        rect.left = max(rect.left, 0);
                        rect.top = max(rect.top, 0);
                        rect.right = min(rect.right, static_cast<int>(inputImage->width));
@@ -388,8 +376,9 @@ void BridgeNodeCallbackOD(INode *node)
                }
        }
        // Object detection failed so do not go forward.
-       if (outputBuffer->getInputs().size() == 0)
+       if (outputBuffer->getInputs().empty())
                return;
+
        callbackNode->setOutputBuffer(outputBuffer);
 }
 
@@ -498,7 +487,7 @@ void BranchNodeCallback(INode *node)
 //                -----> object_detection ---                 -----> image_classification ---------
 TEST(SingloTaskManager, MultipleNodesBasedGraphFShouldWork)
 {
-       const int fld_answer[][2] = { { 243, 133 }, { 404, 135 }, { 347, 197 }, { 250, 266 }, { 385, 266 } };
+       const vector<Point> fld_answer = { { 243, 133 }, { 404, 135 }, { 347, 197 }, { 250, 266 }, { 385, 266 } };
        const std::string ic_answer = "Banana";
 
        cv::Mat cv_image[2];
@@ -559,10 +548,8 @@ TEST(SingloTaskManager, MultipleNodesBasedGraphFShouldWork)
                                                auto fld_result = dynamic_pointer_cast<FldResultType>(result);
                                                unsigned int idx = 0;
 
-                                               for (auto &point : fld_result->_points) {
-                                                       ASSERT_EQ(point.x, fld_answer[idx][0]);
-                                                       ASSERT_EQ(point.y, fld_answer[idx++][1]);
-                                               }
+                                               for (auto &point : fld_result->_points)
+                                                       ASSERT_EQ(point, fld_answer[idx++]);
                                        } else if (result->_type == ResultType::IMAGE_CLASSIFICATION) {
                                                SINGLEO_LOGD("IC result received at endpoint");
                                                auto ic_result = dynamic_pointer_cast<IcResultType>(result);