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
|
/*
* typespeed - measures your typing speed
* Copyright (C) 1999-2003 Jani Ollikainen <bestis@iki.fi>
* & Jaakko Manelius <jman@iki.fi>
* Copyright (C) 2006-2007 Tobias Stoeckmann <tobias@bugol.de>
*
* 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif /* HAVE_SYS_PARAM_H */
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif /* HAVE_SYS_TYPES_H */
#ifdef HAVE_DIRENT_H
#include <dirent.h>
#endif /* HAVE_DIRENT_H */
#include <err.h>
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif /* HAVE_STDLIB_H */
#ifdef HAVE_STRING_H
#include <string.h>
#endif /* HAVE_STRING_H */
#include "typespeed.h"
extern void freewords(void);
extern int loadwords(char *);
extern char worddir[MAXPATHLEN];
extern struct rawdata words;
int
main(void)
{
char conv[2], input[1024], wordpath[MAXPATHLEN];
int exp_retval, retval;
size_t exp_count;
DIR *data;
FILE *file;
struct dirent *dp;
(void)snprintf(worddir, sizeof(worddir), "t_loadwords_data");
if ((data = opendir("./t_loadwords_data")) == NULL)
return EXIT_FAILURE;
while ((dp = readdir(data)) != NULL) {
if (strlen(dp->d_name) < 3)
continue;
/*
* Parse expected wordcount out of comment line.
*/
(void)snprintf(wordpath, sizeof(wordpath),
"t_loadwords_data/%s", dp->d_name);
if ((file = fopen(wordpath, "r")) == NULL)
return EXIT_FAILURE;
memset(input, 0, sizeof(input));
fgets(input, sizeof(input), file);
(void)fclose(file);
exp_count = atoi(input);
/*
* File name begins with expected return value.
*/
conv[0] = dp->d_name[0];
conv[1] = '\0';
exp_retval = atoi(conv);
/*
* Evaluate test
*/
retval = loadwords(dp->d_name);
if (retval != exp_retval) {
fprintf(stderr, "%s - error: %d returned\n",
dp->d_name, retval);
freewords();
continue;
}
if (words.n != exp_count)
fprintf(stderr, "%s - error: n is %zu.\n",
dp->d_name, words.n);
else
fprintf(stderr, "%s - passed\n", dp->d_name);
freewords();
}
(void)closedir(data);
return EXIT_SUCCESS;
}
|