File: domTest.h

package info (click to toggle)
collada-dom 2.4.4%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 17,096 kB
  • sloc: cpp: 156,849; php: 4,567; makefile: 38; sh: 32; python: 14
file content (90 lines) | stat: -rw-r--r-- 2,650 bytes parent folder | download | duplicates (3)
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
/*
* Copyright 2006 Sony Computer Entertainment Inc.
*
* Licensed under the MIT Open Source License, for details please see license.txt or the website
* http://www.opensource.org/licenses/mit-license.php
*
*/ 
#ifndef domTest_h
#define domTest_h

#include <map>
#include <string>

// We use the boost filesystem library for cross-platform file system support. You'll need
// to have boost on your machine for this to work. For the Windows build boost is provided
// in the external-libs folder, but for Linux it's expected that you'll install a boost
// obtained via your distro's package manager. For example on Debian/Ubuntu, you can run
//   apt-get install libboost-filesystem-dev
// to install the boost filesystem library on your machine.
//
// Disable the warnings we get from Boost
// warning C4180: qualifier applied to function type has no meaning; ignored
// warning C4245: 'argument' : conversion from 'int' to 'boost::filesystem::system_error_type', 
//   signed/unsigned mismatch
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4180 4245)
#endif
#include <boost/filesystem/convenience.hpp>
#ifdef _MSC_VER
#pragma warning(pop)
#endif

struct domTest;
std::map<std::string, domTest*>& registeredTests();
boost::filesystem::path& dataPath();
boost::filesystem::path& tmpPath();

struct testResult {
	bool passed;
	std::string file; // If the test failed, the file it failed in.
	int line; // If the test failed, the line number it failed on, or -1 if the line
	          // number isn't available.
	std::string msg; // An error message for the user. Usually empty.

	testResult() : passed(true), line(-1) { }
	testResult(bool passed, const std::string& file = "", int line = -1, const std::string& msg = "")
	  : passed(passed),
			file(file),
	    line(line),
	    msg(msg) {
	}
};

struct domTest {
	std::string name;
	domTest(const std::string& name) : name(name) {
		registeredTests()[name] = this;
	}
	virtual ~domTest() { };
	virtual testResult run() = 0;
};

#define DefineTest(testName) \
	struct domTest_##testName : public domTest { \
		domTest_##testName() : domTest(#testName) { } \
		testResult run();	\
	}; \
	domTest_##testName domTest_##testName##Obj; \
	testResult domTest_##testName::run()

#define CheckResult(val) \
	if (!(val)) { \
		return testResult(false, __FILE__, __LINE__); \
	}

#define CheckTestResult(result) \
	{ \
		testResult res = result; \
		if (!res.passed) \
			return res; \
	}

#define SafeAdd(elt, name, var) \
	daeElement* var = elt->add(name); CheckResult(var);

std::string lookupTestFile(const std::string& fileName);
std::string getTmpFile(const std::string& fileName);

#endif