diff --git a/README.md b/README.md index 2463df3..ccefcb6 100644 --- a/README.md +++ b/README.md @@ -1,224 +1,227 @@ -How To Use ----------- - -Minimalist powerful C unit testing framework. - -You can use CuTest to create unit tests to drive your development -in the style of Extreme Programming. You can also add unit tests to -existing code to ensure that it works as you suspect. - -Your unit tests are an investment. They let you to change your -code and add new features confidently without worrying about -accidentally breaking earlier features. - - -Licensing ---------- - -For details on licensing see license.txt. - - -Getting Started ---------------- - -To add unit testing to your C code the only files you need are -CuTest.c and CuTest.h. - -CuTestTest.c and AllTests.c have been included to provide an -example of how to write unit tests and then how to aggregate them -into suites and into a single AllTests.c file. Suites allow you -to put group tests into logical sets. AllTests.c combines all the -suites and runs them. - -You should not have to look inside CuTest.c. Looking in -CuTestTest.c and AllTests.c (for example usage) should be -sufficient. - -After downloading the sources, run your compiler to create an -executable called AllTests.exe. For example, if you are using -Windows with the cl.exe compiler you would type: - - cl.exe AllTests.c CuTest.c CuTestTest.c - AllTests.exe - -On Unix you should type: - - gcc AllTests.c CuTest.c CuTestTest.c - ./a.out - -This will run all the unit tests associated with CuTest and print -the output on the console. You can replace cl.exe with gcc or -your favorite compiler in the command above. - - -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 "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(); - } - -Then type this on the command line: - - gcc AllTests.c CuTest.c StrUtil.c - -to compile. You can replace gcc with your favorite compiler. -CuTest should be portable enough to handle all Windows and Unix -compilers. Then to run the tests type: - - ./a.out - -This will print an error because we haven't implemented the -StrToUpper function correctly. We are just returning the string -without changing it to upper case. - - char* StrToUpper(char* str) { - return str; - } - -Rewrite this as follows: - - char* StrToUpper(char* str) { - char* p; - for (p = str ; *p ; ++p) *p = toupper(*p); - return str; - } - -Recompile and run the tests again. The test should pass this -time. - - -What To Do Next ---------------- - -At this point you might want to write more tests for the -StrToUpper function. Here are some ideas: - - TestStrToUpper_EmptyString /* pass in "" */ - TestStrToUpper_UpperCase /* pass in "HELLO WORLD" */ - TestStrToUpper_MixedCase /* pass in "HELLO world" */ - TestStrToUpper_Numbers /* pass in "1234 hello" */ - -As you write each one of these tests add it to StrUtilGetSuite -function. If you don't the tests won't be run. Later as you write -other functions and write tests for them be sure to include those -in StrUtilGetSuite also. The StrUtilGetSuite function should -include all the tests in StrUtil.c - -Over time you will create another file called FunkyStuff.c -containing other functions unrelated to StrUtil. Follow the same -pattern. Create a FunkyStuffGetSuite function in FunkyStuff.c. -And add FunkyStuffGetSuite to AllTests.c. - -The framework is designed in the way it is so that it is easy to -organize a lot of tests. - -The Big Picture ---------------- - -Each individual test corresponds to a CuTest. These are grouped -to form a CuSuite. CuSuites can hold CuTests or other CuSuites. -AllTests.c collects all the CuSuites in the program into a single -CuSuite which it then runs as a single CuSuite. - -The project is open source so feel free to take a peek under the -hood at the CuTest.c file to see how it works. CuTestTest.c -contains tests for CuTest.c. So CuTest tests itself. - -Since AllTests.c has a main() you will need to exclude this when -you are building your product. Here is a nicer way to do this if -you want to avoid messing with multiple builds. Remove the main() -in AllTests.c. Note that it just calls RunAllTests(). Instead -we'll call this directly from the main program. - -Now in the main() of the actual program check to see if the -command line option "--test" was passed. If it was then I call -RunAllTests() from AllTests.c. Otherwise run the real program. - -Shipping the tests with the code can be useful. If you customers -complain about a problem you can ask them to run the unit tests -and send you the output. This can help you to quickly isolate the -piece of your system that is malfunctioning in the customer's -environment. - -CuTest offers a rich set of CuAssert functions. Here is a list: - - void CuAssert(CuTest* tc, char* message, int condition); - void CuAssertTrue(CuTest* tc, int condition); - void CuAssertStrEquals(CuTest* tc, char* expected, char* actual); - void CuAssertIntEquals(CuTest* tc, int expected, int actual); - void CuAssertPtrEquals(CuTest* tc, void* expected, void* actual); - void CuAssertPtrNotNull(CuTest* tc, void* pointer); - -The project is open source and so you can add other more powerful -asserts to make your tests easier to write and more concise. -Please feel free to send me changes you make so that I can -incorporate them into future releases. - -If you see any errors in this document please contact me at -asimjalis@gmail.com. - - -Automating Test Suite Generation --------------------------------- - -make-tests.sh will grep through all the .c files in the current -directory and generate the code to run all the tests contained in -them. Using this script you don't have to worry about writing -AllTests.c or dealing with any of the other suite code. - - -Credits -------- - -[02.23.2003] Dave Glowacki has added -(1) file name and line numbers to the error messages, (2) -AssertDblEquals for doubles, (3) AssertEquals_Msg version of -all the AssertEquals to pass in optional message which is -printed out on assert failure. +Forked from: https://github.com/asimjalis/cutest +Original work: https://sourceforge.net/projects/cutest/ + +How To Use +---------- + +Minimalist powerful C unit testing framework. + +You can use CuTest to create unit tests to drive your development +in the style of Extreme Programming. You can also add unit tests to +existing code to ensure that it works as you suspect. + +Your unit tests are an investment. They let you to change your +code and add new features confidently without worrying about +accidentally breaking earlier features. + + +Licensing +--------- + +For details on licensing see license.txt. + + +Getting Started +--------------- + +To add unit testing to your C code the only files you need are +CuTest.c and CuTest.h. + +CuTestTest.c and AllTests.c have been included to provide an +example of how to write unit tests and then how to aggregate them +into suites and into a single AllTests.c file. Suites allow you +to put group tests into logical sets. AllTests.c combines all the +suites and runs them. + +You should not have to look inside CuTest.c. Looking in +CuTestTest.c and AllTests.c (for example usage) should be +sufficient. + +After downloading the sources, run your compiler to create an +executable called AllTests.exe. For example, if you are using +Windows with the cl.exe compiler you would type: + + cl.exe AllTests.c CuTest.c CuTestTest.c + AllTests.exe + +On Unix you should type: + + gcc AllTests.c CuTest.c CuTestTest.c + ./a.out + +This will run all the unit tests associated with CuTest and print +the output on the console. You can replace cl.exe with gcc or +your favorite compiler in the command above. + + +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 "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(); + } + +Then type this on the command line: + + gcc AllTests.c CuTest.c StrUtil.c + +to compile. You can replace gcc with your favorite compiler. +CuTest should be portable enough to handle all Windows and Unix +compilers. Then to run the tests type: + + ./a.out + +This will print an error because we haven't implemented the +StrToUpper function correctly. We are just returning the string +without changing it to upper case. + + char* StrToUpper(char* str) { + return str; + } + +Rewrite this as follows: + + char* StrToUpper(char* str) { + char* p; + for (p = str ; *p ; ++p) *p = toupper(*p); + return str; + } + +Recompile and run the tests again. The test should pass this +time. + + +What To Do Next +--------------- + +At this point you might want to write more tests for the +StrToUpper function. Here are some ideas: + + TestStrToUpper_EmptyString /* pass in "" */ + TestStrToUpper_UpperCase /* pass in "HELLO WORLD" */ + TestStrToUpper_MixedCase /* pass in "HELLO world" */ + TestStrToUpper_Numbers /* pass in "1234 hello" */ + +As you write each one of these tests add it to StrUtilGetSuite +function. If you don't the tests won't be run. Later as you write +other functions and write tests for them be sure to include those +in StrUtilGetSuite also. The StrUtilGetSuite function should +include all the tests in StrUtil.c + +Over time you will create another file called FunkyStuff.c +containing other functions unrelated to StrUtil. Follow the same +pattern. Create a FunkyStuffGetSuite function in FunkyStuff.c. +And add FunkyStuffGetSuite to AllTests.c. + +The framework is designed in the way it is so that it is easy to +organize a lot of tests. + +The Big Picture +--------------- + +Each individual test corresponds to a CuTest. These are grouped +to form a CuSuite. CuSuites can hold CuTests or other CuSuites. +AllTests.c collects all the CuSuites in the program into a single +CuSuite which it then runs as a single CuSuite. + +The project is open source so feel free to take a peek under the +hood at the CuTest.c file to see how it works. CuTestTest.c +contains tests for CuTest.c. So CuTest tests itself. + +Since AllTests.c has a main() you will need to exclude this when +you are building your product. Here is a nicer way to do this if +you want to avoid messing with multiple builds. Remove the main() +in AllTests.c. Note that it just calls RunAllTests(). Instead +we'll call this directly from the main program. + +Now in the main() of the actual program check to see if the +command line option "--test" was passed. If it was then I call +RunAllTests() from AllTests.c. Otherwise run the real program. + +Shipping the tests with the code can be useful. If you customers +complain about a problem you can ask them to run the unit tests +and send you the output. This can help you to quickly isolate the +piece of your system that is malfunctioning in the customer's +environment. + +CuTest offers a rich set of CuAssert functions. Here is a list: + + void CuAssert(CuTest* tc, char* message, int condition); + void CuAssertTrue(CuTest* tc, int condition); + void CuAssertStrEquals(CuTest* tc, char* expected, char* actual); + void CuAssertIntEquals(CuTest* tc, int expected, int actual); + void CuAssertPtrEquals(CuTest* tc, void* expected, void* actual); + void CuAssertPtrNotNull(CuTest* tc, void* pointer); + +The project is open source and so you can add other more powerful +asserts to make your tests easier to write and more concise. +Please feel free to send me changes you make so that I can +incorporate them into future releases. + +If you see any errors in this document please contact me at +asimjalis-nospam@gmail.com. + + +Automating Test Suite Generation +-------------------------------- + +make-tests.sh will grep through all the .c files in the current +directory and generate the code to run all the tests contained in +them. Using this script you don't have to worry about writing +AllTests.c or dealing with any of the other suite code. + + +Credits +------- + +[02.23.2003] Dave Glowacki has added +(1) file name and line numbers to the error messages, (2) +AssertDblEquals for doubles, (3) AssertEquals_Msg version of +all the AssertEquals to pass in optional message which is +printed out on assert failure. diff --git a/index.html b/index.html index f8c9a42..52f076c 100644 --- a/index.html +++ b/index.html @@ -1,196 +1,196 @@ - - - - - -CuTest: The Cutest C Unit Testing Framework - - - - - - - -
-
-
- -[ - Download Now -| Download Statistics -| Browse Source -| SourceForge -| Blog -| asimjalis(nospam)gmail.com -] - -
- - -

