Change hard coded path to get by using tzplatform API
[platform/core/multimedia/libmm-utility.git] / bmp / test / mm_util_bmp_testsuite.c
1 /*
2  * libmm-utility
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Vineeth T M <vineeth.tm@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <sys/stat.h>
26 #include <mm_util_bmp.h>
27 #include <tzplatform_config.h>
28
29 #define DECODE_RESULT_PATH tzplatform_mkpath(TZ_USER_CONTENT, "decode_test.")
30 #define BUFFER_SIZE 128
31
32 static inline void flush_stdin()
33 {
34         int ch;
35         while ((ch = getchar()) != EOF && ch != '\n') ;
36 }
37
38 int main(int argc, char *argv[])
39 {
40         int ret = 0;
41         mm_util_bmp_data decoded;
42
43         if (argc < 2) {
44                 fprintf(stderr, "\t[usage]\n");
45                 fprintf(stderr, "\t\t1. decode : mm_util_bmp_testsuite decode filepath.bmp\n");
46                 return 0;
47         }
48
49         if (!strcmp("decode", argv[1])) {
50                 ret = mm_util_decode_from_bmp_file(&decoded, argv[2]);
51         } else {
52                 fprintf(stderr, "\tunknown command [%s]\n", argv[1]);
53                 return 0;
54         }
55
56         if (ret != MM_UTIL_ERROR_NONE) {
57                 fprintf(stderr, "\tERROR is occurred %x\n", ret);
58         } else {
59                 fprintf(stderr, "\tBMP OPERATION SUCCESS\n");
60                 {
61                         if (decoded.data) {
62                                 fprintf(stderr, "\t##Decoded data##: %p\t width: %lu\t height:%lu\t size: %llu\n", decoded.data, decoded.width, decoded.height, decoded.size);
63                                 char filename[BUFFER_SIZE] = { 0, };
64                                 memset(filename, 0, BUFFER_SIZE);
65                                 {
66                                         snprintf(filename, BUFFER_SIZE, "%s%s", DECODE_RESULT_PATH, "bmp");
67                                 }
68
69                                 ret = mm_util_encode_bmp_to_file(&decoded, filename);
70
71                                 free(decoded.data);
72                         } else {
73                                 fprintf(stderr, "\tDECODED data is NULL\n");
74                         }
75                 }
76         }
77         return 0;
78 }