friend bool operator==(const ALPS_SPRNG_GENERATOR& x, const ALPS_SPRNG_GENERATOR& y) { detail::buffer buf1(x.sprng_ptr,&ALPS_SPRNG_CALL(pack_rng)); detail::buffer buf2(y.sprng_ptr,&ALPS_SPRNG_CALL(pack_rng)); return buf1 == buf2; }
int main(int argc, char **argv) { if ( argc<4 ) { printf("Usage: logocnv startlogo stoplogo outfile\n"); exit(1); } LVImageSourceRef startimg = LVCreateFileCopyImageSource( lString16(argv[1]) ); if ( startimg.isNull() ) { printf("Cannot open image from file %s\n", argv[1]); exit(1); } printf("Start image: %s %d x %d\n", argv[1], startimg->GetWidth(), startimg->GetHeight()); LVGrayDrawBuf buf1( 600, 800, 3 ); buf1.Draw(startimg, 0, 0, 600, 800, true); LVImageSourceRef stopimg = LVCreateFileCopyImageSource( lString16(argv[2]) ); if ( stopimg.isNull() ) { printf("Cannot open image from file %s\n", argv[2]); exit(1); } printf("Stop image: %s %d x %d\n", argv[1], startimg->GetWidth(), startimg->GetHeight()); LVGrayDrawBuf buf2( 600, 800, 3 ); buf2.Draw(stopimg, 0, 0, 600, 800, true); FILE * out = fopen( argv[3], "wb" ); if ( !out ) { printf("Cannot create output file %s", argv[3]); exit(1); } int written = 0; written += fwrite(buf1.GetScanLine(0), 1, buf1.GetRowSize()*buf1.GetHeight(), out ); written += fwrite(buf2.GetScanLine(0), 1, buf2.GetRowSize()*buf2.GetHeight(), out ); fclose(out); printf("%d bytes written to file %s\n", written, argv[3]); }
SidTuneBase* SidTuneBase::getFromBuffer(const uint_least8_t* const buffer, uint_least32_t bufferLen) { if (buffer == nullptr || bufferLen == 0) { throw loadError(ERR_EMPTY); } if (bufferLen > MAX_FILELEN) { throw loadError(ERR_FILE_TOO_LONG); } buffer_t buf1(buffer, buffer + bufferLen); // Here test for the possible single file formats. std::unique_ptr<SidTuneBase> s(PSID::load(buf1)); if (s.get() == nullptr) { buffer_t buf2; // empty s.reset(MUS::load(buf1, buf2, 0, true)); } if (s.get() != nullptr) { s->acceptSidTune("-", "-", buf1, false); return s.release(); } throw loadError(ERR_UNRECOGNIZED_FORMAT); }
TEST(BufferTest, TestConstructCopy) { Buffer buf1(kTestData, sizeof(kTestData), 256), buf2(buf1); EXPECT_EQ(sizeof(kTestData), buf2.length()); EXPECT_EQ(sizeof(kTestData), buf2.capacity()); // capacity isn't copied EXPECT_EQ(0, memcmp(buf2.data(), kTestData, sizeof(kTestData))); EXPECT_EQ(buf1, buf2); }
ROM_END /**********************************************************************************/ void deco156_state::descramble_sound( const char *tag ) { uint8_t *rom = memregion(tag)->base(); int length = memregion(tag)->bytes(); std::vector<uint8_t> buf1(length); uint32_t x; for (x = 0; x < length; x++) { uint32_t addr; addr = bitswap<24> (x,23,22,21,0, 20, 19,18,17,16, 15,14,13,12, 11,10,9, 8, 7, 6, 5, 4, 3, 2, 1 ); buf1[addr] = rom[x]; } memcpy(rom,&buf1[0],length); }
size_t ReplBacklog::WriteChannel(Channel* channle, int64 offset, size_t len) { if (!IsValidOffset(offset)) { return 0; } int64 total = m_state->master_repl_offset - offset; size_t write_len = 0; if (m_state->repl_backlog_idx >= total) { write_len = total > len ? len : total; Buffer buf(m_repl_backlog + m_state->repl_backlog_idx - total, 0, write_len); channle->Write(buf); } else { int64 start_pos = m_state->repl_backlog_size - total + m_state->repl_backlog_idx; total = total - m_state->repl_backlog_idx; if (total <= len) { write_len = total; }else { write_len = len; } Buffer buf1(m_repl_backlog + start_pos, 0, write_len); channle->Write(buf1); } return write_len; }
void buffer_object_t::test<4>() { S32 channel = 50; S32 bigSize = 16384*2; char str[] = "SecondLife"; S32 smallSize = sizeof(str); LLSegment segment; LLHeapBuffer buf; // use default size of DEFAULT_HEAP_BUFFER_SIZE = 16384 S32 requestSize; requestSize = 16384-1; ensure("1. LLHeapBuffer createSegment failed", (TRUE == buf.createSegment(channel, requestSize, segment)) && segment.size() == requestSize); // second request for remainign 1 byte requestSize = 1; ensure("2. LLHeapBuffer createSegment failed", (TRUE == buf.createSegment(channel, requestSize, segment)) && segment.size() == requestSize); // it should fail now. requestSize = 1; ensure("3. LLHeapBuffer createSegment failed", (FALSE == buf.createSegment(channel, requestSize, segment))); LLHeapBuffer buf1(bigSize); // requst for more than default size but less than total sizeit should fail now. requestSize = 16384 + 1; ensure("4. LLHeapBuffer createSegment failed", (TRUE == buf1.createSegment(channel, requestSize, segment)) && segment.size() == requestSize); LLHeapBuffer buf2((U8*) str, smallSize); requestSize = smallSize; ensure("5. LLHeapBuffer createSegment failed", (TRUE == buf2.createSegment(channel, requestSize, segment)) && segment.size() == requestSize && memcmp(segment.data(), (U8*) str, requestSize) == 0); requestSize = smallSize+1; ensure("6. LLHeapBuffer createSegment failed", (FALSE == buf2.createSegment(channel, requestSize, segment))); }
static void streaming_up_down_test(const SRCParams ¶ms) { // Source noise Samples noise(noise_size); RNG(seed).fill_samples(noise, noise_size); // Upsampled buffer Samples buf1(size_t(double(noise_size + 1) * params.fd / params.fs) + 1); // Downsampled buffer Samples buf2(noise_size + 100); StreamingSRC src; BOOST_REQUIRE(src.open(params)); size_t buf1_data = resample(src, noise, noise_size, buf1, buf1.size()); BOOST_REQUIRE(src.open(SRCParams(params.fd, params.fs, params.a, params.q))); size_t buf2_data = resample(src, buf1, buf1_data, buf2, buf2.size()); BOOST_CHECK(abs(int(buf2_data) - int(noise_size)) <= 1); // Resample introduces not more than -A dB of noise. // 2 resamples introduces twice more noise, -A + 6dB sample_t diff = diff_resampled(params, noise, buf2, MIN(noise_size, buf2_data)); BOOST_MESSAGE("Transform: " << params.fs << "Hz <-> " << params.fd << "Hz Diff: " << value2db(diff) << " dB"); BOOST_CHECK_LE(value2db(diff), -params.a + 7); }
// ROM_REGION( 0x80, "user1", 0 ) /* eeprom */ // ROM_LOAD( "93c46.3k", 0x00, 0x80, CRC(88f8e270) SHA1(cb82203ad38e0c12ea998562b7b785979726afe5) ) ROM_END /**********************************************************************************/ void deco156_state::descramble_sound( const char *tag ) { UINT8 *rom = memregion(tag)->base(); int length = memregion(tag)->bytes(); dynamic_buffer buf1(length); UINT32 x; for (x = 0; x < length; x++) { UINT32 addr; addr = BITSWAP24 (x,23,22,21,0, 20, 19,18,17,16, 15,14,13,12, 11,10,9, 8, 7, 6, 5, 4, 3, 2, 1 ); buf1[addr] = rom[x]; } memcpy(rom,buf1,length); }
void CTest_StringMap::testGetL() { auto_ptr<CGenericStringMap> map( CGenericStringMap::NewL() ); map->SetDeletor(&DeleteHBufC); _LIT(KKey1, "avain1"); _LIT(KValue1, "tavara"); auto_ptr<HBufC> buf1( HBufC::NewL(100) ); buf1->Des().Append( KValue1 ); map->AddDataL( KKey1, buf1.release() ); _LIT(KKey2, "avain2"); _LIT(KValue2, "tavaraa taas"); auto_ptr<HBufC> buf2( HBufC::NewL(100) ); buf2->Des().Append( KValue2 ); map->AddDataL( KKey2, buf2.release() ); HBufC* b = (HBufC*)(map->GetData( KKey1 )); TS_ASSERT(b); TS_ASSERT_EQUALS_DESCRIPTOR(*b, KValue1()); b = (HBufC*)(map->GetData( KKey2 )); TS_ASSERT(b); TS_ASSERT_EQUALS_DESCRIPTOR(*b, KValue2()); _LIT(KKey3, "avain3"); b = (HBufC*)(map->GetData( KKey3 )); TS_ASSERT(! (b) ); TS_ASSERT_EQUALS( map->Count(), 2 ); }
LOCAL_C void testRichTextCutPaste1a() // // { INFO_PRINTF1(_L("Cut & paste, preserving formatting into non-empty document")); TheFileName=_L("z:\\test\\app-framework\\etext\\rtclipb2.pml"); ParseRichTextDocumentLC(); TheText->DeleteL(0,TheText->DocumentLength()); TPtrC buf1(_L("ab")); TheText->InsertL(0,buf1); TheText->InsertL(1,CEditableText::EParagraphDelimiter); TheReadBoard=NULL; TheWriteBoard=NULL; OpenWriteClipboardLC(); TheText->CopyToStoreL(TheWriteBoard->Store(),TheWriteBoard->StreamDictionary(),0,TheText->DocumentLength()); TheText->DeleteL(1,2); // Just leaves the single character 'a' as content. // OpenReadClipboardLC(); TheText->PasteFromStoreL(TheReadBoard->Store(),TheReadBoard->StreamDictionary(),1); // CleanupStack::PopAndDestroy(); // Last clipboard object CleanupStack::PopAndDestroy(); // TheTextObject delete TheGlobalParaLayer; delete TheGlobalCharLayer; }
void AdlPrimitivesDemo::render() { int size = 1024*256; // int size = 1024*64; size = NEXTMULTIPLEOF( size, 512 ); int* host1 = new int[size]; int2* host2 = new int2[size]; int4* host4 = new int4[size]; for(int i=0; i<size; i++) { host1[i] = getRandom(0,0xffff); host2[i] = make_int2( host1[i], i ); host4[i] = make_int4( host2[i].x, host2[i].y, host2[i].x, host2[i].y ); } Buffer<int> buf1( m_deviceData, size ); Buffer<int2> buf2( m_deviceData, size ); Buffer<int4> buf4( m_deviceData, size ); buf1.write( host1, size ); buf2.write( host2, size ); buf4.write( host4, size ); Stopwatch sw( m_deviceData ); m_nTxtLines = 0; sprintf_s(m_txtBuffer[m_nTxtLines++], LINE_CAPACITY, "%d elems", size); // testSort( (Buffer<SortData>&)buf2, size, sw ); testFill1( buf1, size, sw ); testFill2( buf2, size, sw ); testFill4( buf4, size, sw ); test( buf2, size, sw ); delete [] host1; delete [] host2; delete [] host4; }
TEST(BufferTest, TestTransfer) { Buffer buf1(kTestData, sizeof(kTestData), 256U), buf2; buf1.TransferTo(&buf2); EXPECT_EQ(0U, buf1.length()); EXPECT_EQ(0U, buf1.capacity()); EXPECT_EQ(sizeof(kTestData), buf2.length()); EXPECT_EQ(256U, buf2.capacity()); // capacity does transfer EXPECT_EQ(0, memcmp(buf2.data(), kTestData, sizeof(kTestData))); }
int WriteFile(int source_fd , const unsigned int& start , int num , char* outfile_name) { boost::shared_array<char> buf; try { boost::shared_array<char> buf1(new char[num+1]); buf = buf1; } catch(std::bad_alloc& s) { PrintError(AT , "bad allocate"); std::abort(); } buf[num] = '\0'; if(-1 != lseek(source_fd , start , SEEK_SET)) { if(-1 != read(source_fd , buf.get() , num)) { int des_fd = open(outfile_name , O_RDWR|O_CREAT|O_EXCL , S_IRUSR|S_IWUSR); if(des_fd != -1) { if(-1 != write(des_fd,buf.get(),strlen(buf.get()))) { if(-1 == close(des_fd)) { PrintError(AT , "close in WriteFile"); throw std::string("close in WriteFile"); } } else { PrintError(AT , "write in WriteFile"); throw std::string("write in WriteFile"); } } else { PrintError(AT , "open in WriteFile"); throw std::string("open in WriteFile"); } } else { PrintError(AT , "read in WriteFile"); throw std::string("read in WriteFile"); } } else { PrintError(AT , "lseek in WriteFile"); throw std::string("lseek in WriteFile"); } return 0; }
TEST(RealVectorOperators, DivideScalar) { double inputData[] = {100, 300, 500, 700.12, 200, 400, 600, 800}; unsigned numElements = sizeof(inputData)/sizeof(inputData[0]); NimbleDSP::RealVector<double> buf1(inputData, numElements); NimbleDSP::RealVector<double> buf2(0); buf2 = buf1 / 15.0; EXPECT_EQ(numElements, buf2.vec.size()); for (unsigned i=0; i<buf2.vec.size(); i++) { EXPECT_EQ(inputData[i] / 15.0, buf2.vec[i]); } }
TEST(RealVectorOperators, MultiplyScalar) { double inputData[] = {1, 3, 5, 7.12, 2, 4, 6, 8}; unsigned numElements = sizeof(inputData)/sizeof(inputData[0]); NimbleDSP::RealVector<double> buf1(inputData, numElements); NimbleDSP::RealVector<double> buf2(0); buf2 = buf1 * 15.0; EXPECT_EQ(numElements, buf2.vec.size()); for (unsigned i=0; i<buf2.vec.size(); i++) { EXPECT_EQ(inputData[i] * 15, buf2.vec[i]); } }
TEST(RealVectorOperators, PlusBuf) { double inputData[] = {1, 3, 5, 7.12, 2, 4, 6, 8}; unsigned numElements = sizeof(inputData)/sizeof(inputData[0]); NimbleDSP::RealVector<double> buf1(inputData, numElements); NimbleDSP::RealVector<double> buf2(inputData, numElements); NimbleDSP::RealVector<double> buf3(0); buf3 = buf1 + buf2; EXPECT_EQ(numElements, buf3.vec.size()); for (unsigned i=0; i<buf3.vec.size(); i++) { EXPECT_EQ(2*inputData[i], buf3.vec[i]); } }
TEST(RealVectorOperators, DivideBuf) { double inputData[] = {100, 300, 500, 700.12, 200, 400, 600, 800}; double inputData2[] = {-1, 2, 4, 6, 1, 3, 5, 7}; unsigned numElements = sizeof(inputData)/sizeof(inputData[0]); NimbleDSP::RealVector<double> buf1(inputData, numElements); NimbleDSP::RealVector<double> buf2(inputData2, numElements); NimbleDSP::RealVector<double> buf3(0); buf3 = buf1 / buf2; EXPECT_EQ(numElements, buf3.vec.size()); for (unsigned i=0; i<buf3.vec.size(); i++) { EXPECT_EQ(inputData[i]/inputData2[i], buf3.vec[i]); } }
void Player::TagUnit( Object *o ){ // For new players who get a create object uint32 Flags = o->GetUInt32Value( UNIT_DYNAMIC_FLAGS ); Flags |= U_DYN_FLAG_TAPPED_BY_PLAYER; // Update existing players. ByteBuffer buf(500); ByteBuffer buf1(500); o->BuildFieldUpdatePacket(&buf1, UNIT_DYNAMIC_FLAGS, Flags); o->BuildFieldUpdatePacket(&buf, UNIT_DYNAMIC_FLAGS, o->GetUInt32Value( UNIT_DYNAMIC_FLAGS ) ); SendUpdateDataToSet( &buf1, &buf, true ); }
TEST(RealVectorOperators, MultiplyEqualsBuf) { double inputData[] = {1, 3, 5, 7.12, 2, 4, 6, 8}; double inputData2[] = {0, 2, 4, 6, 1, 3, 5, 7}; unsigned numElements = sizeof(inputData)/sizeof(inputData[0]); NimbleDSP::RealVector<double> buf1(inputData, numElements); NimbleDSP::RealVector<double> buf2(inputData2, numElements); EXPECT_EQ(numElements, buf1.vec.size()); buf1 *= buf2; for (unsigned i=0; i<buf1.vec.size(); i++) { EXPECT_EQ(inputData[i]*inputData2[i], buf1.vec[i]); EXPECT_EQ(inputData2[i], buf2.vec[i]); } }
TEST(VectorOperators, Equality) { double inputData[] = {1, 3, 5, 7.12, 2, 4, 6, 8}; double inputData2[] = {0, 2, 4, 6, 1, 3, 5, 7}; double inputData3[] = {0, 2, 4, 6, 1, 3, 5, 7, 8}; unsigned numElements = sizeof(inputData)/sizeof(inputData[0]); unsigned numElements3 = sizeof(inputData3)/sizeof(inputData3[0]); NimbleDSP::Vector<double> buf1(inputData, numElements); NimbleDSP::Vector<double> buf2(inputData2, numElements); NimbleDSP::Vector<double> buf3(inputData3, numElements3); EXPECT_FALSE(buf1 == buf2); EXPECT_TRUE(buf1 != buf2); EXPECT_FALSE(buf3 == buf2); EXPECT_TRUE(buf3 != buf2); EXPECT_TRUE(buf1 == buf1); EXPECT_FALSE(buf1 != buf1); }
BOOST_FIXTURE_TEST_CASE_TEMPLATE(ReceiveTooLarge, T, StreamTransportFixtures, T) { this->initialize(); std::vector<uint8_t> bytes(ndn::MAX_NDN_PACKET_SIZE, 0); Block pkt1 = ndn::encoding::makeBinaryBlock(300, bytes.data(), bytes.size() - 6); ndn::Buffer buf1(pkt1.begin(), pkt1.end()); BOOST_REQUIRE_EQUAL(buf1.size(), ndn::MAX_NDN_PACKET_SIZE); Block pkt2 = ndn::encoding::makeBinaryBlock(301, bytes.data(), bytes.size()); ndn::Buffer buf2(pkt2.begin(), pkt2.end()); BOOST_REQUIRE_GT(buf2.size(), ndn::MAX_NDN_PACKET_SIZE); this->remoteWrite(buf1); // this should succeed BOOST_CHECK_EQUAL(this->transport->getCounters().nInPackets, 1); BOOST_CHECK_EQUAL(this->transport->getCounters().nInBytes, buf1.size()); BOOST_CHECK_EQUAL(this->receivedPackets->size(), 1); BOOST_CHECK_EQUAL(this->transport->getState(), TransportState::UP); int nStateChanges = 0; this->transport->afterStateChange.connect( [this, &nStateChanges] (TransportState oldState, TransportState newState) { switch (nStateChanges) { case 0: BOOST_CHECK_EQUAL(oldState, TransportState::UP); BOOST_CHECK_EQUAL(newState, TransportState::FAILED); break; case 1: BOOST_CHECK_EQUAL(oldState, TransportState::FAILED); BOOST_CHECK_EQUAL(newState, TransportState::CLOSED); break; default: BOOST_CHECK(false); } nStateChanges++; }); this->remoteWrite(buf2, false); // this should fail BOOST_CHECK_EQUAL(nStateChanges, 2); BOOST_CHECK_EQUAL(this->transport->getCounters().nInPackets, 1); BOOST_CHECK_EQUAL(this->transport->getCounters().nInBytes, buf1.size()); BOOST_CHECK_EQUAL(this->receivedPackets->size(), 1); }
void ManyFields::serialize(carbon::CarbonProtocolWriter& writer) const { writer.writeStructBegin(); writer.writeField(1 /* field id */, buf1()); writer.writeField(2 /* field id */, buf2()); writer.writeField(3 /* field id */, buf3()); writer.writeField(4 /* field id */, buf4()); writer.writeField(5 /* field id */, buf5()); writer.writeField(6 /* field id */, buf6()); writer.writeField(7 /* field id */, buf7()); writer.writeField(8 /* field id */, buf8()); writer.writeField(9 /* field id */, buf9()); writer.writeField(10 /* field id */, buf10()); writer.writeField(11 /* field id */, buf11()); writer.writeField(12 /* field id */, buf12()); writer.writeField(13 /* field id */, buf13()); writer.writeField(14 /* field id */, buf14()); writer.writeField(15 /* field id */, buf15()); writer.writeField(16 /* field id */, buf16()); writer.writeField(17 /* field id */, buf17()); writer.writeField(18 /* field id */, buf18()); writer.writeField(19 /* field id */, buf19()); writer.writeField(20 /* field id */, buf20()); writer.writeField(21 /* field id */, buf21()); writer.writeField(22 /* field id */, buf22()); writer.writeField(23 /* field id */, buf23()); writer.writeField(24 /* field id */, buf24()); writer.writeField(25 /* field id */, buf25()); writer.writeField(26 /* field id */, buf26()); writer.writeField(27 /* field id */, buf27()); writer.writeField(28 /* field id */, buf28()); writer.writeField(29 /* field id */, buf29()); writer.writeField(30 /* field id */, buf30()); writer.writeField(31 /* field id */, buf31()); writer.writeField(32 /* field id */, buf32()); writer.writeField(33 /* field id */, buf33()); writer.writeField(34 /* field id */, buf34()); writer.writeField(35 /* field id */, buf35()); writer.writeField(36 /* field id */, buf36()); writer.writeField(37 /* field id */, buf37()); writer.writeField(38 /* field id */, buf38()); writer.writeField(39 /* field id */, buf39()); writer.writeField(40 /* field id */, buf40()); writer.writeFieldStop(); writer.writeStructEnd(); }
/* Used to order the flamelet in increasing value of progress variable */ bool IsProgSmaller(string fl1, string fl2) { size_t pos; string Tst; double T1, T2; pos = fl1.find("Tst"); Tst = fl1.substr(pos+3); istringstream buf1(Tst); buf1 >> T1; pos = fl2.find("Tst"); Tst = fl2.substr(pos+3); istringstream buf2(Tst); buf2 >> T2; return (T2 > T1); }
/* Used to order the flamelet in increasing value of scalar dissipation rate */ bool IsChiLarger(string fl1, string fl2) { size_t pos1, pos2; string chist; double chi1, chi2; pos1 = fl1.find("chi") + 3; pos2 = fl1.find("tf"); chist = fl1.substr(pos1, pos2 - pos1); istringstream buf1(chist); buf1 >> chi1; pos1 = fl2.find("chi") + 3; pos2 = fl2.find("tf"); chist = fl2.substr(pos1, pos2 - pos1); istringstream buf2(chist); buf2 >> chi2; return (chi2 > chi1); }
void proc(INodeTab &nodeTab) { int i; Tab<int> freeC; freeC.ZeroCount(); // find available channels for(i=0;i<100;i++) { int tI = i; if(!mp->chanBank[i].mModded) freeC.Append(1,&tI,0); } // If there are less channels than incoming targets, tell the user and quit out if(nodeTab.Count()>freeC.Count()) { TSTR buf1(GetString(IDS_NOFREE)); TSTR buf2(GetString(IDS_CANNOT)); MessageBox(mp->hwChannelList,buf1,buf2,MB_ICONSTOP | MB_OK); goto leapOut; } // Do the assignment of nodes for(i=0;i<nodeTab.Count();i++) { UI_MAKEBUSY if (theHold.Holding()) theHold.Put(new Restore_FullChannel(mp, i )); mp->ReplaceReference(101+freeC[i],nodeTab[i]); mp->chanBank[freeC[i]].buildFromNode(nodeTab[i]); mp->chanBank[freeC[i]].ReNormalize(); UI_MAKEFREE } leapOut: i=0; }
// ----------------------------------------------------------------------------- // CSTSMidletInfo::DomainOIDL // Getter for domain OID value // ----------------------------------------------------------------------------- const TDesC& CSTSMidletInfo::DomainOID() { TBufC16<KSTSDomNameLength> buf1(KDom); HBufC* domain = buf1.AllocLC(); if (domain->Compare(iDomain->Des())) { TBufC<KSTSDomainOperatorLength> buf2(KSTSDomainOperator); HBufC* tmp = buf2.AllocL(); delete iDomainOID; iDomainOID = tmp; } else { //at this point this is not needed, because oid value is not //specified anywhere } return *iDomainOID; }
void checkReadWriteRoundTrip(KisPaintDeviceSP dev, const QRect &rc) { KisPaintDeviceSP deviceCopy = new KisPaintDevice(*dev.data()); QRect readRect(10, 10, 20, 20); int bufSize = rc.width() * rc.height() * dev->pixelSize(); QScopedPointer<quint8> buf1(new quint8[bufSize]); deviceCopy->readBytes(buf1.data(), rc); deviceCopy->clear(); QVERIFY(deviceCopy->extent().isEmpty()); QScopedPointer<quint8> buf2(new quint8[bufSize]); deviceCopy->writeBytes(buf1.data(), rc); deviceCopy->readBytes(buf2.data(), rc); QVERIFY(!memcmp(buf1.data(), buf2.data(), bufSize)); }
bool UTF8UTIL::_EqualString(const uint8_t *str1, const uint8_t *str2, bool diacSensitive) { std::string string1; std::string string2; string1 = (const char *)str1; string2 = (const char *)str2; int size1 = string1.length(); int len1 = (size1 * sizeof(PA_Unichar)) + 2; int size2 = string2.length(); int len2 = (size2 * sizeof(PA_Unichar)) + 2; std::vector<uint8_t> buf1(len1); std::vector<uint8_t> buf2(len2); PA_ConvertCharsetToCharset( (char *)string1.c_str(), size1, eVTC_UTF_8, (char *)&buf1[0], len1, eVTC_UTF_16 ); PA_ConvertCharsetToCharset( (char *)string2.c_str(), size2, eVTC_UTF_8, (char *)&buf2[0], len2, eVTC_UTF_16 ); return (PA_CompareUnichars((PA_Unichar *)&buf1[0], (PA_Unichar *)&buf2[0], diacSensitive, NULL) == 0); }
static void equivalence_test(const SRCParams ¶ms) { // Source noise Samples noise(noise_size); RNG(seed).fill_samples(noise, noise_size); // Upsampled buffer Samples buf1(size_t(double(noise_size + 1) * params.fd / params.fs) + 1); // Downsampled buffer Samples buf2(noise_size + 100); StreamingSRC src; BufferSRC test; BOOST_MESSAGE("Transform: " << params.fs << "Hz <-> " << params.fd); ///////////////////////////////////////////////////////// // Resample using StreamingSRC BOOST_REQUIRE(src.open(params)); size_t buf1_data = resample(src, noise, noise_size, buf1, buf1.size()); BOOST_REQUIRE(src.open(SRCParams(params.fd, params.fs, params.a, params.q))); size_t buf2_data = resample(src, buf1, buf1_data, buf2, buf2.size()); ///////////////////////////////////////////////////////// // Resample using BufferSRC and check the difference BOOST_REQUIRE(test.open(params)); test.process(noise, noise_size); BOOST_REQUIRE_EQUAL(test.size(), buf1_data); sample_t diff = peak_diff(test.result(), buf1, buf1_data); BOOST_CHECK_LE(diff, SAMPLE_THRESHOLD); BOOST_REQUIRE(test.open(SRCParams(params.fd, params.fs, params.a, params.q))); test.process(buf1, buf1_data); BOOST_REQUIRE_EQUAL(test.size(), buf2_data); diff = peak_diff(test.result(), buf2, buf2_data); BOOST_CHECK_LE(diff, SAMPLE_THRESHOLD); }