| 1 | /* | |
| 2 | * Copyright 1999-2006 University of Chicago | |
| 3 | * | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | */ | |
| 16 | ||
| 17 | #include "globus_provider_test.h" | |
| 18 | #include "wsnt_TopicExpressionType.h" | |
| 19 | #include "wstop_TopicSet.h" | |
| 20 | #include "wstop_TopicSetType.h" | |
| 21 | #include "wstop_SimpleTopicExpression.h" | |
| 22 | #include "globus_xml_buffer.h" | |
| 23 | #include "xsd_QName.h" | |
| 24 | #include "xsd_boolean.h" | |
| 25 | #include "xsd_dateTime.h" | |
| 26 | #include "xsd_int.h" | |
| 27 | ||
| 28 | globus_bool_t | |
| 29 | fault_equals_expectation( | |
| 30 | globus_result_t result, | |
| 31 | xsd_QName * expected_fault, | |
| 32 | xsd_any * fault) | |
| 33 | 243 | { |
| 34 | 243 | char * error_str = NULL; |
| 35 | 243 | globus_bool_t retval = GLOBUS_TRUE; |
| 36 | ||
| 37 | 243 | if (result != GLOBUS_SUCCESS && fault == NULL) |
| 38 | { | |
| 39 | 0 | error_str = globus_error_print_friendly(globus_error_peek(result)); |
| 40 | ||
| 41 | 0 | fprintf(stderr, |
| 42 | "Expected Fault {%s}%s, got %s\n", | |
| 43 | expected_fault->Namespace, | |
| 44 | expected_fault->local, | |
| 45 | error_str); | |
| 46 | 0 | retval = GLOBUS_FALSE; |
| 47 | } | |
| 48 | 243 | else if (fault != NULL) |
| 49 | { | |
| 50 | 243 | if (fault->element == NULL) |
| 51 | { | |
| 52 | 0 | fprintf(stderr, |
| 53 | "Expected {%s}%s got unknown fault\n", | |
| 54 | expected_fault->Namespace, | |
| 55 | expected_fault->local); | |
| 56 | 0 | retval = GLOBUS_FALSE; |
| 57 | } | |
| 58 | else | |
| 59 | { | |
| 60 | 243 | if(! xsd_QName_keyeq(fault->element, expected_fault)) |
| 61 | { | |
| 62 | 0 | fprintf(stderr, |
| 63 | "Expected Fault {%s}%s got {%s}%s\n", | |
| 64 | expected_fault->Namespace, | |
| 65 | expected_fault->local, | |
| 66 | fault->element->Namespace, | |
| 67 | fault->element->local); | |
| 68 | 0 | retval = GLOBUS_FALSE; |
| 69 | } | |
| 70 | } | |
| 71 | } | |
| 72 | else | |
| 73 | { | |
| 74 | 0 | fprintf(stderr, |
| 75 | "Expected Fault {%s}%s got non-fault\n", | |
| 76 | expected_fault->Namespace, | |
| 77 | expected_fault->local); | |
| 78 | 0 | retval = GLOBUS_FALSE; |
| 79 | } | |
| 80 | 243 | if (error_str) |
| 81 | { | |
| 82 | 0 | free(error_str); |
| 83 | } | |
| 84 | 243 | return retval; |
| 85 | } | |
| 86 | /* fault_equals_expectation() */ | |
| 87 | ||
| 88 | globus_bool_t | |
| 89 | fault_occurred( | |
| 90 | globus_result_t result, | |
| 91 | xsd_any * fault) | |
| 92 | 882 | { |
| 93 | 882 | char * error_str = NULL; |
| 94 | 882 | globus_bool_t retval = GLOBUS_FALSE; |
| 95 | ||
| 96 | 882 | if (result != GLOBUS_SUCCESS && fault == NULL) |
| 97 | { | |
| 98 | 0 | error_str = globus_error_print_friendly(globus_error_peek(result)); |
| 99 | ||
| 100 | 0 | fprintf(stderr, |
| 101 | "Got non-success from operation expected to succeed: %s\n", | |
| 102 | error_str); | |
| 103 | 0 | retval = GLOBUS_TRUE; |
| 104 | } | |
| 105 | 882 | else if (fault != NULL) |
| 106 | { | |
| 107 | 0 | if (fault->element != NULL) |
| 108 | { | |
| 109 | 0 | fprintf(stderr, |
| 110 | "Got fault from operation expected to succeed {%s}%s\n", | |
| 111 | fault->element->Namespace, | |
| 112 | fault->element->local); | |
| 113 | } | |
| 114 | else | |
| 115 | { | |
| 116 | 0 | fprintf(stderr, |
| 117 | "Got unknown fault from operation expected to succeed\n"); | |
| 118 | } | |
| 119 | 0 | retval = GLOBUS_TRUE; |
| 120 | } | |
| 121 | ||
| 122 | 882 | if (error_str) |
| 123 | { | |
| 124 | 0 | free(error_str); |
| 125 | } | |
| 126 | 882 | return retval; |
| 127 | } | |
| 128 | /* fault_occurred() */ | |
| 129 | ||
| 130 | globus_bool_t | |
| 131 | any_equal( | |
| 132 | xsd_any * any1, | |
| 133 | xsd_any * any2) | |
| 134 | 1119 | { |
| 135 | 1119 | if (any1->any_info->serialize == xsd_boolean_info.serialize) |
| 136 | { | |
| 137 | /* | |
| 138 | fprintf(stderr, "Comparing %s to %s\n", | |
| 139 | (*(xsd_boolean*)any1->value) ? "true" : "false", | |
| 140 | (*(xsd_boolean*)any2->value) ? "true" : "false"); | |
| 141 | */ | |
| 142 | ||
| 143 | 3 | if (*(xsd_boolean*)any1->value == *(xsd_boolean*)any2->value) |
| 144 | { | |
| 145 | 3 | return GLOBUS_TRUE; |
| 146 | } | |
| 147 | } | |
| 148 | 1116 | else if (any1->any_info->serialize == xsd_anyURI_info.serialize) |
| 149 | { | |
| 150 | char *start1, *end1; | |
| 151 | char *start2, *end2; | |
| 152 | ||
| 153 | /* | |
| 154 | fprintf(stderr, "Comparing %s to %s\n", | |
| 155 | *(xsd_anyURI *)any1->value, | |
| 156 | *(xsd_anyURI *)any2->value); | |
| 157 | */ | |
| 158 | 9 | start1 = *(xsd_anyURI *) any1->value; |
| 159 | ||
| 160 | 18 | while (*start1 != 0 && isspace(*start1)) |
| 161 | { | |
| 162 | 0 | start1++; |
| 163 | } | |
| 164 | 9 | end1 = start1; |
| 165 | 531 | while (*end1 && !isspace(*end1)) |
| 166 | { | |
| 167 | 513 | end1++; |
| 168 | } | |
| 169 | ||
| 170 | 9 | start2 = *(xsd_anyURI *) any2->value; |
| 171 | 18 | while (*start2 != 0 && isspace(*start2)) |
| 172 | { | |
| 173 | 0 | start2++; |
| 174 | } | |
| 175 | 9 | end2 = start2; |
| 176 | 531 | while (*end2 && !isspace(*end2)) |
| 177 | { | |
| 178 | 513 | end2++; |
| 179 | } | |
| 180 | 9 | if (end2 - start2 == end1 - start1) |
| 181 | { | |
| 182 | 9 | if (strncmp(start1, start2, end1-start1) == 0) |
| 183 | { | |
| 184 | 9 | return GLOBUS_TRUE; |
| 185 | } | |
| 186 | } | |
| 187 | } | |
| 188 | 1107 | else if (any1->any_info->serialize == xsd_dateTime_info.serialize) |
| 189 | { | |
| 190 | /* Don't bother comparing times for these tests */ | |
| 191 | 0 | return GLOBUS_TRUE; |
| 192 | } | |
| 193 | 1107 | else if (any1->any_info->serialize == |
| 194 | wsnt_TopicExpressionType_info.serialize) | |
| 195 | { | |
| 196 | wsnt_TopicExpressionType * t1, *t2; | |
| 197 | ||
| 198 | 315 | t1 = any1->value; |
| 199 | 315 | t2 = any2->value; |
| 200 | ||
| 201 | 315 | if ((t1->_Dialect == NULL && t2->_Dialect != NULL) || |
| 202 | (t1->_Dialect != NULL && t1->_Dialect == NULL)) | |
| 203 | { | |
| 204 | 0 | return GLOBUS_FALSE; |
| 205 | } | |
| 206 | 315 | if ((t1->_Dialect != NULL |
| 207 | && t2->_Dialect != NULL | |
| 208 | && strcmp(t1->_Dialect, t2->_Dialect) == 0) || | |
| 209 | (t1->_Dialect == t2->_Dialect)) | |
| 210 | { | |
| 211 | 315 | return (any_equal(t1->any, t2->any)); |
| 212 | } | |
| 213 | } | |
| 214 | 792 | else if (any1->any_info->serialize == xsd_QName_info.serialize || |
| 215 | any1->any_info->serialize == xsd_QName_contents_info.serialize) | |
| 216 | { | |
| 217 | /* | |
| 218 | fprintf(stderr, "Comparing {%s}%s to {%s}%s\n", | |
| 219 | ((xsd_QName*)any1->value)->Namespace, | |
| 220 | ((xsd_QName*)any1->value)->local, | |
| 221 | ((xsd_QName*)any2->value)->Namespace, | |
| 222 | ((xsd_QName*)any2->value)->local); | |
| 223 | */ | |
| 224 | ||
| 225 | 0 | if (xsd_QName_keyeq(any1->value, any2->value)) |
| 226 | { | |
| 227 | 0 | return GLOBUS_TRUE; |
| 228 | } | |
| 229 | } | |
| 230 | 792 | else if (any1->any_info->serialize == xsd_int_info.serialize) |
| 231 | { | |
| 232 | 48 | if (*(xsd_int *)any1->value == *(xsd_int *)any2->value) |
| 233 | { | |
| 234 | 48 | return GLOBUS_TRUE; |
| 235 | } | |
| 236 | } | |
| 237 | 744 | else if (any1->any_info->serialize == xsd_string_info.serialize) |
| 238 | { | |
| 239 | 318 | if ((any1->value == any2->value) || |
| 240 | (strcmp(*(xsd_string *)any1->value, *(xsd_string *)any2->value) == 0)) | |
| 241 | { | |
| 242 | 306 | return GLOBUS_TRUE; |
| 243 | } | |
| 244 | } | |
| 245 | 426 | else if (any1->any_info->serialize == globus_xml_buffer_info.serialize || |
| 246 | any1->any_info->serialize == globus_xml_buffer_contents_info.serialize) | |
| 247 | { | |
| 248 | globus_xml_buffer * expected_buf; | |
| 249 | globus_xml_buffer * actual_buf; | |
| 250 | char * expected_ptr; | |
| 251 | char * actual_ptr; | |
| 252 | int expected_length; | |
| 253 | int actual_length; | |
| 254 | ||
| 255 | /* | |
| 256 | fprintf(stderr, "Comparing %s to %s\n", | |
| 257 | ((globus_xml_buffer *)any1->value)->buffer, | |
| 258 | ((globus_xml_buffer *)any2->value)->buffer); | |
| 259 | */ | |
| 260 | ||
| 261 | 108 | expected_buf = any1->value; |
| 262 | 108 | actual_buf = any2->value; |
| 263 | ||
| 264 | 108 | expected_ptr = expected_buf->buffer; |
| 265 | 108 | actual_ptr = actual_buf->buffer; |
| 266 | ||
| 267 | 108 | expected_length = expected_buf->length; |
| 268 | 108 | actual_length = actual_buf->length; |
| 269 | ||
| 270 | /* Remove leading/trailing whitespace */ | |
| 271 | 240 | while (isspace(*expected_ptr)) |
| 272 | { | |
| 273 | 24 | expected_ptr++; |
| 274 | 24 | expected_length--; |
| 275 | } | |
| 276 | 216 | while (isspace(expected_ptr[expected_length-1])) |
| 277 | { | |
| 278 | 0 | expected_ptr[expected_length-1] = '\0'; |
| 279 | 0 | expected_length--; |
| 280 | } | |
| 281 | 1416 | while (isspace(*actual_ptr)) |
| 282 | { | |
| 283 | 1200 | actual_ptr++; |
| 284 | 1200 | actual_length--; |
| 285 | } | |
| 286 | 1152 | while (isspace(actual_ptr[actual_length-1])) |
| 287 | { | |
| 288 | 936 | actual_length--; |
| 289 | } | |
| 290 | ||
| 291 | 108 | if (expected_length == actual_length) |
| 292 | { | |
| 293 | 108 | if (memcmp( |
| 294 | expected_ptr, | |
| 295 | actual_ptr, | |
| 296 | expected_length) == 0) | |
| 297 | { | |
| 298 | 108 | return GLOBUS_TRUE; |
| 299 | } | |
| 300 | } | |
| 301 | } | |
| 302 | 318 | else if (any1->any_info == &wstop_TopicSetType_info) |
| 303 | { | |
| 304 | 3 | wstop_TopicSetType * topic1 = any1->value; |
| 305 | 3 | wstop_TopicSetType * topic2 = any2->value; |
| 306 | globus_soap_message_handle_t handle1; | |
| 307 | globus_soap_message_handle_t handle2; | |
| 308 | xmlDocPtr doc1; | |
| 309 | xmlDocPtr doc2; | |
| 310 | xmlNodePtr node1; | |
| 311 | xmlNodePtr node2; | |
| 312 | globus_bool_t * seen; | |
| 313 | globus_result_t result; | |
| 314 | int i, j; | |
| 315 | ||
| 316 | 3 | if (topic1->any.length != topic2->any.length) |
| 317 | { | |
| 318 | 0 | return GLOBUS_FALSE; |
| 319 | } | |
| 320 | 3 | seen = calloc(topic2->any.length, sizeof(globus_bool_t)); |
| 321 | 3 | result = globus_soap_message_handle_init_to_dom( |
| 322 | &handle1, | |
| 323 | &doc1); | |
| 324 | 3 | globus_assert(result == GLOBUS_SUCCESS); |
| 325 | 3 | result = globus_soap_message_handle_init_to_dom( |
| 326 | &handle2, | |
| 327 | &doc2); | |
| 328 | 3 | globus_assert(result == GLOBUS_SUCCESS); |
| 329 | ||
| 330 | 3 | result = wstop_TopicSetType_serialize( |
| 331 | &wstop_TopicSet_qname, | |
| 332 | topic1, | |
| 333 | handle1, | |
| 334 | 0); | |
| 335 | 3 | globus_assert(result == GLOBUS_SUCCESS); |
| 336 | 3 | globus_soap_message_handle_destroy(handle1); |
| 337 | ||
| 338 | 3 | result = wstop_TopicSetType_serialize( |
| 339 | &wstop_TopicSet_qname, | |
| 340 | topic2, | |
| 341 | handle2, | |
| 342 | 0); | |
| 343 | 3 | globus_assert(result == GLOBUS_SUCCESS); |
| 344 | 3 | globus_soap_message_handle_destroy(handle2); |
| 345 | ||
| 346 | 3 | i = 0; |
| 347 | 6 | for (node1 = doc1->children; node1 != NULL; node1 = node1->next) |
| 348 | { | |
| 349 | 3 | j = 0; |
| 350 | 3 | for (node2 = doc2->children; node2 != NULL; node2 = node2->next) |
| 351 | { | |
| 352 | 3 | if (seen[j] == GLOBUS_FALSE && |
| 353 | strcmp((char *) node1->name, (char *) node2->name) == 0) | |
| 354 | { | |
| 355 | 3 | seen[j] = GLOBUS_TRUE; |
| 356 | 3 | break; |
| 357 | } | |
| 358 | 0 | j++; |
| 359 | } | |
| 360 | 3 | if (j == topic1->any.length) |
| 361 | { | |
| 362 | 0 | free(seen); |
| 363 | ||
| 364 | 0 | return GLOBUS_FALSE; |
| 365 | } | |
| 366 | 3 | i++; |
| 367 | } | |
| 368 | 6 | for (i = 0; i < topic1->any.length; i++) |
| 369 | { | |
| 370 | 3 | if (!seen[i]) |
| 371 | { | |
| 372 | 0 | free(seen); |
| 373 | 0 | return GLOBUS_FALSE; |
| 374 | } | |
| 375 | } | |
| 376 | 3 | free(seen); |
| 377 | 3 | xmlFreeDoc(doc1); |
| 378 | 3 | xmlFreeDoc(doc2); |
| 379 | 3 | return GLOBUS_TRUE; |
| 380 | ||
| 381 | } | |
| 382 | 315 | else if (any1->any_info == &wstop_SimpleTopicExpression_contents_info) |
| 383 | { | |
| 384 | 315 | if (xsd_QName_keyeq(any1->value, any2->value)) |
| 385 | { | |
| 386 | 195 | return GLOBUS_TRUE; |
| 387 | } | |
| 388 | } | |
| 389 | else | |
| 390 | { | |
| 391 | /* unimplemented type comparison */ | |
| 392 | 0 | fprintf(stderr, |
| 393 | "Unimplemented type comparison for {%s}%s\n", | |
| 394 | any1->any_info->type->Namespace, | |
| 395 | any1->any_info->type->local); | |
| 396 | } | |
| 397 | ||
| 398 | 132 | return GLOBUS_FALSE; |
| 399 | } | |
| 400 | /* any_equal() */ | |
| 401 | ||
| 402 | globus_bool_t | |
| 403 | any_array_equal( | |
| 404 | xsd_any_array * array1, | |
| 405 | xsd_any_array * array2) | |
| 406 | 429 | { |
| 407 | int i,j; | |
| 408 | 429 | globus_bool_t retval = GLOBUS_TRUE; |
| 409 | globus_bool_t * seen; | |
| 410 | ||
| 411 | ||
| 412 | 429 | if (array1->length != array2->length) |
| 413 | { | |
| 414 | 0 | return GLOBUS_FALSE; |
| 415 | } | |
| 416 | ||
| 417 | 429 | seen = calloc(array1->length, sizeof(globus_bool_t)); |
| 418 | ||
| 419 | 429 | if (seen == NULL) |
| 420 | { | |
| 421 | 0 | return GLOBUS_FALSE; |
| 422 | } | |
| 423 | ||
| 424 | 1053 | for (i = 0; i < array1->length; i++) |
| 425 | { | |
| 426 | 1260 | for (j = 0; j < array2->length; j++) |
| 427 | { | |
| 428 | 1260 | if (seen[j]) |
| 429 | { | |
| 430 | /* Already have a match for j in array1, don't allow double | |
| 431 | * match */ | |
| 432 | 504 | continue; |
| 433 | } | |
| 434 | ||
| 435 | /* Don't bother comparing values of different elements */ | |
| 436 | 756 | if (xsd_QName_keyeq( |
| 437 | array1->elements[i].element, | |
| 438 | array2->elements[j].element)) | |
| 439 | { | |
| 440 | 756 | if (array1->elements[i].any_info |
| 441 | != array2->elements[j].any_info) | |
| 442 | { | |
| 443 | 0 | retval = GLOBUS_FALSE; |
| 444 | ||
| 445 | 0 | goto out; |
| 446 | ||
| 447 | } | |
| 448 | 756 | if (any_equal( |
| 449 | &array1->elements[i], | |
| 450 | &array2->elements[j])) | |
| 451 | { | |
| 452 | 624 | seen[j] = GLOBUS_TRUE; |
| 453 | ||
| 454 | 624 | break; |
| 455 | } | |
| 456 | } | |
| 457 | } | |
| 458 | 624 | if (j == array2->length) |
| 459 | { | |
| 460 | 0 | retval = GLOBUS_FALSE; |
| 461 | ||
| 462 | 0 | goto out; |
| 463 | } | |
| 464 | } | |
| 465 | 1053 | for (i = 0; i < array1->length; i++) |
| 466 | { | |
| 467 | 624 | if (!seen[i]) |
| 468 | { | |
| 469 | 0 | retval = GLOBUS_FALSE; |
| 470 | } | |
| 471 | } | |
| 472 | 429 | out: |
| 473 | 429 | free(seen); |
| 474 | 429 | return retval; |
| 475 | } |