]> git.saurik.com Git - apple/security.git/blob - SecurityServer/tests/testutils.h
Security-179.tar.gz
[apple/security.git] / SecurityServer / tests / testutils.h
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18
19 //
20 // testutils - utilities for unit test drivers
21 //
22 #ifndef _H_TESTUTILS
23 #define _H_TESTUTILS
24
25 #include "testclient.h"
26
27
28 //
29 // Global test state
30 //
31 extern bool verbose;
32
33
34 //
35 // Error and diagnostic drivers
36 //
37 void error(const char *fmt, ...) __attribute__((format(printf,1,2)));
38 void error(const CssmCommonError &error, const char *fmt, ...) __attribute__((format(printf,2,3)));
39 void detail(const char *fmt, ...) __attribute__((format(printf,1,2)));
40 void detail(const CssmCommonError &error, const char *msg);
41 void prompt(const char *msg);
42 void prompt();
43
44
45 //
46 // A self-building "fake" context.
47 // (Fake in that it was hand-made without involvement of CSSM.)
48 //
49 class FakeContext : public ::Context {
50 public:
51 FakeContext(CSSM_CONTEXT_TYPE type, CSSM_ALGORITHMS alg, uint32 count);
52 FakeContext(CSSM_CONTEXT_TYPE type, CSSM_ALGORITHMS alg, ...);
53 };
54
55
56 //
57 // A test driver class for ACL tests
58 //
59 class AclTester {
60 public:
61 AclTester(ClientSession &ss, const AclEntryInput *acl);
62
63 void testWrap(const AccessCredentials *cred, const char *howWrong = NULL);
64 void testEncrypt(const AccessCredentials *cred, const char *howWrong = NULL);
65
66 ClientSession &session;
67 KeyHandle keyRef;
68 };
69
70
71 //
72 // A test driver class for database tests
73 //
74 class DbTester {
75 public:
76 DbTester(ClientSession &ss, const char *path,
77 const AccessCredentials *cred, int timeout = 30, bool sleepLock = true);
78
79 operator DbHandle () const { return dbRef; }
80 void unlock(const char *howWrong = NULL);
81 void changePassphrase(const AccessCredentials *cred, const char *howWrong = NULL);
82
83 ClientSession &session;
84 DBParameters params;
85 DLDbIdentifier dbId;
86 DbHandle dbRef;
87 };
88
89
90 #endif //_H_TESTUTILS