1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
|
// -*- c++ -*-
// Generated by assa-genesis
//------------------------------------------------------------------------------
// $Id: regexp_test.cpp,v 1.9 2012/05/21 03:20:39 vlg Exp $
//------------------------------------------------------------------------------
// RegexpTest.cpp
//------------------------------------------------------------------------------
// Copyright (c) 2003,2005 by Vladislav Grinchenko
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version
// 2 of the License, or (at your option) any later version.
//------------------------------------------------------------------------------
//
// Date : Mon Sep 1 14:40:40 2003
//
//------------------------------------------------------------------------------
static const char help_msg[]=
" \n"
" NAME: \n"
" \n"
" regexp_test \n"
" \n"
" DESCRIPTION: \n"
" \n"
" Test driver for Regexp class. \n"
" \n"
" USAGE: \n"
" \n"
" shell> regexp_test [OPTIONS] \n"
" \n"
" OPTIONS: \n"
" \n"
" -D, --log-file NAME - Write debug to NAME file \n"
" -d, --log-stdout - Write debug to standard output \n"
" -z, --log-size NUM - Maximum size debug file can reach (dfl: is 10Mb) \n"
" \n"
" -c, --log-level NUM - Log verbosity \n"
" -s, --with-log-server - Redirect log messages to the log server \n"
" -S, --log-server NAME - Define assa-logd server address \n"
" \n"
" -m, --mask MASK - Mask (default: ALL = 0x7fffffff) \n"
" \n"
" -h, --help - Print this messag \n"
" -v, --version - Print version number \n";
//------------------------------------------------------------------------------
#include <iostream>
#include <assa/Assure.h>
#include <assa/Regexp.h>
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <string>
using std::string;
#include <assa/GenServer.h>
#include <assa/Singleton.h>
#include <assa/TimeVal.h>
enum { RGXP_TEST = ASSA::USR1 };
class RegexpTest :
public ASSA::GenServer,
public ASSA::Singleton<RegexpTest>
{
public:
RegexpTest ();
virtual void init_service ();
virtual void process_events ();
private:
};
/* Useful definitions */
#define REGEXPTEST RegexpTest::get_instance()
#define REACTOR REGEXPTEST->get_reactor()
// Static declarations mandated by Singleton class
ASSA_DECL_SINGLETON(RegexpTest);
RegexpTest::
RegexpTest ()
{
// ---Configuration---
rm_opt ('f', "config-file" );
rm_opt ('n', "instance" );
rm_opt ('p', "port" );
// ---Process bookkeeping---
rm_opt ('b', "daemon" );
rm_opt ('l', "pidfile" );
rm_opt ('L', "ommit-pidfile");
m_ommit_pidfile = "yes";
/*---
* By defauil disable all debugging
*---*/
/* m_mask = ASSA::APP | ASSA::ASSAERR | ASSA::TRACE;
m_log_file = "regexp_test.log";
*/
m_mask = RGXP_TEST;
m_log_stdout = "yes";
}
void
RegexpTest::
init_service ()
{
/* no-op */
}
void
RegexpTest::
process_events ()
{
// trace("RegexpTest::process_events");
const char* test[] = {
"# Comment line", // 0
"", // 1
"[Options]", // 2
"mask=0x0", // 3
" daemon = true", // 4
"\tgtk_options=--g-fatal-warnings --disable-crash-dialog", // 5
"", // 6
" ]Not a valid section [", // 7
"not a valid pair " // 8
};
DL((RGXP_TEST,"= Running regexp_test Test =\n"));
ASSA::Regexp section_pattrn ("\\[[a-zA-Z0-9]+.*]$");
ASSA::Regexp pair_pattrn ("^[ \t]*[a-zA-Z0-9]+.* *= *.*");
DL((RGXP_TEST,"Testing comment match ... "));
if (section_pattrn.match (test [0]) == 0) {
DL((RGXP_TEST," failed to discard comment!\n"));
goto failed;
}
DL((RGXP_TEST,"ok\n"));
DL((RGXP_TEST,"Testing section match ... "));
if (section_pattrn.match (test [2]) < 0) {
DL((RGXP_TEST," failed to match valid section!\n"));
DL((RGXP_TEST," error: \"%s\"\n", section_pattrn.get_error ()));
goto failed;
}
if (section_pattrn.match (test [7]) == 0) {
DL((RGXP_TEST," failed to reject invalid section!\n"));
goto failed;
}
DL((RGXP_TEST,"ok\n"));
DL((RGXP_TEST,"Testing name/value pair match ... "));
for (int i = 3; i < 6; i++) {
if (pair_pattrn.match (test [i]) < 0) {
DL((RGXP_TEST,
" failed to match valid name/value pair!\n"
" input: \"%s\"\n"
" error: %s",
test [i],
section_pattrn.get_error ()));
goto failed;
}
}
DL((RGXP_TEST,"ok\n"));
DL((RGXP_TEST,"Testing name/value pair reject ... "));
if (pair_pattrn.match (test [8]) == 0) {
DL((RGXP_TEST," failed to reject invalid name/value pair!\n"));
goto failed;
}
DL((RGXP_TEST,"ok\n"));
// Shut the service down
DL((ASSA::APP,"Service stopped!\n"));
DL((RGXP_TEST,"= Test passed =\n"));
m_reactor.stopReactor ();
return;
failed:
set_exit_value (1);
DL((RGXP_TEST,"= Test failed =\n"));
m_reactor.stopReactor ();
}
int
main (int argc, char* argv[])
{
static const char release[] = "1.0";
int patch_level = 0;
REGEXPTEST->set_version (release, patch_level);
REGEXPTEST->set_author ("Vladislav Grinchenko");
REGEXPTEST->set_flags (ASSA::GenServer::RMLOG);
REGEXPTEST->init (&argc, argv, help_msg);
REGEXPTEST->init_service ();
REGEXPTEST->process_events ();
return REGEXPTEST->get_exit_value ();
}
|