[ITC][capi-content-mime-type][ACR-1078][Add API]
authorSamuel Peter <samuel.peter@samsung.com>
Fri, 20 Jul 2018 09:40:28 +0000 (15:10 +0530)
committermanoj gupta <manoj.g2@samsung.com>
Fri, 20 Jul 2018 11:05:57 +0000 (11:05 +0000)
Signed-off-by: Samuel Peter <samuel.peter@samsung.com>
Change-Id: Ic4dd1e67154822f68dc23fe9b5b35012ccba652d

packaging/itc/native-mime-type-itc.xml
scripts_tpk/spec.sh
src/itc/mime-type/ITs-mime-type-common.c
src/itc/mime-type/ITs-mime-type-common.h
src/itc/mime-type/ITs-mime-type.c
src/itc/mime-type/res/mobile/Tizen-logo-wallpaper.jpg [new file with mode: 0755]
src/itc/mime-type/res/wearable/Tizen-logo-wallpaper.jpg [new file with mode: 0755]
src/itc/mime-type/tct-mime-type-native_mobile.h
src/itc/mime-type/tct-mime-type-native_wearable.h

index 6cdd0f7..f7fb41b 100755 (executable)
@@ -11,4 +11,8 @@
        <background-category value="media"/>
        <background-category value="sensor"/>
     </ui-application>
+    <privileges>
+    <privilege>http://tizen.org/privilege/mediastorage</privilege>
+    <privilege>http://tizen.org/privilege/externalstorage</privilege>
+    </privileges>
 </manifest>
index 0d615f7..4639af6 100755 (executable)
@@ -447,6 +447,17 @@ case "$1" in
                        chsmack -a "User::App::Shared" $APP_DATA_DIR/*
                        chsmack -e "User::App::Shared" $APP_DATA_DIR/*
                        ;;
+       "org.tizen.mime-type-native-itc")
+                       echo "Installing pre-requisites for the package $1"
+                       mkdir -p $APP_DATA_DIR
+                       chsmack -a "User::App::Shared" $APP_DATA_DIR
+                       chsmack -e "User::App::Shared" $APP_DATA_DIR
+                       cp Tizen-logo-wallpaper.jpg $APP_DATA_DIR/Tizen-logo-wallpaper.jpg
+                       chown -R 5000:5000 $APP_DATA_DIR
+                       chmod -R 777 $APP_DATA_DIR
+                       chsmack -a "User::App::Shared" $APP_DATA_DIR/*
+                       chsmack -e "User::App::Shared" $APP_DATA_DIR/*
+                       ;;
        "org.tizen.video-util-native-itc")
                        echo "Installing pre-requisites for the package $1"
                        mkdir -p $APP_DATA_DIR
index c0578d9..d5a7d68 100755 (executable)
@@ -43,4 +43,26 @@ char* MimeTypeGetError(int nRet)
        return szErrorVal;
 }
 
-/** @} */ //end of itc-mime-type
\ No newline at end of file
+/**
+* @function                    MimeTypeGetDataPath
+* @description                         Get the path to application data directory
+* @parameter   [IN]    char* pszFileName [file name]
+* @return                              Total Path of file "pszFilename"
+*/
+char* MimeTypeGetDataPath(char *pszFileName)
+{
+       char *pszAppData =  app_get_data_path(),*pszImgPath = NULL;
+       if ( pszAppData == NULL || strlen(pszAppData) == 0 )
+       {
+               FPRINTF("[Line : %d][%s] app_get_data_path() returned invalid path\\n", __LINE__, API_NAMESPACE);
+               return NULL;
+       }
+
+       pszImgPath = (char*) calloc(1, strlen(pszAppData) + strlen(pszFileName)+1);
+       if (pszImgPath == NULL)
+               return NULL;
+       sprintf(pszImgPath, "%s%s",pszAppData, pszFileName );
+       return pszImgPath;
+}
+
+/** @} */ //end of itc-mime-type
index 1144f67..4a0933a 100755 (executable)
@@ -18,6 +18,7 @@
 
 #include "tct_common.h"
 #include <mime_type.h>
+#include <app.h>
 
 /** @addtogroup itc-mime-type
 * @ingroup             itc
@@ -25,6 +26,8 @@
 */
 
 #define API_NAMESPACE                  "MIME_TYPE_ITC"
+#define SAMPLE_FILE_PATH               "Tizen-logo-wallpaper.jpg"
+#define PATH_LEN                       1024
 //Add test package related includes here
 
 #define START_TEST {\
 }
 
 char* MimeTypeGetError(int nRet);
