File: utils.cpp

package info (click to toggle)
opentimelineio 0.18.1-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 23,480 kB
  • sloc: cpp: 163,182; python: 50,821; ansic: 6,470; makefile: 1,091; sh: 892; xml: 182; javascript: 2
file content (53 lines) | stat: -rw-r--r-- 1,037 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
// SPDX-License-Identifier: Apache-2.0
// Copyright Contributors to the OpenTimelineIO project

#include "utils.h"

#include <iostream>
#include <memory>

void
assertTrue(bool value)
{
    assert(value);
}

void
assertFalse(bool value)
{
    assert(!value);
}

void
Tests::add_test(std::string const& name, std::function<void(void)> const& test)
{
    _tests.push_back(std::make_pair(name, test));
}

void
Tests::run(int argc, char** argv)
{
    std::vector<std::string> filter;
    for (int arg = 1; arg < argc; ++arg)
    {
        filter.push_back(argv[arg]);
    }

    for (auto const& test: _tests)
    {
        bool run_test = true;
        if (!filter.empty())
        {
            const auto filter_it =
                std::find(filter.begin(), filter.end(), test.first);
            run_test = filter_it != filter.end();
        }

        std::cout << (run_test ? "Running" : "Skipping") << " test "
                  << test.first << std::endl;
        if (run_test)
        {
            test.second();
        }
    }
}