1// BasicTest.h 2 3#ifndef __sk_basic_test_h__ 4#define __sk_basic_test_h__ 5 6#include <SupportDefs.h> 7#include <TestCase.h> 8#include <TestShell.h> 9#include <stdio.h> 10 11#include <set> 12using std::set; 13#include <string> 14using std::string; 15 16 17class BasicTest : public BTestCase 18{ 19public: 20 BasicTest(); 21 22 // This function called before *each* test added in Suite() 23 void setUp(); 24 25 // This function called after *each* test added in Suite() 26 void tearDown(); 27 28 // helper functions 29 30// void nextSubTest(); 31// void nextSubTestBlock(); 32 33 static void execCommand(const string &command); 34 35 static void dumpStat(struct stat &st); 36 37 static void createVolume(string imageFile, string mountPoint, int32 megs, 38 bool makeMountPoint = true); 39 static void deleteVolume(string imageFile, string mountPoint, 40 bool deleteMountPoint = true); 41 42protected: 43 int32 fSubTestNumber; 44 int32 fAvailableFDs; 45}; 46 47 48// Some other helpful stuff. 49 50// == for struct stat 51static 52inline 53bool 54operator==(const struct stat &st1, const struct stat &st2) 55{ 56 return ( 57 st1.st_dev == st2.st_dev 58 && st1.st_ino == st2.st_ino 59 && st1.st_mode == st2.st_mode 60 && st1.st_nlink == st2.st_nlink 61 && st1.st_uid == st2.st_uid 62 && st1.st_gid == st2.st_gid 63 && st1.st_size == st2.st_size 64 && st1.st_blksize == st2.st_blksize 65 && st1.st_atime == st2.st_atime 66 && st1.st_mtime == st2.st_mtime 67 && st1.st_ctime == st2.st_ctime 68 && st1.st_crtime == st2.st_crtime 69 ); 70} 71 72// first parameter is equal to the second or third 73template<typename A, typename B, typename C> 74static 75inline 76bool 77equals(const A &a, const B &b, const C &c) 78{ 79 return (a == b || a == c); 80} 81 82// A little helper class for tests. It works like a set of strings, that 83// are marked tested or untested. 84class TestSet { 85public: 86 typedef set<string> nameset; 87 88public: 89 TestSet() 90 { 91 } 92 93 void add(string name) 94 { 95 if (fTestedNames.find(name) == fTestedNames.end()) 96 fUntestedNames.insert(name); 97 } 98 99 void remove(string name) 100 { 101 if (fUntestedNames.find(name) != fUntestedNames.end()) 102 fUntestedNames.erase(name); 103 else if (fTestedNames.find(name) != fTestedNames.end()) 104 fTestedNames.erase(name); 105 } 106 107 void clear() 108 { 109 fUntestedNames.clear(); 110 fTestedNames.clear(); 111 } 112 113 void rewind() 114 { 115 fUntestedNames.insert(fTestedNames.begin(), fTestedNames.end()); 116 fTestedNames.clear(); 117 } 118 119 bool test(string name, bool dump = BTestShell::GlobalBeVerbose()) 120 { 121 bool result = (fUntestedNames.find(name) != fUntestedNames.end()); 122 if (result) { 123 fUntestedNames.erase(name); 124 fTestedNames.insert(name); 125 } else if (dump) { 126 // dump untested 127 printf("TestSet::test(`%s')\n", name.c_str()); 128 printf("untested:\n"); 129 for (nameset::iterator it = fUntestedNames.begin(); 130 it != fUntestedNames.end(); 131 ++it) { 132 printf(" `%s'\n", it->c_str()); 133 } 134 } 135 return result; 136 } 137 138 bool testDone() 139 { 140 return (fUntestedNames.empty()); 141 } 142 143private: 144 nameset fUntestedNames; 145 nameset fTestedNames; 146}; 147 148 149#endif // __sk_basic_test_h__ 150