+bool FileUtilGetDataPath(char* pAppDataPath);
+bool FileUtilAppendToAppDataPath(char* pInputPath, char* pFinalPath);
+char* MimeTypeGetDataPath(char *pszFileName);
 
 /** @} */ //end of itc-mime-type
 
-#endif  //_ITS_MIME_TYPE_COMMON_H_
\ No newline at end of file
+#endif  //_ITS_MIME_TYPE_COMMON_H_
index 3628e2e..b8eda0e 100755 (executable)
@@ -130,5 +130,122 @@ int ITc_mime_type_get_mime_type_p(void)
        return 0;
 }
 
+//& purpose: Gets the MIME type for the given data.
+//& type: auto
+/**
+* @testcase                    ITc_mime_type_get_mime_type_for_data
+* @since_tizen                         4.0
+* @author              SRID(samuel.peter)
+* @reviewer            SRID(manoj.g2)
+* @type                                auto
+* @description                 Gets the MIME type for the given data.
+* @scenario                            Get mime-type using mime_type_get_mime_type_for_data
+* @apicovered                  mime_type_get_mime_type_for_data
+* @passcase                            if mime_type_get_mime_type_for_data successful
+* @failcase                            if mime_type_get_mime_type_for_data fails
+* @precondition                        NA
+* @postcondition               NA
+*/
+int ITc_mime_type_get_mime_type_for_data(void)
+{
+       START_TEST;
+
+       char *pszMimeType = NULL;
+       char *pszPath = NULL;
+       char *pszOutMimeType = "image//jpeg";
+       FILE *pFilePtr = NULL;
+       int nSize = 0;
+       int nRet = 0;
+
+       pszPath = MimeTypeGetDataPath(SAMPLE_FILE_PATH);
+       if ( NULL == pszPath)
+       {
+               FPRINTF("[Line : %d][%s] MimeTypeGetDataPath failed, error returned\\n", __LINE__, API_NAMESPACE);
+               return 1;
+       }
+
+       pFilePtr = fopen(pszPath, "rb");
+       if(NULL == pFilePtr)
+       {
+               FPRINTF("[Line : %d][%s] unable to open data file: %s\\n", __LINE__, API_NAMESPACE, pszPath);
+               FREE_MEMORY(pszPath);
+               return 1;
+       }
+
+       nSize = sizeof(pFilePtr);
+       nRet = mime_type_get_mime_type_for_data(pFilePtr, nSize, &pszMimeType);
+       PRINT_RESULT_CLEANUP(MIME_TYPE_ERROR_NONE, nRet, "mime_type_get_mime_type_for_data", MimeTypeGetError(nRet), FREE_MEMORY(pszPath);FREE_MEMORY(pFilePtr));
+       CHECK_HANDLE(pszMimeType,"mime_type_get_mime_type_for_data");
+
+       nSize = sizeof(pszOutMimeType);
+       if(!strncmp(pszMimeType, pszOutMimeType, nSize))
+       {
+               FPRINTF("[Line : %d][%s] incorrect mime_type returned.\\n", __LINE__, API_NAMESPACE);
+               FREE_MEMORY(pszMimeType);
+               FREE_MEMORY(pszPath);
+               FREE_MEMORY(pFilePtr);
+               return 1;
+       }
+
+       FPRINTF("[Line : %d][%s] mime_type : %s\\n", __LINE__, API_NAMESPACE, pszMimeType);
+       FREE_MEMORY(pszMimeType);
+       FREE_MEMORY(pszPath);
+       FREE_MEMORY(pFilePtr);
+
+       return 0;
+}
+
+//& purpose: Gets the MIME type for the given file extension.
+//& type: auto
+/**
+* @testcase                    ITc_mime_type_get_mime_type_for_file
+* @since_tizen                         4.0
+* @author              SRID(samuel.peter)
+* @reviewer            SRID(manoj.g2)
+* @type                                auto
+* @description                 Gets the MIME type for the given file.
+* @scenario                            Get mime-type using mime_type_get_mime_type_for_file
+* @apicovered                  mime_type_get_mime_type_for_file
+* @passcase                            if mime_type_get_mime_type_for_file successful
+* @failcase                            if mime_type_get_mime_type_for_file fails
+* @precondition                        NA
+* @postcondition               NA
+*/
+int ITc_mime_type_get_mime_type_for_file(void)
+{
+       START_TEST;
+
+       char *pszMimeType = NULL;
+       char *pszPath = NULL;
+       char *pszOutMimeType = "application//octet-stream";
+       int nSize = 0;
+       int nRet = 0;
+
+       pszPath = MimeTypeGetDataPath(SAMPLE_FILE_PATH);
+       if ( NULL == pszPath)
+       {
+               FPRINTF("[Line : %d][%s] MimeTypeGetDataPath failed, error returned\\n", __LINE__, API_NAMESPACE);
+               return 1;
+       }
+
+       nRet = mime_type_get_mime_type_for_file(pszPath, &pszMimeType);
+       PRINT_RESULT_CLEANUP(MIME_TYPE_ERROR_NONE, nRet, "mime_type_get_mime_type_for_file", MimeTypeGetError(nRet),FREE_MEMORY(pszPath));
+       CHECK_HANDLE(pszMimeType,"mime_type_get_mime_type_for_file");
+
+       nSize = sizeof(pszOutMimeType);
+       if(!strncmp(pszMimeType, pszOutMimeType, nSize))
+       {
+               FPRINTF("[Line : %d][%s] incorrect mime_type returned.\\n", __LINE__, API_NAMESPACE);
+               FREE_MEMORY(pszMimeType);
+               FREE_MEMORY(pszPath);
+               return 1;
+       }
+
+       FPRINTF("[Line : %d][%s] mime_type : %s\\n", __LINE__, API_NAMESPACE, pszMimeType);
+       FREE_MEMORY(pszMimeType);
+       FREE_MEMORY(pszPath);
+
+       return 0;
+}
 /** @} */ //end of itc-mime-type
