1//
2// Test driver program for cdsa_client library
3//
4#include "csptests.h"
5#include "dltests.h"
6
7#include <security_cdsa_client/cssmclient.h>
8#include <stdio.h>
9#include <stdlib.h>
10#include <string.h>
11#include <unistd.h>
12
13using namespace CssmClient;
14extern "C" void malloc_debug(int);
15
16static void usage();
17
18static const char *progname;
19
20// ���������������������������������������������������������������������������
21// 	� main
22// ���������������������������������������������������������������������������
23int main(int argc, char *argv[])
24{
25	extern char *optarg;
26	extern int optind;
27	bool didWork = false;
28	bool autoCommit = true;
29	bool printSchema = false;
30	int ch;
31
32	progname = strrchr(argv[0], '/');
33	progname = progname ? progname + 1 : argv[0];
34
35	try
36	{
37		while ((ch = getopt(argc, argv, "?haAbcdM:D:smwg:")) != -1)
38		{
39			switch(ch)
40			{
41			case 'a':
42				autoCommit=true;
43				break;
44			case 'A':
45				autoCommit=false;
46				break;
47			case 'b':
48				setbuf(stdout, NULL);
49				break;
50			case 'c':
51				csptests();
52				didWork = true;
53				break;
54			case 'm':
55				testmac();
56				didWork = true;
57				break;
58			case 'w':
59				testwrap();
60				didWork = true;
61				break;
62			case 'd':
63				dltests(autoCommit);
64				didWork = true;
65				break;
66			case 's':
67				printSchema = true;
68				break;
69			case 'g':
70				if (strcmp (optarg, "AppleFileDL") == 0)
71				{
72					gSelectedFileGuid = &gGuidAppleFileDL;
73				}
74				else if (strcmp (optarg, "LDAPDL") == 0)
75				{
76					gSelectedFileGuid = &gGuidAppleLDAPDL;
77				}
78				else
79				{
80					didWork = false;
81				}
82				break;
83			case 'D':
84				dumpDb(optarg, printSchema);
85				didWork = true;
86				break;
87			case 'M':
88				malloc_debug(atoi(optarg));
89				break;
90			case '?':
91			case 'h':
92			default:
93				usage();
94			}
95		}
96
97		if (argc != optind)
98			usage();
99
100		if (!didWork)
101			usage();
102
103		Cssm::standard()->terminate();
104	}
105	catch (CommonError &error)
106	{
107		cssmPerror("Tester abort", error.osStatus());
108	}
109
110	return 0;
111}
112
113// ���������������������������������������������������������������������������
114// 	� usage
115// ���������������������������������������������������������������������������
116static void
117usage()
118{
119	printf("usage: %s [-M<malloc_debug>] [-b] [-c] [[-a|-A] -d] [[-s ] [-g AppleFileDL | LDAPDL] -D <db_to_dump>]\n", progname);
120	printf("        -M debug_level  Call malloc_debug(debug_level) to enable malloc debugging.\n");
121	printf("        -b              turn off stdout buffering.\n");
122	printf("        -c              run csp (rotty) tests.\n");
123	printf("        -m              Test Mac\n");
124	printf("        -w              Test Wrap\n");
125	printf("        -d              run dl tests.\n");
126	printf("        -a              Enable AutoCommit for dl modifications (default).\n");
127	printf("        -A              Disable AutoCommit for dl modifications.\n");
128	printf("        -D dbname       Dump a db into a human readable format.\n");
129	printf("        -s              Dump out schema info (use with -D).\n");
130    exit(1);
131}
132
133