common.h
Go to the documentation of this file.
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>
10 
11 
12 
13 
14 
15 #include <misc/auxiliary.h>
16 #include <omalloc/omalloc.h>
17 
18 #include <coeffs/coeffs.h>
19 #include <coeffs/numbers.h>
20 
21 #include <reporter/reporter.h>
22 #include <resources/feResource.h>
23 
24 #ifndef PLURAL_INTERNAL_DECLARATIONS
25 #define PLURAL_INTERNAL_DECLARATIONS
26 #endif
27 
28 #include <polys/nc/gb_hack.h>
29 
30 // #pragma GCC diagnostic ignored "-Wwrite-strings"
31 namespace
32 {
33  static inline std::ostream& operator<< (std::ostream& o, const n_coeffType& type)
34  {
35 #define CASE(A) case A: return o << (" " # A) << " ";
36  switch( type )
37  {
38  CASE(n_unknown);
39  CASE(n_Zp);
40  CASE(n_Q);
41  CASE(n_R);
42  CASE(n_GF);
43  CASE(n_long_R);
44  CASE(n_algExt);
46  CASE(n_long_C);
47  CASE(n_Z);
48  CASE(n_Zn);
49  CASE(n_Znm);
50  CASE(n_Z2m);
51  CASE(n_CF);
52  default: return o << "Unknown type: [" << (const unsigned long) type << "]";
53  }
54 #undef CASE
55  return o;
56  }
57 
58  template<typename T>
59  static inline std::string _2S(T i)
60  {
61  std::stringstream ss;
62  ss << i;
63 // std::string s = ss.str();
64  return ss.str();
65  }
66 
67 
68  static inline std::string _2S(number a, const coeffs r)
69  {
70  n_Test(a,r);
71  StringSetS("");
72  n_Write(a, r);
73 
74  std::stringstream ss;
75  {
76  char* s = StringEndS(); ss << s; omFree(s);
77  }
78 
79  return ss.str();
80 
81  }
82 
83  static inline void PrintSized(/*const*/ number a, const coeffs r, BOOLEAN eoln = TRUE)
84  {
85  std::clog << _2S(a, r) << ", of size: " << n_Size(a, r);
86 
87  if( eoln )
88  std::clog << std::endl;
89  }
90 
91 
92 
93 }
94 
96 {
97  std::ofstream _ofs;
98  bool _redirect;
99  public:
100  GlobalPrintingFixture(bool redirect = false): _redirect(redirect){}
101 
103  {
104  if( _ofs)
105  _ofs.close();
106  }
107 
108  void Redirect()
109  {
110  const int ll = strlen(argv0);
111  const int l = 5 + ll;
112  char* s = (char *)omAlloc0(l);
113  s = strncpy(s, argv0, ll);
114  strncpy(s + ll, ".log", 4);
115  _ofs.open(s); // , ios_base::out)
116  omFreeSize((ADDRESS)s, l);
117 
118  std::clog.rdbuf(_ofs.rdbuf());
119  }
120 
121  virtual bool setUpWorld()
122  {
123  if( _redirect )
124  Redirect();
125 
126  std::clog << std::endl << ( "<world>" ) << std::endl << std::endl;
128 
129  StringSetS("ressources in use (as reported by feStringAppendResources(0):\n");
131 
132  { char* s = StringEndS(); PrintS(s); omFree(s); }
133 
134  return true;
135  }
136 
137  virtual bool tearDownWorld()
138  {
139  std::clog << std::endl << std::endl <<( "</world>" ) << std::endl << std::endl ;
140  return true;
141  }
142  virtual bool setUp() { std::clog << std::endl << std::endl <<( "<test>" ) << std::endl << std::endl; return true; }
143  virtual bool tearDown() { std::clog << std::endl << std::endl <<( "</test>" ) << std::endl << std::endl; return true; }
144 };
145 
146 
147 template void CxxTest::doAssertDiffers<n_Procs_s*, void*>(char const*, unsigned int, char const*, n_Procs_s*, char const*, void*, char const*);
148 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*);
149 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*);
150 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*);
151 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*);
152 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*);
153 template void CxxTest::doAssertEquals<int, int>(char const*, unsigned int, char const*, int, char const*, int, char const*);
154 template void CxxTest::doAssertEquals<n_coeffType, n_coeffType>(char const*, unsigned int, char const*, n_coeffType, char const*, n_coeffType, char const*);
155 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*);
156 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*);
157 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*);
158 
159 template bool CxxTest::differs<n_Procs_s*, void*>(n_Procs_s*, void*);
160 template bool CxxTest::differs<snumber* (*)(long, n_Procs_s*), void*>(snumber* (*)(long, n_Procs_s*), void*);
161 template bool CxxTest::differs<snumber* (*)(snumber*, snumber*, n_Procs_s*), void*>(snumber* (*)(snumber*, snumber*, n_Procs_s*), void*);
162 template bool CxxTest::differs<void (*)(n_Procs_s*, int), void*>(void (*)(n_Procs_s*, int), void*);
163 template bool CxxTest::differs<void (*)(snumber**, n_Procs_s*), void*>(void (*)(snumber**, n_Procs_s*), void*);
164 template bool CxxTest::differs<void (*)(snumber*&, n_Procs_s*), void*>(void (*)(snumber*&, n_Procs_s*), void*);
165 template bool CxxTest::equals<int, int>(int, int);
166 template bool CxxTest::equals<n_coeffType, n_coeffType>(n_coeffType, n_coeffType);
167 template bool CxxTest::equals<snumber* (*)(long, n_Procs_s*), snumber* (*)(long, n_Procs_s*)>(snumber* (*)(long, n_Procs_s*), snumber* (*)(long, n_Procs_s*));
168 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*));
169 template bool CxxTest::equals<void (*)(snumber**, n_Procs_s*), void (*)(snumber**, n_Procs_s*)>(void (*)(snumber**, n_Procs_s*), void (*)(snumber**, n_Procs_s*));
170 template char* CxxTest::numberToString<long>(long, char*, long, unsigned int, unsigned int);
171 
172 template void CxxTest::doAssertDiffers<ip_sring*, void*>(char const*, unsigned int, char const*, ip_sring*, char const*, void*, char const*);
173 template void CxxTest::doAssertEquals<short, int>(char const*, unsigned int, char const*, short, char const*, int, char const*);
174 
175 template bool CxxTest::differs<ip_sring*, void*>(ip_sring*, void*);
176 template bool CxxTest::equals<short, int>(short, int);
177 
178 #endif /* TESTS_COMMON_H */
#define CASE(A)
const CanonicalForm int s
Definition: facAbsFact.cc:55
const poly a
Definition: syzextra.cc:212
void feStringAppendResources(int warn)
Definition: reporter.cc:415
only used if HAVE_RINGS is defined: ?
Definition: coeffs.h:43
?
Definition: coeffs.h:46
&#39;SR_INT&#39; is the type of those integers small enough to fit into 29 bits.
Definition: longrat.h:46
only used if HAVE_RINGS is defined: ?
Definition: coeffs.h:45
used for all transcendental extensions, i.e., the top-most extension in an extension tower is transce...
Definition: coeffs.h:38
rational (GMP) numbers
Definition: coeffs.h:31
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
{p < 2^31}
Definition: coeffs.h:30
#define string
Definition: libparse.cc:1250
Definition: ring.h:209
#define TRUE
Definition: auxiliary.h:144
void * ADDRESS
Definition: auxiliary.h:161
void feInitResources(const char *argv0)
Definition: feResource.cc:170
char * StringEndS()
Definition: reporter.cc:151
real floating point (GMP) numbers
Definition: coeffs.h:34
virtual bool tearDown()
Definition: common.h:143
single prescision (6,6) real numbers
Definition: coeffs.h:32
const ring r
Definition: syzextra.cc:208
Coefficient rings, fields and other domains suitable for Singular polynomials.
only used if HAVE_RINGS is defined: ?
Definition: coeffs.h:44
#define omFree(addr)
Definition: omAllocDecl.h:261
The main handler for Singular numbers which are suitable for Singular polynomials.
void StringSetS(const char *st)
Definition: reporter.cc:128
virtual bool setUp()
Definition: common.h:142
complex floating point (GMP) numbers
Definition: coeffs.h:41
static FORCE_INLINE void n_Write(number &n, const coeffs r, const BOOLEAN bShortOut=TRUE)
Definition: coeffs.h:592
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:739
All the auxiliary stuff.
only used if HAVE_RINGS is defined: ?
Definition: coeffs.h:42
int i
Definition: cfEzgcd.cc:123
void PrintS(const char *s)
Definition: reporter.cc:294
virtual bool tearDownWorld()
Definition: common.h:137
std::ofstream _ofs
Definition: common.h:97
n_coeffType
Definition: coeffs.h:27
virtual bool setUpWorld()
Definition: common.h:121
{p^n < 2^16}
Definition: coeffs.h:33
char * argv0
used for all algebraic extensions, i.e., the top-most extension in an extension tower is algebraic ...
Definition: coeffs.h:35
static jList * T
Definition: janet.cc:37
int BOOLEAN
Definition: auxiliary.h:131
static FORCE_INLINE int n_Size(number n, const coeffs r)
return a non-negative measure for the complexity of n; return 0 only when n represents zero; (used fo...
Definition: coeffs.h:571
#define omAlloc0(size)
Definition: omAllocDecl.h:211
int l
Definition: cfEzgcd.cc:94
ostream & operator<<(ostream &s, const spectrum &spec)
Definition: semic.cc:249
GlobalPrintingFixture(bool redirect=false)
Definition: common.h:100