glib/tests/bookmarkfile-test1.c
changeset 72 403e7f6ed6c5
parent 50 79045913e4e9
equal deleted inserted replaced
71:28ccaba883f4 72:403e7f6ed6c5
    12 //
    12 //
    13 // Description:
    13 // Description:
    14 //
    14 //
    15 
    15 
    16 
    16 
       
    17 #include <sys/stat.h>
    17 #include<stdio.h>
    18 #include<stdio.h>
    18 #include <glib.h>
    19 #include <glib.h>
    19 #define LOG_FILE "c:\\logs\\bookmark_test1_log.txt"
    20 #include <glib/gprintf.h>
    20 #include "std_log_result.h"
    21 #ifdef __SYMBIAN32__
    21 #define LOG_FILENAME_LINE __FILE__, __LINE__
    22 #include "mrt2_glib2_test.h"
       
    23 #endif /*__SYMBIAN32__*/
    22 #define in_FILE "file.xbel"
    24 #define in_FILE "file.xbel"
    23 
       
    24 
       
    25 void create_xml(int result)
       
    26 {
       
    27     if(result)
       
    28         assert_failed = 1;
       
    29     
       
    30     testResultXml("bookmark-test1");
       
    31     close_log_file();
       
    32 }
       
    33 
    25 
    34 int
    26 int
    35 main (int   argc,
    27 main (int   argc,
    36       char *argv[])
    28       char *argv[])
    37     {
    29     {
    42     const gchar *rel_path;
    34     const gchar *rel_path;
    43     time_t time;
    35     time_t time;
    44     const gchar *bookmark_filename = argv[1];
    36     const gchar *bookmark_filename = argv[1];
    45     GError        *error = NULL;
    37     GError        *error = NULL;
    46     gchar **bookmark_uri = NULL;
    38     gchar **bookmark_uri = NULL;
    47         
    39     
       
    40     #ifdef __SYMBIAN32__
       
    41     g_log_set_handler (NULL,  G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, &mrtLogHandler, NULL);
       
    42     g_set_print_handler(mrtPrintHandler);
       
    43     #endif /*__SYMBIAN32__*/
       
    44     
       
    45     g_print("Test bookmarkfile-test1 Start");
    48     bookmark = g_bookmark_file_new();
    46     bookmark = g_bookmark_file_new();
    49     file_load= g_bookmark_file_load_from_file(bookmark, bookmark_filename, &error);
    47     file_load= g_bookmark_file_load_from_file(bookmark, bookmark_filename, &error);
    50     if(file_load != TRUE)
    48     if(file_load != TRUE)
    51         {
    49         {
    52         std_log(LOG_FILENAME_LINE,"g_bookmark_file_load_from_file fails with err:%s",error->message);
    50         g_print("g_bookmark_file_load_from_file fails with err:%s",error->message);
    53         assert_failed = 1;
    51         assert_failed = 1;
    54         }
    52         }
    55     bookmark_data = g_bookmark_file_to_data(bookmark,&uris_len,&error);
    53     bookmark_data = g_bookmark_file_to_data(bookmark,&uris_len,&error);
    56     if(bookmark_data == NULL)
    54     if(bookmark_data == NULL)
    57         {
    55         {
    58         std_log(LOG_FILENAME_LINE,"Bg_bookmark_file_to_data fails with err:%s",error->message);
    56         g_print("Bg_bookmark_file_to_data fails with err:%s",error->message);
    59         assert_failed = 1;
    57         assert_failed = 1;
    60         }
    58         }
    61     rel_path = in_FILE; // Code changed to Hardcode the data file in the c:\ private path. 
    59     rel_path = in_FILE; // Code changed to Hardcode the data file in the c:\ private path. 
    62     file_written = g_bookmark_file_load_from_data_dirs(bookmark, rel_path,NULL, &error);
    60     file_written = g_bookmark_file_load_from_data_dirs(bookmark, rel_path,NULL, &error);
    63     if(file_written == FALSE)
    61     if(file_written == FALSE)
    64            {
    62            {
    65            std_log(LOG_FILENAME_LINE,"g_bookmark_file_load_from_data_dirs fails with err:%s",error->message);
    63            g_print("g_bookmark_file_load_from_data_dirs fails with err:%s",error->message);
    66            assert_failed = 1;
    64            assert_failed = 1;
    67            }
    65            }
    68     
    66     
    69     bookmark_uri = g_bookmark_file_get_uris(bookmark, NULL);
    67     bookmark_uri = g_bookmark_file_get_uris(bookmark, NULL);
    70     if(bookmark_uri == NULL)
    68     if(bookmark_uri == NULL)
    71             {
    69             {
    72             std_log(LOG_FILENAME_LINE,"g_bookmark_file_get_uris fails");
    70             g_print("g_bookmark_file_get_uris fails");
    73             assert_failed = 1;
    71             assert_failed = 1;
    74             }
    72             }
    75           
    73           
    76     bookmark_data = g_bookmark_file_get_mime_type(bookmark,*bookmark_uri,&error);
    74     bookmark_data = g_bookmark_file_get_mime_type(bookmark,*bookmark_uri,&error);
    77     if(bookmark_data == NULL)
    75     if(bookmark_data == NULL)
    78         {
    76         {
    79         std_log(LOG_FILENAME_LINE,"URI cannot be found and the error code:%s",error->message);
    77         g_print("URI cannot be found and the error code:%s",error->message);
    80         assert_failed = 1;
    78         assert_failed = 1;
    81         }
    79         }
    82     g_bookmark_file_set_is_private(bookmark,*bookmark_uri, TRUE);
    80     g_bookmark_file_set_is_private(bookmark,*bookmark_uri, TRUE);
    83     file_written = g_bookmark_file_get_is_private(bookmark,*bookmark_uri, &error);
    81     file_written = g_bookmark_file_get_is_private(bookmark,*bookmark_uri, &error);
    84     if(file_written == FALSE)
    82     if(file_written == FALSE)
    85         {
    83         {
    86         std_log(LOG_FILENAME_LINE,"Private flag is not set in the URI and fails with :%s",error->message);
    84         g_print("Private flag is not set in the URI and fails with :%s",error->message);
    87         assert_failed = 1;
    85         assert_failed = 1;
    88         }
    86         }
    89     
    87     
    90     g_bookmark_file_set_added(bookmark,*bookmark_uri,-1);//-1, To use the current time.
    88     g_bookmark_file_set_added(bookmark,*bookmark_uri,-1);//-1, To use the current time.
    91     time = g_bookmark_file_get_added(bookmark,*bookmark_uri,&error);
    89     time = g_bookmark_file_get_added(bookmark,*bookmark_uri,&error);
    92     if(time == -1)
    90     if(time == -1)
    93         {
    91         {
    94         std_log(LOG_FILENAME_LINE,"URI cannot be found and fails with :%s",error->message);
    92         g_print("URI cannot be found and fails with :%s",error->message);
    95         assert_failed = 1;
    93         assert_failed = 1;
    96         } 
    94         } 
    97     g_strfreev(bookmark_uri);  
    95     g_strfreev(bookmark_uri);  
    98     g_bookmark_file_free(bookmark);
    96     g_bookmark_file_free(bookmark);
    99     
    97     
   100     if(assert_failed)
    98     if(assert_failed)
   101         std_log(LOG_FILENAME_LINE,"Test Fail");
    99         g_print("Test bookmarkfile-test1 Fail");
   102     else
   100     else
   103         std_log(LOG_FILENAME_LINE,"Test Successful");
   101         g_print("Test bookmarkfile-test1 Successful");         
   104          
       
   105    
   102    
   106     create_xml(assert_failed);
   103     #if __SYMBIAN32__
       
   104     testResultXml("bookmarkfile-test1");
       
   105     #endif /* EMULATOR */
   107     return 0;
   106     return 0;
   108     }
   107     }