Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Prog2
/
ell_feladat
/
NHF
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
3d913675
authored
Apr 07, 2021
by
Szeberényi Imre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
typo + cmp w NULL fix
parent
52a4d0bd
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
77 additions
and
41 deletions
+77
-41
Test/Makefile
+1
-1
Test/gtest_lite.h
+59
-29
Test/memtrace.cpp
+16
-10
Test/memtrace.h
+1
-1
No files found.
Test/Makefile
View file @
3d913675
#
# Ehhez hasonlo makefile fut a JPORTA-n
#
# Masolja be a jportara feltoldendo fajlait ebbe a katalog
i
sba (2 db zip, és egy text)
# Masolja be a jportara feltoldendo fajlait ebbe a katalog
u
sba (2 db zip, és egy text)
#
# Zipek kicsomagolasa:
# make unpack
...
...
Test/gtest_lite.h
View file @
3d913675
...
...
@@ -9,7 +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 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.
...
...
@@ -187,7 +187,7 @@
/// https://cpptalk.wordpress.com/2009/09/12/substitution-failure-is-not-an-error-2
/// Használat:
/// CREATE_Has_(size)
/// ... if (Has_size<std::string>::member)...
/// ... if (
_
Has_size<std::string>::member)...
#define CREATE_Has_(X) \
template<typename T> struct _Has_##X { \
struct Fallback { int X; }; \
...
...
@@ -198,6 +198,14 @@ template<typename T> struct _Has_##X { \
static bool const member = sizeof(f<Derived>(0)) == 2; \
};
#define CREATE_Has_fn_(X, S) \
template<typename R, typename T> struct _Has_fn_##X##_##S { \
template<typename C, R (C::*f)() S> struct ChT; \
template<typename D> static char (&f(ChT<D, &D::X>*))[1]; \
template<typename D> static char (&f(...))[2]; \
static bool const fn = sizeof(f<T>(0)) == 1; \
};
/// Segédfüggvény egy publikus adattag, vagy tagfüggvény létezésének tesztelésére
/// fordítási időben
inline
void
hasMember
(...)
{}
...
...
@@ -256,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
:
...
...
@@ -271,9 +280,7 @@ public:
#ifdef MEMTRACE
ablocks
=
memtrace
::
allocated_blocks
();
#endif
#ifndef CPORTA
std
::
cerr
<<
"
\n
---> "
<<
name
<<
std
::
endl
;
#endif // CPORTA
os
<<
"
\n
---> "
<<
name
<<
std
::
endl
;
++
sum
;
}
/// Teszt vége
...
...
@@ -281,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
;
}
...
...
@@ -309,17 +317,20 @@ 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
;
}
/// 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
}
}
};
...
...
@@ -328,8 +339,8 @@ public:
static
Test
&
test
=
Test
::
getTest
();
/// általános sablon a várt értékhez.
template
<
typename
T
1
,
typename
T2
>
std
::
ostream
&
EXPECT_
(
T
1
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
...
...
@@ -337,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
T
1
,
typename
T2
>
std
::
ostream
&
EXPECT_
(
T
1
*
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
...
...
@@ -347,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
...
...
@@ -391,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
T
1
,
typename
T2
>
bool
eq
(
T
1
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
)
{
...
...
@@ -414,8 +433,8 @@ bool eqstrcase(const char *a, const char *b) {
}
template
<
typename
T
1
,
typename
T2
>
bool
ne
(
T
1
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
)
{
...
...
@@ -424,17 +443,17 @@ bool nestr(const char *a, const char *b) {
return
false
;
}
template
<
typename
T
1
,
typename
T2
>
bool
le
(
T
1
a
,
T2
b
)
{
return
a
<=
b
;
}
template
<
typename
T
>
bool
le
(
T
a
,
T
b
)
{
return
a
<=
b
;
}
template
<
typename
T
1
,
typename
T2
>
bool
lt
(
T
1
a
,
T2
b
)
{
return
a
<
b
;
}
template
<
typename
T
>
bool
lt
(
T
a
,
T
b
)
{
return
a
<
b
;
}
template
<
typename
T
1
,
typename
T2
>
bool
ge
(
T
1
a
,
T2
b
)
{
return
a
>=
b
;
}
template
<
typename
T
>
bool
ge
(
T
a
,
T
b
)
{
return
a
>=
b
;
}
template
<
typename
T
1
,
typename
T2
>
bool
gt
(
T
1
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
...
...
@@ -456,6 +475,17 @@ bool almostEQ(T a, T b) {
return
(
aa
-
ba
)
<
aa
*
eps
;
}
/// Segédsablon ostream átirányításához
/// A destruktor visszaállít
class
ostreamRedir
{
std
::
ostream
&
src
;
std
::
streambuf
*
const
save
;
public
:
ostreamRedir
(
std
::
ostream
&
src
,
std
::
ostream
&
dst
)
:
src
(
src
),
save
(
src
.
rdbuf
(
dst
.
rdbuf
()))
{}
~
ostreamRedir
()
{
src
.
rdbuf
(
save
);
}
};
}
// namespace gtest_lite
#endif // GTEST_LITE_H
Test/memtrace.cpp
View file @
3d913675
...
...
@@ -5,8 +5,9 @@ Keszitette: Peregi Tamas, BME IIT, 2011
Kanari: Szeberenyi Imre, 2013.
VS 2012: Szeberényi Imre, 2015.,
mem_dump: 2016.
meset felszabaditaskor: 2018.
me
m
set felszabaditaskor: 2018.
typo: 2019.
poi_check: 2021.
*********************************/
/*definialni kell, ha nem paracssorbol allitjuk be (-DMEMTRACE) */
...
...
@@ -178,7 +179,6 @@ START_NAMESPACE
dying
=
TRUE
;
exit
(
120
);
}
static
void
initialize
();
END_NAMESPACE
...
...
@@ -188,6 +188,7 @@ END_NAMESPACE
#ifdef MEMTRACE_TO_MEMORY
START_NAMESPACE
typedef
struct
_registry_item
{
void
*
p
;
/* mem pointer*/
size_t
size
;
/* size*/
...
...
@@ -197,6 +198,12 @@ START_NAMESPACE
static
registry_item
registry
;
/*sentinel*/
static
registry_item
*
find_registry_item
(
void
*
p
)
{
registry_item
*
n
=
&
registry
;
for
(;
n
->
next
&&
n
->
next
->
p
!=
p
;
n
=
n
->
next
);
return
n
;
}
static
void
print_registry_item
(
registry_item
*
p
)
{
if
(
p
)
{
print_registry_item
(
p
->
next
);
...
...
@@ -225,6 +232,13 @@ START_NAMESPACE
}
return
0
;
}
/* Ellenorzi, hogy a pointer regisztralt-e. Ha nem, akkor 0-val tér vissza */
int
poi_check
(
void
*
pu
)
{
if
(
pu
==
NULL
)
return
1
;
initialize
();
return
find_registry_item
(
P
(
pu
))
->
next
!=
NULL
;
}
END_NAMESPACE
#endif
/*MEMTRACE_TO_MEMORY*/
...
...
@@ -271,14 +285,6 @@ START_NAMESPACE
return
TRUE
;
}
#ifdef MEMTRACE_TO_MEMORY
static
registry_item
*
find_registry_item
(
void
*
p
)
{
registry_item
*
n
=
&
registry
;
for
(;
n
->
next
&&
n
->
next
->
p
!=
p
;
n
=
n
->
next
);
return
n
;
}
#endif
static
void
unregister_memory
(
void
*
p
,
call_t
call
)
{
initialize
();
#ifdef MEMTRACE_TO_FILE
...
...
Test/memtrace.h
View file @
3d913675
...
...
@@ -102,6 +102,7 @@ END_NAMESPACE
#if defined(MEMTRACE_TO_MEMORY)
START_NAMESPACE
int
mem_check
(
void
);
int
poi_check
(
void
*
);
END_NAMESPACE
#endif
...
...
@@ -191,7 +192,6 @@ START_NAMESPACE
void
mem_dump
(
void
const
*
mem
,
size_t
size
,
FILE
*
fp
=
stdout
);
END_NAMESPACE
#endif
/*MEMTRACE_C*/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment