Commit 7f258799 authored by Pierre Aubert's avatar Pierre Aubert
Browse files

Add print test

parent a6efb0f6
Pipeline #98200 passed with stages
in 1 minute and 28 seconds
......@@ -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)
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)
/***************************************
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;
}
......@@ -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)
......
......@@ -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
......
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 to comment