test: Deallocate all memory in isds_DbOwnerInfo_duplicate tests
[libisds.git] / test / offline / isds_DbOwnerInfo_duplicate.c
blob23a024c67913bd86a675caf11add52c0ff544954
1 #include "../test.h"
2 #include "isds.h"
3 #include <string.h>
5 static int test_isds_DbOwnerInfo_duplicate(struct isds_DbOwnerInfo *origin) {
6 struct isds_DbOwnerInfo *copy = isds_DbOwnerInfo_duplicate(origin);
7 TEST_DESTRUCTOR((void(*)(void*))isds_DbOwnerInfo_free, &copy);
9 if (!origin) {
10 if (copy)
11 FAIL_TEST("Duplicate of NULL should be NULL");
12 PASS_TEST;
15 if (!copy)
16 FAIL_TEST("isds_DbOwnerInfo_duplicate() returned NULL instead of "
17 "pointer to copy");
19 TEST_STRING_DUPLICITY(origin->dbID, copy->dbID);
20 TEST_INTPTR_DUPLICITY(origin->dbType, copy->dbType);
21 TEST_STRING_DUPLICITY(origin->ic, copy->ic);
23 /* Name of person */
24 TEST_POINTER_DUPLICITY(origin->personName, copy->personName);
25 if (origin->personName && copy->personName) {
26 TEST_STRING_DUPLICITY(origin->personName->pnFirstName,
27 copy->personName->pnFirstName);
28 TEST_STRING_DUPLICITY(origin->personName->pnMiddleName,
29 copy->personName->pnMiddleName);
30 TEST_STRING_DUPLICITY(origin->personName->pnLastName,
31 copy->personName->pnLastName);
32 TEST_STRING_DUPLICITY(origin->personName->pnLastNameAtBirth,
33 copy->personName->pnLastNameAtBirth);
36 /* Birth of person */
37 TEST_POINTER_DUPLICITY(origin->birthInfo, copy->birthInfo);
38 if(origin->birthInfo && copy->birthInfo) {
39 TEST_POINTER_DUPLICITY(origin->birthInfo->biDate,
40 copy->birthInfo->biDate);
41 if(origin->birthInfo->biDate && copy->birthInfo->biDate) {
42 if (origin->birthInfo->biDate->tm_year !=
43 copy->birthInfo->biDate->tm_year)
44 FAIL_TEST("biDate differs in tm_year: expected=%d, got=%d",
45 origin->birthInfo->biDate->tm_year,
46 copy->birthInfo->biDate->tm_year);
47 if (origin->birthInfo->biDate->tm_mon !=
48 copy->birthInfo->biDate->tm_mon)
49 FAIL_TEST("biDate differs in tm_mon: expected=%d, got=%d",
50 origin->birthInfo->biDate->tm_mon,
51 copy->birthInfo->biDate->tm_mon);
52 if (origin->birthInfo->biDate->tm_mday !=
53 copy->birthInfo->biDate->tm_mday)
54 FAIL_TEST("biDate differs in tm_mday: expected=%d, got=%d",
55 origin->birthInfo->biDate->tm_mday,
56 copy->birthInfo->biDate->tm_mday);
59 TEST_STRING_DUPLICITY(origin->birthInfo->biCity,
60 copy->birthInfo->biCity);
61 TEST_STRING_DUPLICITY(origin->birthInfo->biCounty,
62 copy->birthInfo->biCounty);
63 TEST_STRING_DUPLICITY(origin->birthInfo->biState,
64 copy->birthInfo->biState);
67 /* Post address */
68 TEST_POINTER_DUPLICITY(origin->address, copy->address);
69 if (origin->address && copy->address) {
70 TEST_STRING_DUPLICITY(origin->address->adCity,
71 copy->address->adCity);
72 TEST_STRING_DUPLICITY(origin->address->adStreet,
73 copy->address->adStreet);
74 TEST_STRING_DUPLICITY(origin->address->adNumberInStreet,
75 copy->address->adNumberInStreet);
76 TEST_STRING_DUPLICITY(origin->address->adNumberInMunicipality,
77 copy->address->adNumberInMunicipality);
78 TEST_STRING_DUPLICITY(origin->address->adZipCode,
79 copy->address->adZipCode);
80 TEST_STRING_DUPLICITY(origin->address->adState,
81 copy->address->adState);
84 TEST_STRING_DUPLICITY(origin->nationality, copy->nationality);
85 TEST_STRING_DUPLICITY(origin->email, copy->email);
86 TEST_STRING_DUPLICITY(origin->telNumber, copy->telNumber);
87 TEST_STRING_DUPLICITY(origin->identifier, copy->identifier);
88 TEST_STRING_DUPLICITY(origin->registryCode, copy->registryCode);
89 TEST_INTPTR_DUPLICITY(origin->dbState, copy->dbState);
90 TEST_BOOLEANPTR_DUPLICITY(origin->dbEffectiveOVM, copy->dbEffectiveOVM);
91 TEST_BOOLEANPTR_DUPLICITY(origin->dbOpenAddressing, copy->dbOpenAddressing);
93 PASS_TEST;
97 int main(int argc, char **argv) {
99 INIT_TEST("isds_DbOwnerInfo_duplicate()");
100 if (isds_init())
101 ABORT_UNIT("isds_init() failed");
103 TEST("NULL", test_isds_DbOwnerInfo_duplicate, NULL);
105 struct isds_DbOwnerInfo empty;
106 memset(&empty, 0, sizeof(empty));
107 TEST("Empty structure", test_isds_DbOwnerInfo_duplicate, &empty);
109 /* Full structure */
110 isds_DbType dbType = 2;
111 struct isds_PersonName PersonName = {
112 .pnFirstName = "P1",
113 .pnMiddleName = "P2",
114 .pnLastName = "P3",
115 .pnLastNameAtBirth = "P4"
117 struct tm BiDate = {
118 .tm_year = 1,
119 .tm_mon = 2,
120 .tm_mday = 3
122 struct isds_BirthInfo BirthInfo = {
123 .biDate = &BiDate,
124 .biCity = "B2",
125 .biCounty = "B3",
126 .biState = "B4"
128 struct isds_Address Address = {
129 .adCity = "A1",
130 .adStreet = "A2",
131 .adNumberInStreet = "A3",
132 .adNumberInMunicipality = "A4",
133 .adZipCode = "A5",
134 .adState = "A6"
136 long int DbState = 13;
137 _Bool DbEffectiveOVM = 1;
138 _Bool DbOpenAddressing = 1;
139 struct isds_DbOwnerInfo full = {
140 .dbID = "1",
141 .dbType = &dbType,
142 .ic = "3",
143 .personName = &PersonName,
144 .firmName = "5",
145 .birthInfo = &BirthInfo,
146 .address = &Address,
147 .nationality = "8",
148 .email = "9",
149 .telNumber = "10",
150 .identifier = "11",
151 .registryCode = "12",
152 .dbState = &DbState,
153 .dbEffectiveOVM = &DbEffectiveOVM,
154 .dbOpenAddressing = &DbOpenAddressing
156 TEST("Full structure", test_isds_DbOwnerInfo_duplicate, &full);
158 isds_cleanup();
159 SUM_TEST();