1d25d8e6bSMichael Pfeiffer /* 2d25d8e6bSMichael Pfeiffer ** Copyright 2004, Michael Pfeiffer (laplace@users.sourceforge.net). 3*47a21c5cSAugustin Cavalier ** Distributed under the terms of the MIT License. 4d25d8e6bSMichael Pfeiffer ** 5d25d8e6bSMichael Pfeiffer */ 6d25d8e6bSMichael Pfeiffer 7d25d8e6bSMichael Pfeiffer #ifndef _TEST_H 8d25d8e6bSMichael Pfeiffer #define _TEST_H 9d25d8e6bSMichael Pfeiffer 10d25d8e6bSMichael Pfeiffer #include <stdio.h> 11d25d8e6bSMichael Pfeiffer 12d25d8e6bSMichael Pfeiffer class AssertStatistics { 13d25d8e6bSMichael Pfeiffer private: 14d25d8e6bSMichael Pfeiffer AssertStatistics(); 15d25d8e6bSMichael Pfeiffer 16d25d8e6bSMichael Pfeiffer public: 17d25d8e6bSMichael Pfeiffer static AssertStatistics* GetInstance(); 18d25d8e6bSMichael Pfeiffer AssertFailed()19d25d8e6bSMichael Pfeiffer void AssertFailed() { fAssertions++; fFailed++; } AssertPassed()20d25d8e6bSMichael Pfeiffer void AssertPassed() { fAssertions++; fPassed++; } 21d25d8e6bSMichael Pfeiffer 22d25d8e6bSMichael Pfeiffer void Print(); 23d25d8e6bSMichael Pfeiffer 24d25d8e6bSMichael Pfeiffer int fAssertions; 25d25d8e6bSMichael Pfeiffer int fPassed; 26d25d8e6bSMichael Pfeiffer int fFailed; 27d25d8e6bSMichael Pfeiffer static AssertStatistics* fStatistics; 28d25d8e6bSMichael Pfeiffer }; 29d25d8e6bSMichael Pfeiffer 30d25d8e6bSMichael Pfeiffer class Item 31d25d8e6bSMichael Pfeiffer { 32d25d8e6bSMichael Pfeiffer public: Item()33d25d8e6bSMichael Pfeiffer Item() { Init(); } Item(const Item & item)34d25d8e6bSMichael Pfeiffer Item(const Item& item) : fValue(item.fValue) { Init(); }; Item(int value)35d25d8e6bSMichael Pfeiffer Item(int value) : fValue(value) { Init(); }; ~Item()36d25d8e6bSMichael Pfeiffer virtual ~Item() { fInstances --; } 37d25d8e6bSMichael Pfeiffer Value()38d25d8e6bSMichael Pfeiffer int Value() { return fValue; } 39d25d8e6bSMichael Pfeiffer Equals(Item * item)40d25d8e6bSMichael Pfeiffer bool Equals(Item* item) { 41d25d8e6bSMichael Pfeiffer return item != NULL && fValue == item->fValue; 42d25d8e6bSMichael Pfeiffer } 43d25d8e6bSMichael Pfeiffer GetNumberOfInstances()44d25d8e6bSMichael Pfeiffer static int GetNumberOfInstances() { return fInstances; } 45d25d8e6bSMichael Pfeiffer Print()46d25d8e6bSMichael Pfeiffer void Print() { 47d25d8e6bSMichael Pfeiffer fprintf(stderr, "[%d] %d", fID, fValue); 48d25d8e6bSMichael Pfeiffer // fprintf(stderr, "id: %d; value: %d", fID, fValue); 49d25d8e6bSMichael Pfeiffer } 50d25d8e6bSMichael Pfeiffer 51d25d8e6bSMichael Pfeiffer static int Compare(const void* a, const void* b); 52d25d8e6bSMichael Pfeiffer 53d25d8e6bSMichael Pfeiffer private: Init()54d25d8e6bSMichael Pfeiffer void Init() { 55d25d8e6bSMichael Pfeiffer fID = fNextID ++; 56d25d8e6bSMichael Pfeiffer fInstances ++; 57d25d8e6bSMichael Pfeiffer } 58d25d8e6bSMichael Pfeiffer 59d25d8e6bSMichael Pfeiffer int fID; // unique id for each created Item 60d25d8e6bSMichael Pfeiffer int fValue; // the value of the item 61d25d8e6bSMichael Pfeiffer 62d25d8e6bSMichael Pfeiffer 63d25d8e6bSMichael Pfeiffer static int fNextID; 64d25d8e6bSMichael Pfeiffer static int fInstances; 65d25d8e6bSMichael Pfeiffer }; 66d25d8e6bSMichael Pfeiffer 67d25d8e6bSMichael Pfeiffer 68d25d8e6bSMichael Pfeiffer #endif 69