void CollationServiceTest::TestSeparateTree() { UErrorCode ec = U_ZERO_ERROR; StringEnumeration *iter = Collator::getKeywords(ec); if (!assertTrue("getKeywords != NULL", iter!=NULL)) return; if (!assertSuccess("getKeywords", ec)) return; checkStringEnumeration("getKeywords", *iter, KW, KW_COUNT); delete iter; iter = Collator::getKeywordValues(KW[0], ec); if (!assertTrue("getKeywordValues != NULL", iter!=NULL, FALSE, TRUE)) return; if (!assertSuccess("getKeywordValues", ec)) return; checkStringEnumeration("getKeywordValues", *iter, KWVAL, KWVAL_COUNT); delete iter; UBool isAvailable; Locale equiv = Collator::getFunctionalEquivalent("collation", Locale::createFromName("de"), isAvailable, ec); assertSuccess("getFunctionalEquivalent", ec); assertEquals("getFunctionalEquivalent(de)", "de", equiv.getName()); assertTrue("getFunctionalEquivalent(de).isAvailable==TRUE", isAvailable == TRUE); equiv = Collator::getFunctionalEquivalent("collation", Locale::createFromName("de_DE"), isAvailable, ec); assertSuccess("getFunctionalEquivalent", ec); assertEquals("getFunctionalEquivalent(de_DE)", "de", equiv.getName()); assertTrue("getFunctionalEquivalent(de_DE).isAvailable==TRUE", isAvailable == TRUE); }
void SimplePatternFormatterTest::TestOnePlaceholder() { UErrorCode status = U_ZERO_ERROR; SimplePatternFormatter fmt; fmt.compile("{0} meter", status); assertEquals("PlaceholderCount", 1, fmt.getPlaceholderCount()); UnicodeString appendTo; assertEquals( "format", "1 meter", fmt.format("1", appendTo, status)); assertSuccess("Status", status); // assignment SimplePatternFormatter s; s = fmt; appendTo.remove(); assertEquals( "Assignment", "1 meter", s.format("1", appendTo, status)); // Copy constructor SimplePatternFormatter r(fmt); appendTo.remove(); assertEquals( "Copy constructor", "1 meter", r.format("1", appendTo, status)); assertSuccess("Status", status); }
void SimplePatternFormatterTest::TestOptimization() { UErrorCode status = U_ZERO_ERROR; SimplePatternFormatter fmt; fmt.compile("{2}, {0}, {1} and {3}", status); assertSuccess("Status", status); assertTrue("startsWithPlaceholder", fmt.startsWithPlaceholder(2)); assertFalse("startsWithPlaceholder", fmt.startsWithPlaceholder(0)); UnicodeString values[] = { "freddy", "frog", "leg", "by"}; UnicodeString *params[] = { &values[0], &values[1], &values[2], &values[3]}; int32_t offsets[4]; int32_t expectedOffsets[4] = {5, 13, 0, 22}; // The pattern starts with {2}, so format should append the result of // the rest of the pattern to values[2], the value for {2}. assertEquals( "format", "leg, freddy, frog and by", fmt.format( params, UPRV_LENGTHOF(params), values[2], offsets, UPRV_LENGTHOF(offsets), status)); assertSuccess("Status", status); for (int32_t i = 0; i < UPRV_LENGTHOF(expectedOffsets); ++i) { if (expectedOffsets[i] != offsets[i]) { errln("Expected %d, got %d", expectedOffsets[i], offsets[i]); } } }
/** * Iterate through the given iterator, checking to see that all the strings * in the expected array are present. * @param expected array of strings we expect to see, or NULL * @param expectedCount number of elements of expected, or 0 */ int32_t CollationServiceTest::checkStringEnumeration(const char* msg, StringEnumeration& iter, const char** expected, int32_t expectedCount) { UErrorCode ec = U_ZERO_ERROR; U_ASSERT(expectedCount >= 0 && expectedCount < 31); // [sic] 31 not 32 int32_t i = 0, idxAfterReset = 0, n = iter.count(ec); assertSuccess("count", ec); UnicodeString buf, buffAfterReset; int32_t seenMask = 0; for (;; ++i) { const UnicodeString* s = iter.snext(ec); if (!assertSuccess("snext", ec) || s == NULL) break; if (i != 0) buf.append(UNICODE_STRING_SIMPLE(", ")); buf.append(*s); // check expected list for (int32_t j=0, bit=1; j<expectedCount; ++j, bit<<=1) { if ((seenMask&bit)==0) { UnicodeString exp(expected[j], (char*)NULL); if (*s == exp) { seenMask |= bit; logln((UnicodeString)"Ok: \"" + exp + "\" seen"); } } } } // can't get pesky operator+(const US&, foo) to cooperate; use toString #if !UCONFIG_NO_FORMATTING logln(UnicodeString() + msg + " = [" + buf + "] (" + toString(i) + ")"); #else logln(UnicodeString() + msg + " = [" + buf + "] (??? NO_FORMATTING)"); #endif assertTrue("count verified", i==n); iter.reset(ec); for (;; ++idxAfterReset) { const UChar *s = iter.unext(NULL, ec); if (!assertSuccess("unext", ec) || s == NULL) break; if (idxAfterReset != 0) buffAfterReset.append(UNICODE_STRING_SIMPLE(", ")); buffAfterReset.append(s); } assertTrue("idxAfterReset verified", idxAfterReset==n); assertTrue("buffAfterReset verified", buffAfterReset==buf); // did we see all expected strings? if (((1<<expectedCount)-1) != seenMask) { for (int32_t j=0, bit=1; j<expectedCount; ++j, bit<<=1) { if ((seenMask&bit)==0) { errln((UnicodeString)"FAIL: \"" + expected[j] + "\" not seen"); } } } return n; }
// Constructors }}} // Comments {{{ string Object::getComment() const { // {{{ size_t comment_size = assertSuccess( "getting object comment length", H5Oget_comment(getId(),NULL,0) ); if(comment_size == 0) return string(); scoped_array<char> buffer(new char[comment_size+1]); assertSuccess( "getting object comment", H5Oget_comment(getId(),buffer.get(),comment_size+1) ); return string(buffer.get()); } // }}}
// Test bug9042 void TimeUnitTest::testGreekWithSanitization() { UErrorCode status = U_ZERO_ERROR; Locale elLoc("el"); NumberFormat* numberFmt = NumberFormat::createInstance(Locale("el"), status); if (!assertSuccess("NumberFormat::createInstance for el locale", status, TRUE)) return; numberFmt->setMaximumFractionDigits(1); TimeUnitFormat* timeUnitFormat = new TimeUnitFormat(elLoc, status); if (!assertSuccess("TimeUnitFormat::TimeUnitFormat for el locale", status)) return; timeUnitFormat->setNumberFormat(*numberFmt, status); delete numberFmt; delete timeUnitFormat; }
void MultithreadTest::TestThreadedIntl() { UnicodeString theErr; UErrorCode threadSafeErr = U_ZERO_ERROR; ThreadSafeFormatSharedData sharedData(threadSafeErr); assertSuccess("initializing ThreadSafeFormat", threadSafeErr, TRUE); // // Create and start the test threads // logln("Spawning: %d threads * %d iterations each.", kFormatThreadThreads, kFormatThreadIterations); FormatThreadTest tests[kFormatThreadThreads]; int32_t j; for(j = 0; j < UPRV_LENGTHOF(tests); j++) { tests[j].fNum = j; int32_t threadStatus = tests[j].start(); if (threadStatus != 0) { errln("%s:%d System Error %d starting thread number %d.", __FILE__, __LINE__, threadStatus, j); return; } } for (j=0; j<UPRV_LENGTHOF(tests); j++) { tests[j].join(); logln("Thread # %d is complete..", j); } }
void PatternStringTest::testToPatternSimple() { const char16_t *cases[][2] = {{u"#", u"0"}, {u"0", u"0"}, {u"#0", u"0"}, {u"###", u"0"}, {u"0.##", u"0.##"}, {u"0.00", u"0.00"}, {u"0.00#", u"0.00#"}, {u"#E0", u"#E0"}, {u"0E0", u"0E0"}, {u"#00E00", u"#00E00"}, {u"#,##0", u"#,##0"}, {u"#;#", u"0;0"}, // ignore a negative prefix pattern of '-' since that is the default: {u"#;-#", u"0"}, {u"**##0", u"**##0"}, {u"*'x'##0", u"*x##0"}, {u"a''b0", u"a''b0"}, {u"*''##0", u"*''##0"}, {u"*ЁЯУ║##0", u"*'ЁЯУ║'##0"}, {u"*'роиро┐'##0", u"*'роиро┐'##0"},}; UErrorCode status = U_ZERO_ERROR; for (const char16_t **cas : cases) { UnicodeString input(cas[0]); UnicodeString output(cas[1]); DecimalFormatProperties properties = PatternParser::parseToProperties( input, PatternParser::IGNORE_ROUNDING_NEVER, status); assertSuccess(input, status); UnicodeString actual = PatternStringUtils::propertiesToPatternString(properties, status); assertEquals(input, output, actual); } }
void Dataset::createAndInitialize( Location const& location , Datatype const& datatype , Dataspace const& dataspace , optional<void const*> const& optional_data , optional<DatasetCreationProperties const&> const& optional_creation_properties , optional<DatasetAccessProperties const&> const& optional_access_properties , optional<LinkCreationProperties const&> const& optional_link_creation_properties ) { // {{{ identity = make_shared<Identity>( assertSuccess( "creating dataset", H5Dcreate2( location.getParentId(), location.getNameAsCStr(), datatype.getDatatypeId(), dataspace.getId(), getOptionalPropertiesId(optional_link_creation_properties), getOptionalPropertiesId(optional_creation_properties), getOptionalPropertiesId(optional_access_properties) ) ), H5Dclose ); if(optional_data) write(*optional_data,datatype); } // }}}
void DateFormatRoundTripTest::TestCentury() { UErrorCode status = U_ZERO_ERROR; Locale locale("es_PA"); UnicodeString pattern = "MM/dd/yy hh:mm:ss a z"; SimpleDateFormat fmt(pattern, locale, status); if(!assertSuccess("trying to construct", status))return; UDate date[] = {-55018555891590.05, 0, 0}; UnicodeString result[2]; fmt.format(date[0], result[0]); date[1] = fmt.parse(result[0], status); fmt.format(date[1], result[1]); date[2] = fmt.parse(result[1], status); /* This test case worked OK by accident before. date[1] != date[0], * because we use -80/+20 year window for 2-digit year parsing. * (date[0] is in year 1926, date[1] is in year 2026.) result[1] set * by the first format call returns "07/13/26 07:48:28 p.m. PST", * which is correct, because DST was not used in year 1926 in zone * America/Los_Angeles. When this is parsed, date[1] becomes a time * in 2026, which is "07/13/26 08:48:28 p.m. PDT". There was a zone * offset calculation bug that observed DST in 1926, which was resolved. * Before the bug was resolved, result[0] == result[1] was true, * but after the bug fix, the expected result is actually * result[0] != result[1]. -Yoshito */ /* TODO: We need to review this code and clarify what we really * want to test here. */ //if (date[1] != date[2] || result[0] != result[1]) { if (date[1] != date[2]) { errln("Round trip failure: \"%S\" (%f), \"%S\" (%f)", result[0].getBuffer(), date[1], result[1].getBuffer(), date[2]); } }
void DateFormatRoundTripTest::TestDateFormatRoundTrip() { UErrorCode status = U_ZERO_ERROR; getFieldCal = Calendar::createInstance(status); failure(status, "Calendar::createInstance"); if(!assertSuccess("trying to construct", status))return; int32_t locCount = 0; const Locale *avail = DateFormat::getAvailableLocales(locCount); logln("DateFormat available locales: %d", locCount); if(quick) { SPARSENESS = 18; logln("Quick mode: only testing SPARSENESS = 18"); } TimeZone *tz = TimeZone::createDefault(); UnicodeString temp; logln("Default TimeZone: " + tz->getID(temp)); delete tz; #ifdef TEST_ONE_LOC // define this to just test ONE locale. Locale loc(TEST_ONE_LOC); test(loc); #if INFINITE for(;;) { test(loc); } #endif #else # if INFINITE // Special infinite loop test mode for finding hard to reproduce errors Locale loc = Locale::getDefault(); logln("ENTERING INFINITE TEST LOOP FOR Locale: " + loc.getDisplayName(temp)); for(;;) test(loc); # else test(Locale::getDefault()); #if 1 // installed locales for (int i=0; i < locCount; ++i) { test(avail[i]); } #endif #if 1 // special locales int32_t jCount = CalendarTest::testLocaleCount(); for (int32_t j=0; j < jCount; ++j) { test(Locale(CalendarTest::testLocaleID(j))); } #endif # endif #endif delete getFieldCal; }
SpaceAllocationStatus Dataset::getSpaceAllocationStatus() const { // {{{ H5D_space_status_t status; assertSuccess( "getting dataset space allocation status", H5Dget_space_status(getId(),&status) ); return static_cast<SpaceAllocationStatus>(status); } // }}}
// this is called before main void __appInit() { assertSuccess(svcCreateEvent(&terminationRequestedEvent, RESET_STICKY)); assertSuccess(svcCreateEvent(&sessionManager.sendAllBuffersToArm9Event, RESET_ONESHOT)); assertSuccess(svcCreateSemaphore(&sessionManager.replySemaphore, 0, 9)); assertSuccess(svcCreateEvent(&sessionManager.PXISRV11CommandReceivedEvent, RESET_ONESHOT)); assertSuccess(svcCreateEvent(&sessionManager.PXISRV11ReplySentEvent, RESET_ONESHOT)); initPXI(); for(Result res = 0xD88007FA; res == (Result)0xD88007FA; svcSleepThread(500 * 1000LL)) { res = srvInit(); if(R_FAILED(res) && res != (Result)0xD88007FA) svcBreak(USERBREAK_PANIC); } }
// Compound }}} // Operations }}} // MutableDatatype }}} // TransientDatatype {{{ // Constructors {{{ TransientDatatype::TransientDatatype(CopyOf<Datatype const> other) // {{{ : Identified( assertSuccess( "copying datatype", H5Tcopy(other->getDatatypeId()) ), H5Tclose ) {} // }}}
TransientDatatype::TransientDatatype(H5T_class_t class_id, size_t size) // {{{ : Identified( assertSuccess( "creating datatype", H5Tcreate(class_id,size) ), H5Tclose ) {} // }}}
NormalizerConformanceTest::NormalizerConformanceTest() : normalizer(UnicodeString(), UNORM_NFC) { UErrorCode errorCode = U_ZERO_ERROR; nfc = Normalizer2::getNFCInstance(errorCode); nfd = Normalizer2::getNFDInstance(errorCode); nfkc = Normalizer2::getNFKCInstance(errorCode); nfkd = Normalizer2::getNFKDInstance(errorCode); assertSuccess("", errorCode, true, __FILE__, __LINE__); }
void TimeUnitTest::TestBritishShortHourFallback() { // See ticket #11986 "incomplete fallback in MeasureFormat". UErrorCode status = U_ZERO_ERROR; Formattable oneHour(new TimeUnitAmount(1, TimeUnit::UTIMEUNIT_HOUR, status)); Locale en_GB("en_GB"); TimeUnitFormat formatter(en_GB, UTMUTFMT_ABBREVIATED_STYLE, status); UnicodeString result; formatter.format(oneHour, result, status); assertSuccess("TestBritishShortHourFallback()", status); assertEquals("TestBritishShortHourFallback()", UNICODE_STRING_SIMPLE("1 hr"), result, TRUE); }
void PatternStringTest::testBug13117() { UErrorCode status = U_ZERO_ERROR; DecimalFormatProperties expected = PatternParser::parseToProperties( u"0", PatternParser::IGNORE_ROUNDING_NEVER, status); DecimalFormatProperties actual = PatternParser::parseToProperties( u"0;", PatternParser::IGNORE_ROUNDING_NEVER, status); assertSuccess("Spot 1", status); assertTrue("Should not consume negative subpattern", expected == actual); }
static UBool _aux1ExtremeDates(UDateFormat* fmt, UDate date, UChar* buf, int32_t buflen, char* cbuf, UErrorCode* ec) { int32_t len = udat_format(fmt, date, buf, buflen, 0, ec); if (!assertSuccess("udat_format", ec)) return FALSE; u_austrncpy(cbuf, buf, buflen); if (len < 4) { log_err("FAIL: udat_format(%g) => \"%s\"\n", date, cbuf); } else { log_verbose("udat_format(%g) => \"%s\"\n", date, cbuf); } return TRUE; }
// Fields }}} // Informational {{{ bool Location::exists(optional<LinkAccessProperties const&> const& optional_link_access_properties) const { string const& name = *(this->name); if(name == "." || name == "/") return true; return assertSuccess( "ascertaining location existence", H5Lexists( getParentId(), name.c_str(), getOptionalPropertiesId(optional_link_access_properties) ) ) == 1; }
ComplexDatatype() : PermanentDatatype( assertSuccess( "creating complex datatype", H5Tcreate(H5T_COMPOUND,sizeof(std::complex<T>)) ) ) { std::complex<T> c; Datatype const& member_datatype = datatypeOf<T>::get(); insert("r",0u,member_datatype); insert("i",sizeof(T),member_datatype); lock(); }
Group::Group( Location const& location ) : Object( location.getFile(), assertSuccess( "opening group", H5Gopen2( location.getParentId(), location.getNameAsCStr(), H5P_DEFAULT ) ), H5Gclose ) {}
void RelativeDateTimeFormatterTest::TestEnglishNoQuantityCaps() { UErrorCode status = U_ZERO_ERROR; RelativeDateTimeFormatter fmt( "en", NULL, UDAT_STYLE_LONG, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, status); if (assertSuccess("RelativeDateTimeFormatter", status, TRUE) == FALSE) { return; } RunTest( fmt, kEnglishNoQuantityCaps, UPRV_LENGTHOF(kEnglishNoQuantityCaps), "en caps no quantity"); }
Object::Object( Location const& location , optional<LinkAccessProperties> const& optional_properties ) // {{{ : Contained( location.getFile(), assertSuccess( "opening object", H5Oopen( location.getParentId(), location.getNameAsCStr(), getOptionalPropertiesId(optional_properties) ) ), H5Oclose ) {} // }}}
// class Dataset {{{ // Constructors {{{ Dataset::Dataset( Location const& location , optional<DatasetAccessProperties const&> const& optional_access_properties ) // {{{ : Object( location.getFile(), assertSuccess( "opening dataset", H5Dopen2( location.getParentId(), location.getNameAsCStr(), getOptionalPropertiesId(optional_access_properties) ) ), H5Dclose ) {} // }}}
void SimplePatternFormatterTest::TestNoPlaceholders() { UErrorCode status = U_ZERO_ERROR; SimplePatternFormatter fmt("This doesn''t have templates '{0}"); assertEquals("PlaceholderCount", 0, fmt.getPlaceholderCount()); UnicodeString appendTo; assertEquals( "format", "This doesn't have templates {0}", fmt.format("unused", appendTo, status)); fmt.compile("This has {} bad {012d placeholders", status); assertEquals("PlaceholderCount", 0, fmt.getPlaceholderCount()); appendTo.remove(); assertEquals( "format", "This has {} bad {012d placeholders", fmt.format("unused", appendTo, status)); assertSuccess("Status", status); }
static inline void initPXI(void) { Result res; Handle handles[2] = {0}; PXIReset(); if(PXISyncInterrupt != 0) svcBreak(USERBREAK_PANIC); //0xE0A0183B assertSuccess(svcCreateEvent(&PXISyncInterrupt, RESET_ONESHOT)); if(PXITransferMutex != 0) svcBreak(USERBREAK_PANIC); //0xE0A0183B assertSuccess(svcCreateMutex(&PXITransferMutex, false)); assertSuccess(svcCreateEvent(&handles[0], RESET_ONESHOT)); //receive FIFO not empty assertSuccess(svcCreateEvent(&handles[1], RESET_ONESHOT)); //send FIFO empty assertSuccess(bindPXIInterrupts(&PXISyncInterrupt, &handles[0], &handles[1])); s32 handleIndex; do { while(!PXIIsSendFIFOFull()) PXISendWord(0); res = assertSuccess(svcWaitSynchronization(handles[0], 0LL)); if(R_DESCRIPTION(res) == RD_TIMEOUT) assertSuccess(svcWaitSynchronizationN(&handleIndex, handles, 2, false, -1LL)); else handleIndex = 0; } while(handleIndex != 0); unbindPXIInterrupts(NULL, &handles[0], &handles[1]); PXISendByte(1); while(PXIReceiveByte() < 1); while (!PXIIsReceiveFIFOEmpty()) PXIReceiveWord(); PXISendByte(2); while(PXIReceiveByte() < 2); svcCloseHandle(handles[0]); svcCloseHandle(handles[1]); }
void Dataset::write( void const* data , Datatype const& datatype , optional<Dataspace const&> const& optional_memory_dataspace , optional<Dataspace const&> const& optional_dataset_dataspace , optional<DatasetTransferProperties const&> const& optional_transfer_properties ) const { assertSuccess( "writing data to the dataset", H5Dwrite( getId(), datatype.getDatatypeId(), getOptionalDataspaceId(optional_memory_dataspace), getOptionalDataspaceId(optional_dataset_dataspace), getOptionalPropertiesId(optional_transfer_properties), data ) ); }
// Constructors }}} // Data access {{{ void Dataset::read( void* data , Datatype const& datatype , optional<Dataspace const&> const& optional_memory_dataspace , optional<Dataspace const&> const& optional_dataset_dataspace , optional<DatasetTransferProperties const&> const& optional_transfer_properties ) const { assertSuccess( "reading data from the dataset", H5Dread( getId(), datatype.getDatatypeId(), getOptionalDataspaceId(optional_memory_dataspace), getOptionalDataspaceId(optional_dataset_dataspace), getOptionalPropertiesId(optional_transfer_properties), data ) ); }
void RelativeDateTimeFormatterTest::TestEnglishCaps() { UErrorCode status = U_ZERO_ERROR; RelativeDateTimeFormatter fmt( "en", NULL, UDAT_STYLE_LONG, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, status); if (U_FAILURE(status)) { dataerrln("Failed call to RelativeDateTimeFormatter(\"en\", NULL, UDAT_STYLE_LONG, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, status); : %s", u_errorName(status)); return; } RelativeDateTimeFormatter fmt3(status); // Test assignment and copy constructor with capitalization on. RelativeDateTimeFormatter fmt2(fmt); fmt3 = fmt2; assertSuccess("", status); RunTest(fmt3, kEnglishCaps, UPRV_LENGTHOF(kEnglishCaps), "en caps"); }