Parcourir la source

Completed unit tests under Linux.


git-svn-id: https://svn.microneil.com/svn/CodeDweller-Tests/trunk@19 b3372362-9eaa-4a85-aa2b-6faa1ab7c995
master
adeniz il y a 10 ans
Parent
révision
bde8d7f006
3 fichiers modifiés avec 200 ajouts et 9 suppressions
  1. 10
    0
      TestService/buildAndRun
  2. 78
    0
      TestService/expected_serviceProgram.log
  3. 112
    9
      TestService/serviceProgram.cpp

+ 10
- 0
TestService/buildAndRun Voir le fichier

@@ -20,6 +20,16 @@ rm -f $logFileName

PID=$(ps axl | grep -i serviceProgram |grep -v grep | cut -d ' ' -f 4)
sleep 1

kill -TSTP $PID
sleep 2

kill -CONT $PID
sleep 2

kill -HUP $PID
sleep 2

kill -TERM $PID
sleep 1


+ 78
- 0
TestService/expected_serviceProgram.log Voir le fichier

@@ -1,3 +1,81 @@
Sleeping 2 s
receivedPause(): 1
receivedResume(): 0
receivedRestart(): 0
receivedStop(): 0
Clearing all flags.
receivedPause(): 0
receivedResume(): 0
receivedRestart(): 0
receivedStop(): 0
pauseCbck.pauseFlag: 1
pauseCbck1.pauseFlag: 1
resumeCbck.resumeFlag: 0
resumeCbck1.resumeFlag: 0
restartCbck.restartFlag: 0
restartCbck1.restartFlag: 0
stopCbck.stopFlag: 0
stopCbck1.stopFlag: 0
notStopCbck.stopFlag: 0

Sleeping 2 s
receivedPause(): 0
receivedResume(): 1
receivedRestart(): 0
receivedStop(): 0
Clearing all flags.
receivedPause(): 0
receivedResume(): 0
receivedRestart(): 0
receivedStop(): 0
pauseCbck.pauseFlag: 0
pauseCbck1.pauseFlag: 0
resumeCbck.resumeFlag: 1
resumeCbck1.resumeFlag: 1
restartCbck.restartFlag: 0
restartCbck1.restartFlag: 0
stopCbck.stopFlag: 0
stopCbck1.stopFlag: 0
notStopCbck.stopFlag: 0

Sleeping 2 s
receivedPause(): 0
receivedResume(): 0
receivedRestart(): 1
receivedStop(): 0
Clearing all flags.
receivedPause(): 0
receivedResume(): 0
receivedRestart(): 0
receivedStop(): 0
pauseCbck.pauseFlag: 0
pauseCbck1.pauseFlag: 0
resumeCbck.resumeFlag: 0
resumeCbck1.resumeFlag: 0
restartCbck.restartFlag: 1
restartCbck1.restartFlag: 1
stopCbck.stopFlag: 0
stopCbck1.stopFlag: 0
notStopCbck.stopFlag: 0

Sleeping 2 s
receivedPause(): 0
receivedResume(): 0
receivedRestart(): 0
receivedStop(): 1
Clearing all flags.
receivedPause(): 0
receivedResume(): 0
receivedRestart(): 0
receivedStop(): 0
pauseCbck.pauseFlag: 0
pauseCbck1.pauseFlag: 0
resumeCbck.resumeFlag: 0
resumeCbck1.resumeFlag: 0
restartCbck.restartFlag: 0
restartCbck1.restartFlag: 0
stopCbck.stopFlag: 1
stopCbck1.stopFlag: 1
notStopCbck.stopFlag: 0

Exiting.

+ 112
- 9
TestService/serviceProgram.cpp Voir le fichier

@@ -50,6 +50,60 @@

#include "CodeDweller/service.hpp"

/// Callback functor for Pause message.
class PauseCallback : public CodeDweller::Service::Callback {

public:

PauseCallback() : pauseFlag(false) {}

bool pauseFlag;

void operator()() {
pauseFlag = true;
}

};

PauseCallback pauseCbck;
PauseCallback pauseCbck1;

