2 * Copyright (c) 2005-2006 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
23 * 00DL_Create-Delete.c
28 #include <Security/cssmapi.h>
29 #include <Security/cssmapple.h>
34 #include "testleaks.h"
36 #define DBNAME "testdl.db"
38 static CSSM_APPLEDL_OPEN_PARAMETERS openParameters
=
40 sizeof(CSSM_APPLEDL_OPEN_PARAMETERS
),
41 CSSM_APPLEDL_OPEN_PARAMETERS_VERSION
,
43 kCSSM_APPLEDL_MASK_MODE
,
46 static CSSM_DBINFO dbInfo
=
48 0 /* NumberOfRecordTypes */,
52 CSSM_TRUE
/* IsLocal */,
53 NULL
, /* AccessPath - URL, dir path, etc. */
58 static test1(CSSM_DL_HANDLE dl
)
61 CSSM_DL_DB_HANDLE dldb
= { dl
};
63 /* Case 1 regular create close delete. */
64 pass
&= ok_status(CSSM_DL_DbCreate(dldb
.DLHandle
, DBNAME
,
65 NULL
/* DbLocation */,
67 CSSM_DB_ACCESS_READ
| CSSM_DB_ACCESS_WRITE
,
68 NULL
/* CredAndAclEntry */,
69 NULL
/* &openParameters */,
73 pass
&= ok_status(CSSM_DL_DbClose(dldb
), "CSSM_DL_DbClose");
74 pass
&= ok_status(CSSM_DL_DbDelete(dldb
.DLHandle
, DBNAME
,
75 NULL
/* DbLocation */,
76 NULL
/* AccessCred */), "CSSM_DL_DbDelete");
77 pass
&= is_unix(unlink(DBNAME
), ENOENT
, "unlink");
83 static test2(CSSM_DL_HANDLE dl
)
86 CSSM_DL_DB_HANDLE dldb
= { dl
};
88 /* Case 2 regular create delete then close. */
89 pass
&= ok_status(CSSM_DL_DbCreate(dldb
.DLHandle
, DBNAME
,
90 NULL
/* DbLocation */,
92 CSSM_DB_ACCESS_READ
| CSSM_DB_ACCESS_WRITE
,
93 NULL
/* CredAndAclEntry */,
94 NULL
/* &openParameters */,
98 pass
&= ok_status(CSSM_DL_DbDelete(dldb
.DLHandle
, DBNAME
,
99 NULL
/* DbLocation */,
100 NULL
/* AccessCred */), "CSSM_DL_DbDelete");
101 pass
&= ok_status(CSSM_DL_DbClose(dldb
), "CSSM_DL_DbClose");
102 pass
&= is_unix(unlink(DBNAME
), ENOENT
, "unlink");
108 static test3(CSSM_DL_HANDLE dl
)
111 CSSM_DL_DB_HANDLE dldb
= { dl
};
113 /* Case 3 non autocommit create close delete. */
114 pass
&= ok_status(CSSM_DL_DbCreate(dldb
.DLHandle
, DBNAME
,
115 NULL
/* DbLocation */,
117 CSSM_DB_ACCESS_READ
| CSSM_DB_ACCESS_WRITE
,
118 NULL
/* CredAndAclEntry */,
123 pass
&= ok_status(CSSM_DL_DbClose(dldb
), "CSSM_DL_DbClose");
124 pass
&= ok_status(CSSM_DL_DbDelete(dldb
.DLHandle
, DBNAME
,
125 NULL
/* DbLocation */,
126 NULL
/* AccessCred */), "CSSM_DL_DbDelete");
127 pass
&= is_unix(unlink(DBNAME
), ENOENT
, "unlink");
133 static test4(CSSM_DL_HANDLE dl
)
136 CSSM_DL_DB_HANDLE dldb
= { dl
};
138 /* Case 4 non autocommit create delete then close. */
139 pass
&= ok_status(CSSM_DL_DbCreate(dldb
.DLHandle
, DBNAME
,
140 NULL
/* DbLocation */,
142 CSSM_DB_ACCESS_READ
| CSSM_DB_ACCESS_WRITE
,
143 NULL
/* CredAndAclEntry */,
148 pass
&= ok_status(CSSM_DL_DbDelete(dldb
.DLHandle
, DBNAME
,
149 NULL
/* DbLocation */,
150 NULL
/* AccessCred */), "CSSM_DL_DbDelete");
151 pass
&= ok_status(CSSM_DL_DbClose(dldb
), "CSSM_DL_DbClose");
152 pass
&= is_unix(unlink(DBNAME
), ENOENT
, "unlink");
158 static test5(CSSM_DL_HANDLE dl
)
161 CSSM_DL_DB_HANDLE dldb
= { dl
};
163 /* Case 5 non autocommit create rollback close delete. */
164 pass
&= ok_status(CSSM_DL_DbCreate(dldb
.DLHandle
, DBNAME
,
165 NULL
/* DbLocation */,
167 CSSM_DB_ACCESS_READ
| CSSM_DB_ACCESS_WRITE
,
168 NULL
/* CredAndAclEntry */,
172 pass
&= ok_status(CSSM_DL_PassThrough(dldb
, CSSM_APPLEFILEDL_ROLLBACK
,
173 NULL
, NULL
), "CSSM_APPLEFILEDL_ROLLBACK");
174 pass
&= ok_status(CSSM_DL_DbClose(dldb
), "CSSM_DL_DbClose");
175 pass
&= is_status(CSSM_DL_DbDelete(dldb
.DLHandle
, DBNAME
,
176 NULL
/* DbLocation */, NULL
/* AccessCred */),
177 CSSMERR_DL_DATASTORE_DOESNOT_EXIST
, "CSSM_DL_DbDelete");
178 pass
&= is_unix(unlink(DBNAME
), ENOENT
, "unlink");
184 static test6(CSSM_DL_HANDLE dl
)
187 CSSM_DL_DB_HANDLE dldb
= { dl
};
189 /* Case 6 non autocommit create rollback delete then close. */
190 pass
&= ok_status(CSSM_DL_DbCreate(dldb
.DLHandle
, DBNAME
,
191 NULL
/* DbLocation */,
193 CSSM_DB_ACCESS_READ
| CSSM_DB_ACCESS_WRITE
,
194 NULL
/* CredAndAclEntry */,
199 pass
&= ok_status(CSSM_DL_PassThrough(dldb
, CSSM_APPLEFILEDL_ROLLBACK
,
200 NULL
, NULL
), "CSSM_APPLEFILEDL_ROLLBACK");
201 pass
&= is_status(CSSM_DL_DbDelete(dldb
.DLHandle
, DBNAME
,
202 NULL
/* DbLocation */, NULL
/* AccessCred */),
203 CSSMERR_DL_DATASTORE_DOESNOT_EXIST
, "CSSM_DL_DbDelete");
204 pass
&= ok_status(CSSM_DL_DbClose(dldb
), "CSSM_DL_DbClose");
205 pass
&= is_unix(unlink(DBNAME
), ENOENT
, "unlink");
211 static test7(CSSM_DL_HANDLE dl
)
214 CSSM_DL_DB_HANDLE dldb
= { dl
};
216 /* Case 7 non autocommit create delete rollback then close. */
217 pass
&= ok_status(CSSM_DL_DbCreate(dldb
.DLHandle
, DBNAME
,
218 NULL
/* DbLocation */,
220 CSSM_DB_ACCESS_READ
| CSSM_DB_ACCESS_WRITE
,
221 NULL
/* CredAndAclEntry */,
226 pass
&= ok_status(CSSM_DL_DbDelete(dldb
.DLHandle
, DBNAME
,
227 NULL
/* DbLocation */, NULL
/* AccessCred */), "CSSM_DL_DbDelete");
228 pass
&= ok_status(CSSM_DL_PassThrough(dldb
, CSSM_APPLEFILEDL_ROLLBACK
,
229 NULL
, NULL
), "CSSM_APPLEFILEDL_ROLLBACK");
230 pass
&= ok_status(CSSM_DL_DbClose(dldb
), "CSSM_DL_DbClose");
231 pass
&= is_unix(unlink(DBNAME
), ENOENT
, "unlink");
237 static test8(CSSM_DL_HANDLE dl
)
240 CSSM_DL_DB_HANDLE dldb
= { dl
};
242 /* Case 8 delete non existant db. */
243 pass
&= is_status(CSSM_DL_DbDelete(dldb
.DLHandle
, DBNAME
,
244 NULL
/* DbLocation */, NULL
/* AccessCred */),
245 CSSMERR_DL_DATASTORE_DOESNOT_EXIST
, "CSSM_DL_DbDelete");
252 main(int argc
, char * const *argv
)
254 int guid_alt
= argc
> 1 && !strcmp(argv
[1], "-g");
255 /* {2cb56191-ee6f-432d-a377-853d3c6b949e} */
256 CSSM_GUID s3dl_guid
=
258 0x2cb56191, 0xee6f, 0x432d,
259 { 0xa3, 0x77, 0x85, 0x3d, 0x3c, 0x6b, 0x94, 0x9e }
261 const CSSM_GUID
*guid
= guid_alt
? & s3dl_guid
: &gGuidAppleFileDL
;
264 /* Total number of test cases in this file. */
267 ok(cssm_attach(guid
, &dl
), "cssm_attach");
268 ok(tests_begin(argc
, argv
), "setup");
271 ok(test1(dl
), "create close delete");
272 ok(test2(dl
), "create delete close");
273 ok(test3(dl
), "autocommit off create close delete");
274 ok(test4(dl
), "autocommit off create delete close");
275 ok(test5(dl
), "autocommit off create rollback close delete");
276 ok(test6(dl
), "autocommit off create rollback delete close");
277 ok(test7(dl
), "autocommit off create delete rollback close");
278 ok(test8(dl
), "delete non existant db");
280 ok(cssm_detach(guid
, dl
), "cssm_detach");
281 ok(tests_end(1), "cleanup");
282 TODO
: {ok_leaks("leaks");}