Explorar el Código

Completed preliminary unit test for Linux.


git-svn-id: https://svn.microneil.com/svn/CodeDweller-Tests/trunk@18 b3372362-9eaa-4a85-aa2b-6faa1ab7c995
master
adeniz hace 10 años
padre
commit
7517d123ef

+ 19
- 0
TestService/buildAndRun Ver fichero

@@ -10,3 +10,22 @@ if [ $? -ne 0 ]
then
exit -1
fi

# Run test.
logFileName=serviceProgram.log

rm -f $logFileName

./serviceProgram $(pwd)/$logFileName

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

if cmp expected_$logFileName $logFileName
then
echo CodeDweller::Service under Linux: ok
else
echo CodeDweller::Service under Linux: fail
fi

+ 3
- 0
TestService/expected_serviceProgram.log Ver fichero

@@ -0,0 +1,3 @@
Sleeping 2 s
receivedStop(): 1
receivedStop(): 0

+ 69
- 1
TestService/serviceProgram.cpp Ver fichero

@@ -2,6 +2,27 @@
//
// Service program for testing CodeDweller::Service.
//
// Usage:
//
// serviceProgram <logFileName>
//
// where <logFileName> is the name of a file to write to.
//
// This program:
//
// 1) Registers a callback for the Stop message that sets a stop
// flag.
//
// 2) While the stop flag is false, output a message to the log file
// every 2 seconds.
//
// 3) After Stop is received, output the value returned by
// Service::receivedStop().
//
// 4) Call Service::clearReceivedStop(), and repeate step 3.
//
// 5) Exit.
//
// Copyright (C) 2014 MicroNeil Research Corporation.
//
// This program is part of the MicroNeil Research Open Library Project. For
@@ -25,10 +46,57 @@
#include <unistd.h>

#include <cstdlib>
#include <fstream>

#include "CodeDweller/service.hpp"

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

public:

StopCallback() : stopFlag(false) {}

bool stopFlag;

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

};

StopCallback stopCallback;

int CodeDweller::Service::run() {
sleep(5);

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

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

if (arguments.size() != 2) {
return(EXIT_FAILURE);
}

// Get log file.
std::ofstream logStream(arguments[1]);
// Register the Stop callback.
service.onStopCall(&stopCallback);

while (!stopCallback.stopFlag) {

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

}

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

logStream.close();

return(EXIT_SUCCESS);
}

Cargando…
Cancelar
Guardar