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