test: Deallocate all memory in isds_DbOwnerInfo_duplicate tests
[libisds.git] / test / offline / isds_DbUserInfo_duplicate.c
blob2381929f9ff19facf1534c93848446a566e34978
1 #include "../test.h"
2 #include "isds.h"
4 static int test_isds_DbUserInfo_duplicate(struct isds_DbUserInfo *origin) {
5 struct isds_DbUserInfo *copy = isds_DbUserInfo_duplicate(origin);
7 if (!origin) {
8 if (copy)
9 FAIL_TEST("Duplicate of NULL should be NULL");
10 PASS_TEST;
13 if (!copy)
14 FAIL_TEST("isds_DbUserInfo_duplicate() returned NULL instead of "
15 "pointer to copy");
17 TEST_STRING_DUPLICITY(origin->userID, copy->userID);
18 TEST_INTPTR_DUPLICITY(origin->userType, copy->userType);
19 TEST_INTPTR_DUPLICITY(origin->userPrivils, copy->userPrivils);
21 /* Name of person */
22 TEST_POINTER_DUPLICITY(origin->personName, copy->personName);
23 if (origin->personName && copy->personName) {
24 TEST_STRING_DUPLICITY(origin->personName->pnFirstName,
25 copy->personName->pnFirstName);
26 TEST_STRING_DUPLICITY(origin->personName->pnMiddleName,
27 copy->personName->pnMiddleName);
28 TEST_STRING_DUPLICITY(origin->personName->pnLastName,
29 copy->personName->pnLastName);
30 TEST_STRING_DUPLICITY(origin->personName->pnLastNameAtBirth,
31 copy->personName->pnLastNameAtBirth);
34 /* Post address */
35 TEST_POINTER_DUPLICITY(origin->address, copy->address);
36 if (origin->address && copy->address) {
37 TEST_STRING_DUPLICITY(origin->address->adCity,
38 copy->address->adCity);
39 TEST_STRING_DUPLICITY(origin->address->adStreet,
40 copy->address->adStreet);
41 TEST_STRING_DUPLICITY(origin->address->adNumberInStreet,
42 copy->address->adNumberInStreet);
43 TEST_STRING_DUPLICITY(origin->address->adNumberInMunicipality,
44 copy->address->adNumberInMunicipality);
45 TEST_STRING_DUPLICITY(origin->address->adZipCode,
46 copy->address->adZipCode);
47 TEST_STRING_DUPLICITY(origin->address->adState,
48 copy->address->adState);
51 /* Date of birth */
52 TEST_POINTER_DUPLICITY(origin->biDate,
53 copy->biDate);
54 if(origin->biDate && copy->biDate) {
55 if (origin->biDate->tm_year != copy->biDate->tm_year)
56 FAIL_TEST("biDate differs in tm_year: expected=%d, got=%d",
57 origin->biDate->tm_year, copy->biDate->tm_year);
58 if (origin->biDate->tm_mon != copy->biDate->tm_mon)
59 FAIL_TEST("biDate differs in tm_mon: expected=%d, got=%d",
60 origin->biDate->tm_mon, copy->biDate->tm_mon);
61 if (origin->biDate->tm_mday != copy->biDate->tm_mday)
62 FAIL_TEST("biDate differs in tm_mday: expected=%d, got=%d",
63 origin->biDate->tm_mday, copy->biDate->tm_mday);
66 TEST_INTPTR_DUPLICITY(origin->ic, copy->ic);
67 TEST_INTPTR_DUPLICITY(origin->firmName, copy->firmName);
68 TEST_INTPTR_DUPLICITY(origin->caStreet, copy->caStreet);
69 TEST_INTPTR_DUPLICITY(origin->caCity, copy->caCity);
70 TEST_INTPTR_DUPLICITY(origin->caZipCode, copy->caZipCode);
71 TEST_INTPTR_DUPLICITY(origin->caState, copy->caState);
73 PASS_TEST;
77 int main(int argc, char **argv) {
79 INIT_TEST("isds_DbUserInfo_duplicate()");
80 if (isds_init())
81 ABORT_UNIT("isds_init() failed");
83 TEST("NULL", test_isds_DbUserInfo_duplicate, NULL);
85 struct isds_DbUserInfo *empty;
86 TEST_CALLOC(empty);
87 TEST("Empty structure", test_isds_DbUserInfo_duplicate, empty);
89 /* Full structure */
90 isds_UserType UserType = 2;
91 long int UserPrivils = 3;
92 struct isds_PersonName PersonName = {
93 .pnFirstName = "P1",
94 .pnMiddleName = "P2",
95 .pnLastName = "P3",
96 .pnLastNameAtBirth = "P4"
98 struct isds_Address Address = {
99 .adCity = "A1",
100 .adStreet = "A2",
101 .adNumberInStreet = "A3",
102 .adNumberInMunicipality = "A4",
103 .adZipCode = "A5",
104 .adState = "A6"
106 struct tm BiDate = {
107 .tm_year = 1,
108 .tm_mon = 2,
109 .tm_mday = 3
111 struct isds_DbUserInfo full = {
112 .userID = "1",
113 .userType = &UserType,
114 .userPrivils = &UserPrivils,
115 .personName = &PersonName,
116 .address = &Address,
117 .biDate = &BiDate,
118 .ic = "7",
119 .firmName = "8",
120 .caStreet = "9",
121 .caCity = "10",
122 .caZipCode = "11",
123 .caState = "12"
125 TEST("Full structure", test_isds_DbUserInfo_duplicate, &full);
127 isds_cleanup();
128 SUM_TEST();