Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
CTA-LAPP
PHOENIX_LIBS
PhoenixNotify
Commits
7f258799
Commit
7f258799
authored
Jan 05, 2021
by
Pierre Aubert
Browse files
Add print test
parent
a6efb0f6
Pipeline
#98200
passed with stages
in 1 minute and 28 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
163 additions
and
16 deletions
+163
-16
TESTS/CMakeLists.txt
TESTS/CMakeLists.txt
+1
-0
TESTS/TEST_PRINT_NOTIFY/CMakeLists.txt
TESTS/TEST_PRINT_NOTIFY/CMakeLists.txt
+12
-0
TESTS/TEST_PRINT_NOTIFY/main.cpp
TESTS/TEST_PRINT_NOTIFY/main.cpp
+124
-0
src/PNotify.cpp
src/PNotify.cpp
+24
-16
src/PNotify.h
src/PNotify.h
+2
-0
No files found.
TESTS/CMakeLists.txt
View file @
7f258799
...
...
@@ -3,4 +3,5 @@ cmake_minimum_required(VERSION 2.8)
add_subdirectory
(
TEST_BASE_NOTIFY
)
add_subdirectory
(
TEST_BASE_NOTIFY_2
)
add_subdirectory
(
TEST_PRINT_NOTIFY
)
TESTS/TEST_PRINT_NOTIFY/CMakeLists.txt
0 → 100644
View file @
7f258799
project
(
Phoenix
)
cmake_minimum_required
(
VERSION 2.8
)
add_definitions
(
-DCURRENT_TEST_DIR=
"
${
CMAKE_CURRENT_BINARY_DIR
}
"
)
add_executable
(
test_print_notify main.cpp
)
target_link_libraries
(
test_print_notify phoenix_notify pthread
)
add_test
(
NAME TestPrintNotify
COMMAND
${
CMAKE_CURRENT_BINARY_DIR
}
/test_print_notify
)
TESTS/TEST_PRINT_NOTIFY/main.cpp
0 → 100644
View file @
7f258799
/***************************************
Auteur : Pierre Aubert
Mail : aubertp7@gmail.com
Licence : CeCILL-C
****************************************/
#include <unistd.h>
#include <sys/stat.h>
#include <thread>
#include <fstream>
#include <sstream>
#include <iostream>
#include "PNotify.h"
///Test the PNotify
/** @param[out] b : true on success, false otherwise
*/
void
testPNotify
(
bool
&
b
,
const
std
::
string
&
inputDir
){
b
=
true
;
PNotify
notify
;
notify
.
setFlags
(
IN_NONBLOCK
);
notify
.
resize
(
100lu
);
//Let's have 100 files in buffer
notify
.
addWatch
(
inputDir
,
IN_ALL_EVENTS
);
notify
.
resize
(
100lu
);
//Useless resize for coverage
std
::
cout
<<
"testPNotify : nbMaxEvent = "
<<
notify
.
getMaxEvent
()
<<
std
::
endl
;
size_t
nbCheck
(
10lu
);
for
(
size_t
i
(
0lu
);
i
<
nbCheck
;
++
i
){
PVecPtrNotifyEvent
vecEvent
(
notify
.
scanEvent
());
std
::
cout
<<
"testPNotify check "
<<
i
<<
" : find "
<<
vecEvent
.
size
()
<<
" new events"
<<
std
::
endl
;
if
(
vecEvent
.
size
()
!=
0lu
){
for
(
PVecPtrNotifyEvent
::
iterator
it
(
vecEvent
.
begin
());
it
!=
vecEvent
.
end
();
++
it
){
pnotify_printEvent
(
*
it
);
}
}
usleep
(
800000
);
}
}
///Create test file in the input directory
/** @param inputDir : create files in the given directory
*/
void
testCreateFile
(
const
std
::
string
&
inputDir
){
size_t
nbFile
(
10lu
);
for
(
size_t
i
(
0lu
);
i
<
nbFile
;
++
i
){
std
::
stringstream
fileName
;
fileName
<<
inputDir
<<
"/file_"
<<
i
<<
".txt"
;
std
::
ofstream
fs
;
fs
.
open
(
fileName
.
str
());
if
(
fs
.
is_open
()){
fs
<<
"Some text for file "
<<
i
<<
std
::
endl
;
}
usleep
(
250000
);
}
//Let's rewrite
for
(
size_t
i
(
0lu
);
i
<
nbFile
;
++
i
){
std
::
stringstream
fileName
;
fileName
<<
inputDir
<<
"/file_"
<<
i
<<
".txt"
;
std
::
ofstream
fs
;
fs
.
open
(
fileName
.
str
());
if
(
fs
.
is_open
()){
fs
<<
"Some text for file "
<<
i
<<
" again"
<<
std
::
endl
;
}
usleep
(
250000
);
}
//Let's read
for
(
size_t
i
(
0lu
);
i
<
nbFile
;
++
i
){
std
::
stringstream
fileName
;
fileName
<<
inputDir
<<
"/file_"
<<
i
<<
".txt"
;
std
::
ifstream
fs
;
fs
.
open
(
fileName
.
str
());
if
(
fs
.
is_open
()){
std
::
string
content
;
fs
>>
content
;
std
::
cout
<<
"File "
<<
i
<<
", content = "
<<
content
<<
std
::
endl
;
}
usleep
(
250000
);
}
//Let's remove
for
(
size_t
i
(
0lu
);
i
<
nbFile
;
++
i
){
std
::
stringstream
fileName
;
fileName
<<
inputDir
<<
"/file_"
<<
i
<<
".txt"
;
remove
(
fileName
.
str
().
c_str
());
usleep
(
250000
);
}
}
int
main
(
int
argc
,
char
**
argv
){
std
::
string
inputDir
(
CURRENT_TEST_DIR
);
bool
okThreadPNotify
(
true
);
std
::
thread
thrRecv0
(
testPNotify
,
std
::
ref
(
okThreadPNotify
),
inputDir
);
std
::
thread
thrSend
(
testCreateFile
,
inputDir
);
thrRecv0
.
join
();
thrSend
.
join
();
std
::
cout
<<
"main : okThreadPNotify : "
<<
okThreadPNotify
<<
std
::
endl
;
bool
b
(
okThreadPNotify
);
return
b
-
1
;
}
src/PNotify.cpp
View file @
7f258799
...
...
@@ -105,6 +105,14 @@ bool pnotify_isMovedFrom(PNotifyEvent * event){
return
event
->
mask
&
IN_MOVED_FROM
;
}
///Check mask of event
/** @param event : event to be checked
* @return true if the flag correspond to the expected one
*/
bool
pnotify_isMovedTo
(
PNotifyEvent
*
event
){
return
event
->
mask
&
IN_MOVED_TO
;
}
///Check mask of event
/** @param event : event to be checked
* @return true if the flag correspond to the expected one
...
...
@@ -138,22 +146,22 @@ void pnotify_printEvent(PNotifyEvent * event){
printf
(
"cookie =%4d; "
,
event
->
cookie
);
printf
(
"mask = "
);
if
(
event
->
mask
&
IN_ACCESS
){
printf
(
"IN_ACCESS "
);}
if
(
event
->
mask
&
IN_ATTRIB
){
printf
(
"IN_ATTRIB "
);}
if
(
event
->
mask
&
IN_CLOSE_NOWRITE
){
printf
(
"IN_CLOSE_NOWRITE "
);}
if
(
event
->
mask
&
IN_CLOSE_WRITE
){
printf
(
"IN_CLOSE_WRITE "
);}
if
(
event
->
mask
&
IN_CREATE
){
printf
(
"IN_CREATE "
);}
if
(
event
->
mask
&
IN_DELETE
){
printf
(
"IN_DELETE "
);}
if
(
event
->
mask
&
IN_DELETE_SELF
){
printf
(
"IN_DELETE_SELF "
);}
if
(
event
->
mask
&
IN_IGNORED
){
printf
(
"IN_IGNORED "
);}
if
(
event
->
mask
&
IN_ISDIR
){
printf
(
"IN_ISDIR "
);}
if
(
event
->
mask
&
IN_MODIFY
){
printf
(
"IN_MODIFY "
);}
if
(
event
->
mask
&
IN_MOVE_SELF
){
printf
(
"IN_MOVE_SELF "
);}
if
(
event
->
mask
&
IN_MOVED_FROM
){
printf
(
"IN_MOVED_FROM "
);}
if
(
event
->
mask
&
IN_MOVED_TO
){
printf
(
"IN_MOVED_TO "
);}
if
(
event
->
mask
&
IN_OPEN
){
printf
(
"IN_OPEN "
);}
if
(
event
->
mask
&
IN_Q_OVERFLOW
){
printf
(
"IN_Q_OVERFLOW "
);}
if
(
event
->
mask
&
IN_UNMOUNT
){
printf
(
"IN_UNMOUNT "
);}
if
(
pnotify_isAccess
(
event
)
){
printf
(
"IN_ACCESS "
);}
if
(
pnotify_isAttrib
(
event
)
){
printf
(
"IN_ATTRIB "
);}
if
(
pnotify_isCloseNoWrite
(
event
)
){
printf
(
"IN_CLOSE_NOWRITE "
);}
if
(
pnotify_isCloseWrite
(
event
)
){
printf
(
"IN_CLOSE_WRITE "
);}
if
(
pnotify_isCreate
(
event
)
){
printf
(
"IN_CREATE "
);}
if
(
pnotify_isDelete
(
event
)
){
printf
(
"IN_DELETE "
);}
if
(
pnotify_isDeleteSelf
(
event
)
){
printf
(
"IN_DELETE_SELF "
);}
if
(
pnotify_isIgnored
(
event
)
){
printf
(
"IN_IGNORED "
);}
if
(
pnotify_isIsDir
(
event
)
){
printf
(
"IN_ISDIR "
);}
if
(
pnotify_isModify
(
event
)
){
printf
(
"IN_MODIFY "
);}
if
(
pnotify_isMoveSelf
(
event
)
){
printf
(
"IN_MOVE_SELF "
);}
if
(
pnotify_isMovedFrom
(
event
)
){
printf
(
"IN_MOVED_FROM "
);}
if
(
pnotify_isMovedTo
(
event
)
){
printf
(
"IN_MOVED_TO "
);}
if
(
pnotify_isOpen
(
event
)
){
printf
(
"IN_OPEN "
);}
if
(
pnotify_isQOverflow
(
event
)
){
printf
(
"IN_Q_OVERFLOW "
);}
if
(
pnotify_isUnmount
(
event
)
){
printf
(
"IN_UNMOUNT "
);}
printf
(
"
\n
"
);
if
(
event
->
len
>
0
)
...
...
src/PNotify.h
View file @
7f258799
...
...
@@ -38,6 +38,8 @@ bool pnotify_isUnmount(PNotifyEvent * event);
void
pnotify_printEvent
(
PNotifyEvent
*
event
);
std
::
vector
<
std
::
string
>
pnotify_filterName
(
const
std
::
string
&
fileBegining
,
const
std
::
vector
<
std
::
string
>
&
vecFileName
);
///@brief Class which scan directory content with blocking or non blocking usage
...
...
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