CuTest: C Unit Testing Framework

- - -

Overview

- -CuTest is a unit testing library for the C language. It can be -used to do Extreme Programming and Test-First Development in the -C language. It's a fun and cute library that will make your -programming fun and productive. - -

Benefits

- -
    - -
  • Lower Defects. The tests ensure that your code keeps working -as you make small changes in it. - -
  • Faster Debugging. The tests tell you which subroutine is -broken. You avoid spending hours trying to figure out what's -broken. - -
  • Development Speed. You trust your old code and can keep -adding to it without worrying about bad interactions. If there is -a bad interaction the tests will catch it. - -
  • Permanent Bug Fixes. If every time a bug is reported you -write a quick test, you will guarantee that the bug never -reappears again. - -
  • Fun. As your bug count drops you will begin to enjoy -programming like you've never done before. Running the tests -every few minutes and seeing them pass feels good. - -
- -

Features

- -
    - -
  • Small. Consists of a single .c and .h file. - -
  • Easy to Deploy. Just drop the two files into your source -tree. - -
  • Highly Portable. Works with all major compilers on Windows -(Microsoft, Borland), Linux, Unix, PalmOS. - -
  • Open Source. You can extend it to add more functionality. -The source can be invaluable if you are trying to trace a test -failure. - -
  • Cuteness. Of all the testing frameworks CuTest has the -cutest name :-) - -
