1 #ifndef TESTS_COMMON_H 2 #define TESTS_COMMON_H 3 4 #include <iostream> 5 #include <fstream> 6 #include <string.h> 7 8 #include "cxxtest/TestSuite.h" 9 #include "cxxtest/GlobalFixture.h" 10 11 #include "misc/auxiliary.h" 12 13 #include "coeffs/coeffs.h" 14 #include "coeffs/numbers.h" 15 16 #include "reporter/reporter.h" 17 #include "resources/feResource.h" 18 19 #ifndef PLURAL_INTERNAL_DECLARATIONS 20 #define PLURAL_INTERNAL_DECLARATIONS 21 #endif 22 23 #include "polys/nc/gb_hack.h" 24 25 // #pragma GCC diagnostic ignored "-Wwrite-strings" 26 namespace 27 { 28 static inline std::ostream& operator<< (std::ostream& o, const n_coeffType& type) 29 { 30 #define CASE(A) case A: return o << (" " # A) << " "; 31 switch( type ) 32 { 33 CASE(n_unknown); 34 CASE(n_Zp); 35 CASE(n_Q); 36 CASE(n_R); 37 CASE(n_GF); 38 CASE(n_long_R); 39 CASE(n_algExt); 40 CASE(n_transExt); 41 CASE(n_long_C); 42 CASE(n_Z); 43 CASE(n_Zn); 44 CASE(n_Znm); 45 CASE(n_Z2m); 46 CASE(n_CF); 47 default: return o << "Unknown type: [" << (const unsigned long) type << "]"; 48 } 49 #undef CASE 50 return o; 51 } 52 53 template<typename T> _2S(T i)54 static inline std::string _2S(T i) 55 { 56 std::stringstream ss; 57 ss << i; 58 // std::string s = ss.str(); 59 return ss.str(); 60 } 61 62 _2S(number a,const coeffs r)63 static inline std::string _2S(number a, const coeffs r) 64 { 65 n_Test(a,r); 66 StringSetS(""); 67 n_Write(a, r); 68 69 std::stringstream ss; 70 { 71 char* s = StringEndS(); ss << s; omFree(s); 72 } 73 74 return ss.str(); 75 76 } 77 78 static inline void PrintSized(/*const*/ number a, const coeffs r, BOOLEAN eoln = TRUE) 79 { 80 std::clog << _2S(a, r) << ", of size: " << n_Size(a, r); 81 82 if( eoln ) 83 std::clog << std::endl; 84 } 85 86 87 88 } 89 90 class GlobalPrintingFixture : public CxxTest::GlobalFixture 91 { 92 std::ofstream _ofs; 93 bool _redirect; 94 public: _redirect(redirect)95 GlobalPrintingFixture(bool redirect = false): _redirect(redirect){} 96 ~GlobalPrintingFixture()97 ~GlobalPrintingFixture() 98 { 99 if( _ofs) 100 _ofs.close(); 101 } 102 Redirect()103 void Redirect() 104 { 105 const int ll = strlen(argv0); 106 const int l = 5 + ll; 107 char* s = (char *)omAlloc0(l); 108 s = strncpy(s, argv0, ll); 109 strncpy(s + ll, ".log", 4); 110 _ofs.open(s); // , ios_base::out) 111 omFreeSize((ADDRESS)s, l); 112 113 std::clog.rdbuf(_ofs.rdbuf()); 114 } 115 setUpWorld()116 virtual bool setUpWorld() 117 { 118 if( _redirect ) 119 Redirect(); 120 121 std::clog << std::endl << ( "<world>" ) << std::endl << std::endl; 122 feInitResources(argv0); 123 124 StringSetS("ressources in use (as reported by feStringAppendResources(0):\n"); 125 feStringAppendResources(0); 126 127 { char* s = StringEndS(); PrintS(s); omFree(s); } 128 129 return true; 130 } 131 tearDownWorld()132 virtual bool tearDownWorld() 133 { 134 std::clog << std::endl << std::endl <<( "</world>" ) << std::endl << std::endl ; 135 return true; 136 } setUp()137 virtual bool setUp() { std::clog << std::endl << std::endl <<( "<test>" ) << std::endl << std::endl; return true; } tearDown()138 virtual bool tearDown() { std::clog << std::endl << std::endl <<( "</test>" ) << std::endl << std::endl; return true; } 139 }; 140 141 142 template void CxxTest::doAssertDiffers<n_Procs_s*, void*>(char const*, unsigned int, char const*, n_Procs_s*, char const*, void*, char const*); 143 template void CxxTest::doAssertDiffers<snumber* (*)(long, n_Procs_s*), void*>(char const*, unsigned int, char const*, snumber* (*)(long, n_Procs_s*), char const*, void*, char const*); 144 template void CxxTest::doAssertDiffers<snumber* (*)(snumber*, snumber*, n_Procs_s*), void*>(char const*, unsigned int, char const*, snumber* (*)(snumber*, snumber*, n_Procs_s*), char const*, void*, char const*); 145 template void CxxTest::doAssertDiffers<void (*)(n_Procs_s*, int), void*>(char const*, unsigned int, char const*, void (*)(n_Procs_s*, int), char const*, void*, char const*); 146 template void CxxTest::doAssertDiffers<void (*)(snumber**, n_Procs_s*), void*>(char const*, unsigned int, char const*, void (*)(snumber**, n_Procs_s*), char const*, void*, char const*); 147 template void CxxTest::doAssertDiffers<void (*)(snumber*&, n_Procs_s*), void*>(char const*, unsigned int, char const*, void (*)(snumber*&, n_Procs_s*), char const*, void*, char const*); 148 template void CxxTest::doAssertEquals<int, int>(char const*, unsigned int, char const*, int, char const*, int, char const*); 149 template void CxxTest::doAssertEquals<n_coeffType, n_coeffType>(char const*, unsigned int, char const*, n_coeffType, char const*, n_coeffType, char const*); 150 template void CxxTest::doAssertEquals<snumber* (*)(long, n_Procs_s*), snumber* (*)(long, n_Procs_s*)>(char const*, unsigned int, char const*, snumber* (*)(long, n_Procs_s*), char const*, snumber* (*)(long, n_Procs_s*), char const*); 151 template void CxxTest::doAssertEquals<snumber* (*)(snumber*, snumber*, n_Procs_s*), snumber* (*)(snumber*, snumber*, n_Procs_s*)>(char const*, unsigned int, char const*, snumber* (*)(snumber*, snumber*, n_Procs_s*), char const*, snumber* (*)(snumber*, snumber*, n_Procs_s*), char const*); 152 template void CxxTest::doAssertEquals<void (*)(snumber**, n_Procs_s*), void (*)(snumber**, n_Procs_s*)>(char const*, unsigned int, char const*, void (*)(snumber**, n_Procs_s*), char const*, void (*)(snumber**, n_Procs_s*), char const*); 153 154 template bool CxxTest::differs<n_Procs_s*, void*>(n_Procs_s*, void*); 155 template bool CxxTest::differs<snumber* (*)(long, n_Procs_s*), void*>(snumber* (*)(long, n_Procs_s*), void*); 156 template bool CxxTest::differs<snumber* (*)(snumber*, snumber*, n_Procs_s*), void*>(snumber* (*)(snumber*, snumber*, n_Procs_s*), void*); 157 template bool CxxTest::differs<void (*)(n_Procs_s*, int), void*>(void (*)(n_Procs_s*, int), void*); 158 template bool CxxTest::differs<void (*)(snumber**, n_Procs_s*), void*>(void (*)(snumber**, n_Procs_s*), void*); 159 template bool CxxTest::differs<void (*)(snumber*&, n_Procs_s*), void*>(void (*)(snumber*&, n_Procs_s*), void*); 160 template bool CxxTest::equals<int, int>(int, int); 161 template bool CxxTest::equals<n_coeffType, n_coeffType>(n_coeffType, n_coeffType); 162 template bool CxxTest::equals<snumber* (*)(long, n_Procs_s*), snumber* (*)(long, n_Procs_s*)>(snumber* (*)(long, n_Procs_s*), snumber* (*)(long, n_Procs_s*)); 163 template bool CxxTest::equals<snumber* (*)(snumber*, snumber*, n_Procs_s*), snumber* (*)(snumber*, snumber*, n_Procs_s*)>(snumber* (*)(snumber*, snumber*, n_Procs_s*), snumber* (*)(snumber*, snumber*, n_Procs_s*)); 164 template bool CxxTest::equals<void (*)(snumber**, n_Procs_s*), void (*)(snumber**, n_Procs_s*)>(void (*)(snumber**, n_Procs_s*), void (*)(snumber**, n_Procs_s*)); 165 template char* CxxTest::numberToString<long>(long, char*, long, unsigned int, unsigned int); 166 167 template void CxxTest::doAssertDiffers<ip_sring*, void*>(char const*, unsigned int, char const*, ip_sring*, char const*, void*, char const*); 168 template void CxxTest::doAssertEquals<short, int>(char const*, unsigned int, char const*, short, char const*, int, char const*); 169 170 template bool CxxTest::differs<ip_sring*, void*>(ip_sring*, void*); 171 template bool CxxTest::equals<short, int>(short, int); 172 173 #endif /* TESTS_COMMON_H */ 174