Exclude some lines for code coverage 21/298321/1
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 6 Sep 2023 01:49:00 +0000 (10:49 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 6 Sep 2023 01:49:00 +0000 (10:49 +0900)
This patch excludes some lines. It's hard to make testcases of some errors.

Change-Id: I7d2f07fc2320a8e93a838e2c5818671febbf13a2
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
mime-type/mime_type.cc
mime-type/xdg_mime.cc

index 1d80921..9d03c8b 100644 (file)
@@ -40,21 +40,27 @@ EXPORT int mime_type_get_mime_type(const char* file_extension,
   }
 
   if (file_extension[0] == '.') {
+    // LCOV_EXCL_START
     _E("The file extention includes the leading dot('.')");
     return MIME_TYPE_ERROR_INVALID_PARAMETER;
+    // LCOV_EXCL_STOP
   }
 
   std::string file_name = "." + std::string(file_extension);
   auto xdg_mime_type = content::XdgMime::GetMimeTypeFromFileName(file_name);
   if (xdg_mime_type.empty()) {
+    // LCOV_EXCL_START
     _E("GetMimeTypeFromFileName(%s) is failed", file_name.c_str());
     return MIME_TYPE_ERROR_IO_ERROR;
+    // LCOV_EXCL_STOP
   }
 
   *mime_type = strdup(xdg_mime_type.c_str());
   if (*mime_type == nullptr) {
+    // LCOV_EXCL_START
     _E("Out of memory");
     return MIME_TYPE_ERROR_OUT_OF_MEMORY;
+    // LCOV_EXCL_STOP
   }
 
   return MIME_TYPE_ERROR_NONE;
@@ -74,15 +80,19 @@ EXPORT int mime_type_get_file_extension(const char* mime_type,
 
   auto file_names = content::XdgMime::GetFileNamesFromMimeType(mime_type);
   if (file_names.size() == 0) {
+    // LCOV_EXCL_START
     _E("GetFileNameFromMimeType(%s) is failed", mime_type);
     return MIME_TYPE_ERROR_IO_ERROR;
+    // LCOV_EXCL_STOP
   }
 
   auto** extensions = reinterpret_cast<char**>(
       calloc(file_names.size(), sizeof(char*)));
   if (extensions == nullptr) {
+    // LCOV_EXCL_START
     _E("Out of memory");
     return MIME_TYPE_ERROR_OUT_OF_MEMORY;
+    // LCOV_EXCL_STOP
   }
 
   int index = 0;
@@ -92,11 +102,13 @@ EXPORT int mime_type_get_file_extension(const char* mime_type,
       std::string extension = file_name.substr(pos + 1);
       extensions[index] = strdup(extension.c_str());
       if (extensions[index] == nullptr) {
+        // LCOV_EXCL_START
         _E("Out of memory");
         for (int i = 0; i < index; ++i)
           free(extensions[i]);
         free(extensions);
         return MIME_TYPE_ERROR_OUT_OF_MEMORY;
+        // LCOV_EXCL_STOP
       }
 
       index++;
@@ -121,6 +133,7 @@ EXPORT int mime_type_get_mime_type_for_file(const char* file_path,
   }
 
   if (access(file_path, R_OK) < 0) {
+    // LCOV_EXCL_START
     if (errno == EACCES) {
       _E("Permission denied");
       return MIME_TYPE_ERROR_PERMISSION_DENIED;
@@ -128,30 +141,39 @@ EXPORT int mime_type_get_mime_type_for_file(const char* file_path,
 
     _E("access() is failed. path(%s), errno(%d)", file_path, errno);
     return MIME_TYPE_ERROR_IO_ERROR;
+    // LCOV_EXCL_STOP
   }
 
   struct stat statbuf;
   int ret = stat(file_path, &statbuf);
   if (ret != 0) {
+    // LCOV_EXCL_START
     _E("stat() is failed. path(%s), errno(%d)", file_path, errno);
     return MIME_TYPE_ERROR_IO_ERROR;
+    // LCOV_EXCL_STOP
   }
 
   if (!S_ISREG(statbuf.st_mode)) {
+    // LCOV_EXCL_START
     _E("%s is not regular file", file_path);
     return MIME_TYPE_ERROR_INVALID_PARAMETER;
+    // LCOV_EXCL_START
   }
 
   auto xdg_mime_type = content::XdgMime::GetMimeTypeForFile(file_path);
   if (xdg_mime_type.empty()) {
+    // LCOV_EXCL_START
     _E("GetMimeTypeForFile(%s) is failed", file_path);
     return MIME_TYPE_ERROR_IO_ERROR;
+    // LCOV_EXCL_START
   }
 
   *mime_type = strdup(xdg_mime_type.c_str());
   if (*mime_type == nullptr) {
+    // LCOV_EXCL_START
     _E("Out of memory");
     return MIME_TYPE_ERROR_OUT_OF_MEMORY;
+    // LCOV_EXCL_START
   }
 
   return MIME_TYPE_ERROR_NONE;
@@ -166,14 +188,18 @@ EXPORT int mime_type_get_mime_type_for_data(const void* data, size_t len,
 
   auto xdg_mime_type = content::XdgMime::GetMimeTypeForData(data, len);
   if (xdg_mime_type.empty()) {
+    // LCOV_EXCL_START
     _E("GetMimeTypeForData() is failed");
     return MIME_TYPE_ERROR_IO_ERROR;
+    // LCOV_EXCL_START
   }
 
   *mime_type = strdup(xdg_mime_type.c_str());
   if (*mime_type == nullptr) {
+    // LCOV_EXCL_START
     _E("Out of memory");
     return MIME_TYPE_ERROR_OUT_OF_MEMORY;
+    // LCOV_EXCL_START
   }
 
   return MIME_TYPE_ERROR_NONE;
index caa8195..c022738 100644 (file)
@@ -23,7 +23,7 @@ namespace content {
 std::string XdgMime::GetMimeTypeFromFileName(const std::string& file_name) {
   auto* mime_type = xdg_mime_get_mime_type_from_file_name(file_name.c_str());
   if (mime_type == nullptr)
-    return {};
+    return {};  // LCOV_EXCL_LINE
 
   return std::string(mime_type);
 }
@@ -46,7 +46,7 @@ std::string XdgMime::GetMimeTypeForFile(const std::string& file_path) {
   auto* mime_type = xdg_mime_get_mime_type_for_file(file_path.c_str(),
       &statbuf);
   if (mime_type == nullptr)
-    return {};
+    return {};  // LCOV_EXCL_LINE
 
   return std::string(mime_type);
 }
@@ -55,7 +55,7 @@ std::string XdgMime::GetMimeTypeForData(const void* data, size_t len) {
   int result_prio;
   auto* mime_type = xdg_mime_get_mime_type_for_data(data, len, &result_prio);
   if (mime_type == nullptr)
-    return {};
+    return {};  // LCOV_EXCL_LINE
 
   return std::string(mime_type);
 }