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 "config.h" |
---|
12 | |
---|
13 | #include <misc/auxiliary.h> |
---|
14 | #include <omalloc/omalloc.h> |
---|
15 | |
---|
16 | #include <coeffs/coeffs.h> |
---|
17 | #include <coeffs/numbers.h> |
---|
18 | |
---|
19 | #include <reporter/reporter.h> |
---|
20 | #include <resources/feResource.h> |
---|
21 | |
---|
22 | #ifndef PLURAL_INTERNAL_DECLARATIONS |
---|
23 | #define PLURAL_INTERNAL_DECLARATIONS |
---|
24 | #endif |
---|
25 | |
---|
26 | #ifndef PLURAL_INTERNAL_DECLARATIONS_GB_HACK |
---|
27 | #define PLURAL_INTERNAL_DECLARATIONS_GB_HACK |
---|
28 | #endif |
---|
29 | |
---|
30 | #include <polys/nc/gb_hack.h> |
---|
31 | |
---|
32 | #ifdef HAVE_FACTORY |
---|
33 | int initializeGMP(){ return 1; } // due to Factory... |
---|
34 | int mmInit(void) {return 1; } // ? due to SINGULAR!!!...??? |
---|
35 | #endif |
---|
36 | |
---|
37 | // #pragma GCC diagnostic ignored "-Wwrite-strings" |
---|
38 | namespace |
---|
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 | |
---|
102 | class 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 | |
---|
154 | #endif /* TESTS_COMMON_H */ |
---|