exip  Alpha 0.5.4
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
check_stringTables.c
Go to the documentation of this file.
1 /*==================================================================*\
2 | EXIP - Embeddable EXI Processor in C |
3 |--------------------------------------------------------------------|
4 | This work is licensed under BSD 3-Clause License |
5 | The full license terms and conditions are located in LICENSE.txt |
6 \===================================================================*/
7 
18 #include <stdlib.h>
19 #include <check.h>
20 #include "sTables.h"
21 #include "stringManipulate.h"
22 #include "memManagement.h"
23 #include "dynamicArray.h"
24 
25 /* BEGIN: table tests */
26 
27 START_TEST (test_createValueTable)
28 {
29  ValueTable valueTable;
31 
32  err = createValueTable(&valueTable);
33 
34  fail_unless (err == EXIP_OK, "createValueTable returns error code %d", err);
35  fail_unless (valueTable.count == 0,
36  "createValueTable populates the valueTable with count: %d", valueTable.count);
38  "createValueTable creates dynamic array with %d rows", valueTable.dynArray.arrayEntries);
39  fail_if(valueTable.value == NULL);
40 
41  destroyDynArray(&valueTable.dynArray);
42 }
44 
45 START_TEST (test_addUriEntry)
46 {
48  UriTable uriTable;
49  SmallIndex entryId = 55;
50  String test_uri = {"test_uri_string", 15};
51 
52  // Create the URI table
54  fail_if(err != EXIP_OK);
55 
56  err = addUriEntry(&uriTable, test_uri, &entryId);
57 
58  fail_unless (err == EXIP_OK, "addUriEntry returns error code %d", err);
60  "addUriEntry changed the dynArray.arrayEntries unnecessary");
61  fail_unless (uriTable.count == 1,
62  "addUriEntry did not update count properly");
63  fail_unless (stringEqual(uriTable.uri[0].uriStr, test_uri) == 1,
64  "addUriEntry changed the uriStr");
65  fail_unless (entryId == 0,
66  "addUriEntry returned wrong entryId: %d", entryId);
67 
68  fail_if(uriTable.uri[0].lnTable.ln == NULL);
69 
71 
72  err = addUriEntry(&uriTable, test_uri, &entryId);
73 
74  fail_unless (err == EXIP_OK, "addUriEntry returns error code %d", err);
76  "addUriEntry did not update the dynArray.arrayEntries properly");
78  "addUriEntry did not update rowCount properly");
79  fail_unless (stringEqual(uriTable.uri[DEFAULT_URI_ENTRIES_NUMBER].uriStr, test_uri) == 1,
80  "addUriEntry changed the uriStr");
82  "addUriEntry returned wrong entryId: %d", entryId);
83 
85 
86  destroyDynArray(&uriTable.dynArray);
87 }
89 
90 START_TEST (test_addLnEntry)
91 {
93  LnTable lnTable;
94  Index entryId = 55;
95  String test_ln = {"test_ln_string", 14};
96 
97  err = createDynArray(&lnTable.dynArray, sizeof(LnEntry), DEFAULT_LN_ENTRIES_NUMBER);
98  fail_if(err != EXIP_OK);
99 
100  err = addLnEntry(&lnTable, test_ln, &entryId);
101 
102  fail_unless (err == EXIP_OK, "addLnEntry returns error code %d", err);
104  "addLnEntry changed the dynArray.arrayEntries unnecessary");
105  fail_unless (lnTable.count == 1,
106  "addLnEntry did not update rowCount properly");
107  fail_unless (stringEqual(lnTable.ln[0].lnStr, test_ln) == 1,
108  "addLnEntry changed the lnStr");
109  fail_unless (entryId == 0,
110  "addLnEntry returned wrong entryId: %d", entryId);
111 
112 #if VALUE_CROSSTABLE_USE
113  fail_if(lnTable.ln[0].vxTable != NULL);
114 #endif
115 
117 
118  err = addLnEntry(&lnTable, test_ln, &entryId);
119 
120  fail_unless (err == EXIP_OK, "addLnEntry returns error code %d", err);
122  "addLnEntry did not update the dynArray.arrayEntries properly");
124  "addLnEntry did not update count properly");
125  fail_unless (stringEqual(lnTable.ln[DEFAULT_LN_ENTRIES_NUMBER].lnStr, test_ln) == 1,
126  "addLnEntry changed the lnStr");
128  "addLnEntry returned wrong entryId: %d", entryId);
129 #if VALUE_CROSSTABLE_USE
131 #endif
132  destroyDynArray(&lnTable.dynArray);
133 }
134 END_TEST
135 
136 START_TEST (test_addValueEntry)
137 {
138  EXIStream testStrm;
139  errorCode tmp_err_code = EXIP_UNEXPECTED_ERROR;
140  String testStr = {"TEST-007", 8};
141  EXIGrammarStack gStack;
142 
143  // IV: Initialize the stream
144  {
145  tmp_err_code = initAllocList(&(testStrm.memList));
146  gStack.nextInStack = NULL;
147  gStack.grammar = NULL;
148  testStrm.gStack = &gStack;
149  testStrm.context.bitPointer = 0;
150  testStrm.buffer.bufLen = 0;
151  testStrm.buffer.bufContent = 0;
152  tmp_err_code += createValueTable(&testStrm.valueTable);
153  testStrm.schema = memManagedAllocate(&testStrm.memList, sizeof(EXIPSchema));
154  fail_unless (testStrm.schema != NULL, "Memory alloc error");
155  /* Create and initialize initial string table entries */
156  tmp_err_code += createDynArray(&testStrm.schema->uriTable.dynArray, sizeof(UriEntry), DEFAULT_URI_ENTRIES_NUMBER);
157  tmp_err_code += createUriTableEntries(&testStrm.schema->uriTable, FALSE);
158  }
159  fail_unless (tmp_err_code == EXIP_OK, "initStream returns an error code %d", tmp_err_code);
160 
161  testStrm.gStack->currQNameID.uriId = 1; // http://www.w3.org/XML/1998/namespace
162  testStrm.gStack->currQNameID.lnId = 2; // lang
163 
164  tmp_err_code = addValueEntry(&testStrm, testStr, testStrm.gStack->currQNameID);
165 
166  fail_unless (tmp_err_code == EXIP_OK, "addValueEntry returns an error code %d", tmp_err_code);
167 #if VALUE_CROSSTABLE_USE
168  fail_unless (testStrm.schema->uriTable.uri[testStrm.gStack->currQNameID.uriId].lnTable.ln[testStrm.gStack->currQNameID.lnId].vxTable != NULL, "addValueEntry does not create vxTable");
169  fail_unless (testStrm.schema->uriTable.uri[testStrm.gStack->currQNameID.uriId].lnTable.ln[testStrm.gStack->currQNameID.lnId].vxTable->count == 1, "addValueEntry does not create correct vxTable");
170 #endif
171  fail_unless (testStrm.valueTable.count == 1, "addValueEntry does not create global value entry");
172 
175  freeAllocList(&testStrm.memList);
176 }
177 END_TEST
178 
179 /* END: table tests */
180 
182 {
183  Suite *s = suite_create ("stringTables");
184 
185  {
186  /* Table test case */
187  TCase *tc_tables = tcase_create ("Tables");
188  tcase_add_test (tc_tables, test_createValueTable);
189  tcase_add_test (tc_tables, test_addUriEntry);
190  tcase_add_test (tc_tables, test_addLnEntry);
191  tcase_add_test (tc_tables, test_addValueEntry);
192  suite_add_tcase (s, tc_tables);
193  }
194 
195  return s;
196 }
197 
198 int main (void)
199 {
200  int number_failed;
201  Suite *s = tables_suite();
202  SRunner *sr = srunner_create (s);
203 #ifdef _MSC_VER
205 #endif
207  number_failed = srunner_ntests_failed (sr);
208  srunner_free (sr);
209  return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
210 }