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