TPCCLIB
Loading...
Searching...
No Matches
libtpcnew.c
1/******************************************************************************
2 * This file is not compiled into the library, but it contains main()
3 * which is compiled to an executable, used to test the library functions.
4 *****************************************************************************/
5
6/*****************************************************************************/
7#include "tpcclibConfig.h"
8/*****************************************************************************/
9#include <unistd.h>
10/*****************************************************************************/
11#include "tpcnew.h"
12#include "test_tpcnew.h"
13/*****************************************************************************/
14
15/*****************************************************************************/
16static char *info[] = {
17 "Usage: @P [options]",
18 " ",
19 "Options:",
20 " -stdoptions", // List standard options like --help, -v, etc
21 " -t, --test",
22 " Run all tests for library functions.",
23 0};
24/*****************************************************************************/
25
26/*****************************************************************************/
31int main(
33 int argc,
35 char *argv[ ]
36) {
37 int i, help=0, version=0, verbose=1, error=0, test=0;
38 int ret;
39 char *cptr;
40
41 if(argc==1) {tpcPrintUsage(argv[0], info, stdout); return(0);}
42 for(i=1; i<argc; i++) {
43 if(tpcProcessStdOptions(argv[i], &help, &version, &verbose)==0) continue;
44 cptr=argv[i]; if(*cptr=='-') cptr++; if(*cptr=='-') cptr++;
45 if(strncasecmp(cptr, "TEST", 1)==0) {
46 test=1; continue;
47 } else {
48 error++; break;
49 }
50 }
51 if(error>0) {
52 fprintf(stderr, "Error: specify --help for usage.\n");
53 return(1);
54 }
55 /* Print help or version? */
56 if(help) {tpcPrintUsage(argv[0], info, stdout); return(0);}
57 if(version) {tpcPrintBuild(argv[0], stdout); return(0);}
58
59 if(test==0) return(0);
60
61 if(verbose>0) printf("running tests for library functions...\n");
62 TPCSTATUS status; statusInit(&status); status.verbose=verbose;
63 statusSet(&status, __func__, __FILE__, __LINE__, 0);
64 i=10;
65
66 /* new */
67 i++; if((ret=test_newTemplate(&status))!=0) {
68 fprintf(stderr, "failed (%d).\n", ret);
69 statusPrint(stderr, &status); statusFree(&status);
70 return(i);
71 }
72
73 if(verbose>0) printf("\nAll tests passed.\n\n");
74 statusFree(&status);
75 return(0);
76}
77/*****************************************************************************/
78
79/*****************************************************************************/
int tpcProcessStdOptions(const char *s, int *print_usage, int *print_version, int *verbose_level)
Definition proginfo.c:47
void tpcPrintBuild(const char *program, FILE *fp)
Definition proginfo.c:339
void tpcPrintUsage(const char *program, char *text[], FILE *fp)
Definition proginfo.c:114
void statusPrint(FILE *fp, TPCSTATUS *s)
Definition statusmsg.c:82
void statusInit(TPCSTATUS *s)
Definition statusmsg.c:104
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
Definition statusmsg.c:142
void statusFree(TPCSTATUS *s)
Definition statusmsg.c:126
int verbose
Verbose level, used by statusPrint() etc.
Header file for libtpcnew.