1 // 2 // This file is used to test WorldDescription::strTotalTests() 3 // 4 5 #include <cxxtest/TestSuite.h> 6 #include <cxxtest/DummyDescriptions.h> 7 8 class Factor : public CxxTest::TestSuite 9 { 10 public: 11 class X : public CxxTest::DummyWorldDescription 12 { 13 public: 14 unsigned n; numTotalTests()15 unsigned numTotalTests() const { return n; } 16 }; 17 18 X x; 19 enum Limit { MAX_STRLEN_TOTAL_TESTS = CxxTest::WorldDescription::MAX_STRLEN_TOTAL_TESTS }; 20 char buffer[MAX_STRLEN_TOTAL_TESTS * 2]; 21 convert(unsigned n)22 const char *convert(unsigned n) 23 { 24 x.n = n; 25 return x.strTotalTests(buffer); 26 } 27 test_Some_numbers()28 void test_Some_numbers() 29 { 30 TS_WARN(convert(53)); 31 for (unsigned n = 0; n < 64; ++ n) 32 { 33 TS_ASSERT_DIFFERS(n, 32); 34 TS_WARN(convert(n)); 35 } 36 } 37 38 class ShorterThan 39 { 40 public: operator()41 bool operator()(const char *s, unsigned n) const 42 { 43 unsigned len = 0; 44 while (*s++ != '\0') 45 { 46 ++ len; 47 } 48 return (len < n); 49 } 50 }; 51 52 class NotShorterThan 53 { 54 ShorterThan _shorterThan; 55 56 public: operator()57 bool operator()(const char *s, unsigned n) const { return !_shorterThan(s, n); } 58 }; 59 test_Lengths()60 void test_Lengths() 61 { 62 unsigned reasonableLimit = 60060; 63 for (unsigned n = 0; n < reasonableLimit; ++ n) 64 { 65 TS_ASSERT_RELATION(ShorterThan, convert(n), MAX_STRLEN_TOTAL_TESTS); 66 } 67 TS_ASSERT_RELATION(NotShorterThan, convert(reasonableLimit), MAX_STRLEN_TOTAL_TESTS); 68 } 69 }; 70