forked from alibaba/MNN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMNNTestSuite.h
96 lines (85 loc) · 1.76 KB
/
MNNTestSuite.h
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
89
90
91
92
93
94
95
96
//
// MNNTestSuite.h
// MNN
//
// Created by MNN on 2019/01/10.
// Copyright © 2018, Alibaba Group Holding Limited
//
#ifndef TEST_MNNTEST_H
#define TEST_MNNTEST_H
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
/** test case */
class MNNTestCase {
friend class MNNTestSuite;
public:
/**
* @brief deinitializer
*/
virtual ~MNNTestCase() = default;
/**
* @brief run test case
*/
virtual void run() = 0;
private:
/** case name */
std::string name;
};
/** test suite */
class MNNTestSuite {
public:
/**
* @brief deinitializer
*/
~MNNTestSuite();
/**
* @brief get shared instance
* @return shared instance
*/
static MNNTestSuite* get();
public:
/**
* @brief register runable test case
* @param test test case
* @param name case name
*/
void add(MNNTestCase* test, const char* name);
/**
* @brief run all registered test case
*/
static void runAll();
/**
* @brief run registered test case that matches in name
* @param name case name
*/
static void run(const char* name);
private:
/** get shared instance */
static MNNTestSuite* gInstance;
/** registered test cases */
std::vector<MNNTestCase*> mTests;
};
/**
static register for test case
*/
template <class Case>
class MNNTestRegister {
public:
/**
* @brief initializer. register test case to suite.
* @param name test case name
*/
MNNTestRegister(const char* name) {
MNNTestSuite::get()->add(new Case, name);
}
/**
* @brief deinitializer
*/
~MNNTestRegister() {
}
};
#define MNNTestSuiteRegister(Case, name) static MNNTestRegister<Case> __r##Case(name)
#endif