void TextStreamTestCase::TestLongLong() { static const wxLongLong llvalues[] = { 0, 1, -1, 0x12345678l, -0x12345678l, wxLL(0x123456789abcdef0), wxLL(-0x123456789abcdef0), }; DoTestRoundTrip(llvalues, WXSIZEOF(llvalues)); }
bool Sequence::AppendBlock(SeqBlock * b) { // Quick check to make sure that it doesn't overflow if (((double)mNumSamples) + ((double)b->f->GetLength()) > wxLL(9223372036854775807)) return false; SeqBlock *newBlock = new SeqBlock(); newBlock->start = mNumSamples; newBlock->f = mDirManager->CopyBlockFile(b->f); if (!newBlock->f) { /// \todo Error Could not paste! (Out of disk space?) return false; } //Don't need to Ref because it was done by CopyBlockFile, above... //mDirManager->Ref(newBlock->f); mBlock->Add(newBlock); mNumSamples += newBlock->f->GetLength(); // Don't do a consistency check here because this // function gets called in an inner loop return true; }
wxLongLong wxGetUTCTimeUSec() { #if defined(__WINDOWS__) FILETIME ft; ::GetSystemTimeAsFileTime(&ft); // FILETIME is in 100ns or 0.1us since 1601-01-01, transform to us since // 1970-01-01. wxLongLong t(ft.dwHighDateTime, ft.dwLowDateTime); t /= 10; t -= wxLL(11644473600000000); // Unix - Windows epochs difference in us. return t; #else // non-MSW #ifdef HAVE_GETTIMEOFDAY timeval tv; if ( wxGetTimeOfDay(&tv) != -1 ) { wxLongLong val(tv.tv_sec); val *= MICROSECONDS_PER_SECOND; val += tv.tv_usec; return val; } #endif // HAVE_GETTIMEOFDAY // Fall back to lesser precision function. return wxGetUTCTimeMillis()*MICROSECONDS_PER_MILLISECOND; #endif // MSW/!MSW }
void VarArgTestCase::LongLongPrintf() { const char * const llfmt = "%" wxLongLongFmtSpec "d"; CPPUNIT_ASSERT_EQUAL( "17", wxString::Format(llfmt, wxLL(17)) ); wxLongLong ll = 1234567890; CPPUNIT_ASSERT_EQUAL( "1234567890", wxString::Format(llfmt, ll) ); }
// Get local time as milliseconds since 00:00:00, Jan 1st 1970 wxLongLong wxGetUTCTimeMillis() { // If possible, use a function which avoids conversions from // broken-up time structures to milliseconds #if defined(__WINDOWS__) FILETIME ft; ::GetSystemTimeAsFileTime(&ft); // FILETIME is expressed in 100ns (or 0.1us) units since 1601-01-01, // transform them to ms since 1970-01-01. wxLongLong t(ft.dwHighDateTime, ft.dwLowDateTime); t /= 10000; t -= wxLL(11644473600000); // Unix - Windows epochs difference in ms. return t; #else // !__WINDOWS__ wxLongLong val = MILLISECONDS_PER_SECOND; #if defined(HAVE_GETTIMEOFDAY) struct timeval tp; if ( wxGetTimeOfDay(&tp) != -1 ) { val *= tp.tv_sec; return (val + (tp.tv_usec / MICROSECONDS_PER_MILLISECOND)); } else { wxLogError(_("wxGetTimeOfDay failed.")); return 0; } #elif defined(HAVE_FTIME) struct timeb tp; // ftime() is void and not int in some mingw32 headers, so don't // test the return code (well, it shouldn't fail anyhow...) (void)::ftime(&tp); val *= tp.time; return (val + tp.millitm); #else // no gettimeofday() nor ftime() // If your platform/compiler does not support ms resolution please // do NOT just shut off these warnings, drop me a line instead at // <*****@*****.**> #if defined(__VISUALC__) #pragma message("wxStopWatch will be up to second resolution!") #elif defined(__BORLANDC__) #pragma message "wxStopWatch will be up to second resolution!" #else #warning "wxStopWatch will be up to second resolution!" #endif // compiler val *= wxGetUTCTime(); return val; #endif // time functions #endif // __WINDOWS__/!__WINDOWS__ }
void NumFormatterTestCase::LongLongToString() { if ( !m_locale ) return; CPPUNIT_ASSERT_EQUAL( "1", wxNumberFormatter::ToString(wxLL( 1))); CPPUNIT_ASSERT_EQUAL( "12", wxNumberFormatter::ToString(wxLL( 12))); CPPUNIT_ASSERT_EQUAL( "123", wxNumberFormatter::ToString(wxLL( 123))); CPPUNIT_ASSERT_EQUAL( "1,234", wxNumberFormatter::ToString(wxLL( 1234))); CPPUNIT_ASSERT_EQUAL( "12,345", wxNumberFormatter::ToString(wxLL( 12345))); CPPUNIT_ASSERT_EQUAL( "123,456", wxNumberFormatter::ToString(wxLL( 123456))); CPPUNIT_ASSERT_EQUAL( "1,234,567", wxNumberFormatter::ToString(wxLL( 1234567))); CPPUNIT_ASSERT_EQUAL( "12,345,678", wxNumberFormatter::ToString(wxLL( 12345678))); CPPUNIT_ASSERT_EQUAL("123,456,789", wxNumberFormatter::ToString(wxLL( 123456789))); }
void VsnprintfTestCase::LongLong() { CMP3("123456789", "%lld", (wxLongLong_t)123456789); CMP3("-123456789", "%lld", (wxLongLong_t)-123456789); CMP3("123456789", "%llu", (wxULongLong_t)123456789); #ifdef __WXMSW__ CMP3("123456789", "%I64d", (wxLongLong_t)123456789); CMP3("123456789abcdef", "%I64x", wxLL(0x123456789abcdef)); #endif }
bool Sequence::AppendCoded(wxString fName, sampleCount start, sampleCount len, int channel, int decodeType) { // Quick check to make sure that it doesn't overflow if (((double)mNumSamples) + ((double)len) > wxLL(9223372036854775807)) return false; SeqBlock *newBlock = new SeqBlock(); newBlock->start = mNumSamples; newBlock->f = mDirManager->NewODDecodeBlockFile(fName, start, len, channel, decodeType); mBlock->Add(newBlock); mNumSamples += newBlock->f->GetLength(); return true; }
bool Sequence::AppendAlias(wxString fullPath, sampleCount start, sampleCount len, int channel,bool useOD) { // Quick check to make sure that it doesn't overflow if (((double)mNumSamples) + ((double)len) > wxLL(9223372036854775807)) return false; SeqBlock *newBlock = new SeqBlock(); newBlock->start = mNumSamples; newBlock->f = useOD? mDirManager->NewODAliasBlockFile(fullPath, start, len, channel): mDirManager->NewAliasBlockFile(fullPath, start, len, channel); mBlock->Add(newBlock); mNumSamples += newBlock->f->GetLength(); return true; }
bool Sequence::InsertSilence(sampleCount s0, sampleCount len) { // Quick check to make sure that it doesn't overflow if (((double)mNumSamples) + ((double)len) > wxLL(9223372036854775807)) return false; // Create a new track containing as much silence as we // need to insert, and then call Paste to do the insertion. // We make use of a SilentBlockFile, which takes up no // space on disk. Sequence *sTrack = new Sequence(mDirManager, mSampleFormat); sampleCount idealSamples = GetIdealBlockSize(); sampleCount pos = 0; while (len) { sampleCount l = (len > idealSamples ? idealSamples : len); SeqBlock *w = new SeqBlock(); w->start = pos; w->f = new SilentBlockFile(l); sTrack->mBlock->Add(w); pos += l; len -= l; } sTrack->mNumSamples = pos; bool bResult = Paste(s0, sTrack); delete sTrack; return bResult && ConsistencyCheck(wxT("InsertSilence")); }
if (size) *size = -1; return dir; } if (size) *size = buf.st_size; return file; } #endif #ifdef __WXMSW__ // This is the offset between FILETIME epoch and the Unix/wxDateTime Epoch. static wxInt64 EPOCH_OFFSET_IN_MSEC = wxLL(11644473600000); bool CLocalFileSystem::ConvertFileTimeToCDateTime(CDateTime& time, const FILETIME &ft) { if (!ft.dwHighDateTime && !ft.dwLowDateTime) return false; // See http://trac.wxwidgets.org/changeset/74423 and http://trac.wxwidgets.org/ticket/13098 // Directly converting to time_t wxLongLong t(ft.dwHighDateTime, ft.dwLowDateTime); t /= 10000; // Convert hundreds of nanoseconds to milliseconds. t -= EPOCH_OFFSET_IN_MSEC; if (t < 0) { return false; }
bool Sequence::Paste(sampleCount s, const Sequence *src) { if (s < 0) s = 0; if (s >= mNumSamples) s = mNumSamples; // Quick check to make sure that it doesn't overflow if (((double)mNumSamples) + ((double)src->mNumSamples) > wxLL(9223372036854775807)) return false; BlockArray *srcBlock = src->mBlock; sampleCount addedLen = src->mNumSamples; unsigned int srcNumBlocks = srcBlock->Count(); int sampleSize = SAMPLE_SIZE(mSampleFormat); if (addedLen == 0 || srcNumBlocks == 0) return true; unsigned int b = FindBlock(s); unsigned int numBlocks = mBlock->Count(); if (numBlocks == 0 || (s == mNumSamples && mBlock->Item(numBlocks-1)->f->GetLength() >= mMinSamples)) { // Special case: this track is currently empty, or it's safe to append // onto the end because the current last block is longer than the // minimum size for (unsigned int i = 0; i < srcNumBlocks; i++) AppendBlock(srcBlock->Item(i)); return ConsistencyCheck(wxT("Paste branch one")); } if (b >= 0 && b < numBlocks && mBlock->Item(b)->f->GetLength() + addedLen < mMaxSamples) { // Special case: we can fit all of the new samples inside of // one block! samplePtr buffer = NewSamples(mMaxSamples, mSampleFormat); int splitPoint = s - mBlock->Item(b)->start; Read(buffer, mSampleFormat, mBlock->Item(b), 0, splitPoint); src->Get(buffer + splitPoint*sampleSize, mSampleFormat, 0, addedLen); Read(buffer + (splitPoint + addedLen)*sampleSize, mSampleFormat, mBlock->Item(b), splitPoint, mBlock->Item(b)->f->GetLength() - splitPoint); SeqBlock *largerBlock = new SeqBlock(); largerBlock->start = mBlock->Item(b)->start; int largerBlockLen = mBlock->Item(b)->f->GetLength() + addedLen; if (largerBlockLen > mMaxSamples) largerBlockLen = mMaxSamples; // Prevent overruns, per NGS report for UmixIt. largerBlock->f = mDirManager->NewSimpleBlockFile(buffer, largerBlockLen, mSampleFormat); mDirManager->Deref(mBlock->Item(b)->f); delete mBlock->Item(b); mBlock->Item(b) = largerBlock; for (unsigned int i = b + 1; i < numBlocks; i++) mBlock->Item(i)->start += addedLen; mNumSamples += addedLen; DeleteSamples(buffer); return ConsistencyCheck(wxT("Paste branch two")); } // Case two: if we are inserting four or fewer blocks, // it's simplest to just lump all the data together // into one big block along with the split block, // then resplit it all unsigned int i; BlockArray *newBlock = new BlockArray(); newBlock->Alloc(numBlocks + srcNumBlocks + 2); int newNumBlocks = 0; for (i = 0; i < b; i++) { newBlock->Add(mBlock->Item(i)); newNumBlocks++; } SeqBlock *splitBlock = mBlock->Item(b); sampleCount splitLen = mBlock->Item(b)->f->GetLength(); int splitPoint = s - splitBlock->start; if (srcNumBlocks <= 4) { sampleCount sum = splitLen + addedLen; samplePtr sumBuffer = NewSamples(sum, mSampleFormat); Read(sumBuffer, mSampleFormat, splitBlock, 0, splitPoint); src->Get(sumBuffer + splitPoint * sampleSize, mSampleFormat, 0, addedLen); Read(sumBuffer + (splitPoint + addedLen) * sampleSize, mSampleFormat, splitBlock, splitPoint, splitBlock->f->GetLength() - splitPoint); BlockArray *split = Blockify(sumBuffer, sum); for (i = 0; i < split->Count(); i++) { split->Item(i)->start += splitBlock->start; newBlock->Add(split->Item(i)); newNumBlocks++; } delete split; DeleteSamples(sumBuffer); } else { // The final case is that we're inserting at least five blocks. // We divide these into three groups: the first two get merged // with the first half of the split block, the middle ones get // copied in as is, and the last two get merged with the last // half of the split block. sampleCount srcFirstTwoLen = srcBlock->Item(0)->f->GetLength() + srcBlock->Item(1)->f->GetLength(); sampleCount leftLen = splitPoint + srcFirstTwoLen; samplePtr leftBuffer = NewSamples(leftLen, mSampleFormat); Read(leftBuffer, mSampleFormat, splitBlock, 0, splitPoint); src->Get(leftBuffer + splitPoint*sampleSize, mSampleFormat, 0, srcFirstTwoLen); BlockArray *split = Blockify(leftBuffer, leftLen); for (i = 0; i < split->Count(); i++) { split->Item(i)->start += splitBlock->start; newBlock->Add(split->Item(i)); newNumBlocks++; } delete split; DeleteSamples(leftBuffer); for (i = 2; i < srcNumBlocks - 2; i++) { SeqBlock *insertBlock = new SeqBlock(); insertBlock->start = srcBlock->Item(i)->start + s; insertBlock->f = mDirManager->CopyBlockFile(srcBlock->Item(i)->f); if (!insertBlock->f) { // TODO error: Could not paste! (Out of disk space?) return false; } newBlock->Add(insertBlock); newNumBlocks++; } sampleCount srcLastTwoLen = srcBlock->Item(srcNumBlocks - 2)->f->GetLength() + srcBlock->Item(srcNumBlocks - 1)->f->GetLength(); sampleCount rightSplit = splitBlock->f->GetLength() - splitPoint; sampleCount rightLen = rightSplit + srcLastTwoLen; samplePtr rightBuffer = NewSamples(rightLen, mSampleFormat); sampleCount lastStart = srcBlock->Item(srcNumBlocks - 2)->start; src->Get(rightBuffer, mSampleFormat, lastStart, srcLastTwoLen); Read(rightBuffer + srcLastTwoLen * sampleSize, mSampleFormat, splitBlock, splitPoint, rightSplit); sampleCount pos = s + lastStart; split = Blockify(rightBuffer, rightLen); for (i = 0; i < split->Count(); i++) { split->Item(i)->start += pos; newBlock->Add(split->Item(i)); newNumBlocks++; } delete split; DeleteSamples(rightBuffer); } mDirManager->Deref(splitBlock->f); delete splitBlock; // Copy remaining blocks to new block array and // swap the new block array in for the old for (i = b + 1; i < numBlocks; i++) { mBlock->Item(i)->start += addedLen; newBlock->Add(mBlock->Item(i)); newNumBlocks++; } delete mBlock; mBlock = newBlock; mNumSamples += addedLen; return ConsistencyCheck(wxT("Paste branch three")); }
bool Sequence::Append(samplePtr buffer, sampleFormat format, sampleCount len, XMLWriter* blockFileLog /*=NULL*/) { // Quick check to make sure that it doesn't overflow if (((double)mNumSamples) + ((double)len) > wxLL(9223372036854775807)) return false; samplePtr temp = NULL; if (format != mSampleFormat) { temp = NewSamples(mMaxSamples, mSampleFormat); wxASSERT(temp); } // If the last block is not full, we need to add samples to it int numBlocks = mBlock->Count(); if (numBlocks > 0 && mBlock->Item(numBlocks - 1)->f->GetLength() < mMinSamples) { SeqBlock *lastBlock = mBlock->Item(numBlocks - 1); sampleCount addLen; if (lastBlock->f->GetLength() + len < mMaxSamples) addLen = len; else addLen = GetIdealBlockSize() - lastBlock->f->GetLength(); SeqBlock *newLastBlock = new SeqBlock(); samplePtr buffer2 = NewSamples((lastBlock->f->GetLength() + addLen), mSampleFormat); Read(buffer2, mSampleFormat, lastBlock, 0, lastBlock->f->GetLength()); CopySamples(buffer, format, buffer2 + lastBlock->f->GetLength() * SAMPLE_SIZE(mSampleFormat), mSampleFormat, addLen); newLastBlock->start = lastBlock->start; int newLastBlockLen = lastBlock->f->GetLength() + addLen; newLastBlock->f = mDirManager->NewSimpleBlockFile(buffer2, newLastBlockLen, mSampleFormat, blockFileLog != NULL); if (blockFileLog) ((SimpleBlockFile*)newLastBlock->f)->SaveXML(*blockFileLog); DeleteSamples(buffer2); mDirManager->Deref(lastBlock->f); delete lastBlock; mBlock->Item(numBlocks - 1) = newLastBlock; len -= addLen; mNumSamples += addLen; buffer += addLen * SAMPLE_SIZE(format); } // Append the rest as new blocks while (len) { sampleCount idealSamples = GetIdealBlockSize(); sampleCount l = (len > idealSamples ? idealSamples : len); SeqBlock *w = new SeqBlock(); w->start = mNumSamples; if (format == mSampleFormat) { w->f = mDirManager->NewSimpleBlockFile(buffer, l, mSampleFormat, blockFileLog != NULL); } else { CopySamples(buffer, format, temp, mSampleFormat, l); w->f = mDirManager->NewSimpleBlockFile(temp, l, mSampleFormat, blockFileLog != NULL); } if (blockFileLog) ((SimpleBlockFile*)w->f)->SaveXML(*blockFileLog); mBlock->Add(w); buffer += l * SAMPLE_SIZE(format); mNumSamples += l; len -= l; } if (format != mSampleFormat) DeleteSamples(temp); // JKC: During generate we use Append again and again. // If generating a long sequence this test would give O(n^2) // performance - not good! #ifdef VERY_SLOW_CHECKING ConsistencyCheck(wxT("Append")); #endif return true; }
/* What could be improved here: -Option to prepend a numerical value to the destination filename to maintain the same order as the playlist -Option to create a directory in the destination directory based on playlist name SiW */ void MusikApp::CopyFiles(const MusikSongIdArray &songs) { //--------------------------------// //--- first choose a directory ---// //--------------------------------// wxFileName destdir; wxDirDialog dirdlg( g_MusikFrame, _("Please choose location to copy songs to:"), wxT(""), wxDD_NEW_DIR_BUTTON ); if ( dirdlg.ShowModal() == wxID_OK ) destdir.AssignDir(dirdlg.GetPath()); else return; wxLongLong llFree; wxGetDiskSpace(destdir.GetFullPath(),NULL,&llFree); wxLongLong llNeeded = songs.GetTotalFileSize(); if(llFree < llNeeded) { wxLongLong_t ToLessBytes = llNeeded.GetValue() - llFree.GetValue(); wxString sToLessBytes = wxString::Format(wxT("%")wxLongLongFmtSpec wxT("d"), ToLessBytes); // not enough free space wxString errmsg = wxString::Format(_("There is not enough free space in directory \"%s\". You need %s bytes more free. Continue nevertheless?"),(const wxChar *)destdir.GetFullPath(),(const wxChar *)sToLessBytes); if(wxMessageBox(errmsg, _("File copy warning"),wxYES|wxNO|wxCENTER|wxICON_EXCLAMATION ) == wxNO) { return; } } //-----------------------------------------------------// //--- now just loop through the files and copy them ---// //-----------------------------------------------------// wxProgressDialog dialog(_T("Copy files dialog"), _T("An informative message"), 100, // range g_MusikFrame, // parent wxPD_CAN_ABORT | wxPD_APP_MODAL | // wxPD_AUTO_HIDE | -- try this as well wxPD_ELAPSED_TIME | wxPD_ESTIMATED_TIME | wxPD_REMAINING_TIME); wxLongLong llRemaining = llNeeded; for ( size_t n = 0; n < songs.GetCount(); n++ ) { const wxFileName & sourcename = songs[n].Song()->MetaData.Filename; wxFileName destname( sourcename ); destname.SetPath(destdir.GetPath(0)); // GetPath(0) because the default is GetPath(int flags = wxPATH_GET_VOLUME, destname.SetVolume(destdir.GetVolume()); // i do it this complicated way, because wxFileName::SetPath() is buggy, as it does not handle the volume of path wxLongLong llPercent = ((llNeeded - llRemaining) * wxLL(100) /llNeeded ); if(!dialog.Update(llPercent.ToLong(),wxString::Format(_("copying %s"),(const wxChar *)sourcename.GetFullPath()))) { break; } if(!wxCopyFile( sourcename.GetFullPath(), destname.GetFullPath())) { wxString errmsg = wxString::Format(_("Failed to copy file %s. Continue?"),(const wxChar *)sourcename.GetFullPath()); if(wxMessageBox(errmsg, _("File copy error"),wxYES|wxNO|wxCENTER|wxICON_ERROR ) == wxNO) break; } llRemaining -= songs[n].Song()->MetaData.nFilesize; } dialog.Update(99,wxT("")); // this is needed to make the gauge fill the whole area. dialog.Update(100,wxT("")); }
void wxAnyTestCase::wxVariantConversions() { #if wxUSE_VARIANT // // Test various conversions to and from wxVariant // bool res; // Prepare wxVariants wxVariant vLong(123L); wxVariant vString("ABC"); wxVariant vDouble(TEST_FLOAT_CONST); wxVariant vBool((bool)true); wxVariant vChar('A'); #ifdef wxLongLong_t wxVariant vLongLong(wxLongLong(wxLL(0xAABBBBCCCC))); wxVariant vULongLong(wxULongLong(wxULL(123456))); #endif wxArrayString arrstr; arrstr.push_back("test string"); wxVariant vArrayString(arrstr); wxVariant vDateTime(m_testDateTime); wxVariant vVoidPtr(dummyVoidPointer); wxVariant vCustomType(new wxMyVariantData(MyClass(101))); wxVariant vList; vList.NullList(); vList.Append(15); vList.Append("abc"); // Convert to wxAnys, and then back to wxVariants wxVariant variant; wxAny any(vLong); CPPUNIT_ASSERT(any == 123L); res = any.GetAs(&variant); CPPUNIT_ASSERT(res); CPPUNIT_ASSERT(variant == 123L); // Make sure integer variant has correct type information CPPUNIT_ASSERT(variant.GetLong() == 123); CPPUNIT_ASSERT(variant.GetType() == "long"); // Unsigned long wxAny should convert to "ulonglong" wxVariant any = 1000UL; res = any.GetAs(&variant); CPPUNIT_ASSERT(res); CPPUNIT_ASSERT(variant.GetType() == "ulonglong"); CPPUNIT_ASSERT(variant.GetLong() == 1000); any = vString; CPPUNIT_ASSERT(any == "ABC"); res = any.GetAs(&variant); CPPUNIT_ASSERT(res); CPPUNIT_ASSERT(variant.GetString() == "ABC"); // Must be able to build string wxVariant from wxAny built from // string literal any = "ABC"; res = any.GetAs(&variant); CPPUNIT_ASSERT(res); CPPUNIT_ASSERT(variant.GetType() == "string"); CPPUNIT_ASSERT(variant.GetString() == "ABC"); any = L"ABC"; res = any.GetAs(&variant); CPPUNIT_ASSERT(res); CPPUNIT_ASSERT(variant.GetType() == "string"); #if wxUSE_UNICODE CPPUNIT_ASSERT(variant.GetString() == L"ABC"); #endif any = vDouble; double d = wxANY_AS(any, double); CPPUNIT_ASSERT_DOUBLES_EQUAL(d, TEST_FLOAT_CONST, FEQ_DELTA); res = any.GetAs(&variant); CPPUNIT_ASSERT(res); CPPUNIT_ASSERT_DOUBLES_EQUAL(variant.GetDouble(), TEST_FLOAT_CONST, FEQ_DELTA); any = vBool; CPPUNIT_ASSERT(wxANY_AS(any, bool) == true); res = any.GetAs(&variant); CPPUNIT_ASSERT(res); CPPUNIT_ASSERT(variant.GetBool() == true); any = wxAny(vChar); //CPPUNIT_ASSERT(wxANY_AS(any, wxUniChar) == 'A'); res = any.GetAs(&variant); CPPUNIT_ASSERT(res); CPPUNIT_ASSERT(variant.GetChar() == 'A'); #ifdef wxLongLong_t any = wxAny(vLongLong); CPPUNIT_ASSERT(any == wxLL(0xAABBBBCCCC)); res = any.GetAs(&variant); CPPUNIT_ASSERT(res); CPPUNIT_ASSERT(variant.GetType() == "longlong"); CPPUNIT_ASSERT(variant.GetLongLong() == wxLongLong(wxLL(0xAABBBBCCCC))); #if LONG_MAX == wxINT64_MAX // As a sanity check, test that wxVariant of type 'long' converts // seamlessly to 'longlong' (on some 64-bit systems) any = 0xAABBBBCCCCL; res = any.GetAs(&variant); CPPUNIT_ASSERT(variant.GetLongLong() == wxLongLong(wxLL(0xAABBBBCCCC))); #endif any = wxAny(vULongLong); CPPUNIT_ASSERT(any == wxLL(123456)); res = any.GetAs(&variant); CPPUNIT_ASSERT(res); CPPUNIT_ASSERT(variant.GetType() == "ulonglong"); CPPUNIT_ASSERT(variant.GetULongLong() == wxULongLong(wxULL(123456))); #endif // Cannot test equality for the rest, just test that they convert // back correctly. any = wxAny(vArrayString); res = any.GetAs(&variant); CPPUNIT_ASSERT(res); wxArrayString arrstr2 = variant.GetArrayString(); CPPUNIT_ASSERT(arrstr2 == arrstr); any = m_testDateTime; CPPUNIT_ASSERT(wxANY_AS(any, wxDateTime) == m_testDateTime); any = wxAny(vDateTime); CPPUNIT_ASSERT(wxANY_AS(any, wxDateTime) == m_testDateTime); res = any.GetAs(&variant); CPPUNIT_ASSERT(res); CPPUNIT_ASSERT(variant == m_testDateTime); any = wxAny(vVoidPtr); res = any.GetAs(&variant); CPPUNIT_ASSERT(res); CPPUNIT_ASSERT(variant.GetVoidPtr() == dummyVoidPointer); any = wxAny(vList); CPPUNIT_ASSERT(wxANY_CHECK_TYPE(any, wxAnyList)); wxAnyList anyList = wxANY_AS(any, wxAnyList); CPPUNIT_ASSERT(anyList.GetCount() == 2); CPPUNIT_ASSERT(wxANY_AS((*anyList[0]), int) == 15); CPPUNIT_ASSERT(wxANY_AS((*anyList[1]), wxString) == "abc"); res = any.GetAs(&variant); CPPUNIT_ASSERT(res); CPPUNIT_ASSERT(variant.GetType() == "list"); CPPUNIT_ASSERT(variant.GetCount() == 2); CPPUNIT_ASSERT(variant[0].GetLong() == 15); CPPUNIT_ASSERT(variant[1].GetString() == "abc"); any = wxAny(vCustomType); CPPUNIT_ASSERT(wxANY_CHECK_TYPE(any, wxVariantData*)); res = any.GetAs(&variant); CPPUNIT_ASSERT(res); CPPUNIT_ASSERT(variant.GetType() == "MyClass"); #endif // wxUSE_VARIANT }
{ { wxT("1"), 1, Number_Ok }, { wxT("0"), 0, Number_Ok }, { wxT("a"), 0, Number_Invalid }, { wxT("12345"), 12345, Number_Ok }, { wxT("--1"), 0, Number_Invalid }, { wxT("-1"), -1, Number_Signed | Number_Long }, // this is surprising but consistent with strtoul() behaviour { wxT("-1"), ULONG_MAX, Number_Unsigned | Number_Long }, // this must overflow, even with 64 bit long { wxT("922337203685477580711"), 0, Number_Invalid }, #ifdef wxLongLong_t { wxT("2147483648"), wxLL(2147483648), Number_LongLong }, { wxT("-2147483648"), wxLL(-2147483648), Number_LongLong | Number_Signed }, { wxT("9223372036854775808"), wxULL(9223372036854775808), Number_LongLong | Number_Unsigned }, #endif // wxLongLong_t // Base tests. { wxT("010"), 10, Number_Ok, 10 }, { wxT("010"), 8, Number_Ok, 0 }, { wxT("010"), 8, Number_Ok, 8 }, { wxT("010"), 16, Number_Ok, 16 }, { wxT("0010"), 10, Number_Ok, 10 }, { wxT("0010"), 8, Number_Ok, 0 }, { wxT("0010"), 8, Number_Ok, 8 }, { wxT("0010"), 16, Number_Ok, 16 },