/// Callback functor for Resume message.
class ResumeCallback : public CodeDweller::Service::Callback {

public:

ResumeCallback() : resumeFlag(false) {}

bool resumeFlag;

void operator()() {
resumeFlag = true;
}

};

ResumeCallback resumeCbck;
ResumeCallback resumeCbck1;

/// Callback functor for Restart message.
class RestartCallback : public CodeDweller::Service::Callback {

public:

RestartCallback() : restartFlag(false) {}

bool restartFlag;

void operator()() {
restartFlag = true;
}

};

RestartCallback restartCbck;
RestartCallback restartCbck1;

/// Callback functor for Stop message.
class StopCallback : public CodeDweller::Service::Callback {

@@ -65,15 +119,17 @@ public:

};

StopCallback stopCallback;
StopCallback stopCbck;
StopCallback stopCbck1;
StopCallback notStopCbck;

int CodeDweller::Service::run() {

// Get the singleton.
CodeDweller::Service &service = CodeDweller::Service::getInstance();
CodeDweller::Service &svc = CodeDweller::Service::getInstance();

// Get the log file name.
auto arguments = service.arguments();
auto arguments = svc.arguments();

if (arguments.size() != 2) {
return(EXIT_FAILURE);
@@ -82,19 +138,66 @@ int CodeDweller::Service::run() {
// Get log file.
std::ofstream logStream(arguments[1]);
// Register the Stop callback.
service.onStopCall(&stopCallback);
// Register the callbacks.
svc.onPauseCall(pauseCbck);
svc.onPauseCall(pauseCbck1);

while (!stopCallback.stopFlag) {
svc.onResumeCall(resumeCbck);
svc.onResumeCall(resumeCbck1);

svc.onRestartCall(restartCbck);
svc.onRestartCall(restartCbck1);

svc.onStopCall(stopCbck);
svc.onStopCall(stopCbck1);

while (!stopCbck.stopFlag) {

logStream << "Sleeping 2 s" << std::endl;
sleep(2);

logStream << "receivedPause(): " << svc.receivedPause() << std::endl;
logStream << "receivedResume(): " << svc.receivedResume() << std::endl;
logStream << "receivedRestart(): " << svc.receivedRestart() << std::endl;
logStream << "receivedStop(): " << svc.receivedStop() << std::endl;

logStream << "Clearing all flags." << std::endl;
svc.clearReceivedPause();
svc.clearReceivedResume();
svc.clearReceivedRestart();
svc.clearReceivedStop();

logStream << "receivedPause(): " << svc.receivedPause() << std::endl;
logStream << "receivedResume(): " << svc.receivedResume() << std::endl;
logStream << "receivedRestart(): " << svc.receivedRestart() << std::endl;
logStream << "receivedStop(): " << svc.receivedStop() << std::endl;

logStream << "pauseCbck.pauseFlag: " << pauseCbck.pauseFlag << std::endl;
logStream << "pauseCbck1.pauseFlag: " << pauseCbck1.pauseFlag << std::endl;
logStream << "resumeCbck.resumeFlag: " << resumeCbck.resumeFlag
<< std::endl;
logStream << "resumeCbck1.resumeFlag: " << resumeCbck1.resumeFlag
<< std::endl;
logStream << "restartCbck.restartFlag: " << restartCbck.restartFlag
<< std::endl;
logStream << "restartCbck1.restartFlag: " << restartCbck1.restartFlag
<< std::endl;
logStream << "stopCbck.stopFlag: " << stopCbck.stopFlag << std::endl;
logStream << "stopCbck1.stopFlag: " << stopCbck1.stopFlag << std::endl;
logStream << "notStopCbck.stopFlag: " << notStopCbck.stopFlag << std::endl;

pauseCbck.pauseFlag = false;
pauseCbck1.pauseFlag = false;
resumeCbck.resumeFlag = false;
resumeCbck1.resumeFlag = false;
restartCbck.restartFlag = false;
restartCbck1.restartFlag = false;

logStream << std::endl;

}

logStream << "receivedStop(): " << service.receivedStop() << std::endl;
service.clearReceivedStop();
logStream << "receivedStop(): " << service.receivedStop() << std::endl;
logStream << "Exiting." << std::endl;

logStream.close();


Chargement…
Annuler
Enregistrer