33 |
33 |
34 #include "config.h" |
34 #include "config.h" |
35 #include "testutils.h" |
35 #include "testutils.h" |
36 #include "setupsentry.h" |
36 #include "setupsentry.h" |
37 |
37 |
38 #include "std_log_result.h" |
38 |
39 #include "..\..\..\cpix\src\qrytypes\prefixqrytype.cpp" |
39 #include "..\..\..\cpix\src\qrytypes\prefixqrytype.cpp" |
40 #include "..\..\..\cpix\src\qrytypes\termsqrytype.cpp" |
40 #include "..\..\..\cpix\src\qrytypes\termsqrytype.cpp" |
41 |
41 |
42 #define TEST_DOCUMENT_QBASEAPPCLASS "@0:root test document" |
42 #define TEST_DOCUMENT_QBASEAPPCLASS "@0:root test document" |
43 #define TEST_DOCUMENT_INDEXDB_PATH "c:\\Data\\indexing\\indexdb\\root\\test\\document" |
43 #define TEST_DOCUMENT_INDEXDB_PATH "c:\\Data\\indexing\\indexdb\\root\\test\\document" |
315 ITK_EXPECT(testMgr, |
314 ITK_EXPECT(testMgr, |
316 cpix_Succeeded(idxDb_), |
315 cpix_Succeeded(idxDb_), |
317 "Flushing index has failed"); |
316 "Flushing index has failed"); |
318 if(!cpix_Succeeded(idxDb_)) |
317 if(!cpix_Succeeded(idxDb_)) |
319 { |
318 { |
320 assert_failed = 1; |
319 |
321 } |
320 } |
322 Cpix::PrefixQryType *qryType = new Cpix::PrefixQryType; |
321 Cpix::PrefixQryType *qryType = new Cpix::PrefixQryType; |
323 std::list<std::wstring> list(3,L""); |
322 std::list<std::wstring> list(3,L""); |
324 std::list<std::wstring> list1; |
323 std::list<std::wstring> list1; |
325 qryType->setUp(queryParser_, list, SEARCH_TERM); |
324 qryType->setUp(queryParser_, list, SEARCH_TERM); |
331 { |
330 { |
332 ITK_PANIC("Could not create searcher"); |
331 ITK_PANIC("Could not create searcher"); |
333 } |
332 } |
334 cpix_Hits *Hits1 = qryType->search(searcher); |
333 cpix_Hits *Hits1 = qryType->search(searcher); |
335 cpix_Hits *Hits2 = qryType->search(idxDb_); |
334 cpix_Hits *Hits2 = qryType->search(idxDb_); |
336 testResultXml(xml_file); |
335 |
337 } |
336 } |
338 |
337 |
339 void TestTermsQryType(Itk::TestMgr * ) |
338 void TestTermsQryType(Itk::TestMgr * ) |
340 { |
339 { |
341 char *xml_file = (char *)__FUNCTION__; |
340 |
342 assert_failed = 0; |
|
343 Cpix::TermsQryType qrytype; |
341 Cpix::TermsQryType qrytype; |
344 tearDown(); |
342 tearDown(); |
345 setup(); |
343 setup(); |
346 std::list<std::wstring> list(3, L"term"); |
344 std::list<std::wstring> list(3, L"term"); |
347 std::list<std::wstring> list1; |
345 std::list<std::wstring> list1; |
348 qrytype.setUp(queryParser_, list, SEARCH_TERM); |
346 qrytype.setUp(queryParser_, list, SEARCH_TERM); |
349 qrytype.setUp(queryParser_, list1, SEARCH_TERM); |
347 qrytype.setUp(queryParser_, list1, SEARCH_TERM); |
350 testResultXml(xml_file); |
348 |
351 } |
349 } |
352 |
350 |
353 void testNoBoostingFields(Itk::TestMgr * testMgr) |
351 void testNoBoostingFields(Itk::TestMgr * testMgr) |
354 { |
352 { |
355 // Don't boost Field Alpha in doc1 |
353 // Don't boost Field Alpha in doc1 |
356 char *xml_file = (char *)__FUNCTION__; |
354 |
357 assert_failed = 0; |
|
358 addDocument(testMgr, |
355 addDocument(testMgr, |
359 LDOCUID1, |
356 LDOCUID1, |
360 DOC1CONTENT); |
357 DOC1CONTENT); |
361 addDocument(testMgr, |
358 addDocument(testMgr, |
362 LDOCUID2, |
359 LDOCUID2, |
366 ITK_EXPECT(testMgr, |
363 ITK_EXPECT(testMgr, |
367 cpix_Succeeded(idxDb_), |
364 cpix_Succeeded(idxDb_), |
368 "Flushing index has failed"); |
365 "Flushing index has failed"); |
369 if(!cpix_Succeeded(idxDb_)) |
366 if(!cpix_Succeeded(idxDb_)) |
370 { |
367 { |
371 assert_failed = 1; |
368 |
372 } |
369 } |
373 |
370 |
374 executeSearch(testMgr); |
371 executeSearch(testMgr); |
375 // EXPECTED result is that doc2 first, doc1 second. |
372 // EXPECTED result is that doc2 first, doc1 second. |
376 |
373 |
389 ITK_ASSERT(testMgr, |
386 ITK_ASSERT(testMgr, |
390 str.compare(LDOCUID2) == 0, |
387 str.compare(LDOCUID2) == 0, |
391 "wrong document"); |
388 "wrong document"); |
392 if(str.compare(LDOCUID2) != 0) |
389 if(str.compare(LDOCUID2) != 0) |
393 { |
390 { |
394 assert_failed = 1; |
391 |
395 } |
392 } |
396 } |
393 } |
397 else |
394 else |
398 { |
395 { |
399 assert_failed = 1; |
396 |
400 ITK_PANIC("failed to get _docuid"); |
397 ITK_PANIC("failed to get _docuid"); |
401 } |
398 } |
402 } else { |
399 } else { |
403 ITK_PANIC("could not fetch requested doc"); |
400 ITK_PANIC("could not fetch requested doc"); |
404 assert_failed = 1; |
401 |
405 } |
402 } |
406 FREE_DOC(returnedDoc1, 1); |
403 FREE_DOC(returnedDoc1, 1); |
407 |
404 |
408 cpix_Document |
405 cpix_Document |
409 **returnedDoc2; |
406 **returnedDoc2; |
420 ITK_ASSERT(testMgr, |
417 ITK_ASSERT(testMgr, |
421 str.compare(LDOCUID1) == 0, |
418 str.compare(LDOCUID1) == 0, |
422 "wrong document"); |
419 "wrong document"); |
423 if(str.compare(LDOCUID1) != 0) |
420 if(str.compare(LDOCUID1) != 0) |
424 { |
421 { |
425 assert_failed = 1; |
422 |
426 } |
423 } |
427 } |
424 } |
428 else |
425 else |
429 { |
426 { |
430 assert_failed = 1; |
427 |
431 ITK_PANIC("failed to get _docuid"); |
428 ITK_PANIC("failed to get _docuid"); |
432 } |
429 } |
433 } else { |
430 } else { |
434 ITK_PANIC("could not fetch requested doc"); |
431 ITK_PANIC("could not fetch requested doc"); |
435 assert_failed = 1; |
432 |
436 } |
433 } |
437 FREE_DOC(returnedDoc2, 1); |
434 FREE_DOC(returnedDoc2, 1); |
438 testResultXml(xml_file); |
435 |
439 |
436 |
440 } |
437 } |
441 |
438 |
442 |
439 |
443 |
440 |
444 void testBoostField(Itk::TestMgr * testMgr) |
441 void testBoostField(Itk::TestMgr * testMgr) |
445 { |
442 { |
446 char *xml_file = (char *)__FUNCTION__; |
443 |
447 assert_failed = 0; |
|
448 tearDown(); |
444 tearDown(); |
449 setup(); |
445 setup(); |
450 |
446 |
451 addDocument(testMgr, |
447 addDocument(testMgr, |
452 LDOCUID1, |
448 LDOCUID1, |
461 ITK_EXPECT(testMgr, |
457 ITK_EXPECT(testMgr, |
462 cpix_Succeeded(idxDb_), |
458 cpix_Succeeded(idxDb_), |
463 "Flushing index has failed"); |
459 "Flushing index has failed"); |
464 if(!cpix_Succeeded(idxDb_)) |
460 if(!cpix_Succeeded(idxDb_)) |
465 { |
461 { |
466 assert_failed = 1; |
462 |
467 } |
463 } |
468 |
464 |
469 executeSearch(testMgr); |
465 executeSearch(testMgr); |
470 // EXPECTED result is that doc1 first, doc2 second. |
466 // EXPECTED result is that doc1 first, doc2 second. |
471 |
467 |
484 ITK_ASSERT(testMgr, |
480 ITK_ASSERT(testMgr, |
485 str.compare(LDOCUID1) == 0, |
481 str.compare(LDOCUID1) == 0, |
486 "wrong document"); |
482 "wrong document"); |
487 if(str.compare(LDOCUID1) != 0) |
483 if(str.compare(LDOCUID1) != 0) |
488 { |
484 { |
489 assert_failed = 1; |
485 |
490 } |
486 } |
491 } |
487 } |
492 else |
488 else |
493 { |
489 { |
494 ITK_PANIC("failed to get _docuid"); |
490 ITK_PANIC("failed to get _docuid"); |
495 assert_failed = 1; |
491 |
496 } |
492 } |
497 } else { |
493 } else { |
498 ITK_PANIC("could not fetch requested doc"); |
494 ITK_PANIC("could not fetch requested doc"); |
499 assert_failed = 1; |
495 |
500 } |
496 } |
501 FREE_DOC(returnedDoc1, 1); |
497 FREE_DOC(returnedDoc1, 1); |
502 |
498 |
503 cpix_Document |
499 cpix_Document |
504 **returnedDoc2; |
500 **returnedDoc2; |
515 ITK_ASSERT(testMgr, |
511 ITK_ASSERT(testMgr, |
516 str.compare(LDOCUID2) == 0, |
512 str.compare(LDOCUID2) == 0, |
517 "wrong document"); |
513 "wrong document"); |
518 if(str.compare(LDOCUID2) != 0) |
514 if(str.compare(LDOCUID2) != 0) |
519 { |
515 { |
520 assert_failed = 1; |
516 |
521 } |
517 } |
522 } |
518 } |
523 else |
519 else |
524 { |
520 { |
525 ITK_PANIC("failed to get _docuid"); |
521 ITK_PANIC("failed to get _docuid"); |
526 assert_failed = 1; |
522 |
527 } |
523 } |
528 } else { |
524 } else { |
529 ITK_PANIC("could not fetch requested doc"); |
525 ITK_PANIC("could not fetch requested doc"); |
530 assert_failed = 1; |
526 |
531 } |
527 } |
532 FREE_DOC(returnedDoc2, 1); |
528 FREE_DOC(returnedDoc2, 1); |
533 testResultXml(xml_file); |
529 |
534 } |
530 } |
535 |
531 |
536 void testBoostDocument(Itk::TestMgr * testMgr) |
532 void testBoostDocument(Itk::TestMgr * testMgr) |
537 { |
533 { |
538 char *xml_file = (char *)__FUNCTION__; |
534 |
539 assert_failed = 0; |
|
540 tearDown(); |
535 tearDown(); |
541 setup(); |
536 setup(); |
542 |
537 |
543 addDocument(testMgr, |
538 addDocument(testMgr, |
544 LDOCUID1, |
539 LDOCUID1, |
553 ITK_EXPECT(testMgr, |
548 ITK_EXPECT(testMgr, |
554 cpix_Succeeded(idxDb_), |
549 cpix_Succeeded(idxDb_), |
555 "Flushing index has failed"); |
550 "Flushing index has failed"); |
556 if(!cpix_Succeeded(idxDb_)) |
551 if(!cpix_Succeeded(idxDb_)) |
557 { |
552 { |
558 assert_failed = 1; |
553 |
559 } |
554 } |
560 executeSearch(testMgr); |
555 executeSearch(testMgr); |
561 // EXPECTED result is that doc1 first, doc2 second. |
556 // EXPECTED result is that doc1 first, doc2 second. |
562 |
557 |
563 cpix_Document |
558 cpix_Document |
575 ITK_ASSERT(testMgr, |
570 ITK_ASSERT(testMgr, |
576 str.compare(LDOCUID1) == 0, |
571 str.compare(LDOCUID1) == 0, |
577 "wrong document"); |
572 "wrong document"); |
578 if(str.compare(LDOCUID1) != 0) |
573 if(str.compare(LDOCUID1) != 0) |
579 { |
574 { |
580 assert_failed = 1; |
575 |
581 } |
576 } |
582 } |
577 } |
583 else |
578 else |
584 { |
579 { |
585 ITK_PANIC("failed to get _docuid"); |
580 ITK_PANIC("failed to get _docuid"); |
586 assert_failed = 1; |
581 |
587 } |
582 } |
588 } else { |
583 } else { |
589 ITK_PANIC("could not fetch requested doc"); |
584 ITK_PANIC("could not fetch requested doc"); |
590 assert_failed = 1; |
585 |
591 } |
586 } |
592 FREE_DOC(returnedDoc1, 1); |
587 FREE_DOC(returnedDoc1, 1); |
593 |
588 |
594 cpix_Document |
589 cpix_Document |
595 **returnedDoc2; |
590 **returnedDoc2; |
606 ITK_ASSERT(testMgr, |
601 ITK_ASSERT(testMgr, |
607 str.compare(LDOCUID2) == 0, |
602 str.compare(LDOCUID2) == 0, |
608 "wrong document"); |
603 "wrong document"); |
609 if(str.compare(LDOCUID2) != 0) |
604 if(str.compare(LDOCUID2) != 0) |
610 { |
605 { |
611 assert_failed = 1; |
606 |
612 } |
607 } |
613 } |
608 } |
614 else |
609 else |
615 { |
610 { |
616 ITK_PANIC("failed to get _docuid"); |
611 ITK_PANIC("failed to get _docuid"); |
617 assert_failed = 1; |
612 |
618 } |
613 } |
619 } else { |
614 } else { |
620 ITK_PANIC("could not fetch requested doc"); |
615 ITK_PANIC("could not fetch requested doc"); |
621 assert_failed = 1; |
616 |
622 } |
617 } |
623 FREE_DOC(returnedDoc2, 1); |
618 FREE_DOC(returnedDoc2, 1); |
624 testResultXml(xml_file); |
619 |
625 } |
620 } |
626 |
621 |
627 |
622 |
628 void testBoostQuery(Itk::TestMgr * testMgr) |
623 void testBoostQuery(Itk::TestMgr * testMgr) |
629 { |
624 { |
630 char *xml_file = (char *)__FUNCTION__; |
625 |
631 assert_failed = 0; |
|
632 tearDown(); |
626 tearDown(); |
633 setup(); |
627 setup(); |
634 |
628 |
635 addDocument(testMgr, |
629 addDocument(testMgr, |
636 LDOCUID1, |
630 LDOCUID1, |
641 |
635 |
642 cpix_IdxDb_flush(idxDb_); |
636 cpix_IdxDb_flush(idxDb_); |
643 ITK_EXPECT(testMgr, |
637 ITK_EXPECT(testMgr, |
644 cpix_Succeeded(idxDb_), |
638 cpix_Succeeded(idxDb_), |
645 "Flushing index has failed"); |
639 "Flushing index has failed"); |
646 if(!cpix_Succeeded(idxDb_)) |
640 |
647 { |
|
648 assert_failed = 1; |
|
649 } |
|
650 // doc1_ should be the first result given the following query boost. |
641 // doc1_ should be the first result given the following query boost. |
651 cpix_Query_destroy(query_); |
642 cpix_Query_destroy(query_); |
652 |
643 |
653 query_ = cpix_QueryParser_parse(queryParser_, |
644 query_ = cpix_QueryParser_parse(queryParser_, |
654 BOOST_SEARCH_TERMS); |
645 BOOST_SEARCH_TERMS); |
680 { |
667 { |
681 std::wstring str(id); |
668 std::wstring str(id); |
682 ITK_ASSERT(testMgr, |
669 ITK_ASSERT(testMgr, |
683 str.compare(LDOCUID1) == 0, |
670 str.compare(LDOCUID1) == 0, |
684 "wrong document"); |
671 "wrong document"); |
685 if(str.compare(LDOCUID2) != 0) |
672 |
686 { |
|
687 assert_failed = 1; |
|
688 } |
|
689 } |
673 } |
690 else |
674 else |
691 { |
675 { |
692 ITK_PANIC("failed to get _docuid"); |
676 ITK_PANIC("failed to get _docuid"); |
693 assert_failed = 1; |
677 |
694 } |
678 } |
695 } else { |
679 } else { |
696 ITK_PANIC("could not fetch requested doc"); |
680 ITK_PANIC("could not fetch requested doc"); |
697 assert_failed = 1; |
681 |
698 } |
682 } |
699 FREE_DOC(returnedDoc1, 1); |
683 FREE_DOC(returnedDoc1, 1); |
700 |
684 |
701 cpix_Document |
685 cpix_Document |
702 **returnedDoc2; |
686 **returnedDoc2; |
711 { |
695 { |
712 std::wstring str(id); |
696 std::wstring str(id); |
713 ITK_ASSERT(testMgr, |
697 ITK_ASSERT(testMgr, |
714 str.compare(LDOCUID2) == 0, |
698 str.compare(LDOCUID2) == 0, |
715 "wrong document"); |
699 "wrong document"); |
716 if(str.compare(LDOCUID2) != 0) |
700 |
717 { |
|
718 assert_failed = 1; |
|
719 } |
|
720 } |
701 } |
721 else |
702 else |
722 { |
703 { |
723 ITK_PANIC("failed to get _docuid"); |
704 ITK_PANIC("failed to get _docuid"); |
724 assert_failed = 1; |
705 |
725 } |
706 } |
726 } else { |
707 } else { |
727 ITK_PANIC("could not fetch requested doc"); |
708 ITK_PANIC("could not fetch requested doc"); |
728 assert_failed = 1; |
709 |
729 } |
710 } |
730 FREE_DOC(returnedDoc2, 1); |
711 FREE_DOC(returnedDoc2, 1); |
731 testResultXml(xml_file); |
712 |
732 } |
713 } |
733 }; |
714 }; |
734 |
715 |
735 |
716 |
736 Itk::TesterBase * CreateDocumentTests() |
717 Itk::TesterBase * CreateDocumentTests() |