Fix QRcode error handle 62/289262/1
authorKwanghoon Son <k.son@samsung.com>
Wed, 28 Dec 2022 06:52:38 +0000 (15:52 +0900)
committerkwang son <k.son@samsung.com>
Fri, 3 Mar 2023 09:55:48 +0000 (09:55 +0000)
Change default error MEDIA_VISION_ERROR_NONE to
MEDIA_VISION_ERROR_INTERNAL.

[Issue type] Fix

Change-Id: I61bfa695f98341b979be5d91646831763b9f6298
Signed-off-by: Kwanghoon Son <k.son@samsung.com>
(cherry picked from commit 9234fad3f0a515b33e487e0405d3061437b770f2)

mv_barcode/barcode_generator/src/mv_barcode_generate_open.cpp
test/CMakeLists.txt
test/testsuites/barcode/test_barcode.cpp

index c140bea..32657d4 100644 (file)
@@ -151,9 +151,12 @@ BarcodeQRErrorCorrectionLevel convertECC(mv_barcode_qr_ecc_e ecc)
 
 int convertBarcodeError(int barcodeError)
 {
-       int mvError = MEDIA_VISION_ERROR_NONE;
+       int mvError;
 
        switch (barcodeError) {
+       case BARCODE_ERROR_NONE:
+               mvError = MEDIA_VISION_ERROR_NONE;
+               break;
        case BARCODE_WARNING_INVALID_OPTION:
                mvError = MEDIA_VISION_ERROR_INVALID_PARAMETER;
                break;
@@ -180,8 +183,9 @@ int convertBarcodeError(int barcodeError)
                break;
        case BARCODE_ERROR_INVALID_PATH:
                mvError = MEDIA_VISION_ERROR_INVALID_PATH;
-       default:
                break;
+       default:
+               mvError = MEDIA_VISION_ERROR_INTERNAL;
        }
 
        LOGI("ZInt error code has been converted to the media vision error code "
index 6d990bc..f361f96 100644 (file)
@@ -31,7 +31,9 @@ set(SRC_FILES ${SRC_FILES} testsuites/common/test_common.cpp)
 endif()
 
 add_executable(${PROJECT_NAME} ${SRC_FILES})
-target_link_libraries(${PROJECT_NAME} gtest gtest_main mv_inference mv_image_helper mv_barcode_detector)
+target_link_libraries(${PROJECT_NAME}
+    gtest gtest_main mv_inference mv_image_helper
+    mv_barcode_detector mv_barcode_generator)
 
 if (WITH_DA_PROFILE)
 target_link_libraries(${PROJECT_NAME} vision-source)
index 7dc302a..6d123eb 100644 (file)
@@ -94,4 +94,54 @@ TEST_P(TestBarcode, Detection)
                          MEDIA_VISION_ERROR_NONE);
 }
 
-INSTANTIATE_TEST_CASE_P(GeneralAndSpecial, TestBarcode, testing::ValuesIn(ReadDetPositive1()));
\ No newline at end of file
+INSTANTIATE_TEST_CASE_P(GeneralAndSpecial, TestBarcode, testing::ValuesIn(ReadDetPositive1()));
+
+class TestBarcodeGen : public ::testing::Test
+{
+protected:
+       void SetUp() override
+       {
+               test_file = "/tmp/" + string { testing::UnitTest::GetInstance()->current_test_info()->name() } + ".png";
+       }
+       void TearDown() override
+       {
+               if (access(test_file.c_str(), F_OK) != -1) {
+                       std::remove(test_file.c_str());
+               }
+       }
+
+       mv_engine_config_h engine_cfg = NULL;
+       mv_barcode_type_e type = MV_BARCODE_QR;
+       mv_barcode_qr_mode_e qr_enc_mode = MV_BARCODE_QR_MODE_UTF8;
+       mv_barcode_qr_ecc_e qr_ecc = MV_BARCODE_QR_ECC_LOW;
+       int qr_version = 5;
+       std::string test_file;
+       mv_barcode_image_format_e image_format = MV_BARCODE_IMAGE_FORMAT_PNG;
+};
+
+TEST_F(TestBarcodeGen, SimplePositiveQP)
+{
+       ASSERT_EQ(mv_barcode_generate_image(engine_cfg, "https://test.com", 100, 100, type, qr_enc_mode, qr_ecc, qr_version,
+                                                                               test_file.c_str(), image_format),
+                         MEDIA_VISION_ERROR_NONE);
+}
+
+TEST_F(TestBarcodeGen, SimpleNegativeQR)
+{
+       ASSERT_EQ(mv_barcode_generate_image(engine_cfg, "한글사용https://test.com", 100, 100, type, qr_enc_mode, qr_ecc,
+                                                                               qr_version, test_file.c_str(), image_format),
+                         MEDIA_VISION_ERROR_INTERNAL);
+}
+
+TEST_F(TestBarcodeGen, ColorPositiveQR)
+{
+       ASSERT_EQ(mv_create_engine_config(&engine_cfg), MEDIA_VISION_ERROR_NONE);
+       ASSERT_EQ(mv_engine_config_set_string_attribute(engine_cfg, "MV_BARCODE_GENERATE_ATTR_COLOR_FRONT", "3366ff"),
+                         MEDIA_VISION_ERROR_NONE);
+       ASSERT_EQ(mv_engine_config_set_string_attribute(engine_cfg, "MV_BARCODE_GENERATE_ATTR_COLOR_BACK", "ff9966"),
+                         MEDIA_VISION_ERROR_NONE);
+       ASSERT_EQ(mv_barcode_generate_image(engine_cfg, "1239592https://test.com", 100, 100, type, qr_enc_mode, qr_ecc,
+                                                                               qr_version, test_file.c_str(), image_format),
+                         MEDIA_VISION_ERROR_NONE);
+       ASSERT_EQ(mv_destroy_engine_config(engine_cfg), MEDIA_VISION_ERROR_NONE);
+}