Google
 

Wednesday, April 04, 2007

CuTest Example Compiled with error!

I copy the example from the readme file of CuTest.
However, it compiles with error.

The following the updated version:
DETAILED EXAMPLE

Here is a more detailed example. We will work through a simple
test first exercise. The goal is to create a library of string
utilities. First, lets write a function that converts a
null-terminated string to all upper case.

Ensure that CuTest.c and CuTest.h are accessible from your C
project. Next, create a file called StrUtil.c with these
contents:

#include  <assert.h>
#include 
< setjmp.h>
#include 
<stdlib.h >
#include 
<stdio.h>
#include 
<string.h>
// The origianl version has missed the above includes
#include "CuTest.h"
    
    
char* StrToUpper(char*  str) {
        
return str;
    }
    
    
void  TestStrToUpper(CuTest *tc) {
        
char*  input = strdup(" hello world");
        
char*  actual = StrToUpper(input);
        
char*  expected = " HELLO WORLD";
        CuAssertStrEquals(tc, expected, actual);
    }
   
    CuSuite
* StrUtilGetSuite() {
        CuSuite
* suite =  CuSuiteNew();
        SUITE_ADD_TEST(suite, TestStrToUpper);
        
return suite;
    }

Create another file called AllTests.c with these contents:

    #include  "CuTest.h"
    
    CuSuite
*  StrUtilGetSuite();
    
    
void RunAllTests(void ) {
        CuString 
*output = CuStringNew();
        CuSuite
* suite = CuSuiteNew();
        
        CuSuiteAddSuite(suite, StrUtilGetSuite());
    
        CuSuiteRun(suite);
        CuSuiteSummary(suite, output);
        CuSuiteDetails(suite, output);
        printf(
" %s\n", output->buffer);
    }
    
    
int main(void) {
        RunAllTests();
    }

More detail please see its readme file.
--
Happy day, happy life!

No comments: