void tst_ExceptionSafety::exceptionSignalSlot() { Emitter e; ExceptionThrower thrower; Receiver r1; Receiver r2; // connect a signal to a normal object, a thrower and a normal object again connect(&e, SIGNAL(testSignal()), &r1, SLOT(receiver())); connect(&e, SIGNAL(testSignal()), &thrower, SLOT(thrower())); connect(&e, SIGNAL(testSignal()), &r2, SLOT(receiver())); int code = 0; try { e.emitTestSignal(); } catch (int c) { code = c; } // 5 is the magic number that's thrown by thrower QCOMPARE(code, 5); // assumption: slots are called in the connection order QCOMPARE(r1.received, 1); QCOMPARE(r2.received, 0); }
// connect a signal to a slot that throws an exception // run this through valgrind to make sure it doesn't corrupt void tst_ExceptionSafety::exceptionInSlot() { Emitter emitter; ExceptionThrower thrower; connect(&emitter, SIGNAL(testSignal()), &thrower, SLOT(thrower())); try { emitter.emitTestSignal(); } catch (int i) { QCOMPARE(i, 5); } }
TestObject::TestObject(QObject* parent, Kross::Api::ScriptContainer::Ptr scriptcontainer) : QObject(parent, "TestObject") { connect(this, SIGNAL(testSignal()), this, SLOT(testSignalSlot())); connect(this, SIGNAL(stdoutSignal(const QString&)), this, SLOT(stdoutSlot(const QString&))); connect(this, SIGNAL(stderrSignal(const QString&)), this, SLOT(stderrSlot(const QString&))); scriptcontainer->addQObject(this); //scriptcontainer->addSignal("stdout", this, SIGNAL(stdoutSignal(const QString&))); //scriptcontainer->addSlot("stderr", this, SLOT(stderrSlot(const QString&))); //scriptcontainer->addSignal("myTestSignal", this, SIGNAL(testSignal())); //scriptcontainer->addSlot("myTestSlot", this, SLOT(testSlot())); }
int main(){ #if 0 printf("Test popen start**************\n"); testPopen(); printf("Test popen end **************\n"); #endif #if 0 printf("Test epoll with pipe start **************\n"); testEpollWithPipe(); printf("Test epoll with pipe end **************\n"); #endif #if 0 printf("Test named pipe start **************\n"); testNamedPipe(); printf("Test named pipe end **************\n"); #endif #if 0 printf("Test socket pair start **************\n"); testSocket(1); printf("Test socket pair end **************\n"); #endif #if 0 printf("Test socket start **************\n"); testSocket(2); printf("Test socket end **************\n"); #endif #if 1 printf("Test signal start **************\n"); //testSignal(1); testSignal(2); printf("Test signal end **************\n"); #endif return 1; }
/** * function to generate random time-series with gaps, and corresponding SFTs */ int XLALgenerateRandomData ( REAL4TimeSeries **ts, SFTVector **sfts ) { /* input sanity checks */ XLAL_CHECK ( (ts != NULL) && ( (*ts) == NULL ), XLAL_EINVAL ); XLAL_CHECK ( (sfts != NULL) && ( (*sfts) == NULL ), XLAL_EINVAL ); // test parameters LIGOTimeGPS epoch0 = { 714180733, 0 }; UINT4 numSFTs = 20; REAL8 Tsft = 1000.0; // noise sigma REAL8 sigmaN = 0.1; /* prepare sampling constants */ REAL8 numR4SamplesPerSFT = 2 * 5000; REAL8 dtR4 = (Tsft / numR4SamplesPerSFT); UINT4 numR4SamplesTS = numSFTs * numR4SamplesPerSFT; /* ----- allocate timeseries ----- */ REAL4TimeSeries *outTS; // input timeseries XLAL_CHECK ( (outTS = XLALCreateREAL4TimeSeries ("H1:test timeseries", &epoch0, 0, dtR4, &emptyLALUnit, numR4SamplesTS )) != NULL, XLAL_EFUNC ); REAL4 *TSdata = outTS->data->data; /* initialize timeseries to zero (to allow for gaps) */ memset ( TSdata, 0, outTS->data->length * sizeof (*TSdata) ); /* also set up corresponding SFT timestamps vector */ LIGOTimeGPSVector *timestampsSFT; XLAL_CHECK ( (timestampsSFT = XLALCalloc (1, sizeof(*timestampsSFT)) ) != NULL, XLAL_ENOMEM ); XLAL_CHECK ( (timestampsSFT->data = XLALCalloc (numSFTs, sizeof (*timestampsSFT->data) )) != NULL, XLAL_ENOMEM ); timestampsSFT->length = numSFTs; /* ----- set up random-noise timeseries with gaps ---------- */ for ( UINT4 alpha=0; alpha < numSFTs; alpha ++ ) { /* record this SFT's timestamp */ timestampsSFT->data[alpha] = epoch0; timestampsSFT->data[alpha].gpsSeconds += lround( alpha * Tsft ); /* generate all data-points of this SFT */ for ( UINT4 j=0; j < numR4SamplesPerSFT; j++ ) { UINT4 alpha_j = alpha * numR4SamplesPerSFT + j; REAL8 ti = alpha * Tsft + j * dtR4; /* unit-variance Gaussian noise + sinusoid */ TSdata[alpha_j] = crealf ( testSignal ( ti, sigmaN ) ); } // for js < numR4SamplesPerSFT } /* for alpha < numSFTs */ /* ----- generate SFTs from this timeseries ---------- */ SFTParams XLAL_INIT_DECL(sftParams); sftParams.Tsft = Tsft; sftParams.timestamps = timestampsSFT; sftParams.noiseSFTs = NULL; sftParams.window = NULL; SFTVector *outSFTs; XLAL_CHECK ( (outSFTs = XLALSignalToSFTs ( outTS, &sftParams )) != NULL, XLAL_EFUNC ); /* free memory */ XLALFree ( timestampsSFT->data ); XLALFree ( timestampsSFT ); /* return timeseries and SFTvector */ (*ts) = outTS; (*sfts) = outSFTs; return XLAL_SUCCESS; } // XLALgenerateRandomData()
int test_XLALSincInterpolateSFT ( void ) { REAL8 f0 = 0; // heterodyning frequency REAL8 sigmaN = 0.001; REAL8 dt = 0.1; // sampling frequency = 10Hz LIGOTimeGPS epoch = { 100, 0 }; REAL8 tStart = XLALGPSGetREAL8 ( &epoch ); UINT4 numSamples = 1000; REAL8 Tspan = numSamples * dt; REAL8 df = 1.0 / Tspan; UINT4 numSamples0padded = 3 * numSamples; REAL8 Tspan0padded = numSamples0padded * dt; REAL8 df0padded = 1.0 / Tspan0padded; UINT4 numBins = NhalfPosDC ( numSamples ); UINT4 numBins0padded = NhalfPosDC ( numSamples0padded ); // original timeseries REAL4TimeSeries* ts; XLAL_CHECK ( (ts = XLALCreateREAL4TimeSeries ( "test TS_in", &epoch, f0, dt, &emptyLALUnit, numSamples )) != NULL, XLAL_EFUNC ); for ( UINT4 j = 0; j < numSamples; j ++ ) { ts->data->data[j] = crealf ( testSignal ( tStart + j * dt, sigmaN ) ); } // for j < numSamples // zero-padded to double length REAL4TimeSeries* ts0padded; XLAL_CHECK ( (ts0padded = XLALCreateREAL4TimeSeries ( "test TS_padded", &epoch, f0, dt, &emptyLALUnit, numSamples0padded )) != NULL, XLAL_EFUNC ); memcpy ( ts0padded->data->data, ts->data->data, numSamples * sizeof(ts0padded->data->data[0]) ); memset ( ts0padded->data->data + numSamples, 0, (numSamples0padded - numSamples) * sizeof(ts0padded->data->data[0]) ); // compute FFT on ts and ts0padded REAL4FFTPlan *plan, *plan0padded; XLAL_CHECK ( (plan = XLALCreateForwardREAL4FFTPlan ( numSamples, 0 )) != NULL, XLAL_EFUNC ); XLAL_CHECK ( (plan0padded = XLALCreateForwardREAL4FFTPlan ( numSamples0padded, 0 )) != NULL, XLAL_EFUNC ); COMPLEX8Vector *fft, *fft0padded; XLAL_CHECK ( (fft = XLALCreateCOMPLEX8Vector ( numBins )) != NULL, XLAL_ENOMEM ); XLAL_CHECK ( (fft0padded = XLALCreateCOMPLEX8Vector ( numBins0padded )) != NULL, XLAL_ENOMEM ); XLAL_CHECK ( XLALREAL4ForwardFFT ( fft, ts->data, plan ) == XLAL_SUCCESS, XLAL_EFUNC ); XLAL_CHECK ( XLALREAL4ForwardFFT ( fft0padded, ts0padded->data, plan0padded ) == XLAL_SUCCESS, XLAL_EFUNC ); XLALDestroyREAL4TimeSeries ( ts ); XLALDestroyREAL4TimeSeries ( ts0padded ); XLALDestroyREAL4FFTPlan( plan ); XLALDestroyREAL4FFTPlan( plan0padded ); SFTtype XLAL_INIT_DECL(tmp); tmp.f0 = f0; tmp.deltaF = df; tmp.data = fft; REAL8 Band = 0.5/dt - f0; SFTtype *sft = NULL; XLAL_CHECK ( XLALExtractBandFromSFT ( &sft, &tmp, f0, Band ) == XLAL_SUCCESS, XLAL_EFUNC ); XLALDestroyCOMPLEX8Vector ( fft ); tmp.f0 = f0; tmp.deltaF = df0padded; tmp.data = fft0padded; SFTtype *sft0padded = NULL; XLAL_CHECK ( XLALExtractBandFromSFT ( &sft0padded, &tmp, f0, Band ) == XLAL_SUCCESS, XLAL_EFUNC ); XLALDestroyCOMPLEX8Vector ( fft0padded ); // ---------- interpolate input SFT onto frequency bins of padded-ts FFT for comparison UINT4 Dterms = 16; REAL8 safetyBins = (Dterms + 1.0); // avoid truncated interpolation to minimize errors, set to 0 for seeing boundary-effects [they're not so bad...] REAL8 fMin = f0 + safetyBins * df; fMin = round(fMin / df0padded) * df0padded; UINT4 numBinsOut = numBins0padded - 3 * safetyBins; REAL8 BandOut = (numBinsOut-1) * df0padded; SFTtype *sftUpsampled = NULL; XLAL_CHECK ( XLALExtractBandFromSFT ( &sftUpsampled, sft0padded, fMin + 0.5*df0padded, BandOut - df0padded ) == XLAL_SUCCESS, XLAL_EFUNC ); SFTtype *sftInterpolated; XLAL_CHECK ( (sftInterpolated = XLALSincInterpolateSFT ( sft, fMin, df0padded, numBinsOut, Dterms )) != NULL, XLAL_EFUNC ); // ----- out debug info if ( lalDebugLevel & LALINFO ) { XLAL_CHECK ( write_SFTdata ( "SFT_in.dat", sft ) == XLAL_SUCCESS, XLAL_EFUNC ); XLAL_CHECK ( write_SFTdata ( "SFT_in0padded.dat", sft0padded ) == XLAL_SUCCESS, XLAL_EFUNC ); XLAL_CHECK ( write_SFTdata ( "SFT_upsampled.dat", sftUpsampled ) == XLAL_SUCCESS, XLAL_EFUNC ); XLAL_CHECK ( write_SFTdata ( "SFT_interpolated.dat", sftInterpolated ) == XLAL_SUCCESS, XLAL_EFUNC ); } // if LALINFO // ---------- check accuracy of interpolation VectorComparison XLAL_INIT_DECL(tol); tol.relErr_L1 = 8e-2; tol.relErr_L2 = 8e-2; tol.angleV = 8e-2; tol.relErr_atMaxAbsx = 4e-3; tol.relErr_atMaxAbsy = 4e-3; XLALPrintInfo ("Comparing Dirichlet SFT interpolation with upsampled SFT:\n"); XLAL_CHECK ( XLALCompareSFTs ( sftUpsampled, sftInterpolated, &tol ) == XLAL_SUCCESS, XLAL_EFUNC ); // ---------- free memory XLALDestroySFT ( sft ); XLALDestroySFT ( sft0padded ); XLALDestroySFT ( sftUpsampled ); XLALDestroySFT ( sftInterpolated ); return XLAL_SUCCESS; } // test_XLALSincInterpolateSFT()
int test_XLALSincInterpolateCOMPLEX8TimeSeries ( void ) { COMPLEX8TimeSeries* tsIn; REAL8 f0 = 100; // heterodyning frequency REAL8 dt = 0.1; // sampling frequency = 10Hz LIGOTimeGPS epoch = { 100, 0 }; REAL8 tStart = XLALGPSGetREAL8 ( &epoch ); UINT4 numSamples = 1000; REAL8 Tspan = numSamples * dt; XLAL_CHECK ( (tsIn = XLALCreateCOMPLEX8TimeSeries ( "test TS_in", &epoch, f0, dt, &emptyLALUnit, numSamples )) != NULL, XLAL_EFUNC ); for ( UINT4 j = 0; j < numSamples; j ++ ) { tsIn->data->data[j] = testSignal ( tStart + j * dt, 0 ); } // for j < numSamples // ---------- interpolate this onto new time-samples UINT4 Dterms = 16; REAL8 safety = (Dterms+1.0) * dt; // avoid truncated interpolation to minimize errors, set to 0 for seeing boundary-effects [they're not so bad...] LIGOTimeGPS epochOut = epoch; XLALGPSAdd ( &epochOut, safety ); REAL8 TspanOut = Tspan - 2 * safety; REAL8 dtOut = dt / 10; UINT4 numSamplesOut = lround ( TspanOut / dtOut ); COMPLEX8TimeSeries *tsOut; XLAL_CHECK ( (tsOut = XLALCreateCOMPLEX8TimeSeries ( "test TS_out", &epochOut, f0, dtOut, &emptyLALUnit, numSamplesOut )) != NULL, XLAL_EFUNC ); REAL8 tStartOut = XLALGPSGetREAL8 ( &epochOut ); REAL8Vector *times_out; XLAL_CHECK ( (times_out = XLALCreateREAL8Vector ( numSamplesOut )) != NULL, XLAL_EFUNC ); for ( UINT4 j = 0; j < numSamplesOut; j ++ ) { REAL8 t_j = tStartOut + j * dtOut; times_out->data[j] = t_j; } // for j < numSamplesOut XLAL_CHECK ( XLALSincInterpolateCOMPLEX8TimeSeries ( tsOut->data, times_out, tsIn, Dterms ) == XLAL_SUCCESS, XLAL_EFUNC ); XLALDestroyREAL8Vector ( times_out ); // ---------- check accuracy of interpolation COMPLEX8TimeSeries *tsFull; XLAL_CHECK ( (tsFull = XLALCreateCOMPLEX8TimeSeries ( "test TS_full", &epochOut, f0, dtOut, &emptyLALUnit, numSamplesOut )) != NULL, XLAL_EFUNC ); for ( UINT4 j = 0; j < numSamplesOut; j ++ ) { tsFull->data->data[j] = testSignal ( tStartOut + j * dtOut, 0 ); } // for j < numSamplesOut // ----- out debug info if ( lalDebugLevel & LALINFO ) { XLAL_CHECK ( XLALdumpCOMPLEX8TimeSeries ( "TS_in.dat", tsIn ) == XLAL_SUCCESS, XLAL_EFUNC ); XLAL_CHECK ( XLALdumpCOMPLEX8TimeSeries ( "TS_out.dat", tsOut ) == XLAL_SUCCESS, XLAL_EFUNC ); XLAL_CHECK ( XLALdumpCOMPLEX8TimeSeries ( "TS_full.dat", tsFull ) == XLAL_SUCCESS, XLAL_EFUNC ); } // if LALINFO VectorComparison XLAL_INIT_DECL(tol); tol.relErr_L1 = 2e-2; tol.relErr_L2 = 2e-2; tol.angleV = 2e-2; tol.relErr_atMaxAbsx = 2e-2; tol.relErr_atMaxAbsy = 2e-2; XLALPrintInfo ("Comparing sinc-interpolated timeseries to exact signal timeseries:\n"); VectorComparison XLAL_INIT_DECL(cmp); XLAL_CHECK ( XLALCompareCOMPLEX8Vectors ( &cmp, tsOut->data, tsFull->data, &tol ) == XLAL_SUCCESS, XLAL_EFUNC ); // ---------- free memory XLALDestroyCOMPLEX8TimeSeries ( tsIn ); XLALDestroyCOMPLEX8TimeSeries ( tsOut ); XLALDestroyCOMPLEX8TimeSeries ( tsFull ); return XLAL_SUCCESS; } // test_XLALSincInterpolateCOMPLEX8TimeSeries()
void MainWindow::onClicked() { emit testSignal(m_enum); }
void TestObject::testSlot() { Kross::krossdebug("TestObject::testSlot called"); emit testSignal(); emit testSignalString("This is the emitted TestObject::testSignalString(const QString&)"); }