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

spielwiese
Last change on this file since 141342 was 141342, checked in by Frank Seelisch <seelisch@…>, 13 years ago
nExt replaced by n_algExt and n_transExt
  • Property mode set to 100644
File size: 3.0 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#include <omalloc/omalloc.h>
12#include <misc/auxiliary.h>
13
14#include <coeffs/coeffs.h>
15#include <coeffs/numbers.h>
16
17#include <reporter/reporter.h>
18#include <resources/feResource.h>
19
20#ifdef HAVE_FACTORY
21int initializeGMP(){ return 1; }
22#endif
23
24// #pragma GCC diagnostic ignored "-Wwrite-strings"
25namespace
26{
27  static inline std::ostream& operator<< (std::ostream& o, const n_coeffType& type)
28  {
29#define CASE(A) case A: return o << (" " # A) << " ";
30    switch( type )
31    {
32      CASE(n_unknown);
33      CASE(n_Zp);
34      CASE(n_Q);
35      CASE(n_R);
36      CASE(n_GF);
37      CASE(n_long_R);
38      CASE(n_algExt);
39      CASE(n_transExt);
40      CASE(n_long_C);
41      CASE(n_Z);
42      CASE(n_Zn);
43      CASE(n_Zpn);
44      CASE(n_Z2m);
45      CASE(n_CF);
46      default: return o << "Unknown type: [" << (const unsigned long) type << "]"; 
47    }   
48#undef CASE
49    return o;
50  }
51
52  template<typename T>
53      static inline std::string _2S(T i)
54  {
55    std::stringstream ss;
56    ss << i;
57//    std::string s = ss.str();
58    return ss.str();
59  }
60
61
62  static inline std::string _2S(number a, const coeffs r)
63  {
64    n_Test(a,r);
65    StringSetS(""); 
66    n_Write(a, r);
67
68    const char* s = StringAppendS("");
69
70    std::stringstream ss;  ss << s;
71
72    StringSetS(""); 
73    return ss.str();
74
75  }
76
77  static inline void PrintSized(/*const*/ number a, const coeffs r, BOOLEAN eoln = TRUE)
78  {
79    std::clog << _2S(a, r) << ", of size: " << n_Size(a, r);
80
81    if( eoln ) 
82      std::clog << std::endl; 
83  }
84
85
86
87}
88
89class GlobalPrintingFixture : public CxxTest::GlobalFixture
90{
91   std::ofstream _ofs;
92   bool _redirect;
93  public:
94    GlobalPrintingFixture(bool redirect = false): _redirect(redirect){}
95   
96    ~GlobalPrintingFixture()
97    {
98      if( _ofs)
99        _ofs.close();
100    }
101   
102    void Redirect()
103    {
104      const int ll = strlen(argv0);
105      const int l = 5 + ll;
106      char* s = (char *)omAlloc0(l);
107      s = strncpy(s, argv0, ll);
108      strncpy(s + ll, ".log", 4);
109      _ofs.open(s); // , ios_base::out)
110      omFreeSize((ADDRESS)s, l);
111
112      std::clog.rdbuf(_ofs.rdbuf());
113    }
114
115    virtual bool setUpWorld() 
116    {
117      if( _redirect )
118        Redirect();
119
120      std::clog << std::endl << ( "<world>" ) << std::endl << std::endl;
121      feInitResources(argv0);
122
123      StringSetS("ressources in use (as reported by feStringAppendResources(0):\n");
124      feStringAppendResources(0);
125      PrintS(StringAppendS("\n"));
126     
127      return true;
128    }
129
130    virtual bool tearDownWorld() 
131    {
132        std::clog << std::endl << std::endl <<( "</world>" )  << std::endl  << std::endl ; 
133        return true; 
134    }
135    virtual bool setUp() { std::clog << std::endl << std::endl <<( "<test>" ) << std::endl  << std::endl; return true; }
136    virtual bool tearDown() { std::clog << std::endl << std::endl <<( "</test>" ) << std::endl  << std::endl; return true; }
137};
138
139
140#endif /* TESTS_COMMON_H */
Note: See TracBrowser for help on using the repository browser.