glib/tests/test-utils.c
changeset 72 403e7f6ed6c5
parent 50 79045913e4e9
equal deleted inserted replaced
71:28ccaba883f4 72:403e7f6ed6c5
    14 //
    14 //
    15 
    15 
    16 #undef G_DISABLE_ASSERT
    16 #undef G_DISABLE_ASSERT
    17 #undef G_LOG_DOMAIN
    17 #undef G_LOG_DOMAIN
    18 
    18 
       
    19 #include <sys/stat.h>
       
    20 #include <stdlib.h>
    19 #include <glib.h>
    21 #include <glib.h>
    20 #include <errno.h>
    22 #include <errno.h>
    21 #define LOG_FILE "c:\\logs\\test_utils_log.txt"
    23 #include <glib/gprintf.h>
    22 #include "std_log_result.h"
    24 #ifdef __SYMBIAN32__
    23 #define LOG_FILENAME_LINE __FILE__, __LINE__
    25 #include "mrt2_glib2_test.h"
    24 
    26 #endif /*__SYMBIAN32__*/
    25 void create_xml(int result)
       
    26 {
       
    27     if(result)
       
    28         assert_failed = 1;
       
    29     
       
    30     testResultXml("test_utils_log");
       
    31     close_log_file();
       
    32 }
       
    33 
    27 
    34 static void
    28 static void
    35 gstring_overwrite_int (GString *gstring,
    29 gstring_overwrite_int (GString *gstring,
    36                        guint    pos,
    30                        guint    pos,
    37                        guint32  vuint)
    31                        guint32  vuint)
    97         exit(0);
    91         exit(0);
    98         }
    92         }
    99     
    93     
   100     if(!g_test_trap_has_passed())
    94     if(!g_test_trap_has_passed())
   101         {
    95         {
   102         std_log(LOG_FILENAME_LINE, "g_test_trap_has_passed didnt work as expected");
    96         g_print( "g_test_trap_has_passed didnt work as expected");
   103         assert_failed = 1;
    97         assert_failed = 1;
   104         }
    98         }
   105     }
    99     }
   106 
   100 
   107 void test_g_test_log_type_name()
   101 void test_g_test_log_type_name()
   109     const char *ret;
   103     const char *ret;
   110     ret = g_test_log_type_name(G_TEST_LOG_MESSAGE);
   104     ret = g_test_log_type_name(G_TEST_LOG_MESSAGE);
   111     
   105     
   112     if(strcmp(ret, "message"))
   106     if(strcmp(ret, "message"))
   113         {
   107         {
   114         std_log(LOG_FILENAME_LINE, "g_test_log_type_name didnt work as expected");
   108         g_print( "g_test_log_type_name didnt work as expected");
   115         assert_failed = 1;
   109         assert_failed = 1;
   116         }
   110         }
   117     }
   111     }
   118 
   112 
   119 void test_g_test_timer()
   113 void test_g_test_timer()
   124     ret_time1 = g_test_timer_elapsed();
   118     ret_time1 = g_test_timer_elapsed();
   125     ret_time2 = g_test_timer_last();
   119     ret_time2 = g_test_timer_last();
   126     
   120     
   127     if(!(ret_time1 == ret_time2))
   121     if(!(ret_time1 == ret_time2))
   128         {
   122         {
   129         std_log(LOG_FILENAME_LINE, "g_test_timer* didnt work as expected");
   123         g_print( "g_test_timer* didnt work as expected");
   130         assert_failed = 1;
   124         assert_failed = 1;
   131         }
   125         }
   132     }
   126     }
   133 
   127 
   134 void test_g_log_buffer()
   128 void test_g_log_buffer()
   161             {
   155             {
   162             g_test_log_msg_free(log_msg);
   156             g_test_log_msg_free(log_msg);
   163             }
   157             }
   164         else
   158         else
   165             {
   159             {
   166             std_log(LOG_FILENAME_LINE, "g_test_log_buffer_pop returned NULL");
   160             g_print( "g_test_log_buffer_pop returned NULL");
   167             assert_failed = 1;
   161             assert_failed = 1;
   168             }
   162             }
   169         
   163         
   170         g_test_log_buffer_free(log_buffer);
   164         g_test_log_buffer_free(log_buffer);
   171         }
   165         }
   172     else
   166     else
   173         {
   167         {
   174         std_log(LOG_FILENAME_LINE, "g_test_log_buffer_new returned NULL");
   168         g_print( "g_test_log_buffer_new returned NULL");
   175         assert_failed = 1;
   169         assert_failed = 1;
   176         }
   170         }
   177 
   171 
   178 	g_free (dbuffer);
   172 	g_free (dbuffer);
   179     }
   173     }
   180 
   174 
   181 int main (int argc, char *argv[])
   175 int main (int argc, char *argv[])
   182 {
   176 {
       
   177     #ifdef __SYMBIAN32__
       
   178     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);
       
   179     g_set_print_handler(mrtPrintHandler);
       
   180     #endif /*__SYMBIAN32__*/
       
   181     
       
   182     g_print("Test test-utils Start");
   183     g_test_init(&argc, &argv);
   183     g_test_init(&argc, &argv);
   184     
   184     
   185     test_g_test_trap();
   185     test_g_test_trap();
   186     test_g_test_log_type_name();
   186     test_g_test_log_type_name();
   187     test_g_test_timer();
   187     test_g_test_timer();
   188     test_g_log_buffer();
   188     test_g_log_buffer();
   189     
   189     
   190     if(assert_failed)
   190     if(assert_failed)
   191           std_log(LOG_FILENAME_LINE,"Test Failed");
   191           g_print("Test test-utils Failed");
   192     else
   192     else
   193           std_log(LOG_FILENAME_LINE,"Test Successful");
   193           g_print("Test test-utils Successful");
   194 	
   194 	
   195     create_xml(0);
   195     #if __SYMBIAN32__
       
   196     testResultXml("test-utils");
       
   197     #endif /* EMULATOR */
   196 
   198 
   197 	return 0;
   199 	return 0;
   198 }
   200 }