feisty meow concerns codebase
2.140
test_break_signal.cpp
Go to the documentation of this file.
1
/*****************************************************************************\
2
* *
3
* Name : test_break_signal *
4
* Author : Chris Koeritz *
5
* *
6
*******************************************************************************
7
* Copyright (c) 2004-$now By Author. This program is free software; you can *
8
* redistribute it and/or modify it under the terms of the GNU General Public *
9
* License as published by the Free Software Foundation; either version 2 of *
10
* the License or (at your option) any later version. This is online at: *
11
* http://www.fsf.org/copyleft/gpl.html *
12
* Please send any updates to: fred@gruntose.com *
13
\*****************************************************************************/
14
15
#include <
basis/functions.h
>
16
#include <
basis/guards.h
>
17
#include <
basis/astring.h
>
18
#include <
timely/time_control.h
>
19
#include <
timely/time_stamp.h
>
20
#include <
application/application_shell.h
>
21
#include <
application/hoople_main.h
>
22
#include <
loggers/console_logger.h
>
23
#include <
loggers/critical_events.h
>
24
#include <
loggers/program_wide_logger.h
>
25
#include <
filesystem/filename.h
>
26
#include <
structures/static_memory_gremlin.h
>
27
#include <
unit_test/unit_base.h
>
28
29
#include <signal.h>
30
//hmmm: much better if we had signal handling wrapped in a class instead of using bare calls to the OS signal library.
31
#include <stdio.h>
32
//hmmm: also a flush mechanism for i/o being inside feisty code would be better than this call to stdio.
33
34
using namespace
application
;
35
using namespace
basis
;
36
using namespace
loggers
;
37
using namespace
timely
;
38
using namespace
unit_test
;
39
40
#define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
41
42
static
bool
_leave_now =
false
;
43
44
const
int
DEFAULT_PAUSE_TIME
= 1;
// how long we'll wait, unless told a different time.
45
46
class
test_break_signal :
virtual
public
unit_base
,
virtual
public
application_shell
47
{
48
public
:
49
test_break_signal() :
application_shell
() {}
50
DEFINE_CLASS_NAME
(
"test_break_signal"
);
51
virtual
int
execute();
52
};
53
54
void
handle_break
(
int
formal
(signal))
55
{
56
#undef static_class_name
57
#define static_class_name() "test_break_signal"
58
FUNCDEF
(
"handle_break"
);
59
LOG
(
"we have hit the signal handler for break!"
);
60
_leave_now =
true
;
61
#undef static_class_name
62
}
63
64
int
test_break_signal::execute()
65
{
66
FUNCDEF
(
"execute"
);
67
68
int
pause_time =
DEFAULT_PAUSE_TIME
;
69
if
(
application::_global_argc
>= 2) {
70
astring
passed_pause =
application::_global_argv
[1];
71
pause_time = passed_pause.
convert
(
DEFAULT_PAUSE_TIME
);
72
}
73
74
75
signal(SIGINT,
handle_break
);
76
LOG
(
"starting loop--hit ctrl-C to exit or wait for timeout."
);
77
time_stamp
leave_time(pause_time *
SECOND_ms
);
78
while
(!_leave_now && (
time_stamp
() < leave_time) ) {
79
time_control::sleep_ms(20);
80
}
81
82
// we jump to here when catching the signal.
83
fflush(
NULL_POINTER
);
84
85
critical_events::alert_message(
astring
(class_name()) +
": works for those functions tested."
);
86
87
return
0;
88
}
89
90
HOOPLE_MAIN
(test_break_signal, )
91
application_shell.h
astring.h
application::application_shell
The application_shell is a base object for console programs.
Definition:
application_shell.h:33
basis::astring
Provides a dynamically resizable ASCII character string.
Definition:
astring.h:35
basis::astring::convert
int convert(int default_value) const
Converts the string into a corresponding integer.
Definition:
astring.cpp:760
timely::time_stamp
Represents a point in time relative to the operating system startup time.
Definition:
time_stamp.h:38
unit_test::unit_base
Definition:
unit_base.h:59
console_logger.h
critical_events.h
formal
#define formal(parameter)
This macro just eats what it's passed; it marks unused formal parameters.
Definition:
definitions.h:48
NULL_POINTER
#define NULL_POINTER
The value representing a pointer to nothing.
Definition:
definitions.h:32
DEFINE_CLASS_NAME
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
Definition:
enhance_cpp.h:42
FUNCDEF
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Definition:
enhance_cpp.h:54
filename.h
functions.h
guards.h
hoople_main.h
Provides macros that implement the 'main' program of an application.
HOOPLE_MAIN
#define HOOPLE_MAIN(obj_name, obj_args)
options that should work for most unix and linux apps.
Definition:
hoople_main.h:61
application
Implements an application lock to ensure only one is running at once.
Definition:
application_shell.cpp:40
application::_global_argc
int _global_argc
application::_global_argv
char ** _global_argv
basis
The guards collection helps in testing preconditions and reporting errors.
Definition:
array.h:30
basis::SECOND_ms
const int SECOND_ms
Number of milliseconds in a second.
Definition:
definitions.h:120
loggers
A logger that sends to the console screen using the standard output device.
Definition:
combo_logger.cpp:36
timely
#include <time.h>
Definition:
earth_time.cpp:37
unit_test
Useful support functions for unit testing, especially within hoople.
Definition:
unit_base.cpp:35
program_wide_logger.h
static_memory_gremlin.h
handle_break
void handle_break(int formal(signal))
Definition:
test_break_signal.cpp:54
LOG
#define LOG(s)
Definition:
test_break_signal.cpp:40
DEFAULT_PAUSE_TIME
const int DEFAULT_PAUSE_TIME
Definition:
test_break_signal.cpp:44
time_control.h
time_stamp.h
unit_base.h
nucleus
library
tests_application
test_break_signal.cpp
Generated by
1.9.1