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
f923e648
Commit
f923e648
authored
Jan 05, 2021
by
Pierre Aubert
Browse files
Add test
parent
8fb84760
Pipeline
#98192
passed with stages
in 1 minute and 19 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
191 additions
and
1 deletion
+191
-1
TESTS/CMakeLists.txt
TESTS/CMakeLists.txt
+2
-1
TESTS/TEST_BASE_NOTIFY/CMakeLists.txt
TESTS/TEST_BASE_NOTIFY/CMakeLists.txt
+12
-0
TESTS/TEST_BASE_NOTIFY/main.cpp
TESTS/TEST_BASE_NOTIFY/main.cpp
+82
-0
TESTS/TEST_BASE_NOTIFY_2/CMakeLists.txt
TESTS/TEST_BASE_NOTIFY_2/CMakeLists.txt
+12
-0
TESTS/TEST_BASE_NOTIFY_2/main.cpp
TESTS/TEST_BASE_NOTIFY_2/main.cpp
+83
-0
No files found.
TESTS/CMakeLists.txt
View file @
f923e648
project
(
Phoenix
)
cmake_minimum_required
(
VERSION 2.8
)
add_subdirectory
(
TEST_BASE_NOTIFY
)
add_subdirectory
(
TEST_BASE_NOTIFY_2
)
TESTS/TEST_BASE_NOTIFY/CMakeLists.txt
0 → 100644
View file @
f923e648
project
(
Phoenix
)
cmake_minimum_required
(
VERSION 2.8
)
add_definitions
(
-DCURRENT_TEST_DIR=
"
${
CMAKE_CURRENT_BINARY_DIR
}
"
)
add_executable
(
test_base_notify main.cpp
)
target_link_libraries
(
test_base_notify phoenix_notify pthread
)
add_test
(
NAME TestBaseNotify
COMMAND
${
CMAKE_CURRENT_BINARY_DIR
}
/test_base_notify
)
TESTS/TEST_BASE_NOTIFY/main.cpp
0 → 100644
View file @
f923e648
/***************************************
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
nodify
;
nodify
.
resize
(
100lu
);
//Let's have 100 files in buffer
nodify
.
setWatch
(
inputDir
,
IN_NONBLOCK
,
IN_CLOSE_WRITE
);
size_t
nbCheck
(
5lu
);
for
(
size_t
i
(
0lu
);
i
<
nbCheck
;
++
i
){
std
::
vector
<
std
::
string
>
vecNewFile
(
nodify
.
scanFileName
());
std
::
cout
<<
"testPNotify check "
<<
i
<<
" : find "
<<
vecNewFile
.
size
()
<<
" new files"
<<
std
::
endl
;
if
(
vecNewFile
.
size
()
!=
0lu
){
for
(
std
::
vector
<
std
::
string
>::
iterator
it
(
vecNewFile
.
begin
());
it
!=
vecNewFile
.
end
();
++
it
){
std
::
cout
<<
"
\t
"
<<
(
*
it
)
<<
std
::
endl
;
}
}
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
(
500000
);
}
}
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
;
}
TESTS/TEST_BASE_NOTIFY_2/CMakeLists.txt
0 → 100644
View file @
f923e648
project
(
Phoenix
)
cmake_minimum_required
(
VERSION 2.8
)
add_definitions
(
-DCURRENT_TEST_DIR=
"
${
CMAKE_CURRENT_BINARY_DIR
}
"
)
add_executable
(
test_base_notify2 main.cpp
)
target_link_libraries
(
test_base_notify2 phoenix_notify pthread
)
add_test
(
NAME TestBaseNotify2
COMMAND
${
CMAKE_CURRENT_BINARY_DIR
}
/test_base_notify2
)
TESTS/TEST_BASE_NOTIFY_2/main.cpp
0 → 100644
View file @
f923e648
/***************************************
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
nodify
;
nodify
.
setFlags
(
IN_NONBLOCK
);
nodify
.
resize
(
100lu
);
//Let's have 100 files in buffer
nodify
.
addWatch
(
inputDir
,
IN_CLOSE_WRITE
);
size_t
nbCheck
(
5lu
);
for
(
size_t
i
(
0lu
);
i
<
nbCheck
;
++
i
){
std
::
vector
<
std
::
string
>
vecNewFile
(
nodify
.
scanFileName
());
std
::
cout
<<
"testPNotify check "
<<
i
<<
" : find "
<<
vecNewFile
.
size
()
<<
" new files"
<<
std
::
endl
;
if
(
vecNewFile
.
size
()
!=
0lu
){
for
(
std
::
vector
<
std
::
string
>::
iterator
it
(
vecNewFile
.
begin
());
it
!=
vecNewFile
.
end
();
++
it
){
std
::
cout
<<
"
\t
"
<<
(
*
it
)
<<
std
::
endl
;
}
}
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
(
500000
);
}
}
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
;
}
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