glib/tests/bookmarkfile-test1.c
changeset 59 09fa7c3c5079
child 72 403e7f6ed6c5
equal deleted inserted replaced
52:bf6a71c50e42 59:09fa7c3c5079
       
     1 // Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 
       
    17 #include<stdio.h>
       
    18 #include <glib.h>
       
    19 #define LOG_FILE "c:\\logs\\bookmark_test1_log.txt"
       
    20 #include "std_log_result.h"
       
    21 #define LOG_FILENAME_LINE __FILE__, __LINE__
       
    22 #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 
       
    34 int
       
    35 main (int   argc,
       
    36       char *argv[])
       
    37     {
       
    38     GBookmarkFile* bookmark;
       
    39     gsize uris_len;
       
    40     gchar *bookmark_data = NULL;
       
    41     gboolean file_written,file_load;
       
    42     const gchar *rel_path;
       
    43     time_t time;
       
    44     const gchar *bookmark_filename = argv[1];
       
    45     GError        *error = NULL;
       
    46     gchar **bookmark_uri = NULL;
       
    47         
       
    48     bookmark = g_bookmark_file_new();
       
    49     file_load= g_bookmark_file_load_from_file(bookmark, bookmark_filename, &error);
       
    50     if(file_load != TRUE)
       
    51         {
       
    52         std_log(LOG_FILENAME_LINE,"g_bookmark_file_load_from_file fails with err:%s",error->message);
       
    53         assert_failed = 1;
       
    54         }
       
    55     bookmark_data = g_bookmark_file_to_data(bookmark,&uris_len,&error);
       
    56     if(bookmark_data == NULL)
       
    57         {
       
    58         std_log(LOG_FILENAME_LINE,"Bg_bookmark_file_to_data fails with err:%s",error->message);
       
    59         assert_failed = 1;
       
    60         }
       
    61     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);
       
    63     if(file_written == FALSE)
       
    64            {
       
    65            std_log(LOG_FILENAME_LINE,"g_bookmark_file_load_from_data_dirs fails with err:%s",error->message);
       
    66            assert_failed = 1;
       
    67            }
       
    68     
       
    69     bookmark_uri = g_bookmark_file_get_uris(bookmark, NULL);
       
    70     if(bookmark_uri == NULL)
       
    71             {
       
    72             std_log(LOG_FILENAME_LINE,"g_bookmark_file_get_uris fails");
       
    73             assert_failed = 1;
       
    74             }
       
    75           
       
    76     bookmark_data = g_bookmark_file_get_mime_type(bookmark,*bookmark_uri,&error);
       
    77     if(bookmark_data == NULL)
       
    78         {
       
    79         std_log(LOG_FILENAME_LINE,"URI cannot be found and the error code:%s",error->message);
       
    80         assert_failed = 1;
       
    81         }
       
    82     g_bookmark_file_set_is_private(bookmark,*bookmark_uri, TRUE);
       
    83     file_written = g_bookmark_file_get_is_private(bookmark,*bookmark_uri, &error);
       
    84     if(file_written == FALSE)
       
    85         {
       
    86         std_log(LOG_FILENAME_LINE,"Private flag is not set in the URI and fails with :%s",error->message);
       
    87         assert_failed = 1;
       
    88         }
       
    89     
       
    90     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);
       
    92     if(time == -1)
       
    93         {
       
    94         std_log(LOG_FILENAME_LINE,"URI cannot be found and fails with :%s",error->message);
       
    95         assert_failed = 1;
       
    96         } 
       
    97     g_strfreev(bookmark_uri);  
       
    98     g_bookmark_file_free(bookmark);
       
    99     
       
   100     if(assert_failed)
       
   101         std_log(LOG_FILENAME_LINE,"Test Fail");
       
   102     else
       
   103         std_log(LOG_FILENAME_LINE,"Test Successful");
       
   104          
       
   105    
       
   106     create_xml(assert_failed);
       
   107     return 0;
       
   108     }