Changeset 4540

Show
Ignore:
Timestamp:
02/08/07 18:58:20 (2 years ago)
Author:
morris
Message:

Add a small test suite

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • libwired/trunk/Makefile.in

    r4535 r4540  
    1111 
    1212DISTFILES               = LICENSE Makefile Makefile.in config.guess config.h.in \ 
    13                                   config.status config.sub configure configure.in install-sh \ 
    14                                   libwired 
    15 SOURCEDIRS              = $(top_srcdir)/libwired 
     13                                  config.status config.sub configure configure.in install-sh libwired 
     14SOURCEDIRS              = $(top_srcdir)/libwired $(top_srcdir)/test 
    1615 
    1716VPATH                   = $(subst $(empty) $(empty),:,$(shell find $(SOURCEDIRS) -name ".*" -prune -o -type d -print)) 
    18 LIBWIREDOBJECTS = $(addprefix $(objdir)/libwired/,$(notdir $(patsubst %.c,%.o,$(shell find $(top_srcdir)/libwired -name "*.c")))) 
    19 HEADERS                 = $(addprefix $(headerdir)/,$(notdir $(shell find $(top_srcdir)/libwired -name "*.h"))) 
     17LIBWIREDOBJECTS = $(addprefix $(objdir)/libwired/,$(sort $(notdir $(patsubst %.c,%.o,$(shell find libwired -name "*.c"))))) 
     18TESTOBJECTS             = $(addprefix $(objdir)/libwired/,$(notdir $(patsubst %.c,%.o,$(shell find test -name "*.c")))) 
     19TESTSOBJECTS    = $(addprefix $(objdir)/libwired/,$(notdir $(patsubst %.c,%.o,$(shell find test/tests -name "*.c")))) 
     20HEADERS                 = $(addprefix $(headerdir)/,$(notdir $(shell find libwired -name "*.h"))) 
    2021                           
    2122DEFS                    = @DEFS@ 
     
    3334ARCHIVE                 = ar rcs $@ 
    3435 
    35 .PHONY: all dist clean distclean scmclean 
     36.PHONY: all test dist clean distclean scmclean 
     37 
     38all: $(rundir)/lib/libwired.a 
    3639 
    3740ifeq ($(WI_MAINTAINER), 1) 
    38 all: Makefile configure config.h.in $(rundir)/lib/libwired.a 
    39 else 
    40 all: $(rundir)/lib/libwired.a 
    41 endif 
     41all: Makefile configure config.h.in $(rundir)/test 
    4242 
    43 ifeq ($(WI_MAINTAINER), 1) 
    4443Makefile: Makefile.in config.status 
    45         ./config.status 
     44        $(top_srcdir)/config.status 
    4645         
    4746configure: configure.in 
     
    5756        @test -d $(@D) || mkdir -p $(@D) 
    5857        $(ARCHIVE) $(LIBWIREDOBJECTS) 
    59  
     58         
    6059$(objdir)/libwired/%.o: %.c 
    6160        @test -d $(@D) || mkdir -p $(@D) 
     
    7069        cp $< $@ 
    7170 
     71test: $(rundir)/test 
     72         
     73$(rundir)/test: $(rundir)/lib/libwired.a test/testlist.h test/testlist.inc $(TESTOBJECTS) 
     74        @test -d $(@D) || mkdir -p $(@D) 
     75        $(LINK) $(TESTOBJECTS) $(LIBS) 
     76        @$(rundir)/test 
     77 
     78test/testlist.h: $(TESTSOBJECTS) 
     79        -grep WI_TEST_EXPORT $(wildcard test/tests/*.c) > $@ 
     80         
     81test/testlist.inc: test/testlist.h 
     82        perl -ne '$$s=(split(/\s+/))[2]; $$s=~ s/(\w+).*/$$1/; print "wi_tests_run_test(\"$$s\", $$s);";' $< > $@ 
     83         
    7284dist: 
    7385        rm -rf libwired-$(WI_VERSION) 
     
    91103        rm -f $(headerdir)/*.h 
    92104        rm -f $(rundir)/lib/libwired.a 
     105        rm -f $(rundir)/test 
    93106        rm -rf autom4te.cache 
    94107 
     
    105118ifeq ($(WI_MAINTAINER), 1) 
    106119-include $(LIBWIREDOBJECTS:.o=.d) 
     120-include $(TESTOBJECTS:.o=.d) 
    107121endif 
  • libwired/trunk/libwired/base/wi-assert.h

    r4437 r4540  
    3434#include <wired/wi-log.h> 
    3535 
    36 #define WI_ASSERT(exp, fmt, ...) \ 
    37         WI_STMT_START                                                                                                   \ 
    38                 if(!(exp)) {                                                                                            \ 
    39                         wi_log_warn(WI_STR("Assertion failed at %s:%u: " fmt),  \ 
    40                                 __FILE__, __LINE__, ## __VA_ARGS__);                            \ 
    41                         wi_crash();                                                                                             \ 
    42                 }                                                                                                                       \ 
     36#define WI_ASSERT(exp, fmt, ...)                                                                \ 
     37        WI_STMT_START                                                                                           \ 
     38                if(!(exp)) {                                                                                    \ 
     39                        (*wi_assert_handler)(WI_STR(__FILE__), __LINE__,        \ 
     40                                WI_STR(fmt), ## __VA_ARGS__);                                   \ 
     41                }                                                                                                               \ 
    4342        WI_STMT_END 
    4443 
     44 
     45typedef void                                                    wi_assert_handler_func_t(wi_string_t *, wi_uinteger_t, wi_string_t *, ...); 
     46 
     47 
     48WI_EXPORT wi_assert_handler_func_t              *wi_assert_handler; 
     49 
    4550#endif /* WI_ASSERT_H */ 
  • libwired/trunk/libwired/base/wi-base.c

    r4511 r4540  
    7373        wi_socket_register(); 
    7474        wi_string_register(); 
     75        wi_test_register(); 
    7576         
    7677#ifdef WI_TERMCAP 
     
    111112        wi_settings_initialize(); 
    112113        wi_socket_initialize(); 
     114        wi_test_initialize(); 
    113115         
    114116#ifdef WI_TERMCAP 
  • libwired/trunk/libwired/base/wi-base.h

    r4494 r4540  
    6060#endif 
    6161 
     62#define _WI_STRINGIFY(s)                        #s 
     63#define WI_STRINGIFY(s)                         _WI_STRINGIFY(s) 
     64 
    6265#if __LP64__ 
    6366#define WI_32                                           0 
  • libwired/trunk/libwired/base/wi-byteorder.h

    r4437 r4540  
    4141 
    4242 
    43 #define WI_SWAP_INT16(n)
    44     ((uint16_t) ((((uint16_t) (n) & 0xFF00) >> 8) |
     43#define WI_SWAP_INT16(n)                                                                                               
     44    ((uint16_t) ((((uint16_t) (n) & 0xFF00) >> 8) |                                           
    4545                                 (((uint16_t) (n) & 0x00FF) << 8))) 
    4646 
    47 #define WI_SWAP_INT32(n)
    48     ((uint32_t) ((((uint32_t) (n) & 0xFF000000) >> 24) |
    49                                  (((uint32_t) (n) & 0x00FF0000) >>  8) |
    50                                  (((uint32_t) (n) & 0x0000FF00) <<  8) |
     47#define WI_SWAP_INT32(n)                                                                                               
     48    ((uint32_t) ((((uint32_t) (n) & 0xFF000000) >> 24) |                               
     49                                 (((uint32_t) (n) & 0x00FF0000) >>  8) |                               
     50                                 (((uint32_t) (n) & 0x0000FF00) <<  8) |                               
    5151                                 (((uint32_t) (n) & 0x000000FF) << 24))) 
    5252 
    53 #define WI_SWAP_INT64(n)
    54         ((uint64_t) ((((uint64_t) (n) & 0xFF00000000000000ULL) >> 56) |
    55                                  (((uint64_t) (n) & 0x00FF000000000000ULL) >> 40) |
    56                                  (((uint64_t) (n) & 0x0000FF0000000000ULL) >> 24) |
    57                                  (((uint64_t) (n) & 0x000000FF00000000ULL) >>  8) |
    58                                  (((uint64_t) (n) & 0x00000000FF000000ULL) <<  8) |
    59                                  (((uint64_t) (n) & 0x0000000000FF0000ULL) << 24) |
    60                                  (((uint64_t) (n) & 0x000000000000FF00ULL) << 40) |
     53#define WI_SWAP_INT64(n)                                                                                               
     54        ((uint64_t) ((((uint64_t) (n) & 0xFF00000000000000ULL) >> 56) |               
     55                                 (((uint64_t) (n) & 0x00FF000000000000ULL) >> 40) |           
     56                                 (((uint64_t) (n) & 0x0000FF0000000000ULL) >> 24) |           
     57                                 (((uint64_t) (n) & 0x000000FF00000000ULL) >>  8) |           
     58                                 (((uint64_t) (n) & 0x00000000FF000000ULL) <<  8) |           
     59                                 (((uint64_t) (n) & 0x0000000000FF0000ULL) << 24) |           
     60                                 (((uint64_t) (n) & 0x000000000000FF00ULL) << 40) |           
    6161                                 (((uint64_t) (n) & 0x00000000000000FFULL) << 56))) 
    6262 
  • libwired/trunk/libwired/base/wi-private.h

    r4511 r4540  
    6363WI_EXPORT void                                  wi_string_register(void); 
    6464WI_EXPORT void                                  wi_terminal_register(void); 
     65WI_EXPORT void                                  wi_test_register(void); 
    6566WI_EXPORT void                                  wi_timer_register(void); 
    6667WI_EXPORT void                                  wi_thread_register(void); 
     
    9091WI_EXPORT void                                  wi_string_initialize(void); 
    9192WI_EXPORT void                                  wi_terminal_initialize(void); 
     93WI_EXPORT void                                  wi_test_initialize(void); 
    9294WI_EXPORT void                                  wi_timer_initialize(void); 
    9395WI_EXPORT void                                  wi_thread_initialize(void); 
  • libwired/trunk/libwired/data/wi-string.c

    r4511 r4540  
    11241124         
    11251125        for(i = 0; i < newstring->length; i++) 
    1126                 newstring->string[i] = toupper((unsigned int) newstring->string[i]); 
     1126                newstring->string[i] = tolower((unsigned int) newstring->string[i]); 
    11271127         
    11281128        return wi_autorelease(newstring); 
     
    11381138         
    11391139        for(i = 0; i < newstring->length; i++) 
    1140                 newstring->string[i] = tolower((unsigned int) newstring->string[i]); 
     1140                newstring->string[i] = toupper((unsigned int) newstring->string[i]); 
    11411141         
    11421142        return wi_autorelease(newstring); 
     
    11611161                if(wi_string_length(component) > 0) 
    11621162                        wi_array_add_data(array, component); 
    1163                 else if(i == 0 || i == count - 1
     1163                else if(i == 0
    11641164                        wi_array_add_data(array, WI_STR("/")); 
    11651165        } 
     
    14061406 
    14071407 
     1408wi_string_t * wi_string_path_extension(wi_string_t *path) { 
     1409        wi_uinteger_t   index; 
     1410         
     1411        index = wi_string_index_of_char(path, '.', WI_STRING_BACKWARDS); 
     1412 
     1413        if(index != WI_NOT_FOUND && index + 1 < path->length) 
     1414                return wi_string_by_deleting_characters_to_index(path, index + 1); 
     1415         
     1416        return WI_STR(""); 
     1417} 
     1418 
     1419 
     1420 
    14081421void wi_string_delete_path_extension(wi_string_t *path) { 
    14091422        wi_uinteger_t   index; 
  • libwired/trunk/libwired/data/wi-string.h

    r4437 r4540  
    131131WI_EXPORT void                                                          wi_string_delete_last_path_component(wi_string_t *); 
    132132WI_EXPORT wi_string_t *                                         wi_string_by_deleting_last_path_component(wi_string_t *); 
     133WI_EXPORT wi_string_t *                                         wi_string_path_extension(wi_string_t *); 
    133134WI_EXPORT void                                                          wi_string_delete_path_extension(wi_string_t *); 
    134135WI_EXPORT wi_string_t *                                         wi_string_by_deleting_path_extension(wi_string_t *); 
  • libwired/trunk/libwired/system/wi-log.c

    r4511 r4540  
    6565wi_boolean_t                                    wi_log_startup = false; 
    6666wi_boolean_t                                    wi_log_tool = false; 
     67wi_boolean_t                                    wi_log_plain = false; 
    6768wi_boolean_t                                    wi_log_syslog = false; 
    6869wi_boolean_t                                    wi_log_file = false; 
     
    166167        else if(wi_log_tool) 
    167168                fprintf((priority < LOG_INFO) ? stderr : stdout, "%s: %s\n", name, cstring); 
     169        else if(wi_log_plain) 
     170                fprintf((priority < LOG_INFO) ? stderr : stdout, "%s\n", cstring); 
    168171 
    169172        if(wi_log_syslog) 
  • libwired/trunk/libwired/system/wi-log.h

    r4437 r4540  
    6262WI_EXPORT wi_boolean_t                          wi_log_startup; 
    6363WI_EXPORT wi_boolean_t                          wi_log_tool; 
     64WI_EXPORT wi_boolean_t                          wi_log_plain; 
    6465WI_EXPORT wi_boolean_t                          wi_log_syslog; 
    6566WI_EXPORT wi_boolean_t                          wi_log_file; 
  • libwired/trunk/libwired/wired.h

    r4437 r4540  
    5959#include <wired/wi-system.h> 
    6060#include <wired/wi-terminal.h> 
     61#include <wired/wi-tests.h> 
    6162#include <wired/wi-timer.h> 
    6263#include <wired/wi-thread.h>