static void TestFilter() { UErrorCode status = U_ZERO_ERROR; UChar filt[128]; UChar buf[128]; UChar exp[128]; char *cbuf; int32_t limit; const char* DATA[] = { "[^c]", /* Filter out 'c' */ "abcde", "\\u0061\\u0062c\\u0064\\u0065", "", /* No filter */ "abcde", "\\u0061\\u0062\\u0063\\u0064\\u0065" }; int32_t DATA_length = UPRV_LENGTHOF(DATA); int32_t i; UTransliterator* hex = utrans_open("Any-Hex", UTRANS_FORWARD, NULL,0,NULL,&status); if (hex == 0 || U_FAILURE(status)) { log_err("FAIL: utrans_open(Unicode-Hex) failed, error=%s\n", u_errorName(status)); goto exit; } for (i=0; i<DATA_length; i+=3) { /*u_uastrcpy(filt, DATA[i]);*/ u_charsToUChars(DATA[i], filt, (int32_t)strlen(DATA[i])+1); utrans_setFilter(hex, filt, -1, &status); if (U_FAILURE(status)) { log_err("FAIL: utrans_setFilter() failed, error=%s\n", u_errorName(status)); goto exit; } /*u_uastrcpy(buf, DATA[i+1]);*/ u_charsToUChars(DATA[i+1], buf, (int32_t)strlen(DATA[i+1])+1); limit = 5; utrans_transUChars(hex, buf, NULL, 128, 0, &limit, &status); if (U_FAILURE(status)) { log_err("FAIL: utrans_transUChars() failed, error=%s\n", u_errorName(status)); goto exit; } cbuf=aescstrdup(buf, -1); u_charsToUChars(DATA[i+2], exp, (int32_t)strlen(DATA[i+2])+1); if (0 == u_strcmp(buf, exp)) { log_verbose("Ok: %s | %s -> %s\n", DATA[i+1], DATA[i], cbuf); } else { log_err("FAIL: %s | %s -> %s, expected %s\n", DATA[i+1], DATA[i], cbuf, DATA[i+2]); } } exit: utrans_close(hex); }
static void TestBreakIteratorCAPI() { UErrorCode status = U_ZERO_ERROR; UBreakIterator *word, *sentence, *line, *character, *b, *bogus; int32_t start,pos,end,to; int32_t i; int32_t count = 0; UChar text[50]; /* Note: the adjacent "" are concatenating strings, not adding a \" to the string, which is probably what whoever wrote this intended. Don't fix, because it would throw off the hard coded break positions in the following tests. */ u_uastrcpy(text, "He's from Africa. ""Mr. Livingston, I presume?"" Yeah"); /*test ubrk_open()*/ log_verbose("\nTesting BreakIterator open functions\n"); /* Use french for fun */ word = ubrk_open(UBRK_WORD, "en_US", text, u_strlen(text), &status); if(status == U_FILE_ACCESS_ERROR) { log_data_err("Check your data - it doesn't seem to be around\n"); return; } else if(U_FAILURE(status)){ log_err_status(status, "FAIL: Error in ubrk_open() for word breakiterator: %s\n", myErrorName(status)); } else{ log_verbose("PASS: Successfully opened word breakiterator\n"); } sentence = ubrk_open(UBRK_SENTENCE, "en_US", text, u_strlen(text), &status); if(U_FAILURE(status)){ log_err_status(status, "FAIL: Error in ubrk_open() for sentence breakiterator: %s\n", myErrorName(status)); return; } else{ log_verbose("PASS: Successfully opened sentence breakiterator\n"); } line = ubrk_open(UBRK_LINE, "en_US", text, u_strlen(text), &status); if(U_FAILURE(status)){ log_err("FAIL: Error in ubrk_open() for line breakiterator: %s\n", myErrorName(status)); return; } else{ log_verbose("PASS: Successfully opened line breakiterator\n"); } character = ubrk_open(UBRK_CHARACTER, "en_US", text, u_strlen(text), &status); if(U_FAILURE(status)){ log_err("FAIL: Error in ubrk_open() for character breakiterator: %s\n", myErrorName(status)); return; } else{ log_verbose("PASS: Successfully opened character breakiterator\n"); } /*trying to open an illegal iterator*/ bogus = ubrk_open((UBreakIteratorType)5, "en_US", text, u_strlen(text), &status); if(U_SUCCESS(status)){ log_err("FAIL: Error in ubrk_open() for BOGUS breakiterator. Expected U_ILLEGAL_ARGUMENT_ERROR\n"); } if(U_FAILURE(status)){ if(status != U_ILLEGAL_ARGUMENT_ERROR){ log_err("FAIL: Error in ubrk_open() for BOGUS breakiterator. Expected U_ILLEGAL_ARGUMENT_ERROR\n Got %s\n", myErrorName(status)); } } status=U_ZERO_ERROR; /* ======= Test ubrk_countAvialable() and ubrk_getAvialable() */ log_verbose("\nTesting ubrk_countAvailable() and ubrk_getAvailable()\n"); count=ubrk_countAvailable(); /* use something sensible w/o hardcoding the count */ if(count < 0){ log_err("FAIL: Error in ubrk_countAvialable() returned %d\n", count); } else{ log_verbose("PASS: ubrk_countAvialable() successful returned %d\n", count); } for(i=0;i<count;i++) { log_verbose("%s\n", ubrk_getAvailable(i)); if (ubrk_getAvailable(i) == 0) log_err("No locale for which breakiterator is applicable\n"); else log_verbose("A locale %s for which breakiterator is applicable\n",ubrk_getAvailable(i)); } /*========Test ubrk_first(), ubrk_last()...... and other functions*/ log_verbose("\nTesting the functions for word\n"); start = ubrk_first(word); if(start!=0) log_err("error ubrk_start(word) did not return 0\n"); log_verbose("first (word = %d\n", (int32_t)start); pos=ubrk_next(word); if(pos!=4) log_err("error ubrk_next(word) did not return 4\n"); log_verbose("next (word = %d\n", (int32_t)pos); pos=ubrk_following(word, 4); if(pos!=5) log_err("error ubrl_following(word,4) did not return 6\n"); log_verbose("next (word = %d\n", (int32_t)pos); end=ubrk_last(word); if(end!=49) log_err("error ubrk_last(word) did not return 49\n"); log_verbose("last (word = %d\n", (int32_t)end); pos=ubrk_previous(word); log_verbose("%d %d\n", end, pos); pos=ubrk_previous(word); log_verbose("%d \n", pos); if (ubrk_isBoundary(word, 2) != FALSE) { log_err("error ubrk_isBoundary(word, 2) did not return FALSE\n"); } pos=ubrk_current(word); if (pos != 4) { log_err("error ubrk_current() != 4 after ubrk_isBoundary(word, 2)\n"); } if (ubrk_isBoundary(word, 4) != TRUE) { log_err("error ubrk_isBoundary(word, 4) did not return TRUE\n"); } log_verbose("\nTesting the functions for character\n"); ubrk_first(character); pos = ubrk_following(character, 5); if(pos!=6) log_err("error ubrk_following(character,5) did not return 6\n"); log_verbose("Following (character,5) = %d\n", (int32_t)pos); pos=ubrk_following(character, 18); if(pos!=19) log_err("error ubrk_following(character,18) did not return 19\n"); log_verbose("Followingcharacter,18) = %d\n", (int32_t)pos); pos=ubrk_preceding(character, 22); if(pos!=21) log_err("error ubrk_preceding(character,22) did not return 21\n"); log_verbose("preceding(character,22) = %d\n", (int32_t)pos); log_verbose("\nTesting the functions for line\n"); pos=ubrk_first(line); if(pos != 0) log_err("error ubrk_first(line) returned %d, expected 0\n", (int32_t)pos); pos = ubrk_next(line); pos=ubrk_following(line, 18); if(pos!=22) log_err("error ubrk_following(line) did not return 22\n"); log_verbose("following (line) = %d\n", (int32_t)pos); log_verbose("\nTesting the functions for sentence\n"); ubrk_first(sentence); pos = ubrk_current(sentence); log_verbose("Current(sentence) = %d\n", (int32_t)pos); pos = ubrk_last(sentence); if(pos!=49) log_err("error ubrk_last for sentence did not return 49\n"); log_verbose("Last (sentence) = %d\n", (int32_t)pos); ubrk_first(sentence); to = ubrk_following( sentence, 0 ); if (to == 0) log_err("ubrk_following returned 0\n"); to = ubrk_preceding( sentence, to ); if (to != 0) log_err("ubrk_preceding didn't return 0\n"); if (ubrk_first(sentence)!=ubrk_current(sentence)) { log_err("error in ubrk_first() or ubrk_current()\n"); } /*---- */ /*Testing ubrk_open and ubrk_close()*/ log_verbose("\nTesting open and close for us locale\n"); b = ubrk_open(UBRK_WORD, "fr_FR", text, u_strlen(text), &status); if (U_FAILURE(status)) { log_err("ubrk_open for word returned NULL: %s\n", myErrorName(status)); } ubrk_close(b); /* Test setText and setUText */ { UChar s1[] = {0x41, 0x42, 0x20, 0}; UChar s2[] = {0x41, 0x42, 0x43, 0x44, 0x45, 0}; UText *ut = NULL; UBreakIterator *bb; int j; log_verbose("\nTesting ubrk_setText() and ubrk_setUText()\n"); status = U_ZERO_ERROR; bb = ubrk_open(UBRK_WORD, "en_US", NULL, 0, &status); TEST_ASSERT_SUCCESS(status); ubrk_setText(bb, s1, -1, &status); TEST_ASSERT_SUCCESS(status); ubrk_first(bb); j = ubrk_next(bb); TEST_ASSERT(j == 2); ut = utext_openUChars(ut, s2, -1, &status); ubrk_setUText(bb, ut, &status); TEST_ASSERT_SUCCESS(status); j = ubrk_next(bb); TEST_ASSERT(j == 5); ubrk_close(bb); utext_close(ut); } ubrk_close(word); ubrk_close(sentence); ubrk_close(line); ubrk_close(character); }
/** * @bug 4073003 */ void Test4073003() { int32_t pos,i; UDate d,dd; UChar *datestr; UChar temp[15]; UErrorCode status = U_ZERO_ERROR; UDateFormat *fmt; UChar *result, *result2; const char* tests [] = { "12/25/61", "12/25/1961", "4/3/1999", "4/3/99" }; fmt= udat_open(UDAT_SHORT,UDAT_SHORT ,NULL, NULL, 0, NULL, 0, &status); if(U_FAILURE(status)) { log_data_err("FAIL: error in creating the dateformat using short date and time style: %s (Are you missing data?)\n", myErrorName(status)); return; } u_uastrcpy(temp, "m/D/yy"); udat_applyPattern(fmt, FALSE, temp, u_strlen(temp)); for(i= 0; i < 4; i+=2) { status=U_ZERO_ERROR; datestr=(UChar*)malloc(sizeof(UChar) * (strlen(tests[i])+1)); u_uastrcpy(datestr, tests[i]); pos=0; d = udat_parse(fmt, datestr, u_strlen(datestr), &pos, &status); if(U_FAILURE(status)){ log_err("ERROR : in test 4073003: %s\n", myErrorName(status)); } free(datestr); datestr=(UChar*)malloc(sizeof(UChar) * (strlen(tests[i+1])+1)); u_uastrcpy(datestr, tests[i+1]); pos=0; status=U_ZERO_ERROR; dd = udat_parse(fmt, datestr, u_strlen(datestr), &pos, &status); if(U_FAILURE(status)){ log_err("ERROR : in test 4073003: %s\n", myErrorName(status)); } free(datestr); result =myFormatit(fmt, d); result2 =myFormatit(fmt, dd); if(!result || !result2) { log_data_err("Fail: could not format - exitting test\n"); return; } if (u_strcmp(result, result2)!=0){ log_err("Fail: %s != %s\n", austrdup(result), austrdup(result2) ); } else{ log_verbose("Ok: %s == %s\n", austrdup(result), austrdup(result2) ); } } udat_close(fmt); }
int main (int argc, char **argv) { int s = -1; int fd = -1; Arguments arg; Tunnel *tunnel; int closed; parse_arguments (argc, argv, &arg); if ((debug_level == 0 || debug_file != NULL) && arg.use_daemon) daemon (0, 1); #ifdef DEBUG_MODE if (debug_level != 0 && debug_file == NULL) debug_file = stderr; #else openlog ("htc", LOG_PID, LOG_DAEMON); #endif log_notice ("htc (%s) %s started with arguments:", PACKAGE, VERSION); log_notice (" me = %s", arg.me); log_notice (" device = %s", arg.device ? arg.device : "(null)"); log_notice (" host_name = %s", arg.host_name ? arg.host_name : "(null)"); log_notice (" host_port = %d", arg.host_port); log_notice (" proxy_name = %s", arg.proxy_name ? arg.proxy_name : "(null)"); log_notice (" proxy_port = %d", arg.proxy_port); log_notice (" proxy_buffer_size = %d", arg.proxy_buffer_size); log_notice (" proxy_buffer_timeout = %d", arg.proxy_buffer_timeout); log_notice (" content_length = %d", arg.content_length); log_notice (" forward_port = %d", arg.forward_port); log_notice (" max_connection_age = %d", arg.max_connection_age); log_notice (" use_std = %d", arg.use_std); log_notice (" strict_content_length = %d", arg.strict_content_length); log_notice (" keep_alive = %d", arg.keep_alive); log_notice (" proxy_authorization = %s", arg.proxy_authorization ? arg.proxy_authorization : "(null)"); log_notice (" user_agent = %s", arg.user_agent ? arg.user_agent : "(null)"); log_notice (" debug_level = %d", debug_level); if (arg.forward_port != -1) { struct in_addr addr; addr.s_addr = INADDR_ANY; s = server_socket (addr, arg.forward_port, 0); log_debug ("server_socket (%d) = %d", arg.forward_port, s); if (s == -1) { log_error ("couldn't create server socket: %s", strerror (errno)); log_exit (1); } } #ifdef DEBUG_MODE signal (SIGPIPE, log_sigpipe); #else signal (SIGPIPE, SIG_IGN); #endif for (;;) { time_t last_tunnel_write; if (arg.device) { fd = open_device (arg.device); log_debug ("open_device (\"%s\") = %d", arg.device, fd); if (fd == -1) { log_error ("couldn't open %s: %s", arg.device, strerror (errno)); log_exit (1); } /* Check that fd is not 0 (clash with --stdin-stdout) */ if (fd == 0) { log_notice("changing fd from %d to 3",fd); if (dup2 (fd, 3) != 3) { log_error ("couldn't dup2 (%d, 3): %s",fd,strerror(errno)); log_exit (1); } } } else if (arg.forward_port != -1) { log_debug ("waiting for connection on port %d", arg.forward_port); fd = wait_for_connection_on_socket (s); log_debug ("wait_for_connection_on_socket (%d) = %d", s, fd); if (fd == -1) { log_error ("couldn't forward port %d: %s", arg.forward_port, strerror (errno)); log_exit (1); } /* Check that fd is not 0 (clash with --stdin-stdout) */ if (fd == 0) { log_notice ("changing fd from %d to 3",fd); if (dup2 (fd, 3) != 3) { log_error ("couldn't dup2 (%d, 3): %s",fd,strerror(errno)); log_exit (1); } } } else if (arg.use_std) { log_debug ("using stdin as fd"); fd = 0; if (fcntl(fd,F_SETFL,O_NONBLOCK)==-1) { log_error ("couldn't set stdin to non-blocking mode: %s", strerror(errno)); log_exit (1); } /* Usage of stdout (fd = 1) is checked later. */ } log_debug ("creating a new tunnel"); tunnel = tunnel_new_client (arg.host_name, arg.host_port, arg.proxy_name, arg.proxy_port, arg.content_length); if (tunnel == NULL) { log_error ("couldn't create tunnel"); log_exit (1); } if (tunnel_setopt (tunnel, "strict_content_length", &arg.strict_content_length) == -1) log_debug ("tunnel_setopt strict_content_length error: %s", strerror (errno)); if (tunnel_setopt (tunnel, "keep_alive", &arg.keep_alive) == -1) log_debug ("tunnel_setopt keep_alive error: %s", strerror (errno)); if (tunnel_setopt (tunnel, "max_connection_age", &arg.max_connection_age) == -1) log_debug ("tunnel_setopt max_connection_age error: %s", strerror (errno)); if (arg.proxy_authorization != NULL) { ssize_t len; char *auth; len = encode_base64 (arg.proxy_authorization, strlen (arg.proxy_authorization), &auth); if (len == -1) { log_error ("encode_base64 error: %s", strerror (errno)); } else { char *str = malloc (len + 7); if (str == NULL) { log_error ("out of memory when encoding " "authorization string"); log_exit (1); } strcpy (str, "Basic "); strcat (str, auth); free (auth); if (tunnel_setopt (tunnel, "proxy_authorization", str) == -1) log_error ("tunnel_setopt proxy_authorization error: %s", strerror (errno)); free (str); } } if (arg.user_agent != NULL) { if (tunnel_setopt (tunnel, "user_agent", arg.user_agent) == -1) log_error ("tunnel_setopt user_agent error: %s", strerror (errno)); } if (tunnel_connect (tunnel) == -1) { log_error ("couldn't open tunnel: %s", strerror (errno)); log_exit (1); } if (arg.proxy_name) log_notice ("connected to %s:%d via %s:%d", arg.host_name, arg.host_port, arg.proxy_name, arg.proxy_port); else log_notice ("connected to %s:%d", arg.host_name, arg.host_port); closed = FALSE; time (&last_tunnel_write); while (!closed) { struct pollfd pollfd[2]; int keep_alive_timeout; int timeout; time_t t; int n; pollfd[0].fd = fd; pollfd[0].events = POLLIN; pollfd[1].fd = tunnel_pollin_fd (tunnel); pollfd[1].events = POLLIN; time (&t); timeout = 1000 * (arg.keep_alive - (t - last_tunnel_write)); keep_alive_timeout = TRUE; if (timeout < 0) timeout = 0; if (arg.proxy_buffer_timeout != -1 && arg.proxy_buffer_timeout < timeout) { timeout = arg.proxy_buffer_timeout; keep_alive_timeout = FALSE; } log_annoying ("poll () ..."); n = poll (pollfd, 2, timeout); log_annoying ("... = %d", n); if (n == -1) { log_error ("poll error: %s", strerror (errno)); log_exit (1); } else if (n == 0) { log_verbose ("poll() timed out"); if (keep_alive_timeout) { tunnel_padding (tunnel, 1); time (&last_tunnel_write); } else { if (tunnel_maybe_pad (tunnel, arg.proxy_buffer_size) > 0) time (&last_tunnel_write); } continue; } handle_input ("device or port", tunnel, fd, pollfd[0].revents, handle_device_input, &closed); handle_input ("tunnel", tunnel, fd, pollfd[1].revents, handle_tunnel_input, &closed); if (pollfd[0].revents & POLLIN) time (&last_tunnel_write); } log_debug ("destroying tunnel"); if (fd != 0) { close (fd); } tunnel_destroy (tunnel); if (arg.proxy_name) log_notice ("disconnected from %s:%d via %s:%d", arg.host_name, arg.host_port, arg.proxy_name, arg.proxy_port); else log_notice ("disconnected from %s%d", arg.host_name, arg.host_port); } log_debug ("closing server socket"); close (s); log_exit (0); }
static void doTestVariant(UCollator* myCollation, const UChar source[], const UChar target[], UCollationResult result) { int32_t sortklen1, sortklen2, sortklenmax, sortklenmin; int temp=0, gSortklen1=0,gSortklen2=0; UCollationResult compareResult, compareResulta, keyResult, compareResultIter = result; uint8_t *sortKey1, *sortKey2, *sortKey1a, *sortKey2a; uint32_t sLen = u_strlen(source); uint32_t tLen = u_strlen(target); char buffer[256]; uint32_t len; UErrorCode status = U_ZERO_ERROR; UColAttributeValue norm = ucol_getAttribute(myCollation, UCOL_NORMALIZATION_MODE, &status); UCharIterator sIter, tIter; compareResult = ucol_strcoll(myCollation, source, sLen, target, tLen); if (compareResult != result) { log_err("ucol_strcoll with explicit length returned wrong result (%i exp. %i): %s, %s\n", compareResult, result, aescstrdup(source,-1), aescstrdup(target,-1)); } compareResulta = ucol_strcoll(myCollation, source, -1, target, -1); if (compareResulta != result) { log_err("ucol_strcoll with null terminated strings returned wrong result (%i exp. %i): %s, %s\n", compareResult, result, aescstrdup(source,-1), aescstrdup(target,-1)); } uiter_setString(&sIter, source, sLen); uiter_setString(&tIter, target, tLen); compareResultIter = ucol_strcollIter(myCollation, &sIter, &tIter, &status); if(compareResultIter != result) { log_err("different results in iterative comparison for UTF-16 encoded strings. %s, %s\n", aescstrdup(source,-1), aescstrdup(target,-1)); } /* convert the strings to UTF-8 and do try comparing with char iterator and ucol_strcollUTF8 */ { char utf8Source[256], utf8Target[256]; int32_t utf8SourceLen = 0, utf8TargetLen = 0; u_strToUTF8(utf8Source, 256, &utf8SourceLen, source, sLen, &status); if(U_FAILURE(status)) { /* probably buffer is not big enough */ log_verbose("Src UTF-8 buffer too small! Will not compare!\n"); } else { u_strToUTF8(utf8Target, 256, &utf8TargetLen, target, tLen, &status); if(U_SUCCESS(status)) { { /* ucol_strcollUTF8 */ compareResulta = ucol_strcollUTF8(myCollation, utf8Source, utf8SourceLen, utf8Target, utf8TargetLen, &status); if (U_FAILURE(status)) { log_err("Error in ucol_strcollUTF8 with explicit length\n"); status = U_ZERO_ERROR; } else if (compareResulta != result) { log_err("ucol_strcollUTF8 with explicit length returned wrong result (%i exp. %i): %s, %s\n", compareResulta, result, aescstrdup(source,-1), aescstrdup(target,-1)); } compareResulta = ucol_strcollUTF8(myCollation, utf8Source, -1, utf8Target, -1, &status); if (U_FAILURE(status)) { log_err("Error in ucol_strcollUTF8 with null terminated strings\n"); status = U_ZERO_ERROR; } else if (compareResulta != result) { log_err("ucol_strcollUTF8 with null terminated strings returned wrong result (%i exp. %i): %s, %s\n", compareResulta, result, aescstrdup(source,-1), aescstrdup(target,-1)); } } { /* char iterator over UTF8 */ UCollationResult compareResultUTF8Iter = result, compareResultUTF8IterNorm = result; uiter_setUTF8(&sIter, utf8Source, utf8SourceLen); uiter_setUTF8(&tIter, utf8Target, utf8TargetLen); compareResultUTF8Iter = ucol_strcollIter(myCollation, &sIter, &tIter, &status); ucol_setAttribute(myCollation, UCOL_NORMALIZATION_MODE, UCOL_ON, &status); sIter.move(&sIter, 0, UITER_START); tIter.move(&tIter, 0, UITER_START); compareResultUTF8IterNorm = ucol_strcollIter(myCollation, &sIter, &tIter, &status); ucol_setAttribute(myCollation, UCOL_NORMALIZATION_MODE, norm, &status); if(compareResultUTF8Iter != compareResultIter) { log_err("different results in iterative comparison for UTF-16 and UTF-8 encoded strings. %s, %s\n", aescstrdup(source,-1), aescstrdup(target,-1)); } if(compareResultUTF8Iter != compareResultUTF8IterNorm) { log_err("different results in iterative when normalization is turned on with UTF-8 strings. %s, %s\n", aescstrdup(source,-1), aescstrdup(target,-1)); } } } else { log_verbose("Target UTF-8 buffer too small! Did not compare!\n"); } if(U_FAILURE(status)) { log_verbose("UTF-8 strcoll failed! Ignoring result\n"); } } } /* testing the partial sortkeys */ if(1) { /*!QUICK*/ int32_t i = 0; int32_t partialSizes[] = { 3, 1, 2, 4, 8, 20, 80 }; /* just size 3 in the quick mode */ int32_t partialSizesSize = 1; if(getTestOption(QUICK_OPTION) <= 0) { partialSizesSize = 7; } /*log_verbose("partial sortkey test piecesize=");*/ for(i = 0; i < partialSizesSize; i++) { UCollationResult partialSKResult = result, partialNormalizedSKResult = result; /*log_verbose("%i ", partialSizes[i]);*/ partialSKResult = compareUsingPartials(myCollation, source, sLen, target, tLen, partialSizes[i], &status); if(partialSKResult != result) { log_err("Partial sortkey comparison returned wrong result (%i exp. %i): %s, %s (size %i)\n", partialSKResult, result, aescstrdup(source,-1), aescstrdup(target,-1), partialSizes[i]); } if(getTestOption(QUICK_OPTION) <= 0 && norm != UCOL_ON) { /*log_verbose("N ");*/ ucol_setAttribute(myCollation, UCOL_NORMALIZATION_MODE, UCOL_ON, &status); partialNormalizedSKResult = compareUsingPartials(myCollation, source, sLen, target, tLen, partialSizes[i], &status); ucol_setAttribute(myCollation, UCOL_NORMALIZATION_MODE, norm, &status); if(partialSKResult != partialNormalizedSKResult) { log_err("Partial sortkey comparison gets different result when normalization is on: %s, %s (size %i)\n", aescstrdup(source,-1), aescstrdup(target,-1), partialSizes[i]); } } } /*log_verbose("\n");*/ } sortklen1=ucol_getSortKey(myCollation, source, sLen, NULL, 0); sortklen2=ucol_getSortKey(myCollation, target, tLen, NULL, 0); sortklenmax = (sortklen1>sortklen2?sortklen1:sortklen2); sortklenmin = (sortklen1<sortklen2?sortklen1:sortklen2); (void)sortklenmin; /* Suppress set but not used warning. */ sortKey1 =(uint8_t*)malloc(sizeof(uint8_t) * (sortklenmax+1)); sortKey1a=(uint8_t*)malloc(sizeof(uint8_t) * (sortklenmax+1)); ucol_getSortKey(myCollation, source, sLen, sortKey1, sortklen1+1); ucol_getSortKey(myCollation, source, -1, sortKey1a, sortklen1+1); sortKey2 =(uint8_t*)malloc(sizeof(uint8_t) * (sortklenmax+1)); sortKey2a=(uint8_t*)malloc(sizeof(uint8_t) * (sortklenmax+1)); ucol_getSortKey(myCollation, target, tLen, sortKey2, sortklen2+1); ucol_getSortKey(myCollation, target, -1, sortKey2a, sortklen2+1); /* Check that sort key generated with null terminated string is identical */ /* to that generted with a length specified. */ if (uprv_strcmp((const char *)sortKey1, (const char *)sortKey1a) != 0 || uprv_strcmp((const char *)sortKey2, (const char *)sortKey2a) != 0 ) { log_err("Sort Keys from null terminated and explicit length strings differ.\n"); } /*memcmp(sortKey1, sortKey2,sortklenmax);*/ temp= uprv_strcmp((const char *)sortKey1, (const char *)sortKey2); gSortklen1 = uprv_strlen((const char *)sortKey1)+1; gSortklen2 = uprv_strlen((const char *)sortKey2)+1; if(sortklen1 != gSortklen1){ log_err("SortKey length does not match Expected: %i Got: %i\n",sortklen1, gSortklen1); log_verbose("Generated sortkey: %s\n", sortKeyToString(myCollation, sortKey1, buffer, &len)); } if(sortklen2!= gSortklen2){ log_err("SortKey length does not match Expected: %i Got: %i\n", sortklen2, gSortklen2); log_verbose("Generated sortkey: %s\n", sortKeyToString(myCollation, sortKey2, buffer, &len)); } if(temp < 0) { keyResult=UCOL_LESS; } else if(temp > 0) { keyResult= UCOL_GREATER; } else { keyResult = UCOL_EQUAL; } reportCResult( source, target, sortKey1, sortKey2, compareResult, keyResult, compareResultIter, result ); free(sortKey1); free(sortKey2); free(sortKey1a); free(sortKey2a); }
/************************************************************************** Initialize audio system and autoselect a plugin **************************************************************************/ void audio_real_init(const char *const spec_name, const char *const prefered_plugin_name) { const char *filename; const char *file_capstr; char us_capstr[] = "+soundspec"; if (strcmp(prefered_plugin_name, "none") == 0) { /* We explicitly choose none plugin, silently skip the code below */ log_verbose("Proceeding with sound support disabled."); tagfile = NULL; return; } if (num_plugins_used == 1) { /* We only have the dummy plugin, skip the code but issue an advertise */ log_normal(_("No real audio plugin present.")); log_normal(_("Proceeding with sound support disabled.")); log_normal(_("For sound support, install SDL_mixer")); log_normal("http://www.libsdl.org/projects/SDL_mixer/index.html"); tagfile = NULL; return; } if (!spec_name) { log_fatal("No sound spec-file given!"); exit(EXIT_FAILURE); } log_verbose("Initializing sound using %s...", spec_name); filename = soundspec_fullname(spec_name); if (!filename) { log_error("Cannot find sound spec-file \"%s\".", spec_name); log_normal(_("To get sound you need to download a sound set!")); log_normal(_("Get sound sets from <%s>."), "http://www.freeciv.org/wiki/Sounds"); log_normal(_("Proceeding with sound support disabled.")); tagfile = NULL; return; } if (!(tagfile = secfile_load(filename, TRUE))) { log_fatal(_("Could not load sound spec-file '%s':\n%s"), filename, secfile_error()); exit(EXIT_FAILURE); } file_capstr = secfile_lookup_str(tagfile, "soundspec.options"); if (NULL == file_capstr) { log_fatal("Audio spec-file \"%s\" doesn't have capability string.", filename); exit(EXIT_FAILURE); } if (!has_capabilities(us_capstr, file_capstr)) { log_fatal("sound spec-file appears incompatible:"); log_fatal(" file: \"%s\"", filename); log_fatal(" file options: %s", file_capstr); log_fatal(" supported options: %s", us_capstr); exit(EXIT_FAILURE); } if (!has_capabilities(file_capstr, us_capstr)) { log_fatal("sound spec-file claims required option(s) " "which we don't support:"); log_fatal(" file: \"%s\"", filename); log_fatal(" file options: %s", file_capstr); log_fatal(" supported options: %s", us_capstr); exit(EXIT_FAILURE); } free((void *) filename); atexit(audio_shutdown); if (prefered_plugin_name[0] != '\0') { if (!audio_select_plugin(prefered_plugin_name)) log_normal(_("Proceeding with sound support disabled.")); return; } #ifdef AUDIO_SDL if (audio_select_plugin("sdl")) return; #endif log_normal(_("No real audio subsystem managed to initialize!")); log_normal(_("Perhaps there is some misconfiguration or bad permissions.")); log_normal(_("Proceeding with sound support disabled.")); }
UBool testTag(const char* frag, UBool in_Root, UBool in_te, UBool in_te_IN) { int32_t passNum=pass; /* Make array from input params */ UBool is_in[3]; const char *NAME[] = { "ROOT", "TE", "TE_IN" }; /* Now try to load the desired items */ UResourceBundle* theBundle = NULL; char tag[99]; char action[256]; UErrorCode status = U_ZERO_ERROR,expected_resource_status = U_ZERO_ERROR; UChar* base = NULL; UChar* expected_string = NULL; const UChar* string = NULL; char item_tag[10]; int32_t i,j; int32_t actual_bundle; int32_t resultLen; const char *testdatapath = loadTestData(&status); is_in[0] = in_Root; is_in[1] = in_te; is_in[2] = in_te_IN; strcpy(item_tag, "tag"); status = U_ZERO_ERROR; theBundle = ures_open(testdatapath, "root", &status); if(U_FAILURE(status)) { ures_close(theBundle); log_err("Couldn't open root bundle in %s", testdatapath); return FALSE; } ures_close(theBundle); theBundle = NULL; for (i=0; i<bundles_count; ++i) { strcpy(action,"construction for"); strcat(action, param[i].name); status = U_ZERO_ERROR; theBundle = ures_open(testdatapath, param[i].name, &status); /*theBundle = ures_open("c:\\icu\\icu\\source\\test\\testdata\\testdata", param[i].name, &status);*/ CONFIRM_ErrorCode(status,param[i].expected_constructor_status); if(i == 5) actual_bundle = 0; /* ne -> default */ else if(i == 3) actual_bundle = 1; /* te_NE -> te */ else if(i == 4) actual_bundle = 2; /* te_IN_NE -> te_IN */ else actual_bundle = i; expected_resource_status = U_MISSING_RESOURCE_ERROR; for (j=e_te_IN; j>=e_Root; --j) { if (is_in[j] && param[i].inherits[j]) { if(j == actual_bundle) /* it's in the same bundle OR it's a nonexistent=default bundle (5) */ expected_resource_status = U_ZERO_ERROR; else if(j == 0) expected_resource_status = U_USING_DEFAULT_WARNING; else expected_resource_status = U_USING_FALLBACK_WARNING; log_verbose("%s[%d]::%s: in<%d:%s> inherits<%d:%s>. actual_bundle=%s\n", param[i].name, i, frag, j, is_in[j]?"Yes":"No", j, param[i].inherits[j]?"Yes":"No", param[actual_bundle].name); break; } } for (j=param[i].where; j>=0; --j) { if (is_in[j]) { if(base != NULL) { free(base); base = NULL; } base=(UChar*)malloc(sizeof(UChar)*(strlen(NAME[j]) + 1)); u_uastrcpy(base,NAME[j]); break; } else { if(base != NULL) { free(base); base = NULL; } base = (UChar*) malloc(sizeof(UChar) * 1); *base = 0x0000; } } /*-------------------------------------------------------------------- */ /* string */ strcpy(tag,"string_"); strcat(tag,frag); strcpy(action,param[i].name); strcat(action, ".ures_get(" ); strcat(action,tag); strcat(action, ")"); string= kERROR; status = U_ZERO_ERROR; ures_getStringByKey(theBundle, tag, &resultLen, &status); if(U_SUCCESS(status)) { status = U_ZERO_ERROR; string=ures_getStringByKey(theBundle, tag, &resultLen, &status); } log_verbose("%s got %d, expected %d\n", action, status, expected_resource_status); CONFIRM_ErrorCode(status, expected_resource_status); if(U_SUCCESS(status)){ expected_string=(UChar*)malloc(sizeof(UChar)*(u_strlen(base) + 3)); u_strcpy(expected_string,base); } else { expected_string = (UChar*)malloc(sizeof(UChar)*(u_strlen(kERROR) + 1)); u_strcpy(expected_string,kERROR); } CONFIRM_EQ(string, expected_string); free(expected_string); ures_close(theBundle); } free(base); return (UBool)(passNum == pass); }
/** * Testing the discontigous contractions */ static void TestDiscontiguos() { const char *rulestr = "&z < AB < X\\u0300 < ABC < X\\u0300\\u0315"; UChar rule[50]; int rulelen = u_unescape(rulestr, rule, 50); const char *src[] = { "ADB", "ADBC", "A\\u0315B", "A\\u0315BC", /* base character blocked */ "XD\\u0300", "XD\\u0300\\u0315", /* non blocking combining character */ "X\\u0319\\u0300", "X\\u0319\\u0300\\u0315", /* blocking combining character */ "X\\u0314\\u0300", "X\\u0314\\u0300\\u0315", /* contraction prefix */ "ABDC", "AB\\u0315C","X\\u0300D\\u0315", "X\\u0300\\u0319\\u0315", "X\\u0300\\u031A\\u0315", /* ends not with a contraction character */ "X\\u0319\\u0300D", "X\\u0319\\u0300\\u0315D", "X\\u0300D\\u0315D", "X\\u0300\\u0319\\u0315D", "X\\u0300\\u031A\\u0315D" }; const char *tgt[] = { /* non blocking combining character */ "A D B", "A D BC", "A \\u0315 B", "A \\u0315 BC", /* base character blocked */ "X D \\u0300", "X D \\u0300\\u0315", /* non blocking combining character */ "X\\u0300 \\u0319", "X\\u0300\\u0315 \\u0319", /* blocking combining character */ "X \\u0314 \\u0300", "X \\u0314 \\u0300\\u0315", /* contraction prefix */ "AB DC", "AB \\u0315 C","X\\u0300 D \\u0315", "X\\u0300\\u0315 \\u0319", "X\\u0300 \\u031A \\u0315", /* ends not with a contraction character */ "X\\u0300 \\u0319D", "X\\u0300\\u0315 \\u0319D", "X\\u0300 D\\u0315D", "X\\u0300\\u0315 \\u0319D", "X\\u0300 \\u031A\\u0315D" }; int size = 20; UCollator *coll; UErrorCode status = U_ZERO_ERROR; int count = 0; UCollationElements *iter; UCollationElements *resultiter; coll = ucol_openRules(rule, rulelen, UCOL_OFF, UCOL_DEFAULT_STRENGTH,NULL, &status); iter = ucol_openElements(coll, rule, 1, &status); resultiter = ucol_openElements(coll, rule, 1, &status); if (U_FAILURE(status)) { log_err_status(status, "Error opening collation rules -> %s\n", u_errorName(status)); return; } while (count < size) { UChar str[20]; UChar tstr[20]; int strLen = u_unescape(src[count], str, 20); UChar *s; ucol_setText(iter, str, strLen, &status); if (U_FAILURE(status)) { log_err("Error opening collation iterator\n"); return; } u_unescape(tgt[count], tstr, 20); s = tstr; log_verbose("count %d\n", count); for (;;) { uint32_t ce; UChar *e = u_strchr(s, 0x20); if (e == 0) { e = u_strchr(s, 0); } ucol_setText(resultiter, s, (int32_t)(e - s), &status); ce = ucol_next(resultiter, &status); if (U_FAILURE(status)) { log_err("Error manipulating collation iterator\n"); return; } while (ce != UCOL_NULLORDER) { if (ce != (uint32_t)ucol_next(iter, &status) || U_FAILURE(status)) { log_err("Discontiguos contraction test mismatch\n"); return; } ce = ucol_next(resultiter, &status); if (U_FAILURE(status)) { log_err("Error getting next collation element\n"); return; } } s = e + 1; if (*e == 0) { break; } } ucol_reset(iter); backAndForth(iter); count ++; } ucol_closeElements(resultiter); ucol_closeElements(iter); ucol_close(coll); }
static void TestSearchCollatorElements(void) { const TSCEItem * tsceItemPtr; for (tsceItemPtr = tsceItems; tsceItemPtr->locale != NULL; tsceItemPtr++) { UErrorCode status = U_ZERO_ERROR; UCollator* ucol = ucol_open(tsceItemPtr->locale, &status); if ( U_SUCCESS(status) ) { UCollationElements * uce = ucol_openElements(ucol, tsceText, kLen_tsceText, &status); if ( U_SUCCESS(status) ) { int32_t offset, element; const int32_t * nextOffsetPtr; const int32_t * limitOffsetPtr; nextOffsetPtr = tsceItemPtr->offsets; limitOffsetPtr = tsceItemPtr->offsets + tsceItemPtr->offsetsLen; do { offset = ucol_getOffset(uce); element = ucol_next(uce, &status); log_verbose("(%s) offset=%2d ce=%08x\n", tsceItemPtr->locale, offset, element); if ( element == 0 ) { log_err("error, locale %s, ucol_next returned element 0\n", tsceItemPtr->locale ); } if ( nextOffsetPtr < limitOffsetPtr ) { if (offset != *nextOffsetPtr) { log_err("error, locale %s, expected ucol_next -> ucol_getOffset %d, got %d\n", tsceItemPtr->locale, *nextOffsetPtr, offset ); nextOffsetPtr = limitOffsetPtr; break; } nextOffsetPtr++; } else { log_err("error, locale %s, ucol_next returned more elements than expected\n", tsceItemPtr->locale ); } } while ( U_SUCCESS(status) && element != UCOL_NULLORDER ); if ( nextOffsetPtr < limitOffsetPtr ) { log_err("error, locale %s, ucol_next returned fewer elements than expected\n", tsceItemPtr->locale ); } ucol_setOffset(uce, kLen_tsceText, &status); status = U_ZERO_ERROR; nextOffsetPtr = tsceItemPtr->offsets + tsceItemPtr->offsetsLen; limitOffsetPtr = tsceItemPtr->offsets; do { offset = ucol_getOffset(uce); element = ucol_previous(uce, &status); if ( element == 0 ) { log_err("error, locale %s, ucol_previous returned element 0\n", tsceItemPtr->locale ); } if ( nextOffsetPtr > limitOffsetPtr ) { nextOffsetPtr--; if (offset != *nextOffsetPtr) { log_err("error, locale %s, expected ucol_previous -> ucol_getOffset %d, got %d\n", tsceItemPtr->locale, *nextOffsetPtr, offset ); nextOffsetPtr = limitOffsetPtr; break; } } else { log_err("error, locale %s, ucol_previous returned more elements than expected\n", tsceItemPtr->locale ); } } while ( U_SUCCESS(status) && element != UCOL_NULLORDER ); if ( nextOffsetPtr > limitOffsetPtr ) { log_err("error, locale %s, ucol_previous returned fewer elements than expected\n", tsceItemPtr->locale ); } ucol_closeElements(uce); } else { log_err("error, locale %s, ucol_openElements failed: %s\n", tsceItemPtr->locale, u_errorName(status) ); } ucol_close(ucol); } else { log_data_err("error, locale %s, ucol_open failed: %s\n", tsceItemPtr->locale, u_errorName(status) ); } } }
backup_disk_t *partition_load(const disk_t *disk_car, const int verbose) { FILE *f_backup; char *buffer; char *pos=NULL; int taille; backup_disk_t *new_backup=NULL; backup_disk_t *list_backup; list_backup=(backup_disk_t*)MALLOC(sizeof(*list_backup)); list_backup->list.prev= &list_backup->list; list_backup->list.next = &list_backup->list; if(verbose>1) { log_trace("partition_load\n"); } f_backup=fopen("backup.log","r"); if(!f_backup) { log_error("Can't open backup.log file: %s\n",strerror(errno)); return list_backup; } buffer=(char *)MALLOC(BACKUP_MAXSIZE); taille=fread(buffer,1,BACKUP_MAXSIZE,f_backup); buffer[(taille<BACKUP_MAXSIZE?taille:BACKUP_MAXSIZE-1)]='\0'; if(verbose>1) { log_info("partition_load backup.log size=%d\n",taille); } for(pos=buffer;pos<buffer+taille;pos++) { if(*pos=='\n') { *pos='\0'; } } pos=buffer; while(pos!=NULL && pos<buffer+taille) { if(*pos=='#') { pos++; if(verbose>1) { log_verbose("new disk: %s\n",pos); } if(new_backup!=NULL) td_list_add_tail(&new_backup->list,&list_backup->list); new_backup=(backup_disk_t*)MALLOC(sizeof(*new_backup)); new_backup->description[0]='\0'; new_backup->list_part=NULL; new_backup->my_time=strtol(pos,&pos,10); if(pos!=NULL) { strncpy(new_backup->description,++pos,sizeof(new_backup->description)); new_backup->description[sizeof(new_backup->description)-1]='\0'; } } else if(new_backup!=NULL) { partition_t *new_partition=partition_new(disk_car->arch); char status; unsigned int part_type; unsigned long part_size; unsigned long part_offset; if(verbose>1) { log_verbose("new partition\n"); } if(sscanf(pos,"%2u : start=%10lu, size=%10lu, Id=%02X, %c\n", &new_partition->order, &part_offset, &part_size,&part_type,&status)==5) { new_partition->part_offset=(uint64_t)part_offset*disk_car->sector_size; new_partition->part_size=(uint64_t)part_size*disk_car->sector_size; if(disk_car->arch->set_part_type!=NULL) disk_car->arch->set_part_type(new_partition,part_type); switch(status) { case 'P': new_partition->status=STATUS_PRIM; break; case '*': new_partition->status=STATUS_PRIM_BOOT; break; case 'L': new_partition->status=STATUS_LOG; break; default: new_partition->status=STATUS_DELETED; break; } { int insert_error=0; new_backup->list_part=insert_new_partition(new_backup->list_part, new_partition, 0, &insert_error); if(insert_error>0) free(new_partition); } } else { log_critical("partition_load: sscanf failed\n"); free(new_partition); pos=NULL; } } if(pos!=NULL) { while(*pos!='\0' && pos<buffer+taille) pos++; pos++; } } if(new_backup!=NULL) td_list_add_tail(&new_backup->list,&list_backup->list); fclose(f_backup); free(buffer); return list_backup; }
/* * Select a locking type * type: locking type; if < 0, then read config tree value */ int init_locking(int type, struct cmd_context *cmd, int suppress_messages) { if (getenv("LVM_SUPPRESS_LOCKING_FAILURE_MESSAGES")) suppress_messages = 1; if (type < 0) type = find_config_tree_int(cmd, global_locking_type_CFG, NULL); _blocking_supported = find_config_tree_bool(cmd, global_wait_for_locks_CFG, NULL); switch (type) { case 0: init_no_locking(&_locking, cmd, suppress_messages); log_warn("WARNING: Locking disabled. Be careful! " "This could corrupt your metadata."); return 1; case 1: log_very_verbose("%sFile-based locking selected.", _blocking_supported ? "" : "Non-blocking "); if (!init_file_locking(&_locking, cmd, suppress_messages)) { log_error_suppress(suppress_messages, "File-based locking initialisation failed."); break; } return 1; #ifdef HAVE_LIBDL case 2: if (!is_static()) { log_very_verbose("External locking selected."); if (init_external_locking(&_locking, cmd, suppress_messages)) return 1; } if (!find_config_tree_bool(cmd, global_fallback_to_clustered_locking_CFG, NULL)) { log_error_suppress(suppress_messages, "External locking initialisation failed."); break; } #endif #ifdef CLUSTER_LOCKING_INTERNAL log_very_verbose("Falling back to internal clustered locking."); /* Fall through */ case 3: log_very_verbose("Cluster locking selected."); if (!init_cluster_locking(&_locking, cmd, suppress_messages)) { log_error_suppress(suppress_messages, "Internal cluster locking initialisation failed."); break; } return 1; #endif case 4: log_verbose("Read-only locking selected. " "Only read operations permitted."); if (!init_readonly_locking(&_locking, cmd, suppress_messages)) break; return 1; case 5: init_dummy_locking(&_locking, cmd, suppress_messages); log_verbose("Locking disabled for read-only access."); return 1; default: log_error("Unknown locking type requested."); return 0; } if ((type == 2 || type == 3) && find_config_tree_bool(cmd, global_fallback_to_local_locking_CFG, NULL)) { log_warn_suppress(suppress_messages, "WARNING: Falling back to local file-based locking."); log_warn_suppress(suppress_messages, "Volume Groups with the clustered attribute will " "be inaccessible."); if (init_file_locking(&_locking, cmd, suppress_messages)) return 1; else log_error_suppress(suppress_messages, "File-based locking initialisation failed."); } if (!ignorelockingfailure()) return 0; log_verbose("Locking disabled - only read operations permitted."); init_readonly_locking(&_locking, cmd, suppress_messages); return 1; }
static void *rx_callback(struct bladerf *dev, struct bladerf_stream *stream, struct bladerf_metadata *meta, void *samples, size_t num_samples, void *user_data) { unsigned int requests; /* Pending requests */ unsigned int next_idx; unsigned int samples_idx; void *next_buf = NULL; /* Next buffer to submit for reception */ struct bladerf_sync *s = (struct bladerf_sync *)user_data; struct sync_worker *w = s->worker; struct buffer_mgmt *b = &s->buf_mgmt; /* Check if the caller has requested us to shut down. We'll keep the * SHUTDOWN bit set through our transition into the IDLE state so we * can act on it there. */ pthread_mutex_lock(&w->request_lock); requests = w->requests; pthread_mutex_unlock(&w->request_lock); if (requests & SYNC_WORKER_STOP) { log_verbose("%s worker: Got STOP request upon entering callback. " "Ending stream.\n", MODULE_STR(s)); return NULL; } pthread_mutex_lock(&b->lock); /* Get the index of the buffer that was just filled */ samples_idx = sync_buf2idx(b, samples); if (b->resubmit_count == 0) { if (b->status[b->prod_i] == SYNC_BUFFER_EMPTY) { /* This buffer is now ready for the consumer */ b->status[samples_idx] = SYNC_BUFFER_FULL; pthread_cond_signal(&b->buf_ready); /* Update the state of the buffer being submitted next */ next_idx = b->prod_i; b->status[next_idx] = SYNC_BUFFER_IN_FLIGHT; next_buf = b->buffers[next_idx]; /* Advance to the next buffer for the next callback */ b->prod_i = (next_idx + 1) % b->num_buffers; log_verbose("%s worker: buf[%u] = full, buf[%u] = in_flight\n", MODULE_STR(s), samples_idx, next_idx); } else { /* TODO propgate back the RX Overrun to the sync_rx() caller */ log_debug("RX overrun @ buffer %u\r\n", samples_idx); next_buf = samples; b->resubmit_count = s->stream_config.num_xfers - 1; } } else { /* We're still recovering from an overrun at this point. Just * turn around and resubmit this buffer */ next_buf = samples; b->resubmit_count--; log_verbose("Resubmitting buffer %u (%u resubmissions left)\r\n", samples_idx, b->resubmit_count); } pthread_mutex_unlock(&b->lock); return next_buf; }
void TestCzechMonths459() { int32_t lneed, pos; UChar *pattern=NULL, *tzID=NULL; UChar *juneStr, *julyStr; UDateFormat *fmt; UCalendar *cal; UDate june, july, d; UErrorCode status = U_ZERO_ERROR; UChar *date; ctest_setTimeZone(NULL, &status); fmt = udat_open(UDAT_FULL, UDAT_FULL, "cs", NULL, 0, NULL, 0, &status); if(U_FAILURE(status)){ log_data_err("Error in constructing the date format -> %s (Are you missing data?)\n", u_errorName(status)); ctest_resetTimeZone(); return; } lneed=0; lneed=udat_toPattern(fmt, TRUE, NULL, lneed, &status); if(status==U_BUFFER_OVERFLOW_ERROR){ status=U_ZERO_ERROR; pattern=(UChar*)malloc(sizeof(UChar) * (lneed+1) ); udat_toPattern(fmt, TRUE, pattern, lneed+1, &status); } if(U_FAILURE(status)){ log_err("Error in extracting the pattern\n"); } tzID=(UChar*)malloc(sizeof(UChar) * 4); u_uastrcpy(tzID, "GMT"); cal=ucal_open(tzID, u_strlen(tzID), "cs", UCAL_GREGORIAN, &status); if(U_FAILURE(status)){ log_err("error in ucal_open caldef : %s\n", myErrorName(status)); } ucal_setDate(cal, 1997, UCAL_JUNE, 15, &status); june=ucal_getMillis(cal, &status); ucal_setDate(cal, 1997, UCAL_JULY, 15, &status); july=ucal_getMillis(cal, &status); juneStr = myDateFormat(fmt, june); julyStr = myDateFormat(fmt, july); pos=0; if(juneStr == NULL) { log_data_err("Can't load juneStr. Quitting.\n"); return; } d = udat_parse(fmt, juneStr, u_strlen(juneStr), &pos, &status); date = myDateFormat(fmt, d); if(U_SUCCESS(status)){ UChar* out1 = myDateFormat(fmt, june); UChar* out2 = myDateFormat(fmt, d); if(u_strcmp(out1, out2) !=0) log_err("Error in handling the czech month june\n"); else log_verbose("Pass: Date = %s (czech month June)\n", aescstrdup(date, -1)); }else{ log_err("udat_parse failed. Error. %s\n",u_errorName(status)); } pos=0; d = udat_parse(fmt, julyStr, u_strlen(julyStr), &pos, &status); date = myDateFormat(fmt, d); if(u_strcmp(myDateFormat(fmt, july), myDateFormat(fmt, d) ) !=0) log_err("Error in handling the czech month july\n"); else log_verbose("Pass: Date = %s (czech month July)\n", aescstrdup(date, -1)); ctest_resetTimeZone(); udat_close(fmt); ucal_close(cal); free(pattern); free(tzID); }
static void _expect(const UTransliterator* trans, const char* cfrom, const char* cto) { /* u_uastrcpy has no capacity param for the buffer -- so just * make all buffers way too big */ enum { CAP = 256 }; UChar from[CAP]; UChar to[CAP]; UChar buf[CAP]; const UChar *ID; int32_t IDLength; const char *id; UErrorCode status = U_ZERO_ERROR; int32_t limit; UTransPosition pos; XReplaceable xrep; XReplaceable *xrepPtr = &xrep; UReplaceableCallbacks xrepVtable; u_uastrcpy(from, cfrom); u_uastrcpy(to, cto); ID = utrans_getUnicodeID(trans, &IDLength); id = aescstrdup(ID, IDLength); /* utrans_transUChars() */ u_strcpy(buf, from); limit = u_strlen(buf); utrans_transUChars(trans, buf, NULL, CAP, 0, &limit, &status); if (U_FAILURE(status)) { log_err("FAIL: utrans_transUChars() failed, error=%s\n", u_errorName(status)); return; } if (0 == u_strcmp(buf, to)) { log_verbose("Ok: utrans_transUChars(%s) x %s -> %s\n", id, cfrom, cto); } else { char actual[CAP]; u_austrcpy(actual, buf); log_err("FAIL: utrans_transUChars(%s) x %s -> %s, expected %s\n", id, cfrom, actual, cto); } /* utrans_transIncrementalUChars() */ u_strcpy(buf, from); pos.start = pos.contextStart = 0; pos.limit = pos.contextLimit = u_strlen(buf); utrans_transIncrementalUChars(trans, buf, NULL, CAP, &pos, &status); utrans_transUChars(trans, buf, NULL, CAP, pos.start, &pos.limit, &status); if (U_FAILURE(status)) { log_err("FAIL: utrans_transIncrementalUChars() failed, error=%s\n", u_errorName(status)); return; } if (0 == u_strcmp(buf, to)) { log_verbose("Ok: utrans_transIncrementalUChars(%s) x %s -> %s\n", id, cfrom, cto); } else { char actual[CAP]; u_austrcpy(actual, buf); log_err("FAIL: utrans_transIncrementalUChars(%s) x %s -> %s, expected %s\n", id, cfrom, actual, cto); } /* utrans_trans() */ InitXReplaceableCallbacks(&xrepVtable); InitXReplaceable(&xrep, cfrom); limit = u_strlen(from); utrans_trans(trans, (UReplaceable*)xrepPtr, &xrepVtable, 0, &limit, &status); if (U_FAILURE(status)) { log_err("FAIL: utrans_trans() failed, error=%s\n", u_errorName(status)); FreeXReplaceable(&xrep); return; } if (0 == u_strcmp(xrep.text, to)) { log_verbose("Ok: utrans_trans(%s) x %s -> %s\n", id, cfrom, cto); } else { char actual[CAP]; u_austrcpy(actual, xrep.text); log_err("FAIL: utrans_trans(%s) x %s -> %s, expected %s\n", id, cfrom, actual, cto); } FreeXReplaceable(&xrep); /* utrans_transIncremental() */ InitXReplaceable(&xrep, cfrom); pos.start = pos.contextStart = 0; pos.limit = pos.contextLimit = u_strlen(from); utrans_transIncremental(trans, (UReplaceable*)xrepPtr, &xrepVtable, &pos, &status); utrans_trans(trans, (UReplaceable*)xrepPtr, &xrepVtable, pos.start, &pos.limit, &status); if (U_FAILURE(status)) { log_err("FAIL: utrans_transIncremental() failed, error=%s\n", u_errorName(status)); FreeXReplaceable(&xrep); return; } if (0 == u_strcmp(xrep.text, to)) { log_verbose("Ok: utrans_transIncremental(%s) x %s -> %s\n", id, cfrom, cto); } else { char actual[CAP]; u_austrcpy(actual, xrep.text); log_err("FAIL: utrans_transIncremental(%s) x %s -> %s, expected %s\n", id, cfrom, actual, cto); } FreeXReplaceable(&xrep); }
static struct dm_ioctl *_flatten(struct dm_task *dmt, unsigned repeat_count) { const size_t min_size = 16 * 1024; const int (*version)[3]; struct dm_ioctl *dmi; struct target *t; struct dm_target_msg *tmsg; size_t len = sizeof(struct dm_ioctl); void *b, *e; int count = 0; for (t = dmt->head; t; t = t->next) { len += sizeof(struct dm_target_spec); len += strlen(t->params) + 1 + ALIGNMENT; count++; } if (count && (dmt->sector || dmt->message)) { log_error("targets and message are incompatible"); return NULL; } if (count && dmt->newname) { log_error("targets and newname are incompatible"); return NULL; } if (count && dmt->geometry) { log_error("targets and geometry are incompatible"); return NULL; } if (dmt->newname && (dmt->sector || dmt->message)) { log_error("message and newname are incompatible"); return NULL; } if (dmt->newname && dmt->geometry) { log_error("geometry and newname are incompatible"); return NULL; } if (dmt->geometry && (dmt->sector || dmt->message)) { log_error("geometry and message are incompatible"); return NULL; } if (dmt->sector && !dmt->message) { log_error("message is required with sector"); return NULL; } if (dmt->newname) len += strlen(dmt->newname) + 1; if (dmt->message) len += sizeof(struct dm_target_msg) + strlen(dmt->message) + 1; if (dmt->geometry) len += strlen(dmt->geometry) + 1; /* * Give len a minimum size so that we have space to store * dependencies or status information. */ if (len < min_size) len = min_size; /* Increase buffer size if repeating because buffer was too small */ while (repeat_count--) len *= 2; if (!(dmi = dm_malloc(len))) return NULL; memset(dmi, 0, len); version = &_cmd_data_v4[dmt->type].version; dmi->version[0] = (*version)[0]; dmi->version[1] = (*version)[1]; dmi->version[2] = (*version)[2]; dmi->data_size = len; dmi->data_start = sizeof(struct dm_ioctl); if (dmt->minor >= 0) { if (dmt->major <= 0) { log_error("Missing major number for persistent device."); goto bad; } if (!_dm_multiple_major_support && dmt->allow_default_major_fallback && dmt->major != _dm_device_major) { log_verbose("Overriding major number of %" PRIu32 " with %" PRIu32 " for persistent device.", dmt->major, _dm_device_major); dmt->major = _dm_device_major; } dmi->flags |= DM_PERSISTENT_DEV_FLAG; dmi->dev = MKDEV(dmt->major, dmt->minor); } /* Does driver support device number referencing? */ if (_dm_version_minor < 3 && !dmt->dev_name && !dmt->uuid && dmi->dev) { if (!_lookup_dev_name(dmi->dev, dmi->name, sizeof(dmi->name))) { log_error("Unable to find name for device (%" PRIu32 ":%" PRIu32 ")", dmt->major, dmt->minor); goto bad; } log_verbose("device (%" PRIu32 ":%" PRIu32 ") is %s " "for compatibility with old kernel", dmt->major, dmt->minor, dmi->name); } /* FIXME Until resume ioctl supplies name, use dev_name for readahead */ if (dmt->dev_name && (dmt->type != DM_DEVICE_RESUME || dmt->minor < 0 || dmt->major < 0)) strncpy(dmi->name, dmt->dev_name, sizeof(dmi->name)); if (dmt->uuid) strncpy(dmi->uuid, dmt->uuid, sizeof(dmi->uuid)); if (dmt->type == DM_DEVICE_SUSPEND) dmi->flags |= DM_SUSPEND_FLAG; if (dmt->no_flush) dmi->flags |= DM_NOFLUSH_FLAG; if (dmt->read_only) dmi->flags |= DM_READONLY_FLAG; if (dmt->skip_lockfs) dmi->flags |= DM_SKIP_LOCKFS_FLAG; if (dmt->query_inactive_table) { if (_dm_version_minor < 16) log_warn("WARNING: Inactive table query unsupported " "by kernel. It will use live table."); dmi->flags |= DM_QUERY_INACTIVE_TABLE_FLAG; } dmi->target_count = count; dmi->event_nr = dmt->event_nr; b = (void *) (dmi + 1); e = (void *) ((char *) dmi + len); for (t = dmt->head; t; t = t->next) if (!(b = _add_target(t, b, e))) { log_error("Ran out of memory building ioctl parameter"); goto bad; } if (dmt->newname) strcpy(b, dmt->newname); if (dmt->message) { tmsg = (struct dm_target_msg *) b; tmsg->sector = dmt->sector; strcpy(tmsg->message, dmt->message); } if (dmt->geometry) strcpy(b, dmt->geometry); return dmi; bad: _dm_zfree_dmi(dmi); return NULL; }
/** * Test for CollationElementIterator previous and next for the whole set of * unicode characters. */ static void TestUnicodeChar() { UChar source[0x100]; UCollator *en_us; UCollationElements *iter; UErrorCode status = U_ZERO_ERROR; UChar codepoint; UChar *test; en_us = ucol_open("en_US", &status); if (U_FAILURE(status)){ log_err_status(status, "ERROR: in creation of collation data using ucol_open()\n %s\n", myErrorName(status)); return; } for (codepoint = 1; codepoint < 0xFFFE;) { test = source; while (codepoint % 0xFF != 0) { if (u_isdefined(codepoint)) *(test ++) = codepoint; codepoint ++; } if (u_isdefined(codepoint)) *(test ++) = codepoint; if (codepoint != 0xFFFF) codepoint ++; *test = 0; iter=ucol_openElements(en_us, source, u_strlen(source), &status); if(U_FAILURE(status)){ log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n", myErrorName(status)); ucol_close(en_us); return; } /* A basic test to see if it's working at all */ log_verbose("codepoint testing %x\n", codepoint); backAndForth(iter); ucol_closeElements(iter); /* null termination test */ iter=ucol_openElements(en_us, source, -1, &status); if(U_FAILURE(status)){ log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n", myErrorName(status)); ucol_close(en_us); return; } /* A basic test to see if it's working at all */ backAndForth(iter); ucol_closeElements(iter); } ucol_close(en_us); }
static int _dm_task_run_v1(struct dm_task *dmt) { struct dm_ioctl_v1 *dmi; unsigned int command; dmi = _flatten_v1(dmt); if (!dmi) { log_error("Couldn't create ioctl argument."); return 0; } if (!_open_control()) return 0; if ((unsigned) dmt->type >= (sizeof(_cmd_data_v1) / sizeof(*_cmd_data_v1))) { log_error(INTERNAL ERROR "unknown device-mapper task %d", dmt->type); goto bad; } command = _cmd_data_v1[dmt->type].cmd; if (dmt->type == DM_DEVICE_TABLE) dmi->flags |= DM_STATUS_TABLE_FLAG; log_debug("dm %s %s %s%s%s [%u]", _cmd_data_v1[dmt->type].name, dmi->name, dmi->uuid, dmt->newname ? " " : "", dmt->newname ? dmt->newname : "", dmi->data_size); if (dmt->type == DM_DEVICE_LIST) { if (!_dm_names_v1(dmi)) goto bad; } #ifdef DM_IOCTLS else if (ioctl(_control_fd, command, dmi) < 0) { if (_log_suppress) log_verbose("device-mapper: %s ioctl failed: %s", _cmd_data_v1[dmt->type].name, strerror(errno)); else log_error("device-mapper: %s ioctl failed: %s", _cmd_data_v1[dmt->type].name, strerror(errno)); goto bad; } #else /* Userspace alternative for testing */ #endif if (dmi->flags & DM_BUFFER_FULL_FLAG) /* FIXME Increase buffer size and retry operation (if query) */ log_error("WARNING: libdevmapper buffer too small for data"); switch (dmt->type) { case DM_DEVICE_CREATE: add_dev_node(dmt->dev_name, MAJOR(dmi->dev), MINOR(dmi->dev), dmt->uid, dmt->gid, dmt->mode, 0); break; case DM_DEVICE_REMOVE: rm_dev_node(dmt->dev_name, 0); break; case DM_DEVICE_RENAME: rename_dev_node(dmt->dev_name, dmt->newname, 0); break; case DM_DEVICE_MKNODES: if (dmi->flags & DM_EXISTS_FLAG) add_dev_node(dmt->dev_name, MAJOR(dmi->dev), MINOR(dmi->dev), dmt->uid, dmt->gid, dmt->mode, 0); else rm_dev_node(dmt->dev_name, 0); break; case DM_DEVICE_STATUS: case DM_DEVICE_TABLE: if (!_unmarshal_status_v1(dmt, dmi)) goto bad; break; case DM_DEVICE_SUSPEND: case DM_DEVICE_RESUME: dmt->type = DM_DEVICE_INFO; if (!dm_task_run(dmt)) goto bad; _dm_zfree_dmi_v1(dmi); /* We'll use what info returned */ return 1; } dmt->dmi.v1 = dmi; return 1; bad: _dm_zfree_dmi_v1(dmi); return 0; }
/** * Test for CollationElementIterator.previous() * * @bug 4108758 - Make sure it works with contracting characters * */ static void TestPrevious() { UCollator *coll=NULL; UChar rule[50]; UChar *source; UCollator *c1, *c2, *c3; UCollationElements *iter; UErrorCode status = U_ZERO_ERROR; UChar test1[50]; UChar test2[50]; u_uastrcpy(test1, "What subset of all possible test cases?"); u_uastrcpy(test2, "has the highest probability of detecting"); coll = ucol_open("en_US", &status); iter=ucol_openElements(coll, test1, u_strlen(test1), &status); log_verbose("English locale testing back and forth\n"); if(U_FAILURE(status)){ log_err_status(status, "ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n", myErrorName(status)); ucol_close(coll); return; } /* A basic test to see if it's working at all */ backAndForth(iter); ucol_closeElements(iter); ucol_close(coll); /* Test with a contracting character sequence */ u_uastrcpy(rule, "&a,A < b,B < c,C, d,D < z,Z < ch,cH,Ch,CH"); c1 = ucol_openRules(rule, u_strlen(rule), UCOL_OFF, UCOL_DEFAULT_STRENGTH, NULL, &status); log_verbose("Contraction rule testing back and forth with no normalization\n"); if (c1 == NULL || U_FAILURE(status)) { log_err("Couldn't create a RuleBasedCollator with a contracting sequence\n %s\n", myErrorName(status)); return; } source=(UChar*)malloc(sizeof(UChar) * 20); u_uastrcpy(source, "abchdcba"); iter=ucol_openElements(c1, source, u_strlen(source), &status); if(U_FAILURE(status)){ log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n", myErrorName(status)); return; } backAndForth(iter); ucol_closeElements(iter); ucol_close(c1); /* Test with an expanding character sequence */ u_uastrcpy(rule, "&a < b < c/abd < d"); c2 = ucol_openRules(rule, u_strlen(rule), UCOL_OFF, UCOL_DEFAULT_STRENGTH, NULL, &status); log_verbose("Expansion rule testing back and forth with no normalization\n"); if (c2 == NULL || U_FAILURE(status)) { log_err("Couldn't create a RuleBasedCollator with a contracting sequence.\n %s\n", myErrorName(status)); return; } u_uastrcpy(source, "abcd"); iter=ucol_openElements(c2, source, u_strlen(source), &status); if(U_FAILURE(status)){ log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n", myErrorName(status)); return; } backAndForth(iter); ucol_closeElements(iter); ucol_close(c2); /* Now try both */ u_uastrcpy(rule, "&a < b < c/aba < d < z < ch"); c3 = ucol_openRules(rule, u_strlen(rule), UCOL_DEFAULT, UCOL_DEFAULT_STRENGTH,NULL, &status); log_verbose("Expansion/contraction rule testing back and forth with no normalization\n"); if (c3 == NULL || U_FAILURE(status)) { log_err("Couldn't create a RuleBasedCollator with a contracting sequence.\n %s\n", myErrorName(status)); return; } u_uastrcpy(source, "abcdbchdc"); iter=ucol_openElements(c3, source, u_strlen(source), &status); if(U_FAILURE(status)){ log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n", myErrorName(status)); return; } backAndForth(iter); ucol_closeElements(iter); ucol_close(c3); source[0] = 0x0e41; source[1] = 0x0e02; source[2] = 0x0e41; source[3] = 0x0e02; source[4] = 0x0e27; source[5] = 0x61; source[6] = 0x62; source[7] = 0x63; source[8] = 0; coll = ucol_open("th_TH", &status); log_verbose("Thai locale testing back and forth with normalization\n"); iter=ucol_openElements(coll, source, u_strlen(source), &status); if(U_FAILURE(status)){ log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n", myErrorName(status)); return; } backAndForth(iter); ucol_closeElements(iter); ucol_close(coll); /* prev test */ source[0] = 0x0061; source[1] = 0x30CF; source[2] = 0x3099; source[3] = 0x30FC; source[4] = 0; coll = ucol_open("ja_JP", &status); log_verbose("Japanese locale testing back and forth with normalization\n"); iter=ucol_openElements(coll, source, u_strlen(source), &status); if(U_FAILURE(status)){ log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n", myErrorName(status)); return; } backAndForth(iter); ucol_closeElements(iter); ucol_close(coll); free(source); }
void TestConstruction1() { UResourceBundle *test1 = 0, *test2 = 0; const UChar *result1, *result2; int32_t resultLen; UChar temp[7]; UErrorCode err = U_ZERO_ERROR; const char* testdatapath ; const char* locale="te_IN"; log_verbose("Testing ures_open()......\n"); testdatapath=loadTestData(&err); if(U_FAILURE(err)) { log_data_err("Could not load testdata.dat %s \n",myErrorName(err)); return; } test1=ures_open(testdatapath, NULL, &err); if(U_FAILURE(err)) { log_err("construction of %s did not succeed : %s \n",NULL, myErrorName(err)); return; } test2=ures_open(testdatapath, locale, &err); if(U_FAILURE(err)) { log_err("construction of %s did not succeed : %s \n",locale, myErrorName(err)); return; } result1= ures_getStringByKey(test1, "string_in_Root_te_te_IN", &resultLen, &err); result2= ures_getStringByKey(test2, "string_in_Root_te_te_IN", &resultLen, &err); if (U_FAILURE(err)) { log_err("Something threw an error in TestConstruction(): %s\n", myErrorName(err)); return; } u_uastrcpy(temp, "TE_IN"); if(u_strcmp(result2, temp)!=0) { int n; log_err("Construction test failed for ures_open();\n"); if(!getTestOption(VERBOSITY_OPTION)) log_info("(run verbose for more information)\n"); log_verbose("\nGot->"); for(n=0;result2[n];n++) { log_verbose("%04X ",result2[n]); } log_verbose("<\n"); log_verbose("\nWant>"); for(n=0;temp[n];n++) { log_verbose("%04X ",temp[n]); } log_verbose("<\n"); } log_verbose("for string_in_Root_te_te_IN, default.txt had %s\n", austrdup(result1)); log_verbose("for string_in_Root_te_te_IN, te_IN.txt had %s\n", austrdup(result2)); /* Test getVersionNumber*/ log_verbose("Testing version number\n"); log_verbose("for getVersionNumber : %s\n", ures_getVersionNumber(test1)); ures_close(test1); ures_close(test2); }
/** * Test for getOffset() and setOffset() */ static void TestOffset() { UErrorCode status= U_ZERO_ERROR; UCollator *en_us=NULL; UCollationElements *iter, *pristine; int32_t offset; OrderAndOffset *orders; int32_t orderLength=0; int count = 0; UChar test1[50]; UChar test2[50]; u_uastrcpy(test1, "What subset of all possible test cases?"); u_uastrcpy(test2, "has the highest probability of detecting"); en_us = ucol_open("en_US", &status); log_verbose("Testing getOffset and setOffset for collations\n"); iter = ucol_openElements(en_us, test1, u_strlen(test1), &status); if(U_FAILURE(status)){ log_err_status(status, "ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n", myErrorName(status)); ucol_close(en_us); return; } /* testing boundaries */ ucol_setOffset(iter, 0, &status); if (U_FAILURE(status) || ucol_previous(iter, &status) != UCOL_NULLORDER) { log_err("Error: After setting offset to 0, we should be at the end " "of the backwards iteration"); } ucol_setOffset(iter, u_strlen(test1), &status); if (U_FAILURE(status) || ucol_next(iter, &status) != UCOL_NULLORDER) { log_err("Error: After setting offset to end of the string, we should " "be at the end of the backwards iteration"); } /* Run all the way through the iterator, then get the offset */ orders = getOrders(iter, &orderLength); offset = ucol_getOffset(iter); if (offset != u_strlen(test1)) { log_err("offset at end != length %d vs %d\n", offset, u_strlen(test1) ); } /* Now set the offset back to the beginning and see if it works */ pristine=ucol_openElements(en_us, test1, u_strlen(test1), &status); if(U_FAILURE(status)){ log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n", myErrorName(status)); ucol_close(en_us); return; } status = U_ZERO_ERROR; ucol_setOffset(iter, 0, &status); if (U_FAILURE(status)) { log_err("setOffset failed. %s\n", myErrorName(status)); } else { assertEqual(iter, pristine); } ucol_closeElements(pristine); ucol_closeElements(iter); free(orders); /* testing offsets in normalization buffer */ test1[0] = 0x61; test1[1] = 0x300; test1[2] = 0x316; test1[3] = 0x62; test1[4] = 0; ucol_setAttribute(en_us, UCOL_NORMALIZATION_MODE, UCOL_ON, &status); iter = ucol_openElements(en_us, test1, 4, &status); if(U_FAILURE(status)){ log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n", myErrorName(status)); ucol_close(en_us); return; } count = 0; while (ucol_next(iter, &status) != UCOL_NULLORDER && U_SUCCESS(status)) { switch (count) { case 0: if (ucol_getOffset(iter) != 1) { log_err("ERROR: Offset of iteration should be 1\n"); } break; case 3: if (ucol_getOffset(iter) != 4) { log_err("ERROR: Offset of iteration should be 4\n"); } break; default: if (ucol_getOffset(iter) != 3) { log_err("ERROR: Offset of iteration should be 3\n"); } } count ++; } ucol_reset(iter); count = 0; while (ucol_previous(iter, &status) != UCOL_NULLORDER && U_SUCCESS(status)) { switch (count) { case 0: case 1: if (ucol_getOffset(iter) != 3) { log_err("ERROR: Offset of iteration should be 3\n"); } break; case 2: if (ucol_getOffset(iter) != 1) { log_err("ERROR: Offset of iteration should be 1\n"); } break; default: if (ucol_getOffset(iter) != 0) { log_err("ERROR: Offset of iteration should be 0\n"); } } count ++; } if(U_FAILURE(status)){ log_err("ERROR: in iterating collation elements %s\n", myErrorName(status)); } ucol_closeElements(iter); ucol_close(en_us); }
static void TestFileStream(void){ int32_t c = 0; int32_t c1=0; UErrorCode status = U_ZERO_ERROR; const char* testdatapath = loadTestData(&status); char* fileName = (char*) malloc(uprv_strlen(testdatapath) +10); FileStream* stream = NULL; /* these should not be closed */ FileStream* pStdin = T_FileStream_stdin(); FileStream* pStdout = T_FileStream_stdout(); FileStream* pStderr = T_FileStream_stderr(); const char* testline = "This is a test line"; int32_t bufLen = (int32_t)strlen(testline)+10; char* buf = (char*) malloc(bufLen); int32_t retLen = 0; if(pStdin==NULL){ log_err("failed to get T_FileStream_stdin()"); } if(pStdout==NULL){ log_err("failed to get T_FileStream_stdout()"); } if(pStderr==NULL){ log_err("failed to get T_FileStream_stderr()"); } uprv_strcpy(fileName,testdatapath); uprv_strcat(fileName,".dat"); stream = T_FileStream_open(fileName, "r"); if(stream==NULL){ log_data_err("T_FileStream_open failed to open %s\n",fileName); } else { if(!T_FileStream_file_exists(fileName)){ log_data_err("T_FileStream_file_exists failed to verify existence of %s \n",fileName); } retLen=T_FileStream_read(stream,&c,1); if(retLen==0){ log_data_err("T_FileStream_read failed to read from %s \n",fileName); } retLen=0; T_FileStream_rewind(stream); T_FileStream_read(stream,&c1,1); if(c!=c1){ log_data_err("T_FileStream_rewind failed to rewind %s \n",fileName); } T_FileStream_rewind(stream); c1 = T_FileStream_peek(stream); if(c!=c1){ log_data_err("T_FileStream_peek failed to peekd %s \n",fileName); } c = T_FileStream_getc(stream); T_FileStream_ungetc(c,stream); if(c!= T_FileStream_getc(stream)){ log_data_err("T_FileStream_ungetc failed to d %s \n",fileName); } if(T_FileStream_size(stream)<=0){ log_data_err("T_FileStream_size failed to d %s \n",fileName); } if(T_FileStream_error(stream)){ log_data_err("T_FileStream_error shouldn't have an error %s\n",fileName); } if(!T_FileStream_error(NULL)){ log_err("T_FileStream_error didn't get an error %s\n",fileName); } T_FileStream_putc(stream, 0x20); if(!T_FileStream_error(stream)){ /* Warning writing to a read-only file may not consistently fail on all platforms (e.g. HP-UX, FreeBSD, MacOSX) */ log_verbose("T_FileStream_error didn't get an error when writing to a readonly file %s\n",fileName); } T_FileStream_close(stream); } /* test writing function */ stream=NULL; uprv_strcpy(fileName,testdatapath); uprv_strcat(fileName,".tmp"); stream = T_FileStream_open(fileName,"w+"); if(stream == NULL){ log_data_err("Could not open %s for writing\n",fileName); } else { c= '$'; T_FileStream_putc(stream,c); T_FileStream_rewind(stream); if(c != T_FileStream_getc(stream)){ log_data_err("T_FileStream_putc failed %s\n",fileName); } T_FileStream_rewind(stream); T_FileStream_writeLine(stream,testline); T_FileStream_rewind(stream); T_FileStream_readLine(stream,buf,bufLen); if(uprv_strncmp(testline, buf,uprv_strlen(buf))!=0){ log_data_err("T_FileStream_writeLine failed %s\n",fileName); } T_FileStream_rewind(stream); T_FileStream_write(stream,testline,(int32_t)strlen(testline)); T_FileStream_rewind(stream); retLen = T_FileStream_read(stream, buf, bufLen); if(uprv_strncmp(testline, buf,retLen)!=0){ log_data_err("T_FileStream_write failed %s\n",fileName); } T_FileStream_close(stream); } if(!T_FileStream_remove(fileName)){ log_data_err("T_FileStream_remove failed to delete %s\n",fileName); } free(fileName); free(buf); }
static void TestBug672() { UErrorCode status = U_ZERO_ERROR; UChar pattern[20]; UChar text[50]; int i; int result[3][3]; u_uastrcpy(pattern, "resume"); u_uastrcpy(text, "Time to resume updating my resume."); for (i = 0; i < 3; ++ i) { UCollator *coll = ucol_open(LOCALES[i], &status); UCollationElements *pitr = ucol_openElements(coll, pattern, -1, &status); UCollationElements *titer = ucol_openElements(coll, text, -1, &status); if (U_FAILURE(status)) { log_err_status(status, "ERROR: in creation of either the collator or the collation iterator :%s\n", myErrorName(status)); return; } log_verbose("locale tested %s\n", LOCALES[i]); while (ucol_next(pitr, &status) != UCOL_NULLORDER && U_SUCCESS(status)) { } if (U_FAILURE(status)) { log_err("ERROR: reversing collation iterator :%s\n", myErrorName(status)); return; } ucol_reset(pitr); ucol_setOffset(titer, u_strlen(pattern), &status); if (U_FAILURE(status)) { log_err("ERROR: setting offset in collator :%s\n", myErrorName(status)); return; } result[i][0] = ucol_getOffset(titer); log_verbose("Text iterator set to offset %d\n", result[i][0]); /* Use previous() */ ucol_previous(titer, &status); result[i][1] = ucol_getOffset(titer); log_verbose("Current offset %d after previous\n", result[i][1]); /* Add one to index */ log_verbose("Adding one to current offset...\n"); ucol_setOffset(titer, ucol_getOffset(titer) + 1, &status); if (U_FAILURE(status)) { log_err("ERROR: setting offset in collator :%s\n", myErrorName(status)); return; } result[i][2] = ucol_getOffset(titer); log_verbose("Current offset in text = %d\n", result[i][2]); ucol_closeElements(pitr); ucol_closeElements(titer); ucol_close(coll); } if (uprv_memcmp(result[0], result[1], 3) != 0 || uprv_memcmp(result[1], result[2], 3) != 0) { log_err("ERROR: Different locales have different offsets at the same character\n"); } }
/** * Tests surrogate support. * NOTE: This test used \\uD801\\uDC01 pair, which is now assigned to Desseret * Therefore, another (unassigned) code point was used for this test. */ static void TestSurrogates(void) { static const char str[] = "&z<'\\uD800\\uDC00'<'\\uD800\\uDC0A\\u0308'<A"; int len = strlen(str); int rlen = 0; UChar rules[sizeof(str)]; UCollator *myCollation; UCollator *enCollation; UErrorCode status = U_ZERO_ERROR; UChar source[][4] = {{'z', 0, 0}, {0xD800, 0xDC00, 0}, {0xD800, 0xDC0A, 0x0308, 0}, {0xD800, 0xDC02}}; UChar target[][4] = {{0xD800, 0xDC00, 0}, {0xD800, 0xDC0A, 0x0308, 0}, {'A', 0, 0}, {0xD800, 0xDC03}}; int count = 0; uint8_t enresult[20], myresult[20]; int enlen, mylen; /* tests for open rules with surrogate rules */ rlen = u_unescape(str, rules, len); enCollation = ucol_open("en_US", &status); if (U_FAILURE(status)) { log_err_status(status, "ERROR: in creation of collator :%s\n", myErrorName(status)); return; } myCollation = ucol_openRules(rules, rlen, UCOL_OFF, UCOL_TERTIARY,NULL, &status); if (U_FAILURE(status)) { ucol_close(enCollation); log_err("ERROR: in creation of rule based collator :%s\n", myErrorName(status)); return; } /* this test is to verify the supplementary sort key order in the english collator */ log_verbose("start of english collation supplementary characters test\n"); while (count < 2) { doTest(enCollation, source[count], target[count], UCOL_LESS); count ++; } doTest(enCollation, source[count], target[count], UCOL_GREATER); log_verbose("start of tailored collation supplementary characters test\n"); count = 0; /* tests getting collation elements for surrogates for tailored rules */ while (count < 4) { doTest(myCollation, source[count], target[count], UCOL_LESS); count ++; } /* tests that \uD800\uDC02 still has the same value, not changed */ enlen = ucol_getSortKey(enCollation, source[3], 2, enresult, 20); mylen = ucol_getSortKey(myCollation, source[3], 2, myresult, 20); if (enlen != mylen || uprv_memcmp(enresult, myresult, enlen) != 0) { log_verbose("Failed : non-tailored supplementary characters should have the same value\n"); } ucol_close(enCollation); ucol_close(myCollation); enCollation = NULL; myCollation = NULL; }
/** * Test for setText() */ static void TestSetText() { int32_t c,i; UErrorCode status = U_ZERO_ERROR; UCollator *en_us=NULL; UCollationElements *iter1, *iter2; UChar test1[50]; UChar test2[50]; u_uastrcpy(test1, "What subset of all possible test cases?"); u_uastrcpy(test2, "has the highest probability of detecting"); en_us = ucol_open("en_US", &status); log_verbose("testing setText for Collation elements\n"); iter1=ucol_openElements(en_us, test1, u_strlen(test1), &status); if(U_FAILURE(status)){ log_err_status(status, "ERROR: in creation of collation element iterator1 using ucol_openElements()\n %s\n", myErrorName(status)); ucol_close(en_us); return; } iter2=ucol_openElements(en_us, test2, u_strlen(test2), &status); if(U_FAILURE(status)){ log_err("ERROR: in creation of collation element iterator2 using ucol_openElements()\n %s\n", myErrorName(status)); ucol_close(en_us); return; } /* Run through the second iterator just to exercise it */ c = ucol_next(iter2, &status); i = 0; while ( ++i < 10 && (c != UCOL_NULLORDER)) { if (U_FAILURE(status)) { log_err("iter2->next() returned an error. %s\n", myErrorName(status)); ucol_closeElements(iter2); ucol_closeElements(iter1); ucol_close(en_us); return; } c = ucol_next(iter2, &status); } /* Now set it to point to the same string as the first iterator */ ucol_setText(iter2, test1, u_strlen(test1), &status); if (U_FAILURE(status)) { log_err("call to iter2->setText(test1) failed. %s\n", myErrorName(status)); } else { assertEqual(iter1, iter2); } /* Now set it to point to a null string with fake length*/ ucol_setText(iter2, NULL, 2, &status); if (status != U_ILLEGAL_ARGUMENT_ERROR) { log_err("call to iter2->setText(null, 2) should yield an illegal-argument-error - %s\n", myErrorName(status)); } ucol_closeElements(iter2); ucol_closeElements(iter1); ucol_close(en_us); }
void backAndForth(UCollationElements *iter) { /* Run through the iterator forwards and stick it into an array */ int32_t idx, o; UErrorCode status = U_ZERO_ERROR; int32_t orderLength = 0; OrderAndOffset *orders = getOrders(iter, &orderLength); /* Now go through it backwards and make sure we get the same values */ idx = orderLength; ucol_reset(iter); /* synwee : changed */ while ((o = ucol_previous(iter, &status)) != UCOL_NULLORDER) { #if TEST_OFFSETS int32_t offset = #endif ucol_getOffset(iter); idx -= 1; if (o != orders[idx].order) { if (o == 0) idx ++; else { while (idx > 0 && orders[-- idx].order == 0) { /* nothing... */ } if (o != orders[idx].order) { log_err("Mismatched order at index %d: 0x%8.8X vs. 0x%8.8X\n", idx, orders[idx].order, o); goto bail; } } } #if TEST_OFFSETS if (offset != orders[idx].offset) { log_err("Mismatched offset at index %d: %d vs. %d\n", idx, orders[idx].offset, offset); goto bail; } #endif } while (idx != 0 && orders[idx - 1].order == 0) { idx -= 1; } if (idx != 0) { log_err("Didn't get back to beginning - index is %d\n", idx); ucol_reset(iter); log_err("\nnext: "); if ((o = ucol_next(iter, &status)) != UCOL_NULLORDER) { log_err("Error at %x\n", o); } log_err("\nprev: "); if ((o = ucol_previous(iter, &status)) != UCOL_NULLORDER) { log_err("Error at %x\n", o); } log_verbose("\n"); } bail: free(orders); }
U_CDECL_END U_CDECL_BEGIN static void U_CALLCONV DataDrivenScanf(void) { #if !UCONFIG_NO_FORMATTING && !UCONFIG_NO_FILE_IO UErrorCode errorCode; TestDataModule *dataModule; TestData *testData; const DataMap *testCase; DataDrivenLogger logger; UChar uBuffer[512]; char cBuffer[512]; char cExpected[sizeof(cBuffer)]; UnicodeString tempStr; UChar format[512]; UChar expectedResult[512]; UChar argument[512]; int32_t i; int8_t i8, expected8; int16_t i16, expected16; int32_t i32, expected32; int64_t i64, expected64; double dbl, expectedDbl; volatile float flt, expectedFlt; // Use volatile in order to get around an Intel compiler issue. int32_t uBufferLenReturned; //const char *fileLocale = "en_US_POSIX"; //int32_t uFileBufferLenReturned; //UFILE *testFile; errorCode=U_ZERO_ERROR; dataModule=TestDataModule::getTestDataModule("icuio", logger, errorCode); if(U_SUCCESS(errorCode)) { testData=dataModule->createTestData("scanf", errorCode); if(U_SUCCESS(errorCode)) { for(i=0; testData->nextCase(testCase, errorCode); ++i) { if(U_FAILURE(errorCode)) { log_err("error retrieving icuio/printf test case %d - %s\n", i, u_errorName(errorCode)); errorCode=U_ZERO_ERROR; continue; } u_memset(uBuffer, 0x2A, sizeof(uBuffer)/sizeof(uBuffer[0])); uBuffer[sizeof(uBuffer)/sizeof(uBuffer[0])-1] = 0; tempStr=testCase->getString("format", errorCode); tempStr.extract(format, sizeof(format)/sizeof(format[0]), errorCode); tempStr=testCase->getString("result", errorCode); tempStr.extract(expectedResult, sizeof(expectedResult)/sizeof(expectedResult[0]), errorCode); tempStr=testCase->getString("argument", errorCode); tempStr.extract(argument, sizeof(argument)/sizeof(argument[0]), errorCode); u_austrncpy(cBuffer, format, sizeof(cBuffer)); if(U_FAILURE(errorCode)) { log_err("error retrieving icuio/printf test case %d - %s\n", i, u_errorName(errorCode)); errorCode=U_ZERO_ERROR; continue; } log_verbose("Test %d: format=\"%s\"\n", i, cBuffer); switch (testCase->getString("argumentType", errorCode)[0]) { case 0x64: // 'd' double expectedDbl = atof(u_austrcpy(cBuffer, expectedResult)); uBufferLenReturned = u_sscanf_u(argument, format, &dbl); //uFileBufferLenReturned = u_fscanf_u(testFile, format, dbl); if (dbl != expectedDbl) { log_err("error in scanf test case[%d] Got: %f Exp: %f\n", i, dbl, expectedDbl); } break; case 0x66: // 'f' float expectedFlt = (float)atof(u_austrcpy(cBuffer, expectedResult)); uBufferLenReturned = u_sscanf_u(argument, format, &flt); //uFileBufferLenReturned = u_fscanf_u(testFile, format, flt); if (flt != expectedFlt) { log_err("error in scanf test case[%d] Got: %f Exp: %f\n", i, flt, expectedFlt); } break; case 0x31: // '1' int8_t expected8 = (int8_t)uto64(expectedResult); uBufferLenReturned = u_sscanf_u(argument, format, &i8); //uFileBufferLenReturned = u_fscanf_u(testFile, format, i8); if (i8 != expected8) { log_err("error in scanf test case[%d] Got: %02X Exp: %02X\n", i, i8, expected8); } break; case 0x32: // '2' int16_t expected16 = (int16_t)uto64(expectedResult); uBufferLenReturned = u_sscanf_u(argument, format, &i16); //uFileBufferLenReturned = u_fscanf_u(testFile, format, i16); if (i16 != expected16) { log_err("error in scanf test case[%d] Got: %04X Exp: %04X\n", i, i16, expected16); } break; case 0x34: // '4' int32_t expected32 = (int32_t)uto64(expectedResult); uBufferLenReturned = u_sscanf_u(argument, format, &i32); //uFileBufferLenReturned = u_fscanf_u(testFile, format, i32); if (i32 != expected32) { log_err("error in scanf test case[%d] Got: %08X Exp: %08X\n", i, i32, expected32); } break; case 0x38: // '8' int64_t expected64 = uto64(expectedResult); uBufferLenReturned = u_sscanf_u(argument, format, &i64); //uFileBufferLenReturned = u_fscanf_u(testFile, format, i64); if (i64 != expected64) { log_err("error in scanf 64-bit. Test case = %d\n", i); } break; case 0x73: // 's' char * u_austrcpy(cExpected, expectedResult); uBufferLenReturned = u_sscanf_u(argument, format, cBuffer); //uFileBufferLenReturned = u_fscanf_u(testFile, format, cBuffer); if (strcmp(cBuffer, cExpected) != 0) { log_err("error in scanf char * string. Got \"%s\" Expected \"%s\". Test case = %d\n", cBuffer, cExpected, i); } break; case 0x53: // 'S' UChar * uBufferLenReturned = u_sscanf_u(argument, format, uBuffer); //uFileBufferLenReturned = u_fscanf_u(testFile, format, argument); if (u_strcmp(uBuffer, expectedResult) != 0) { u_austrcpy(cExpected, format); u_austrcpy(cBuffer, uBuffer); log_err("error in scanf UChar * string %s Got: \"%s\". Test case = %d\n", cExpected, cBuffer, i); } break; default: uBufferLenReturned = 0; //uFileBufferLenReturned = 0; log_err("Unknown type %c for test %d\n", testCase->getString("argumentType", errorCode)[0], i); } if (uBufferLenReturned != 1) { log_err("error scanf converted %d arguments. Test case = %d\n", uBufferLenReturned, i); } if(U_FAILURE(errorCode)) { log_err("error running icuio/printf test case %d - %s\n", i, u_errorName(errorCode)); errorCode=U_ZERO_ERROR; continue; } // u_fclose(testFile); } delete testData; } delete dataModule; } else { log_data_err("Failed: could not load test icuio data\n"); } #endif }
/** * @bug 4056591 * Verify the function of the [s|g]et2DigitYearStart() API. */ void Test4056591() { int i; UCalendar *cal; UDateFormat *def; UDate start,exp,got; UChar s[10]; UChar *gotdate, *expdate; UChar pat[10]; UDate d[4]; UErrorCode status = U_ZERO_ERROR; const char* strings[] = { "091225", "091224", "611226", "991227" }; log_verbose("Testing s[get] 2 digit year start regressively\n"); cal=ucal_open(NULL, 0, "en_US", UCAL_GREGORIAN, &status); if(U_FAILURE(status)){ log_data_err("error in ucal_open caldef : %s - (Are you missing data?)\n", myErrorName(status)); return; } ucal_setDateTime(cal, 1809, UCAL_DECEMBER, 25, 17, 40, 30, &status); d[0]=ucal_getMillis(cal, &status); if(U_FAILURE(status)){ log_err("Error: failure in get millis: %s\n", myErrorName(status)); } ucal_setDateTime(cal, 1909, UCAL_DECEMBER, 24, 17, 40, 30, &status); d[1]=ucal_getMillis(cal, &status); ucal_setDateTime(cal, 1861, UCAL_DECEMBER, 26, 17, 40, 30, &status); d[2]=ucal_getMillis(cal, &status); ucal_setDateTime(cal, 1999, UCAL_DECEMBER, 27, 17, 40, 30, &status); d[3]=ucal_getMillis(cal, &status); u_uastrcpy(pat, "yyMMdd"); def = udat_open(UDAT_IGNORE,UDAT_IGNORE,NULL, NULL, 0, pat, u_strlen(pat), &status); if(U_FAILURE(status)) { log_err_status(status, "FAIL: error in creating the dateformat using u_openPattern(): %s\n", myErrorName(status)); return; } start = 1800; udat_set2DigitYearStart(def, start, &status); if(U_FAILURE(status)) log_err("ERROR: in setTwoDigitStartDate: %s\n", myErrorName(status)); if( (udat_get2DigitYearStart(def, &status) != start)) log_err("ERROR: get2DigitYearStart broken\n"); for(i = 0; i < 4; ++i) { u_uastrcpy(s, strings[i]); exp = d[i]; got = udat_parse(def, s, u_strlen(s), 0, &status); gotdate=myFormatit(def, got); expdate=myFormatit(def, exp); if (gotdate == NULL || expdate == NULL) { log_err("myFormatit failed!\n"); } else if(u_strcmp(gotdate, expdate) !=0){ log_err("set2DigitYearStart broken for %s \n got: %s, expected: %s\n", austrdup(s), austrdup(gotdate), austrdup(expdate) ); } } udat_close(def); ucal_close(cal); }
U_CDECL_END U_CDECL_BEGIN static void U_CALLCONV DataDrivenPrintfPrecision(void) { #if !UCONFIG_NO_FORMATTING && !UCONFIG_NO_FILE_IO UErrorCode errorCode; TestDataModule *dataModule; TestData *testData; const DataMap *testCase; DataDrivenLogger logger; UChar uBuffer[512]; char cBuffer[512]; char cFormat[sizeof(cBuffer)]; char cExpected[sizeof(cBuffer)]; UnicodeString tempStr; UChar format[512]; UChar expectedResult[512]; UChar argument[512]; int32_t precision; int32_t i; int8_t i8; int16_t i16; int32_t i32; int64_t i64; double dbl; int32_t uBufferLenReturned; errorCode=U_ZERO_ERROR; dataModule=TestDataModule::getTestDataModule("icuio", logger, errorCode); if(U_SUCCESS(errorCode)) { testData=dataModule->createTestData("printfPrecision", errorCode); if(U_SUCCESS(errorCode)) { for(i=0; testData->nextCase(testCase, errorCode); ++i) { if(U_FAILURE(errorCode)) { log_err("error retrieving icuio/printf test case %d - %s\n", i, u_errorName(errorCode)); errorCode=U_ZERO_ERROR; continue; } u_memset(uBuffer, 0x2A, sizeof(uBuffer)/sizeof(uBuffer[0])); uBuffer[sizeof(uBuffer)/sizeof(uBuffer[0])-1] = 0; tempStr=testCase->getString("format", errorCode); tempStr.extract(format, sizeof(format)/sizeof(format[0]), errorCode); tempStr=testCase->getString("result", errorCode); tempStr.extract(expectedResult, sizeof(expectedResult)/sizeof(expectedResult[0]), errorCode); tempStr=testCase->getString("argument", errorCode); tempStr.extract(argument, sizeof(argument)/sizeof(argument[0]), errorCode); precision=testCase->getInt28("precision", errorCode); u_austrncpy(cBuffer, format, sizeof(cBuffer)); if(U_FAILURE(errorCode)) { log_err("error retrieving icuio/printf test case %d - %s\n", i, u_errorName(errorCode)); errorCode=U_ZERO_ERROR; continue; } log_verbose("Test %d: format=\"%s\"\n", i, cBuffer); switch (testCase->getString("argumentType", errorCode)[0]) { case 0x64: // 'd' double dbl = atof(u_austrcpy(cBuffer, argument)); uBufferLenReturned = u_sprintf_u(uBuffer, format, precision, dbl); break; case 0x31: // '1' int8_t i8 = (int8_t)uto64(argument); uBufferLenReturned = u_sprintf_u(uBuffer, format, precision, i8); break; case 0x32: // '2' int16_t i16 = (int16_t)uto64(argument); uBufferLenReturned = u_sprintf_u(uBuffer, format, precision, i16); break; case 0x34: // '4' int32_t i32 = (int32_t)uto64(argument); uBufferLenReturned = u_sprintf_u(uBuffer, format, precision, i32); break; case 0x38: // '8' int64_t i64 = uto64(argument); uBufferLenReturned = u_sprintf_u(uBuffer, format, precision, i64); break; case 0x73: // 's' char * u_austrncpy(cBuffer, uBuffer, sizeof(cBuffer)); uBufferLenReturned = u_sprintf_u(uBuffer, format, precision, cBuffer); break; case 0x53: // 'S' UChar * uBufferLenReturned = u_sprintf_u(uBuffer, format, precision, argument); break; default: uBufferLenReturned = 0; log_err("Unknown type %c for test %d\n", testCase->getString("argumentType", errorCode)[0], i); } if (u_strcmp(uBuffer, expectedResult) != 0) { u_austrncpy(cBuffer, uBuffer, sizeof(cBuffer)); u_austrncpy(cFormat, format, sizeof(cFormat)); u_austrncpy(cExpected, expectedResult, sizeof(cExpected)); cBuffer[sizeof(cBuffer)-1] = 0; log_err("FAILURE test case %d \"%s\" - Got: \"%s\" Expected: \"%s\"\n", i, cFormat, cBuffer, cExpected); } if (uBufferLenReturned <= 0) { log_err("FAILURE test case %d - \"%s\" is an empty string.\n", i, cBuffer); } else if (uBuffer[uBufferLenReturned-1] == 0 || uBuffer[uBufferLenReturned] != 0 || uBuffer[uBufferLenReturned+1] != 0x2A || uBuffer[uBufferLenReturned+2] != 0x2A) { u_austrncpy(cBuffer, uBuffer, sizeof(cBuffer)); cBuffer[sizeof(cBuffer)-1] = 0; log_err("FAILURE test case %d - \"%s\" wrong amount of characters was written. Got %d.\n", i, cBuffer, uBufferLenReturned); } if(U_FAILURE(errorCode)) { log_err("error running icuio/printf test case %d - %s\n", i, u_errorName(errorCode)); errorCode=U_ZERO_ERROR; continue; } } delete testData; } delete dataModule; } else { log_data_err("Failed: could not load test icuio data\n"); } #endif }
/** * @bug 4029195 */ void Test4029195() { int32_t resultlength, resultlengthneeded; UChar *fmdt, *todayS, *rt; UChar *pat=NULL; UChar *temp; UDate today, d1; UDateFormat *df; int32_t parsepos; UErrorCode status = U_ZERO_ERROR; log_verbose("Testing date format and parse function in regression test\n"); today = ucal_getNow(); df = udat_open(UDAT_DEFAULT,UDAT_DEFAULT ,"en_US", NULL, 0, NULL, 0, &status); if(U_FAILURE(status)) { log_data_err("FAIL: error in creating the dateformat using default date and time style : %s (Are you missing data?)\n", myErrorName(status)); return; } resultlength=0; resultlengthneeded=udat_toPattern(df, TRUE, NULL, resultlength, &status); if(status==U_BUFFER_OVERFLOW_ERROR) { status=U_ZERO_ERROR; resultlength=resultlengthneeded + 1; pat=(UChar*)malloc(sizeof(UChar) * resultlength); udat_toPattern(df, TRUE, pat, resultlength, &status); } log_verbose("pattern: %s\n", austrdup(pat)); fmdt = myFormatit(df, today); if(fmdt) { log_verbose("today: %s\n", austrdup(fmdt)); } else { log_data_err("ERROR: couldn't format, exitting test"); return; } temp=(UChar*)malloc(sizeof(UChar) * 10); u_uastrcpy(temp, "M yyyy dd"); udat_applyPattern(df, TRUE, temp, u_strlen(temp)); todayS =myFormatit(df, today); log_verbose("After teh pattern is applied\n today: %s\n", austrdup(todayS) ); parsepos=0; d1=udat_parse(df, todayS, u_strlen(todayS), &parsepos, &status); if(U_FAILURE(status)) { log_err("FAIL: Error in parsing using udat_parse(.....): %s\n", myErrorName(status)); } rt =myFormatit(df, d1); log_verbose("today: %s\n", austrdup(rt) ); log_verbose("round trip: %s\n", austrdup(rt) ); if(u_strcmp(rt, todayS)!=0) { log_err("Fail: Want %s Got %s\n", austrdup(todayS), austrdup(rt) ); } else log_verbose("Pass: parse and format working fine\n"); udat_close(df); free(temp); if(pat != NULL) { free(pat); } }
static void toolutil_findDirname(void) { int i; struct { const char *inBuf; int32_t outBufLen; UErrorCode expectStatus; const char *expectResult; } testCases[] = { { U_FILE_SEP_STRING "usr" U_FILE_SEP_STRING "bin" U_FILE_SEP_STRING "pkgdata", 200, U_ZERO_ERROR, U_FILE_SEP_STRING "usr" U_FILE_SEP_STRING "bin", }, { U_FILE_SEP_STRING "usr" U_FILE_SEP_STRING "bin" U_FILE_SEP_STRING "pkgdata", 2, U_BUFFER_OVERFLOW_ERROR, NULL }, { U_FILE_ALT_SEP_STRING "usr" U_FILE_ALT_SEP_STRING "bin" U_FILE_ALT_SEP_STRING "pkgdata", 200, U_ZERO_ERROR, U_FILE_ALT_SEP_STRING "usr" U_FILE_ALT_SEP_STRING "bin" }, { U_FILE_ALT_SEP_STRING "usr" U_FILE_ALT_SEP_STRING "bin" U_FILE_ALT_SEP_STRING "pkgdata", 2, U_BUFFER_OVERFLOW_ERROR, NULL }, { U_FILE_ALT_SEP_STRING "usr" U_FILE_ALT_SEP_STRING "bin" U_FILE_SEP_STRING "pkgdata", 200, U_ZERO_ERROR, U_FILE_ALT_SEP_STRING "usr" U_FILE_ALT_SEP_STRING "bin" }, { U_FILE_ALT_SEP_STRING "usr" U_FILE_SEP_STRING "bin" U_FILE_ALT_SEP_STRING "pkgdata", 200, U_ZERO_ERROR, U_FILE_ALT_SEP_STRING "usr" U_FILE_SEP_STRING "bin" }, { U_FILE_ALT_SEP_STRING "usr" U_FILE_ALT_SEP_STRING "bin" U_FILE_ALT_SEP_STRING "pkgdata", 2, U_BUFFER_OVERFLOW_ERROR, NULL }, { U_FILE_ALT_SEP_STRING "vmlinuz", 200, U_ZERO_ERROR, U_FILE_ALT_SEP_STRING }, { U_FILE_SEP_STRING "vmlinux", 200, U_ZERO_ERROR, U_FILE_SEP_STRING }, { "pkgdata", 0, U_BUFFER_OVERFLOW_ERROR, NULL }, { "pkgdata", 2, U_ZERO_ERROR, "" } }; int32_t count=(sizeof(testCases)/sizeof(testCases[0])); log_verbose("Testing findDirname()\n"); for(i=0;i<count;i++) { const char *result; const char *input = STRNULL(testCases[i].inBuf); const char *expect = STRNULL(testCases[i].expectResult); UErrorCode status = U_ZERO_ERROR; uprv_memset(toolutil_testBuf, 0x55, TOOLUTIL_TESTBUF_SIZE); log_verbose("Test case [%d/%d]: %s\n", i, count-1, input); result = STRNULL(findDirname(testCases[i].inBuf, toolutil_testBuf, testCases[i].outBufLen, &status)); log_verbose(" -> %s, \n", u_errorName(status)); if(status != testCases[i].expectStatus) { log_verbose("FAIL: Test case [%d/%d]: %s got error code %s but expected %s\n", i, count-1, input, u_errorName(status), u_errorName(testCases[i].expectStatus)); } if(result==expect||!strcmp(result,expect)) { log_verbose(" = -> %s \n", result); } else { log_err("FAIL: Test case [%d/%d]: %s -> %s but expected %s\n", i, count-1, input, result, expect); } } }