Commit e0175492 by Szeberényi Imre

gtest_lite cmp w. NULL fix

parent becdcbee
......@@ -9,8 +9,7 @@
* Sz.I. 2018 (template), ENDM, ENDMsg, nullptr_t
* Sz.I. 2019 singleton
* Sz.I. 2021 ASSERT.., STRCASE...
* Sz.I. 2021 EXPEXT_REGEXP
* Sz.I. 2021 CREATE_Has_fn_
* Sz.I. 2021 EXPEXT_REGEXP, CREATE_Has_fn_, cmp w. NULL
*
* A tesztelés legalapvetőbb funkcióit támogató függvények és makrók.
* Nem szálbiztos megvalósítás.
......@@ -265,12 +264,13 @@ struct Test {
bool tmp; ///< temp a kivételkezeléshez;
std::string name; ///< éppen futó teszt neve
std::fstream null; ///< nyelő, ha nem kell kiírni semmit
std::ostream& os; ///< ide írunk
static Test& getTest() {
static Test instance;///< egyedüli (singleton) példány
return instance;
}
private: /// singleton minta miatt
Test() :sum(0), failed(0), status(false), null("/dev/null") {}
Test() :sum(0), failed(0), status(false), null("/dev/null"), os(std::cout) {}
Test(const Test&);
void operator=(const Test&);
public:
......@@ -280,11 +280,7 @@ public:
#ifdef MEMTRACE
ablocks = memtrace::allocated_blocks();
#endif
#ifndef CPORTA
std::cerr << "\n---> " << name << std::endl;
#else
std::cout << "\n---> " << name << std::endl;
#endif // CPORTA
os << "\n---> " << name << std::endl;
++sum;
}
/// Teszt vége
......@@ -292,15 +288,16 @@ public:
#ifdef MEMTRACE
if (memchk && ablocks != memtrace::allocated_blocks()) {
status = false;
return std::cerr << "** Lehet, hogy nem szabaditott fel minden memoriat! **" << std::endl;
return os << "** Lehet, hogy nem szabaditott fel minden memoriat! **" << std::endl;
}
#endif
os << (status ? " SIKERES" : "** HIBAS ****") << "\t" << name << " <---" << std::endl;
#ifdef CPORTA
if (!status)
#endif // CPORTA
std::cerr << (status ? " SIKERES" : "** HIBAS ****") << "\t" << name << " <---" << std::endl;
#endif // CPORTA
if (!status)
return std::cerr;
return os;
else
return null;
}
......@@ -320,7 +317,7 @@ public:
size_t i = str.rfind("\\");
if (i == std::string::npos) i = str.rfind("/");
if (i == std::string::npos) i = 0; else i++;
return std::cerr << "\n**** " << &file[i] << "(" << line << "): " << expr << " ****" << std::endl;
return os << "\n**** " << &file[i] << "(" << line << "): " << expr << " ****" << std::endl;
}
return null;
}
......@@ -328,10 +325,11 @@ public:
/// Destruktor
~Test() {
if (sum != 0) {
os << "\n==== TESZT VEGE ==== HIBAS/OSSZES: " << failed << "/" << sum << std::endl;
#ifdef CPORTA
if (failed)
#endif // CPORTA
std::cerr << "\n==== TESZT VEGE ==== HIBAS/OSSZES: " << failed << "/" << sum << std::endl;
#endif // CPORTA
}
}
};
......@@ -341,8 +339,8 @@ public:
static Test& test = Test::getTest();
/// általános sablon a várt értékhez.
template <typename T1, typename T2>
std::ostream& EXPECT_(T1 exp, T2 act, bool (*pred)(T1, T2), const char *file, int line,
template <typename T>
std::ostream& EXPECT_(T exp, T act, bool (*pred)(T, T), const char *file, int line,
const char *expr, const char *lhs = "elvart", const char *rhs = "aktual") {
return test.expect(pred(exp, act), file, line, expr)
<< "** " << lhs << ": " << std::boolalpha << exp
......@@ -350,8 +348,8 @@ std::ostream& EXPECT_(T1 exp, T2 act, bool (*pred)(T1, T2), const char *file, in
}
/// pointerre specializált sablon a várt értékhez.
template <typename T1, typename T2>
std::ostream& EXPECT_(T1* exp, T2* act, bool (*pred)(T1*, T2*), const char *file, int line,
template <typename T>
std::ostream& EXPECT_(T* exp, T* act, bool (*pred)(T*, T*), const char *file, int line,
const char *expr, const char *lhs = "elvart", const char *rhs = "aktual") {
return test.expect(pred(exp, act), file, line, expr)
<< "** " << lhs << ": " << (void*) exp
......@@ -360,8 +358,16 @@ std::ostream& EXPECT_(T1* exp, T2* act, bool (*pred)(T1*, T2*), const char *file
#if __cplusplus >= 201103L
/// nullptr-re specializált sablon a várt értékhez.
template <typename T1>
std::ostream& EXPECT_(T1* exp, std::nullptr_t act, bool (*pred)(T1*, std::nullptr_t), const char *file, int line,
template <typename T>
std::ostream& EXPECT_(std::nullptr_t exp, T* act, bool (*pred)(T*, T*), const char *file, int line,
const char *expr, const char *lhs = "elvart", const char *rhs = "aktual") {
return test.expect(pred(exp, act), file, line, expr)
<< "** " << lhs << ": " << (void*) exp
<< "\n** " << rhs << ": " << (void*) act << std::endl;
}
template <typename T>
std::ostream& EXPECT_(T* exp, std::nullptr_t act, bool (*pred)(T*, T*), const char *file, int line,
const char *expr, const char *lhs = "elvart", const char *rhs = "aktual") {
return test.expect(pred(exp, act), file, line, expr)
<< "** " << lhs << ": " << (void*) exp
......@@ -404,8 +410,8 @@ std::ostream& EXPECTREGEXP(E exp, S str, int match, const char *err, const char
/// segéd sablonok a relációkhoz.
/// azért nem STL (algorithm), mert csak a függvény lehet, hogy menjen a deduckció
template <typename T1, typename T2>
bool eq(T1 a, T2 b) { return a == b; }
template <typename T>
bool eq(T a, T b) { return a == b; }
inline
bool eqstr(const char *a, const char *b) {
......@@ -427,8 +433,8 @@ bool eqstrcase(const char *a, const char *b) {
}
template <typename T1, typename T2>
bool ne(T1 a, T2 b) { return a != b; }
template <typename T>
bool ne(T a, T b) { return a != b; }
inline
bool nestr(const char *a, const char *b) {
......@@ -437,17 +443,17 @@ bool nestr(const char *a, const char *b) {
return false;
}
template <typename T1, typename T2>
bool le(T1 a, T2 b) { return a <= b; }
template <typename T>
bool le(T a, T b) { return a <= b; }
template <typename T1, typename T2>
bool lt(T1 a, T2 b) { return a < b; }
template <typename T>
bool lt(T a, T b) { return a < b; }
template <typename T1, typename T2>
bool ge(T1 a, T2 b) { return a >= b; }
template <typename T>
bool ge(T a, T b) { return a >= b; }
template <typename T1, typename T2>
bool gt(T1 a, T2 b) { return a > b; }
template <typename T>
bool gt(T a, T b) { return a > b; }
/// Segédsablon valós számok összehasonlításához
/// Nem bombabiztos, de nekünk most jó lesz
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment