[Home | Contact | What's New? | Products | Services | Tips | Mike |
Living with Schizoaffective Disorder
                      Why Unit Testing?

    Testing a computer program from its visible user interface is like
   trying to test this advanced computer chip from its two external pins:

            In --->[ One Million Transistors ]---> Out

      Unit testing software source code is like testing each
      design cell of a complex chip in complete isolation.

Mike Crawford's C++ Memory Management
and Testing Library

Memory management, automated testing, debugging and utility classes,
as well as GNU-Style Makefiles that you will find useful for most C++ projects.

Michael David Crawford, Baritone,

libmdc is Free Software, distributed under the terms of the Boost Software License - Version 1.0.


To build libmdc, you will need to build and install the Boost C++ Libraries on your system. If you use Linux, check to see whether your distribution already provides a Boost package, and use that.

To test libmdc, you will need the CPPUnit C++ unit test framework. Note that you can build and use libmdc without building or running the unit tests.

Supported Platforms

This release requires GNU Make to build. However, it should be easy to use the source files with other build systems. I will be supporting other environments such as the Freescale CodeWarrior Development Tools, Texas Instruments Code Composer Studio and Microsoft Visual C++ soon.

The November 12, 2005 Release was tested with Fedora Core 4 GNU/Linux on a Pentium III and Mac OS X 10.3.9 on a Blue and White PowerPC G3 Macintosh.


Large Scale C++ Software Design cover

Large Scale C++ Software Design

John Lakos

[ Buy]  


Proper documentation remains to be written. However, most of the header files have some documentation comments. Also look at the unit tests (*.t.cpp) for sample code.

The CPPUnit.mk and CPPUnit.t.mk unit test compilation framework is fully documented in the form of a long comment at the beginning of CPPUnit.mk. The Makefile is also fully commented to help you understand how to use CPPUnit.mk.

Before you write too many unit tests for your own code, I recommend you purchase a copy of John Lakos' excellent book Large Scale C++ Software Design. Read chapters 4 - Physical Heirarchy - and 5 - levelization - first.

I cannot emphasize strongly enough the importance of reading Lakos' book.


                    Mike Crawford's C++ Library

         Memory management, testing, debugging and utility classes,
                    useful in most C++ projects.

                       June 22, 2012 Release




             Michael David Crawford, Process Architect

                  Dulcinea Technologies Corporation
                   Software of Elegance and Beauty



                            PO Box 6888
                         Portland OR 97228

                         +1 (503) 928-7501

Copyright (C) 2005 GoingWare Inc., 2012 Michael David Crawford.

Distributed under the terms of Boost Software License - Version 1.0, as stated
in the accompanying file LICENSE_1_0.txt.  If you did not receive that file,
you may read it on the World Wide Web at:


Please report license violations via eMail to Mike Crawford at


The Boost Software License, Version 1.0 is *quite* similar to the MIT License,
also known as the X Consortium License, the X11 License or the X Window

But the two licenses are *NOT* the same, in fact there are *many* significant
differences between the two!

                          READ THEM OR WEEP.


libmdc is a set of memory management, automated testing, debugging and utility
classes, as well as GNU Make-style Makefiles that you will find useful for most
C++ projects.

Everything is in the namespace "mdc".


   2012-06-22 - libmdc's homepage has been moved from GoingWare, Inc.'s old
                website to Dulcinea Technologies Corporation's site.

              - The Copyright originally held by GoingWare Inc. is now
                assigned to Michael David Crawford.

              - The user can choose either at compile time or by editing
                the top-level Makefile which ISO C++ or C Language Standard
                Specification to comply with.  Thus more-modern compilers may
                benefit from such language features as c99's "restricted"
                keyword, while at the same time libmdc remains compatible with
                older tools that don't know about restricted pointers.

              - Built and tested with a wider variety of compilers on a wider
                variety of operating systems, for example with the LLVM
                toolchain, as well as on Haiku (http://www.haiku-os.org/),
                BeOS 5 Pro and Windows XP.  The 2005 release only supported
                g++ on Mac OS X and Linux.


There aren't any dependencies on anything outside this directory except for;

   * A *Reasonably* ISO/IEC 14882 Standards-Compliant C++ Compiler

      JTC1/SC22/WG21 - The C++ Standards Committe

         Strict Standards Compliance is *not* required, but many tools are
         *still* in widespread use despite being *completely* borked.

      The C++ Programming Language (Thid Edition and Special Edition)
         by Bjarne Stroustrup

      The Annotated C++ Reference Manual
         by Margaret A. Ellis and Bjarne Stroustrup

     C++ Frequently Asked Questions

     C++ FAQs, 2nd Edition
        by Marshall P. Cline, Greg Lomow, Mike Girou

     Information technology - Programming languages - C++
        ISO/IEC 14882:2011

     Programming languages - C++
        ISO/IEC 14882:2003 (Withdrawn)

     Programming languages - C++
        ISO/EIC 14882:1998 (Withdrawn)

   * The C++ Standard Library


   * The Standard Template Library


   * The Boost C++ Libraries


   * The C Standard Library


   * GNU Make


   * A Command Interpreter that is compliant with IEEE Std 1003.1-2008,
     more commonly known as the Bourne Shell or POSIX Shell


   * The CPPUnit Unit Testing Framework

To build libmdc's executables, just type:

    $ make

To build then run the the unit tests as well as other automated tests:

    $ make test

There is no "make install" yet.

The library so far contains:

CPPUnit.mk, CPPUnit.t.mk

Sub-makefiles to make it a lot easier to build CPPUnit unit tests
with GNU make.


non-owning smart pointer; forbids NULL pointers.


pointer debugging, best used with valgrind, purify or spotlight.


throws an exception when given a NULL pointer.


The exception it throws.


Debugging macro, aborts or drops into debugger when its
assertion evaluates to false.  This is used instead
of the standard library assert so it may be separately
disabled. Assertions are enabled by default, for
release builds, #define MDC_NO_ASSERT 1 or
pass -DMDC_NO_ASSERT=1 to the C++ compiler.


meant for testing failed assertions in unit tests.
You can configure mdc_assert to throw this exception with


on POSIX systems, throw this exception after a system
call fails so that the catcher can print a good error message


The beginning of class invariant assertions for the Standard Library

valid_ptr is a smart pointer like auto_ptr, scoped_ptr or
shared_ptr, except that it doesn't take ownership of the pointer
it holds.  Instead, construct a valid_ptr from a pointer that
your class or function is given to use, but not manage.  It will
throw a null_ptr_exception and optionally assert if the pointer
is ever NULL.

Besides validating the pointer it is given, valid_ptrs serve as
documentation to help make ownership issues clear.  Using valid_ptrs
as class member variables indicates that the pointers are used by,
but not owned by the class.  Similarly, declaring them as function
parameters indicates that the pointers passed in cannot be NULL, and
again that ownership of them is not captured by the receiving function.

Use either scoped_ptr, shared_ptr or auto_ptr for situations where
pointer ownership is required.  Which one to use depends on the
requirements of each situation.

There is sample code too: the tests.  There are unit tests
for most of the classes that use the CPPUnit automated test

There is also a simple program called HeaderCheck that I used
to debug some problems with my header files while I was first
writing valid_ptr.h.  CPPUnit does some extreme macro and
template magic, so HeaderCheck serves as a simpler testbed.

Enjoy! -- Mike
[Home | Contact | What's New? | Products | Services | Tips | Mike]