Commit e0175492 by Szeberényi Imre

gtest_lite cmp w. NULL fix

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