source: git/libpolys/tests/common.h @ 405407

spielwiese
Last change on this file since 405407 was dc4782, checked in by Hans Schoenemann <hannes@…>, 10 years ago
chg: factory/libfac is not optional, removing HAVE_FACTORY/HAVE_LIBFAC
  • Property mode set to 100644
File size: 7.2 KB
Line 
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#ifdef HAVE_CONFIG_H
12#include "libpolysconfig.h"
13#endif /* HAVE_CONFIG_H */
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
34int initializeGMP(){ return 1; } // due to Factory...
35int mmInit(void) {return 1; } // ? due to SINGULAR!!!...???
36
37// #pragma GCC diagnostic ignored "-Wwrite-strings"
38namespace
39{
40  static inline std::ostream& operator<< (std::ostream& o, const n_coeffType& type)
41  {
42#define CASE(A) case A: return o << (" " # A) << " ";
43    switch( type )
44    {
45      CASE(n_unknown);
46      CASE(n_Zp);
47      CASE(n_Q);
48      CASE(n_R);
49      CASE(n_GF);
50      CASE(n_long_R);
51      CASE(n_algExt);
52      CASE(n_transExt);
53      CASE(n_long_C);
54      CASE(n_Z);
55      CASE(n_Zn);
56      CASE(n_Znm);
57      CASE(n_Z2m);
58      CASE(n_CF);
59      default: return o << "Unknown type: [" << (const unsigned long) type << "]";
60    }
61#undef CASE
62    return o;
63  }
64
65  template<typename T>
66      static inline std::string _2S(T i)
67  {
68    std::stringstream ss;
69    ss << i;
70//    std::string s = ss.str();
71    return ss.str();
72  }
73
74
75  static inline std::string _2S(number a, const coeffs r)
76  {
77    n_Test(a,r);
78    StringSetS("");
79    n_Write(a, r);
80
81    std::stringstream ss; 
82    {
83      char* s = StringEndS();  ss << s; omFree(s); 
84    }
85
86    return ss.str();
87
88  }
89
90  static inline void PrintSized(/*const*/ number a, const coeffs r, BOOLEAN eoln = TRUE)
91  {
92    std::clog << _2S(a, r) << ", of size: " << n_Size(a, r);
93
94    if( eoln )
95      std::clog << std::endl;
96  }
97
98
99
100}
101
102class GlobalPrintingFixture : public CxxTest::GlobalFixture
103{
104   std::ofstream _ofs;
105   bool _redirect;
106  public:
107    GlobalPrintingFixture(bool redirect = false): _redirect(redirect){}
108
109    ~GlobalPrintingFixture()
110    {
111      if( _ofs)
112        _ofs.close();
113    }
114
115    void Redirect()
116    {
117      const int ll = strlen(argv0);
118      const int l = 5 + ll;
119      char* s = (char *)omAlloc0(l);
120      s = strncpy(s, argv0, ll);
121      strncpy(s + ll, ".log", 4);
122      _ofs.open(s); // , ios_base::out)
123      omFreeSize((ADDRESS)s, l);
124
125      std::clog.rdbuf(_ofs.rdbuf());
126    }
127
128    virtual bool setUpWorld()
129    {
130      if( _redirect )
131        Redirect();
132
133      std::clog << std::endl << ( "<world>" ) << std::endl << std::endl;
134      feInitResources(argv0);
135
136      StringSetS("ressources in use (as reported by feStringAppendResources(0):\n");
137      feStringAppendResources(0);
138       
139      { char* s = StringEndS(); PrintS(s); omFree(s); }
140       
141      return true;
142    }
143
144    virtual bool tearDownWorld()
145    {
146        std::clog << std::endl << std::endl <<( "</world>" )  << std::endl  << std::endl ;
147        return true;
148    }
149    virtual bool setUp() { std::clog << std::endl << std::endl <<( "<test>" ) << std::endl  << std::endl; return true; }
150    virtual bool tearDown() { std::clog << std::endl << std::endl <<( "</test>" ) << std::endl  << std::endl; return true; }
151};
152
153
154template void CxxTest::doAssertDiffers<n_Procs_s*, void*>(char const*, unsigned int, char const*, n_Procs_s*, char const*, void*, char const*);
155template 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*);
156template 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*);
157template 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*);
158template 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*);
159template 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*);
160template void CxxTest::doAssertEquals<int, int>(char const*, unsigned int, char const*, int, char const*, int, char const*);
161template void CxxTest::doAssertEquals<n_coeffType, n_coeffType>(char const*, unsigned int, char const*, n_coeffType, char const*, n_coeffType, char const*);
162template 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*);
163template 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*);
164template 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*);
165
166template bool CxxTest::differs<n_Procs_s*, void*>(n_Procs_s*, void*);
167template bool CxxTest::differs<snumber* (*)(long, n_Procs_s*), void*>(snumber* (*)(long, n_Procs_s*), void*);
168template bool CxxTest::differs<snumber* (*)(snumber*, snumber*, n_Procs_s*), void*>(snumber* (*)(snumber*, snumber*, n_Procs_s*), void*);
169template bool CxxTest::differs<void (*)(n_Procs_s*, int), void*>(void (*)(n_Procs_s*, int), void*);
170template bool CxxTest::differs<void (*)(snumber**, n_Procs_s*), void*>(void (*)(snumber**, n_Procs_s*), void*);
171template bool CxxTest::differs<void (*)(snumber*&, n_Procs_s*), void*>(void (*)(snumber*&, n_Procs_s*), void*);
172template bool CxxTest::equals<int, int>(int, int);
173template bool CxxTest::equals<n_coeffType, n_coeffType>(n_coeffType, n_coeffType);
174template bool CxxTest::equals<snumber* (*)(long, n_Procs_s*), snumber* (*)(long, n_Procs_s*)>(snumber* (*)(long, n_Procs_s*), snumber* (*)(long, n_Procs_s*));
175template 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*));
176template bool CxxTest::equals<void (*)(snumber**, n_Procs_s*), void (*)(snumber**, n_Procs_s*)>(void (*)(snumber**, n_Procs_s*), void (*)(snumber**, n_Procs_s*));
177template char* CxxTest::numberToString<long>(long, char*, long, unsigned int, unsigned int);
178
179template void CxxTest::doAssertDiffers<ip_sring*, void*>(char const*, unsigned int, char const*, ip_sring*, char const*, void*, char const*);
180template void CxxTest::doAssertEquals<short, int>(char const*, unsigned int, char const*, short, char const*, int, char const*);
181
182template bool CxxTest::differs<ip_sring*, void*>(ip_sring*, void*);
183template bool CxxTest::equals<short, int>(short, int);
184
185#endif /* TESTS_COMMON_H */
Note: See TracBrowser for help on using the repository browser.