- - -

Licensing

- -CuTest is distributed under the zlib/libpng -license. See license.txt in the distribution for text of license. The -intent of the license is to: - -
    - -
  • Keep the license as simple as possible -
  • Encourage the use of CuTest in both free and commercial applications and libraries -
  • Keep the source code together -
  • Give credit to the CuTest contributors for their work - -
- -If you find CuTest useful we would like to hear about it. - - -

Getting Started

- -

For a detailed tutorial see README in the distribution. This shows you how -to organize your tests and how to autogenerate the AllTests.c file from your -source files. - -

To add unit testing to your C code the only files you need -are CuTest.c and CuTest.h. - -

CuTestTest.c and AllTests.c have been included to provide an -example of how to write unit tests and then how to aggregate them -into suites and into a single AllTests.c file. Suites allow you -to put unit tests for different parts of your code in different -files. AllTests.c combines all the suites and runs them. - -

You should not have to look inside CuTest.c. Looking in -CuTestTest.c (for example usage) should be sufficient. - -

After downloading the sources, run your compiler to create an -executable called AllTests.exe. For example, if you are using -Windows you would type: - -

-cl AllTests.c CuTest.c CuTestTest.c
-AllTests.exe
-
- -

This will run all the unit tests associated with CuTest and -print the output on the console. - -

