File: Framework.cpp

package info (click to toggle)
hippomocks 5.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 672 kB
  • sloc: cpp: 7,791; ansic: 31; makefile: 28
file content (37 lines) | stat: -rw-r--r-- 1,193 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "Framework.h"

template <>
void check_equal(float a, float b, const char *sa, const char *sb) {
    if (a != b) throw BaseException("%s(%f) != %s(%f)", sa, a, sb, b);
}

template <>
void check_equal<const char *, const char *>(const char *a, const char *b, const char *sa, const char *sb) {
    if (strcmp(a, b) != 0) { throw BaseException("%s(%s) != %s(%s)", sa, a, sb, b); }
}

bool TestRegistry::RunTests() {
    char spinner[5] = "\\|/-";
    unsigned long i = 0, s = 0;
    size_t spinidx = 0;
    for (std::vector<Test *>::iterator it = tests.begin(); it != tests.end(); ++it) {
        Test *t = *it;
        i++;
        try {
            t->Run();
            s++;
        } catch (std::exception &e) {
            printf("Test %s failed with exception: %s\n", t->name.c_str(), e.what());
        } catch (int e) {
            printf("Test %s failed with error code: %d\n", t->name.c_str(), e);
        } catch (...) {
            printf("Test %s failed with ellipsis-caught error\n", t->name.c_str());
        }
        printf("%c\r", spinner[spinidx]);
        spinidx = (spinidx + 1) % 4;
    }
    printf("%lu of %lu tests successful\n", s, i);
    return !(s == i);
}