source: trunk/UNIT_TESTER/test_helpers.h

Last change on this file was 19339, checked in by westram, 22 months ago
  • reintegrates 'refactor' into 'trunk'
    • eliminates old interface of GBS_strstruct
    • add a few new unittests (editor-config string + some PT-SERVER-functions)
  • adds: log:branches/refactor@19300:19338
File size: 1.8 KB
Line 
1// ============================================================= //
2//                                                               //
3//   File      : test_helpers.h                                  //
4//   Purpose   :                                                 //
5//                                                               //
6//   Coded by Ralf Westram (coder@reallysoft.de) in March 2011   //
7//   Institute of Microbiology (Technical University Munich)     //
8//   http://www.arb-home.de/                                     //
9//                                                               //
10// ============================================================= //
11
12#ifndef TEST_HELPERS_H
13#define TEST_HELPERS_H
14
15#ifndef ARB_STRBUF_H
16#include <arb_strbuf.h>
17#endif
18
19template<typename FUN>
20inline void streamIntFunResults(GBS_strstruct& out, FUN fun, int start, int end, int width) {
21    for (int i = start; i <= end; ++i) {
22        int res = fun(i);
23        out.nprintf(20, "%*i", width, res);
24    }
25}
26template<typename FUN>
27inline void streamIntFunResultsInBrackets(GBS_strstruct& out, FUN fun, int start, int end, int width) {
28    for (int i = start; i <= end; ++i) {
29        int  res = fun(i);
30        char buffer[30];
31        sprintf(buffer, "[%i]", res);
32        out.nprintf(30, "%*s", width+2, buffer);
33    }
34}
35
36template<typename FUN>
37inline char *collectIntFunResults(FUN fun, int start, int end, int width, int try_underflow, int try_overflow) {
38    GBS_strstruct out(1000);
39    if (try_underflow) streamIntFunResultsInBrackets(out, fun, start-try_underflow, start-1, width);
40    streamIntFunResults(out, fun, start, end, width);
41    if (try_overflow) streamIntFunResultsInBrackets(out, fun, end+1, end+try_overflow, width);
42    return out.release();
43}
44
45#else
46#error test_helpers.h included twice
47#endif // TEST_HELPERS_H
Note: See TracBrowser for help on using the repository browser.