For more details on how to use the library look at the README file included -with the distribution. - -

Contribute

- -

We hope you CuTest saves you time and helps you produce high quality -software. - -

If you find CuTest useful, let us know. Tell us what platform you are using -it on (Windows, Linux, etc), and what kinds of applications you are using it -with. - -

If you would like to contribute documentation or tutorials to this project -please send e-mail. - -
-
- -


- -Copyright © 2002-2003, Asim Jalis (asimjalis(nospam)gmail.com). -All rights reserved. - - - - -

-SourceForge.net Logo - - - + + + + + +CuTest: The Cutest C Unit Testing Framework + + + + + + + +
+
+


+ +[ + Download Now +| Download Statistics +| Browse Source +| SourceForge +| Blog +| asimjalis(nospam)gmail.com +] + +
+ + +

CuTest: C Unit Testing Framework

+ + +

Overview

+ +CuTest is a unit testing library for the C language. It can be +used to do Extreme Programming and Test-First Development in the +C language. It's a fun and cute library that will make your +programming fun and productive. + +

Benefits

+ +
    + +
  • Lower Defects. The tests ensure that your code keeps working +as you make small changes in it. + +
  • Faster Debugging. The tests tell you which subroutine is +broken. You avoid spending hours trying to figure out what's +broken. + +
  • Development Speed. You trust your old code and can keep +adding to it without worrying about bad interactions. If there is +a bad interaction the tests will catch it. + +
  • Permanent Bug Fixes. If every time a bug is reported you +write a quick test, you will guarantee that the bug never +reappears again. + +
  • Fun. As your bug count drops you will begin to enjoy +programming like you've never done before. Running the tests +every few minutes and seeing them pass feels good. + +
+ +

Features

+ +
    + +
  • Small. Consists of a single .c and .h file. + +
  • Easy to Deploy. Just drop the two files into your source +tree. + +
  • Highly Portable. Works with all major compilers on Windows +(Microsoft, Borland), Linux, Unix, PalmOS. + +
  • Open Source. You can extend it to add more functionality. +The source can be invaluable if you are trying to trace a test +failure. + +
  • Cuteness. Of all the testing frameworks CuTest has the +cutest name :-) + +
+ + +

Licensing

+ +CuTest is distributed under the zlib/libpng +license. See license.txt in the distribution for text of license. The +intent of the license is to: + +
    + +
  • Keep the license as simple as possible +
  • Encourage the use of CuTest in both free and commercial applications and libraries +
  • Keep the source code together +
  • Give credit to the CuTest contributors for their work + +
+ +If you find CuTest useful we would like to hear about it. + + +

