[go: up one dir, main page]

Menu

[r384]: / trunk / src / test_tools.c  Maximize  Restore  History

Download this file

101 lines (86 with data), 2.2 kB

  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
/* gcc -DTESTING -g -I.. -Wall -Werror test_tools.c tools.c && valgrind --leak-check=yes --show-reachable=yes ./a.out */
#include "tools.h"
#include <stdio.h>
#include <stdlib.h>
int
main(
)
{
/* upcase() && lowcase() */
{
char foo[64];
sprintf(foo, "foobar");
printf("Before case-conversion: '%s'\n", foo);
upcase(foo);
printf("After upcase: '%s'\n", foo);
lowcase(foo);
printf("After lowcase: '%s'\n", foo);
sprintf(foo, "unicode öä ¹²³");
printf("Before case-conversion: '%s'\n", foo);
upcase(foo);
printf("After upcase: '%s'\n", foo);
lowcase(foo);
printf("After lowcase: '%s'\n", foo);
}
/* randname() */
{
char foo[64];
int i, j;
#define LEN 8
for (i = 0; i < 2; i++) {
switch (i) {
case 0:
sprintf(foo, "user");
break;
case 1:
sprintf(foo, "username");
break;
}
printf("randname: starting with '%s' (len = %d)\n", foo, LEN);
for (j = 0; j < LEN * 2; j++) {
randname(foo, LEN, '#');
printf("round %02d: '%s'\n", j, foo);
}
}
printf("Generating random stuff:\n");
for (i = 0; i < 4; i++) {
foo[0] = '\0';
randname(foo, LEN, '#');
printf("round %d: '%s'\n", i, foo);
}
}
/* pos() && lastpos() */
{
char foo[64];
sprintf(foo, "There is no greater power in the universe than "
"the need for freedom.");
printf("String: '%s'\n", foo);
printf("First occurance of 'o' is at %d\n", pos(foo, 'o'));
printf("Last occurance of 'o' is at %d\n", lastpos(foo, 'o'));
}
/* nextword() && lastword() */
{
char foo[64];
char *ptr;
sprintf(foo, "There is no greater power in the universe than "
"the need for freedom.");
printf("Words (after the first one):\n");
ptr = nextword(foo);
while (ptr != NULL) {
printf("'%s'\n", ptr);
ptr = nextword(ptr);
}
printf("Last word: '%s'\n", lastword(foo));
}
/* get_short_localtime() && get_timestamp() */
{
time_t t;
t = rand();
printf("Some timestamps:\n");
printf("Localtime: '%s'\n", get_short_localtime());
printf("Long: '%s'\n", get_timestamp(NULL, TIMESTAMP_LONG));
printf("Short: '%s'\n", get_timestamp(NULL, TIMESTAMP_SHORT));
printf("Abritary: '%s'\n", get_timestamp(&t, TIMESTAMP_LONG));
}
return 0;
}