2 * Copyright (c) 2005 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 * 01DL_CreateReleation.c
28 #include <Security/cssmapi.h>
29 #include <Security/cssmapple.h>
35 #define DBNAME "testdl"
37 CSSM_APPLEDL_OPEN_PARAMETERS openParameters
=
39 sizeof(CSSM_APPLEDL_OPEN_PARAMETERS
),
40 CSSM_APPLEDL_OPEN_PARAMETERS_VERSION
,
42 kCSSM_APPLEDL_MASK_MODE
,
47 0 /* NumberOfRecordTypes */,
51 CSSM_TRUE
/* IsLocal */,
52 NULL
, /* AccessPath - URL, dir path, etc. */
55 CSSM_DB_SCHEMA_ATTRIBUTE_INFO attributeInfo
[] =
61 CSSM_DB_ATTRIBUTE_FORMAT_STRING
67 CSSM_DB_ATTRIBUTE_FORMAT_STRING
70 CSSM_DB_SCHEMA_INDEX_INFO indexInfo
[] =
76 CSSM_DB_INDEX_ON_ATTRIBUTE
81 CSSM_DB_INDEX_NONUNIQUE
,
82 CSSM_DB_INDEX_ON_ATTRIBUTE
87 CSSM_DB_INDEX_NONUNIQUE
,
88 CSSM_DB_INDEX_ON_ATTRIBUTE
93 { 5, (uint8
*)"value" }
95 CSSM_DB_ATTRIBUTE_DATA attributeData
[] =
99 CSSM_DB_ATTRIBUTE_NAME_AS_STRING
,
101 CSSM_DB_ATTRIBUTE_FORMAT_STRING
103 sizeof(values
) / sizeof(CSSM_DATA
),
108 CSSM_DB_ATTRIBUTE_NAME_AS_STRING
,
110 CSSM_DB_ATTRIBUTE_FORMAT_STRING
112 sizeof(values
) / sizeof(CSSM_DATA
),
116 CSSM_DB_RECORD_ATTRIBUTE_DATA attributes
=
120 sizeof(attributeData
) / sizeof(CSSM_DB_ATTRIBUTE_DATA
),
125 static test1(CSSM_DL_HANDLE dl
)
128 CSSM_DL_DB_HANDLE dldb
= { dl
};
129 CSSM_DB_UNIQUE_RECORD_PTR uniqueId
;
131 pass
&= ok_status(CSSM_DL_DbCreate(dl
, DBNAME
, NULL
/* DbLocation */,
133 CSSM_DB_ACCESS_READ
| CSSM_DB_ACCESS_WRITE
,
134 NULL
/* CredAndAclEntry */,
139 pass
&= is_status(CSSM_DL_DataInsert(dldb
,
140 attributes
.DataRecordType
,
144 CSSMERR_DL_INVALID_RECORDTYPE
, "CSSM_DL_DataInsert no table");
146 pass
&= ok_status(CSSM_DL_CreateRelation(dldb
,
149 sizeof(attributeInfo
) / sizeof(CSSM_DB_SCHEMA_ATTRIBUTE_INFO
),
151 sizeof(indexInfo
) / sizeof(CSSM_DB_SCHEMA_INDEX_INFO
),
152 indexInfo
), "CSSM_DL_CreateRelation");
154 pass
&= ok_status(CSSM_DL_DataInsert(dldb
,
155 attributes
.DataRecordType
,
158 &uniqueId
), "CSSM_DL_DataInsert");
160 pass
&= is_status(CSSM_DL_DataInsert(dldb
,
161 attributes
.DataRecordType
,
165 CSSMERR_DL_INVALID_UNIQUE_INDEX_DATA
, "CSSM_DL_DataInsert dupe");
167 pass
&= ok_status(CSSM_DL_FreeUniqueRecord(dldb
, uniqueId
),
168 "CSSM_DL_FreeUniqueRecord");
170 pass
&= ok_status(CSSM_DL_DbClose(dldb
),
177 static test2(CSSM_DL_HANDLE dl
)
180 CSSM_DL_DB_HANDLE dldb
= { dl
};
181 CSSM_DB_UNIQUE_RECORD_PTR uniqueId
;
183 pass
&= ok_status(CSSM_DL_DbCreate(dl
, DBNAME
, NULL
/* DbLocation */,
185 CSSM_DB_ACCESS_READ
| CSSM_DB_ACCESS_WRITE
,
186 NULL
/* CredAndAclEntry */,
191 pass
&= ok_status(CSSM_DL_DbClose(dldb
),
194 pass
&= ok_status(CSSM_DL_DbOpen(dl
, DBNAME
, NULL
/* DbLocation */,
195 CSSM_DB_ACCESS_READ
| CSSM_DB_ACCESS_WRITE
,
196 NULL
/* CredAndAclEntry */,
201 pass
&= is_status(CSSM_DL_DataInsert(dldb
,
202 attributes
.DataRecordType
,
206 CSSMERR_DL_INVALID_RECORDTYPE
, "CSSM_DL_DataInsert no table");
208 pass
&= ok_status(CSSM_DL_CreateRelation(dldb
,
211 sizeof(attributeInfo
) / sizeof(CSSM_DB_SCHEMA_ATTRIBUTE_INFO
),
213 sizeof(indexInfo
) / sizeof(CSSM_DB_SCHEMA_INDEX_INFO
),
214 indexInfo
), "CSSM_DL_CreateRelation");
216 pass
&= ok_status(CSSM_DL_DataInsert(dldb
,
217 attributes
.DataRecordType
,
220 &uniqueId
), "CSSM_DL_DataInsert fails unless 4039735 is fixed");
222 pass
&= is_status(CSSM_DL_DataInsert(dldb
,
223 attributes
.DataRecordType
,
227 CSSMERR_DL_INVALID_UNIQUE_INDEX_DATA
,
228 "CSSM_DL_DataInsert dupe");
230 pass
&= ok_status(CSSM_DL_FreeUniqueRecord(dldb
, uniqueId
),
231 "CSSM_DL_FreeUniqueRecord");
233 pass
&= ok_status(CSSM_DL_DbClose(dldb
),
240 main(int argc
, char * const *argv
)
242 int guid_alt
= argc
> 1 && !strcmp(argv
[1], "-g");
243 /* {2cb56191-ee6f-432d-a377-853d3c6b949e} */
244 CSSM_GUID s3dl_guid
=
246 0x2cb56191, 0xee6f, 0x432d,
247 { 0xa3, 0x77, 0x85, 0x3d, 0x3c, 0x6b, 0x94, 0x9e }
249 const CSSM_GUID
*guid
= guid_alt
? & s3dl_guid
: &gGuidAppleFileDL
;
256 pass
&= ok(cssm_attach(guid
, &dl
), "cssm_attach");
257 pass
&= ok(tests_begin(argc
, argv
), "tests_begin");
259 pass
&= ok(test1(dl
), "insert record in new table with ac off");
260 pass
&= ok_status(CSSM_DL_DbDelete(dl
, DBNAME
, NULL
/* DbLocation */,
261 NULL
/* AccessCred */), "CSSM_DL_DbDelete");
262 pass
&= ok(test2(dl
),
263 "insert record in existing db in new table with ac off");
264 pass
&= ok_status(CSSM_DL_DbDelete(dl
, DBNAME
, NULL
/* DbLocation */,
265 NULL
/* AccessCred */), "CSSM_DL_DbDelete");
266 pass
&= ok(cssm_detach(guid
, dl
), "cssm_detach");
268 return !tests_end(pass
);