Changeset 1724

Show
Ignore:
Timestamp:
03/14/07 20:18:57
Author:
pvanhoof
Message:

Design by contract with tinymail, first idea

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/README

    r1537 r1724  
    2828You'll need it if you build with --enable-unit-tests which will compile the 
    2929unit tests. Check the sources of the unit tests for more information. 
     30 
     31It's highly recommended to set the CFLAGS environment to include -DDEBUG and  
     32-DDBC: CFLAGS="-DDBC -DDEBUG" ./autogen.sh --enable-unit-tests .... 
     33 
     34The DBC define will enable Design By Contract assertions, the DEBUG define will 
     35enable certain debugging checks, assertions, features and messages. 
    3036 
    3137Run all unit tests with 'make check'. 
  • trunk/libtinymail/tny-device.c

    r1007 r1724  
    3333tny_device_reset (TnyDevice *self) 
    3434{ 
    35 #ifdef DEBUG 
    36         if (!TNY_DEVICE_GET_IFACE (self)->reset_func) 
    37                g_critical ("You must implement tny_device_reset\n"); 
     35#ifdef DBC /* require */ 
     36        g_assert (TNY_IS_DEVICE (self)); 
     37        g_assert (TNY_DEVICE_GET_IFACE (self)->reset_func != NULL); 
    3838#endif 
    3939 
    4040        TNY_DEVICE_GET_IFACE (self)->reset_func (self); 
     41 
     42#ifdef DBC /* ensure */ 
     43#endif 
     44 
    4145        return; 
    4246} 
     
    6064tny_device_force_online (TnyDevice *self) 
    6165{ 
    62 #ifdef DEBUG 
    63         if (!TNY_DEVICE_GET_IFACE (self)->force_online_func) 
    64                g_critical ("You must implement tny_device_force_online\n"); 
     66#ifdef DBC /* require */ 
     67        g_assert (TNY_IS_DEVICE (self)); 
     68        g_assert (TNY_DEVICE_GET_IFACE (self)->force_online_func != NULL); 
    6569#endif 
    6670 
    6771        TNY_DEVICE_GET_IFACE (self)->force_online_func (self); 
     72 
     73#ifdef DBC /* ensure */ 
     74        g_assert (tny_device_is_online (self) == TRUE); 
     75#endif 
     76 
    6877        return; 
    6978} 
     
    7887tny_device_force_offline (TnyDevice *self) 
    7988{ 
    80 #ifdef DEBUG 
    81         if (!TNY_DEVICE_GET_IFACE (self)->force_offline_func) 
    82                g_critical ("You must implement tny_device_force_offline\n"); 
     89#ifdef DBC /* require */ 
     90        g_assert (TNY_IS_DEVICE (self)); 
     91        g_assert (TNY_DEVICE_GET_IFACE (self)->force_offline_func != NULL); 
    8392#endif 
    8493 
    8594        TNY_DEVICE_GET_IFACE (self)->force_offline_func (self); 
     95 
     96#ifdef DBC /* ensure */ 
     97        g_assert (tny_device_is_online (self) == FALSE); 
     98#endif 
     99 
    86100        return; 
    87101} 
     
    109123tny_device_is_online (TnyDevice *self) 
    110124{ 
    111 #ifdef DEBUG 
    112         if (!TNY_DEVICE_GET_IFACE (self)->is_online_func) 
    113                 g_critical ("You must implement tny_device_is_online\n"); 
     125        gboolean retval; 
     126 
     127#ifdef DBC /* require */ 
     128        g_assert (TNY_IS_DEVICE (self)); 
     129        g_assert (TNY_DEVICE_GET_IFACE (self)->is_online_func != NULL); 
    114130#endif 
    115131 
    116         return TNY_DEVICE_GET_IFACE (self)->is_online_func (self); 
     132        retval = TNY_DEVICE_GET_IFACE (self)->is_online_func (self); 
     133 
     134#ifdef DBC /* ensure */ 
     135#endif 
     136 
     137        return retval; 
    117138} 
    118139 
     
    165186                  NULL 
    166187                }; 
    167              
     188 
    168189                type = g_type_register_static (G_TYPE_INTERFACE,  
    169190                        "TnyDevice", &info, 0);