All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
regTest.h
Go to the documentation of this file.
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_BASE_TF_REG_TEST_H
8#define PXR_BASE_TF_REG_TEST_H
9
13
14#include "pxr/pxr.h"
15
16#include "pxr/base/tf/api.h"
18#include "pxr/base/tf/hash.h"
19#include "pxr/base/tf/hashmap.h"
20#include <string>
21
22PXR_NAMESPACE_OPEN_SCOPE
23
72class TfRegTest {
73public:
89 static int Main(int argc, char *argv[]) {
90 return GetInstance()._Main(argc, argv);
91 }
92
93 TF_API
94 static TfRegTest& GetInstance();
95
97 typedef bool (*RegFunc)();
98
104 typedef bool (*RegFuncWithArgs)(int argc, char *argv[]);
105
106 TF_API
107 bool Register(const char* name, RegFunc);
108 TF_API
109 bool Register(const char* name, RegFuncWithArgs);
110
111private:
112 friend class TfSingleton<TfRegTest>;
113 TF_API
114 int _Main(int argc, char *argv[]);
115
116 void _PrintTestNames();
117
118 typedef TfHashMap<std::string, RegFunc, TfHash> _Hash;
119 typedef TfHashMap<std::string, RegFuncWithArgs, TfHash> _HashWithArgs;
120 _Hash _functionTable;
121 _HashWithArgs _functionTableWithArgs;
122};
123
124TF_API_TEMPLATE_CLASS(TfSingleton<TfRegTest>);
125
132#define TF_ADD_REGTEST(name) \
133 bool Tf_RegTst##name = TfRegTest::GetInstance().Register(#name, Test_##name)
134
135PXR_NAMESPACE_CLOSE_SCOPE
136
137#endif
TfRegTest is a singleton class, which is used to register functions with either type bool (*)(int,...
Definition: regTest.h:72
static int Main(int argc, char *argv[])
Run a single regression test function, returning 0 if the function succeeded and 1 otherwise.
Definition: regTest.h:89
bool(* RegFunc)()
Type of a function with no arguments.
Definition: regTest.h:97
bool(* RegFuncWithArgs)(int argc, char *argv[])
Type of a function with arguments.
Definition: regTest.h:104
Manage a single instance of an object (see.
Definition: singleton.h:105
Manage a single instance of an object.