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 #ifndef PLURAL_INTERNAL_DECLARATIONS_GB_HACK
29 #define PLURAL_INTERNAL_DECLARATIONS_GB_HACK
30 #endif
31 
32 #include <polys/nc/gb_hack.h>
33 
34 // #pragma GCC diagnostic ignored "-Wwrite-strings"
35 namespace
36 {
37  static inline std::ostream& operator<< (std::ostream& o, const n_coeffType& type)
38  {
39 #define CASE(A) case A: return o << (" " # A) << " ";
40  switch( type )
41  {
42  CASE(n_unknown);
43  CASE(n_Zp);
44  CASE(n_Q);
45  CASE(n_R);
46  CASE(n_GF);
47  CASE(n_long_R);
48  CASE(n_algExt);
50  CASE(n_long_C);
51  CASE(n_Z);
52  CASE(n_Zn);
53  CASE(n_Znm);
54  CASE(n_Z2m);
55  CASE(n_CF);
56  default: return o << "Unknown type: [" << (const unsigned long) type << "]";
57  }
58 #undef CASE
59  return o;
60  }
61 
62  template<typename T>
63  static inline std::string _2S(T i)
64  {
65  std::stringstream ss;
66  ss << i;
67 // std::string s = ss.str();
68  return ss.str();
69  }
70 
71 
72  static inline std::string _2S(number a, const coeffs r)
73  {
74  n_Test(a,r);
75  StringSetS("");
76  n_Write(a, r);
77 
78  std::stringstream ss;
79  {
80  char* s = StringEndS(); ss << s; omFree(s);
81  }
82 
83  return ss.str();
84 
85  }
86 
87  static inline void PrintSized(/*const*/ number a, const coeffs r, BOOLEAN eoln = TRUE)
88  {
89  std::clog << _2S(a, r) << ", of size: " << n_Size(a, r);
90 
91  if( eoln )
92  std::clog << std::endl;
93  }
94 
95 
96 
97 }
98 
100 {
101  std::ofstream _ofs;
102  bool _redirect;
103  public:
104  GlobalPrintingFixture(bool redirect = false): _redirect(redirect){}
105 
107  {
108  if( _ofs)
109  _ofs.close();
110  }
111 
112  void Redirect()
113  {
114  const int ll = strlen(argv0);
115  const int l = 5 + ll;
116  char* s = (char *)omAlloc0(l);
117  s = strncpy(s, argv0, ll);
118  strncpy(s + ll, ".log", 4);
119  _ofs.open(s); // , ios_base::out)
120  omFreeSize((ADDRESS)s, l);
121 
122  std::clog.rdbuf(_ofs.rdbuf());
123  }
124 
125  virtual bool setUpWorld()
126  {
127  if( _redirect )
128  Redirect();
129 
130  std::clog << std::endl << ( "<world>" ) << std::endl << std::endl;
131  feInitResources(argv0);
132 
133  StringSetS("ressources in use (as reported by feStringAppendResources(0):\n");
135 
136  { char* s = StringEndS(); PrintS(s); omFree(s); }
137 
138  return true;
139  }
140 
141  virtual bool tearDownWorld()
142  {
143  std::clog << std::endl << std::endl <<( "</world>" ) << std::endl << std::endl ;
144  return true;
145  }
146  virtual bool setUp() { std::clog << std::endl << std::endl <<( "<test>" ) << std::endl << std::endl; return true; }
147  virtual bool tearDown() { std::clog << std::endl << std::endl <<( "</test>" ) << std::endl << std::endl; return true; }
148 };
149 
150 
151 template void CxxTest::doAssertDiffers<n_Procs_s*, void*>(char const*, unsigned int, char const*, n_Procs_s*, char const*, void*, char const*);
152 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*);
153 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*);
154 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*);
155 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*);
156 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*);
157 template void CxxTest::doAssertEquals<int, int>(char const*, unsigned int, char const*, int, char const*, int, char const*);
158 template void CxxTest::doAssertEquals<n_coeffType, n_coeffType>(char const*, unsigned int, char const*, n_coeffType, char const*, n_coeffType, char const*);
159 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*);
160 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*);
161 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*);
162 
163 template bool CxxTest::differs<n_Procs_s*, void*>(n_Procs_s*, void*);
164 template bool CxxTest::differs<snumber* (*)(long, n_Procs_s*), void*>(snumber* (*)(long, n_Procs_s*), void*);
165 template bool CxxTest::differs<snumber* (*)(snumber*, snumber*, n_Procs_s*), void*>(snumber* (*)(snumber*, snumber*, n_Procs_s*), void*);
166 template bool CxxTest::differs<void (*)(n_Procs_s*, int), void*>(void (*)(n_Procs_s*, int), void*);
167 template bool CxxTest::differs<void (*)(snumber**, n_Procs_s*), void*>(void (*)(snumber**, n_Procs_s*), void*);
168 template bool CxxTest::differs<void (*)(snumber*&, n_Procs_s*), void*>(void (*)(snumber*&, n_Procs_s*), void*);
169 template bool CxxTest::equals<int, int>(int, int);
170 template bool CxxTest::equals<n_coeffType, n_coeffType>(n_coeffType, n_coeffType);
171 template bool CxxTest::equals<snumber* (*)(long, n_Procs_s*), snumber* (*)(long, n_Procs_s*)>(snumber* (*)(long, n_Procs_s*), snumber* (*)(long, n_Procs_s*));
172 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*));
173 template bool CxxTest::equals<void (*)(snumber**, n_Procs_s*), void (*)(snumber**, n_Procs_s*)>(void (*)(snumber**, n_Procs_s*), void (*)(snumber**, n_Procs_s*));
174 template char* CxxTest::numberToString<long>(long, char*, long, unsigned int, unsigned int);
175 
176 template void CxxTest::doAssertDiffers<ip_sring*, void*>(char const*, unsigned int, char const*, ip_sring*, char const*, void*, char const*);
177 template void CxxTest::doAssertEquals<short, int>(char const*, unsigned int, char const*, short, char const*, int, char const*);
178 
179 template bool CxxTest::differs<ip_sring*, void*>(ip_sring*, void*);
180 template bool CxxTest::equals<short, int>(short, int);
181 
182 #endif /* TESTS_COMMON_H */
#define CASE(A)
const const intvec const intvec const ring _currRing const const intvec const intvec const ring _currRing int
Definition: gb_hack.h:53
const CanonicalForm int s
Definition: facAbsFact.cc:55
const poly a
Definition: syzextra.cc:212
void feStringAppendResources(int warn)
Definition: reporter.cc:410
only used if HAVE_RINGS is defined: ?
Definition: coeffs.h:42
?
Definition: coeffs.h:45
'SR_INT' 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:44
used for all transcendental extensions, i.e., the top-most extension in an extension tower is transce...
Definition: coeffs.h:37
rational (GMP) numbers
Definition: coeffs.h:30
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
{p < 2^31}
Definition: coeffs.h:29
#define string
Definition: libparse.cc:1250
Definition: ring.h:203
#define TRUE
Definition: auxiliary.h:144
void * ADDRESS
Definition: auxiliary.h:161
void feInitResources(const char *argv0)
Definition: feResource.cc:164
char * StringEndS()
Definition: reporter.cc:151
real floating point (GMP) numbers
Definition: coeffs.h:33
virtual bool tearDown()
Definition: common.h:147
single prescision (6,6) real numbers
Definition: coeffs.h:31
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:43
#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:146
complex floating point (GMP) numbers
Definition: coeffs.h:40
static FORCE_INLINE void n_Write(number &n, const coeffs r, const BOOLEAN bShortOut=TRUE)
Definition: coeffs.h:590
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:918
All the auxiliary stuff.
only used if HAVE_RINGS is defined: ?
Definition: coeffs.h:41
int i
Definition: cfEzgcd.cc:123
void PrintS(const char *s)
Definition: reporter.cc:294
virtual bool tearDownWorld()
Definition: common.h:141
std::ofstream _ofs
Definition: common.h:101
n_coeffType
Definition: coeffs.h:26
virtual bool setUpWorld()
Definition: common.h:125
{p^n < 2^16}
Definition: coeffs.h:32
used for all algebraic extensions, i.e., the top-most extension in an extension tower is algebraic ...
Definition: coeffs.h:34
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:569
#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:104