home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / test / cintltst / cbiapts.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-19  |  6.9 KB  |  195 lines

  1. /*
  2. *****************************************************************************************
  3. *                                                                                       *
  4. * COPYRIGHT:                                                                            *
  5. *   (C) Copyright Taligent, Inc.,  1996                                                 *
  6. *   (C) Copyright International Business Machines Corporation,  1999                    *
  7. *   Licensed Material - Program-Property of IBM - All Rights Reserved.                  *
  8. *   US Government Users Restricted Rights - Use, duplication, or disclosure             *
  9. *   restricted by GSA ADP Schedule Contract with IBM Corp.                              *
  10. *                                                                                       *
  11. *****************************************************************************************
  12. ********************************************************************************
  13. *
  14. * File CBIAPTS.C
  15. *
  16. * Modification History:
  17. *        Name                     Description            
  18. *     Madhu Katragadda              Creation
  19. *********************************************************************************
  20. /*C API TEST FOR BREAKITERATOR */
  21. /**
  22. * This is an API test.  It doesn't test very many cases, and doesn't
  23. * try to test the full functionality.  It just calls each function in the class and
  24. * verifies that it works on a basic level.
  25. **/
  26. #include "uloc.h"
  27. #include "ubrk.h"
  28. #include "utypes.h"
  29. #include "ustring.h"
  30. #include "cintltst.h"
  31. #include "cbiapts.h"
  32. #include<stdio.h>
  33. #include<string.h>
  34.  
  35.  
  36. void addBrkIterAPITest(TestNode** root)
  37. {
  38.     addTest(root, &TestBreakIteratorCAPI, "tstxtbd/capitst/TestBreakIteratorCAPI");
  39.  
  40. }
  41.  
  42. void TestBreakIteratorCAPI()
  43. {
  44.     UErrorCode status = U_ZERO_ERROR;
  45.     UBreakIterator *word, *sentence, *line, *character, *b;
  46.     UChar text[50];
  47.     UTextOffset start,pos,end,to;
  48.     int32_t count = 0;
  49.     u_uastrcpy(text, "He's from Africa. ""Mr. Livingston, I presume?"" Yeah");
  50.     status  = U_ZERO_ERROR;
  51.  
  52. /*test ubrk_open()*/
  53.     log_verbose("\nTesting BreakIterator open functions\n");
  54.                                             
  55.     /* Use french for fun */
  56.     word         = ubrk_open(UBRK_WORD, "en_US", text, u_strlen(text), &status);
  57.     if(U_FAILURE(status)){
  58.         log_err("FAIL: Error in ubrk_open() for word breakiterator: %s\n", myErrorName(status));
  59.     }
  60.     else{
  61.         log_verbose("PASS: Successfully opened  word breakiterator\n");
  62.     }
  63.     
  64.     sentence     = ubrk_open(UBRK_SENTENCE, "en_US", text, u_strlen(text), &status);
  65.     if(U_FAILURE(status)){
  66.         log_err("FAIL: Error in ubrk_open() for sentence breakiterator: %s\n", myErrorName(status));
  67.     }
  68.     else{
  69.         log_verbose("PASS: Successfully opened  sentence breakiterator\n");
  70.     }
  71.     
  72.     line         = ubrk_open(UBRK_SENTENCE, "en_US", text, u_strlen(text), &status);
  73.     if(U_FAILURE(status)){
  74.         log_err("FAIL: Error in ubrk_open() for line breakiterator: %s\n", myErrorName(status));
  75.     }
  76.     else{
  77.         log_verbose("PASS: Successfully opened  line breakiterator\n");
  78.     }
  79.     
  80.     character     = ubrk_open(UBRK_SENTENCE, "en_US", text, u_strlen(text), &status);
  81.     if(U_FAILURE(status)){
  82.         log_err("FAIL: Error in ubrk_open() for character breakiterator: %s\n", myErrorName(status));
  83.     }
  84.     else{
  85.         log_verbose("PASS: Successfully opened  character breakiterator\n");
  86.     }
  87.  
  88. /* ======= Test ubrk_countAvialable() and ubrk_getAvilable() */
  89.  
  90.     log_verbose("\nTesting ubrk_countAvailable() and ubrk_getAvailable()\n");
  91.     count=ubrk_countAvailable();
  92.     /* use something sensible w/o hardcoding the count */
  93.     if(count < 0){
  94.         log_err("FAIL: Error in ubrk_countAvialable() returned %d\n", count);
  95.     }
  96.     else{
  97.         log_verbose("PASS: ubrk_countAvialable() successful returned %d\n", count);
  98.     }
  99.  
  100.  
  101. /*========Test ubrk_first(), ubrk_last()...... and other functions*/
  102.   
  103.    log_verbose("\nTesting the functions for word\n");
  104.     start = ubrk_first(word);
  105.     if(start!=0)
  106.         log_err("error ubrk_start(word) did not return 0\n");
  107.     log_verbose("first (word = %d\n", (int32_t)start);
  108.        pos=ubrk_next(word);
  109.     if(pos!=4)
  110.         log_err("error ubrk_next(word) did not return 4\n");
  111.     log_verbose("next (word = %d\n", (int32_t)pos);
  112.     pos=ubrk_following(word, 4);
  113.     if(pos!=5)
  114.         log_err("error ubrl_following(word,4) did not return 6\n");
  115.     log_verbose("next (word = %d\n", (int32_t)pos);
  116.     end=ubrk_last(word);
  117.     if(end!=49)
  118.         log_err("error ubrk_last(word) did not return 49\n");
  119.     log_verbose("last (word = %d\n", (int32_t)end);
  120.     
  121.     pos=ubrk_previous(word);
  122.     log_verbose("%d   %d\n", end, pos);
  123.      
  124.     pos=ubrk_previous(word);
  125.     log_verbose("%d \n", pos);
  126.  
  127.  
  128.  
  129.  
  130.     
  131.     log_verbose("\nTesting the functions for character\n");
  132.     ubrk_first(character);
  133.     pos = ubrk_following(character, 5);
  134.     if(pos!=18)
  135.        log_err("error ubrk_following(character,5) did not return 18\n");
  136.     log_verbose("Following (character,5) = %d\n", (int32_t)pos);
  137.     pos=ubrk_following(character, 18);
  138.     if(pos!=22)
  139.        log_err("error ubrk_following(character,18) did not return 22\n");
  140.     log_verbose("Followingcharacter,18) = %d\n", (int32_t)pos);
  141.     pos=ubrk_preceding(character, 22);
  142.     if(pos!=18)
  143.        log_err("error ubrk_preceding(character,22) did not return 18\n");
  144.     log_verbose("preceding(character,22) = %d\n", (int32_t)pos);
  145.     
  146.  
  147.     log_verbose("\nTesting the functions for line\n");
  148.     ubrk_first(line);
  149.     pos = ubrk_next(line);
  150.     if(pos!=18)
  151.         log_err("error ubrk_next(line) did not return 18\n");
  152.     log_verbose("Next (line) = %d\n", (int32_t)pos);
  153.     pos=ubrk_following(line, 18);
  154.     if(pos!=22)
  155.         log_err("error ubrk_following(line) did not return 22\n");
  156.     log_verbose("following (line) = %d\n", (int32_t)pos);
  157.  
  158.     
  159.     log_verbose("\nTesting the functions for sentence\n");
  160.     ubrk_first(sentence);
  161.     pos = ubrk_current(sentence);
  162.     log_verbose("Current(sentence) = %d\n", (int32_t)pos);
  163.        pos = ubrk_last(sentence);
  164.     if(pos!=49)
  165.         log_err("error ubrk_last for sentence did not return 49\n");
  166.     log_verbose("Last (sentence) = %d\n", (int32_t)pos);
  167.     ubrk_first(sentence);
  168.     to = ubrk_following( sentence, 0 );
  169.     if (to == 0) log_err("ubrk_following returned 0\n");
  170.     to = ubrk_preceding( sentence, to );
  171.     if (to != 0) log_err("ubrk_preceding didn't return 0\n");
  172.     if (ubrk_first(sentence)!=ubrk_current(sentence)) {
  173.         log_err("error in ubrk_first() or ubrk_current()\n");
  174.     }
  175.     
  176.  
  177.     /*---- */
  178. /*Testing ubrk_open and ubrk_close()*/
  179.    log_verbose("\nTesting open and close for us locale\n");
  180.     b = ubrk_open(UBRK_WORD, "fr_FR", text, u_strlen(text), &status);
  181.     if (U_FAILURE(status)) {
  182.         log_err("ubrk_open for word returned NULL: %s\n", myErrorName(status));
  183.     }
  184.     ubrk_close(b);
  185.  
  186.   
  187.     
  188.     ubrk_close(word);
  189.     ubrk_close(sentence);
  190.     ubrk_close(line);
  191.     ubrk_close(character);
  192.  
  193.  
  194. }
  195.