Getting Started

+ +

For a detailed tutorial see README in the distribution. This shows you how +to organize your tests and how to autogenerate the AllTests.c file from your +source files. + +

To add unit testing to your C code the only files you need +are CuTest.c and CuTest.h. + +

CuTestTest.c and AllTests.c have been included to provide an +example of how to write unit tests and then how to aggregate them +into suites and into a single AllTests.c file. Suites allow you +to put unit tests for different parts of your code in different +files. AllTests.c combines all the suites and runs them. + +

You should not have to look inside CuTest.c. Looking in +CuTestTest.c (for example usage) should be sufficient. + +

After downloading the sources, run your compiler to create an +executable called AllTests.exe. For example, if you are using +Windows you would type: + +

+cl AllTests.c CuTest.c CuTestTest.c
+AllTests.exe
+
+ +

This will run all the unit tests associated with CuTest and +print the output on the console. + +

For more details on how to use the library look at the README file included +with the distribution. + +

Contribute

+ +

We hope you CuTest saves you time and helps you produce high quality +software. + +

If you find CuTest useful, let us know. Tell us what platform you are using +it on (Windows, Linux, etc), and what kinds of applications you are using it +with. + +

If you would like to contribute documentation or tutorials to this project +please send e-mail. + +
+
+ +


+ +Copyright © 2002-2003, Asim Jalis (asimjalis(nospam)gmail.com). +All rights reserved. + + + + +

+SourceForge.net Logo + + + diff --git a/license.txt b/license.txt index 5f053ba..fd81689 100644 --- a/license.txt +++ b/license.txt @@ -1,38 +1,38 @@ -NOTE - -The license is based on the zlib/libpng license. For more details see -http://www.opensource.org/licenses/zlib-license.html. The intent of the -license is to: - -- keep the license as simple as possible -- encourage the use of CuTest in both free and commercial applications - and libraries -- keep the source code together -- give credit to the CuTest contributors for their work - -If you ship CuTest in source form with your source distribution, the -following license document must be included with it in unaltered form. -If you find CuTest useful we would like to hear about it. - -LICENSE - -Copyright (c) 2003 Asim Jalis - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not -claim that you wrote the original software. If you use this software in -a product, an acknowledgment in the product documentation would be -appreciated but is not required. - -2. Altered source versions must be plainly marked as such, and must not -be misrepresented as being the original software. - -3. This notice may not be removed or altered from any source -distribution. +NOTE + +The license is based on the zlib/libpng license. For more details see +http://www.opensource.org/licenses/zlib-license.html. The intent of the +license is to: + +- keep the license as simple as possible +- encourage the use of CuTest in both free and commercial applications + and libraries +- keep the source code together +- give credit to the CuTest contributors for their work + +If you ship CuTest in source form with your source distribution, the +following license document must be included with it in unaltered form. +If you find CuTest useful we would like to hear about it. + +LICENSE + +Copyright (c) 2003 Asim Jalis + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not +claim that you wrote the original software. If you use this software in +a product, an acknowledgment in the product documentation would be +appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and must not +be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. diff --git a/style.css b/style.css index 7759d5a..072d888 100644 --- a/style.css +++ b/style.css @@ -1,21 +1,21 @@ -BODY { - font-family: "Verdana,Arial,sans-serif"; - font-size: 10pt; -} -PRE.LIST { - background: #CFD9FF; - border: 1ex solid #AAAAE6; - padding: 1ex; -} - -PRE.SNIP { - background: #CFD9FF; - padding: 1ex; -} - -PRE.CONSOLE { - color: #CCCCCC; - background: #000000; - font-family: "Courier New,Courier"; - padding: 1ex; -} +BODY { + font-family: "Verdana,Arial,sans-serif"; + font-size: 10pt; +} +PRE.LIST { + background: #CFD9FF; + border: 1ex solid #AAAAE6; + padding: 1ex; +} + +PRE.SNIP { + background: #CFD9FF; + padding: 1ex; +} + +PRE.CONSOLE { + color: #CCCCCC; + background: #000000; + font-family: "Courier New,Courier"; + padding: 1ex; +}