File: testutil.hpp

package info (click to toggle)
python-nixio 1.5.4%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,888 kB
  • sloc: python: 12,527; cpp: 832; makefile: 25
file content (88 lines) | stat: -rw-r--r-- 2,208 bytes parent folder | download
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <iostream>
#include <string>
#include <boost/optional.hpp>
#include <nix.hpp>


int compare(const std::string &a, const std::string &b) {
    if (a != b) {
        std::cout << "Expected '" << a << "' got '" << b << "'" << std::endl;
        return 1;
    }
    return 0;
}

int compare(const std::vector<std::string> &a, const std::vector<std::string> &b) {
    if (a != b) {
        std::cout << "Mismatch in string vectors" << std::endl;
        std::cout << "Expected {";
        for (const auto& i : a) {
            std::cout << i << " ";
        }
        std::cout << "} got {";
        for (const auto& i : b) {
            std::cout << i << " ";

        }
        std::cout << "}" << std::endl;
        return 1;
    }
    return 0;
}

template <typename T>
int compare(const T a, const T b) {
    if (a != b) {
        std::cout << "Expected '" << a << "' got '" << b << "'" << std::endl;
        return 1;
    }
    return 0;
}

template <typename T>
int compare(const std::string &a, boost::optional<T> b) {
    return compare(a, nix::util::deRef(b));
}

template <typename T>
int compare(const std::vector<T> &a, const std::vector<T> &b, std::string name = "") {
    if (a != b) {
        std::cout << "Mismatch in data vectors";
        if (name != "") {
            std::cout << " (name: " << name << ")";
        }
        std::cout << std::endl;
        std::cout << "Expected {";
        for (const auto& i : a) {
            std::cout << i << " ";
        }
        std::cout << "} got {";
        for (const auto& i : b) {
            std::cout << i << " ";

        }
        std::cout << "}" << std::endl;
        return 1;
    }
    return 0;
}

int compare(const nix::NDSize &a, const nix::NDSize &b, std::string name = "") {
    if (a != b) {
        std::cout << "Mismatch in data extents";
        if (name != "") {
            std::cout << " (name: " << name << ")";
        }
        std::cout << std::endl;
        std::cout << "Exp " << a << "Got " << b << std::endl;
        return 1;
    }
    return 0;
}

int testassert(bool cond, std::string message = "") {
    if (!cond && message != "") {
        std::cout << message << std::endl;
    }
    return !cond;
}