"Fossies" - the Fresh Open Source Software Archive

Member "statist-1.4.2/tests/check_memory_handling.c" (30 Sep 2006, 2133 Bytes) of package /linux/privat/old/statist-1.4.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #include <stdlib.h>
    2 #include <memory_handling.h>
    3 
    4 #include <check.h>
    5 
    6 
    7 START_TEST(test_small_malloc)
    8 {
    9     void * mem=NULL;
   10     mem=mymalloc(1000);
   11 
   12     fail_unless(mem!=NULL,"Got no memory!");
   13 
   14     myfree(mem);
   15 }
   16 END_TEST
   17 
   18 
   19 START_TEST(test_small_calloc)
   20 {
   21     void * mem=NULL;
   22     int i=0;
   23 
   24     mem=mycalloc(100,100);
   25 
   26     fail_unless(mem!=NULL,"Got no memory!");
   27 
   28     for(i=0; i<100*100;i++) {
   29         if (((char*) mem)[i] != 0)  
   30             fail("Memory was not clear!");
   31     }
   32 
   33     myfree(mem);
   34 }
   35 END_TEST
   36 
   37 START_TEST(test_small_m_calloc)
   38 {
   39     void * mem=NULL;
   40     int i=0;
   41 
   42     mem=m_calloc(100,100);
   43 
   44     fail_unless(mem!=NULL,"Got no memory!");
   45 
   46     for(i=0; i<100*100;i++) {
   47         if (((char*) mem)[i] != 0)  
   48             fail("Memory was not clear!");
   49     }
   50 
   51     m_freeall();
   52 }
   53 END_TEST
   54 
   55 
   56 START_TEST(test_mult_m_calloc)
   57 {
   58     void **memarray=NULL;
   59 #define CHUNKS (10) 
   60 #define CHUNKSIZE (1000)
   61     int i=0;
   62     int j=0;
   63 
   64     memarray=m_calloc(CHUNKS,sizeof(void *));
   65 
   66     fail_unless(memarray!=NULL,"Got no memory!");
   67 
   68     for(i=0; i<CHUNKS;i++) {
   69         memarray[i]=m_calloc(1, CHUNKSIZE);
   70 
   71         for(j=0; j<CHUNKSIZE;j++) {
   72             if (((char*) memarray[i])[j] != 0)  
   73                 fail("Memory was not clear!");
   74         }
   75     }
   76 
   77     m_freeall();
   78 }
   79 END_TEST
   80 
   81 /******************************************************************************
   82  * Test Suites
   83  */
   84 
   85 Suite *memory_suite (void) 
   86 { 
   87      Suite *s = suite_create("Memory Handling"); 
   88      TCase *tc_core = tcase_create("Simple");
   89      TCase *tc_m_calloc = tcase_create("M_calloc()");
   90        
   91      suite_add_tcase (s, tc_core);
   92      suite_add_tcase (s, tc_m_calloc);
   93         
   94      tcase_add_test (tc_core, test_small_malloc); 
   95      tcase_add_test (tc_core, test_small_calloc); 
   96 
   97      tcase_add_test (tc_m_calloc, test_small_m_calloc );
   98      tcase_add_test (tc_m_calloc, test_mult_m_calloc );
   99      return s; 
  100 }
  101 
  102 /******************************************************************************
  103  * Main 
  104  */
  105 
  106 int main (void) 
  107 /* standard code from the check-0.9.2 tutorial          */
  108 { 
  109     int nf; 
  110 
  111     Suite *s = memory_suite(); 
  112 
  113     SRunner *sr = srunner_create(s); 
  114     srunner_run_all (sr, CK_NORMAL);
  115     /* srunner_run_all (sr, CK_VERBOSE); */
  116     nf = srunner_ntests_failed(sr); 
  117     srunner_free(sr); 
  118     return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 
  119 }
  120 
  121