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
|
// $Id: charpool2.cc 2845 2009-09-01 09:33:31Z rafi $
// Advanced tests for yapet/pwgen/charpool.*
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifdef HAVE_IOSTREAM
# include <iostream>
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <typeinfo>
#include <charpool.h>
#include "testpaths.h"
using namespace YAPET::PWGEN;
const char t_letters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
const char t_digits[] = "0123456789";
const char t_punct[] = ".,;:-!?'";
const char t_special[] = "_+\"*%&/()[]={}<>";
const char t_other[] = "@#\\|$~`^";
int main (int, char**) {
#ifndef TESTS_VERBOSE
int stdout_redir_fd = open("/dev/null", O_WRONLY | O_APPEND);
dup2(stdout_redir_fd,STDOUT_FILENO);
#endif
std::cout << std::endl;
try {
CharacterPool tmp1 (LETTERS | PUNCT | OTHER);
if (tmp1.hadPoolReads(LETTERS))
return 1;
if (tmp1.hadPoolReads(PUNCT))
return 1;
if (tmp1.hadPoolReads(OTHER))
return 1;
if (tmp1.getPoolsWithRead() != 0)
return 1;
if (tmp1.numPoolsNotRead() != 3)
return 1;
size_t start;
size_t len;
len =tmp1.getPoolPos(LETTERS, &start);
if ( len != strlen(t_letters) )
return 1;
if (tmp1[start] != t_letters[0])
return 1;
if (tmp1[start+len-1] != t_letters[strlen(t_letters)-1])
return 1;
if (!tmp1.hadPoolReads(LETTERS))
return 1;
if (tmp1.numPoolsNotRead() != 2)
return 1;
len = tmp1.getPoolPos(PUNCT, &start);
if ( len != strlen(t_punct) )
return 1;
if (tmp1[start] != t_punct[0])
return 1;
if (tmp1[start+len-1] != t_punct[strlen(t_punct)-1])
return 1;
if (!tmp1.hadPoolReads(PUNCT))
return 1;
if (tmp1.numPoolsNotRead() != 1)
return 1;
len = tmp1.getPoolPos(OTHER, &start);
if ( len != strlen(t_other) )
return 1;
if (tmp1[start] != t_other[0])
return 1;
if (tmp1[start+len-1] != t_other[strlen(t_other)-1])
return 1;
if (!tmp1.hadPoolReads(OTHER))
return 1;
if (tmp1.numPoolsNotRead() != 0)
return 1;
len = tmp1.getPoolPos(DIGITS, &start);
if (! (start == 0 && len == 0))
return 1;
len = tmp1.getPoolPos(SPECIAL, &start);
if (! (start == 0 && len == 0))
return 1;
} catch (std::exception& ex) {
std::cout << typeid (ex).name() << ": " << ex.what() << std::endl;
return 1;
}
return 0;
}
|