-/** @} */ //end of itc-mime-type-testcases
\ No newline at end of file
+/** @} */ //end of itc-mime-type-testcases
diff --git a/src/itc/mime-type/res/mobile/Tizen-logo-wallpaper.jpg b/src/itc/mime-type/res/mobile/Tizen-logo-wallpaper.jpg
new file mode 100755 (executable)
index 0000000..44c663a
Binary files /dev/null and b/src/itc/mime-type/res/mobile/Tizen-logo-wallpaper.jpg differ
diff --git a/src/itc/mime-type/res/wearable/Tizen-logo-wallpaper.jpg b/src/itc/mime-type/res/wearable/Tizen-logo-wallpaper.jpg
new file mode 100755 (executable)
index 0000000..44c663a
Binary files /dev/null and b/src/itc/mime-type/res/wearable/Tizen-logo-wallpaper.jpg differ
index c9b49bc..706e578 100755 (executable)
@@ -24,10 +24,14 @@ extern void ITs_mime_type_cleanup(void);
 
 extern int ITc_mime_type_get_file_extension_p(void);
 extern int ITc_mime_type_get_mime_type_p(void);
+extern int ITc_mime_type_get_mime_type_for_file(void);
+extern int ITc_mime_type_get_mime_type_for_data(void);
 
 testcase tc_array[] = {
        {"ITc_mime_type_get_file_extension_p",ITc_mime_type_get_file_extension_p,ITs_mime_type_startup,ITs_mime_type_cleanup},
        {"ITc_mime_type_get_mime_type_p",ITc_mime_type_get_mime_type_p,ITs_mime_type_startup,ITs_mime_type_cleanup},
+       {"ITc_mime_type_get_mime_type_for_file",ITc_mime_type_get_mime_type_for_file,ITs_mime_type_startup,ITs_mime_type_cleanup},
+       {"ITc_mime_type_get_mime_type_for_data",ITc_mime_type_get_mime_type_for_data,ITs_mime_type_startup,ITs_mime_type_cleanup},
        {NULL, NULL}
 };
 
index c9b49bc..706e578 100755 (executable)
@@ -24,10 +24,14 @@ extern void ITs_mime_type_cleanup(void);
 
 extern int ITc_mime_type_get_file_extension_p(void);
 extern int ITc_mime_type_get_mime_type_p(void);
+extern int ITc_mime_type_get_mime_type_for_file(void);
+extern int ITc_mime_type_get_mime_type_for_data(void);
 
 testcase tc_array[] = {
        {"ITc_mime_type_get_file_extension_p",ITc_mime_type_get_file_extension_p,ITs_mime_type_startup,ITs_mime_type_cleanup},
        {"ITc_mime_type_get_mime_type_p",ITc_mime_type_get_mime_type_p,ITs_mime_type_startup,ITs_mime_type_cleanup},
+       {"ITc_mime_type_get_mime_type_for_file",ITc_mime_type_get_mime_type_for_file,ITs_mime_type_startup,ITs_mime_type_cleanup},
+       {"ITc_mime_type_get_mime_type_for_data",ITc_mime_type_get_mime_type_for_data,ITs_mime_type_startup,ITs_mime_type_cleanup},
        {NULL, NULL}
 };