diff options
| author | MenTaLguY <mental@rydia.net> | 2006-01-16 02:36:01 +0000 |
|---|---|---|
| committer | mental <mental@users.sourceforge.net> | 2006-01-16 02:36:01 +0000 |
| commit | 179fa413b047bede6e32109e2ce82437c5fb8d34 (patch) | |
| tree | a5a6ac2c1708bd02288fbd8edb2ff500ff2e0916 /cxxtest/sample/TraitsTest.h | |
| download | inkscape-179fa413b047bede6e32109e2ce82437c5fb8d34.tar.gz inkscape-179fa413b047bede6e32109e2ce82437c5fb8d34.zip | |
moving trunk for module inkscape
(bzr r1)
Diffstat (limited to 'cxxtest/sample/TraitsTest.h')
| -rw-r--r-- | cxxtest/sample/TraitsTest.h | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/cxxtest/sample/TraitsTest.h b/cxxtest/sample/TraitsTest.h new file mode 100644 index 000000000..14659385d --- /dev/null +++ b/cxxtest/sample/TraitsTest.h @@ -0,0 +1,69 @@ +#ifndef __TRAITSTEST_H +#define __TRAITSTEST_H + +// +// This example shows how to use TS_ASSERT_EQUALS for your own classes +// +#include <cxxtest/TestSuite.h> +#include <cxxtest/ValueTraits.h> + +// +// Define your class with operator== +// +#include <stdio.h> +#include <string.h> + +class Pet +{ + char _name[128]; +public: + Pet( const char *petName ) { strcpy( _name, petName ); } + + const char *name() const { return _name; } + + bool operator== ( const Pet &other ) const + { + return !strcmp( name(), other.name() ); + } +}; + +// +// Instantiate CxxTest::ValueTraits<*your class*> +// Note: Most compilers do not require that you define both +// ValueTraits<const T> and ValueTraits<T>, but some do. +// +namespace CxxTest +{ + CXXTEST_TEMPLATE_INSTANTIATION + class ValueTraits<const Pet> + { + char _asString[256]; + + public: + ValueTraits( const Pet &pet ) { sprintf( _asString, "Pet(\"%s\")", pet.name() ); } + const char *asString() const { return _asString; } + }; + + CXXTEST_COPY_CONST_TRAITS( Pet ); +} + +// +// Here's how it works +// +class TestFunky : public CxxTest::TestSuite +{ +public: + void testPets() + { + Pet pet1("dog"), pet2("cat"); + TS_ASSERT_EQUALS( pet1, pet2 ); + Pet cat("cat"), gato("cat"); + TS_ASSERT_DIFFERS( cat, gato ); +#ifdef _CXXTEST_HAVE_STD + typedef CXXTEST_STD(string) String; + TS_ASSERT_EQUALS( String("Hello"), String("World!") ); +#endif // _CXXTEST_HAVE_STD + } +}; + +#endif // __TRAITSTEST_H |
