summaryrefslogtreecommitdiff
path: root/tests/unit/qmap
diff options
context:
space:
mode:
authorChristoph Berg <myon@debian.org>2026-10-09 14:12:35 +0200
committerChristoph Berg <myon@debian.org>2026-10-09 14:12:35 +0200
commitffc62c792c9a5196cb4ce7a353287dfe20db6524 (patch)
tree1269efa852935b183daae4bb33a58d1b4d2ffb53 /tests/unit/qmap
parent059831534c7e884f0a607ed86b582fd00d821731 (diff)
New upstream version 3.3.0~beta1+dfsgupstream/3.3.0_beta1+dfsg
Diffstat (limited to 'tests/unit/qmap')
-rw-r--r--tests/unit/qmap/CMakeLists.txt22
-rw-r--r--tests/unit/qmap/test_livecq_parser.cpp52
-rw-r--r--tests/unit/qmap/test_qmap_candidates.f90185
-rw-r--r--tests/unit/qmap/test_qmap_q65_connection.f90123
-rw-r--r--tests/unit/qmap/test_qmap_q65_handoff.f90116
-rw-r--r--tests/unit/qmap/test_qmap_symspec_contract.f9067
6 files changed, 565 insertions, 0 deletions
diff --git a/tests/unit/qmap/CMakeLists.txt b/tests/unit/qmap/CMakeLists.txt
index 0d0b73ac..2feeef62 100644
--- a/tests/unit/qmap/CMakeLists.txt
+++ b/tests/unit/qmap/CMakeLists.txt
@@ -43,3 +43,25 @@ add_executable (test_qmap_decode_click_coalescer
)
target_link_libraries (test_qmap_decode_click_coalescer Qt5::Test Qt5::Widgets)
add_test (NAME test_qmap_decode_click_coalescer COMMAND test_qmap_decode_click_coalescer)
+
+add_executable (test_qmap_candidates test_qmap_candidates.f90)
+target_include_directories (test_qmap_candidates PRIVATE ${CMAKE_BINARY_DIR}/qmap/libqmap)
+target_link_libraries (test_qmap_candidates PRIVATE qmap_impl)
+add_test (NAME test_qmap_candidates COMMAND test_qmap_candidates)
+
+add_executable (test_qmap_symspec_contract test_qmap_symspec_contract.f90)
+target_link_libraries (test_qmap_symspec_contract PRIVATE qmap_impl)
+add_test (NAME test_qmap_symspec_contract COMMAND test_qmap_symspec_contract)
+
+add_executable (test_qmap_q65_handoff test_qmap_q65_handoff.f90)
+target_include_directories (test_qmap_q65_handoff PRIVATE ${CMAKE_BINARY_DIR}/qmap/libqmap)
+target_link_libraries (test_qmap_q65_handoff PRIVATE qmap_impl)
+add_test (NAME test_qmap_q65_handoff COMMAND test_qmap_q65_handoff)
+
+add_executable (test_qmap_q65_connection
+ ${CMAKE_SOURCE_DIR}/tests/unit/q65/q65_test_fixture.f90
+ test_qmap_q65_connection.f90)
+target_include_directories (test_qmap_q65_connection PRIVATE ${CMAKE_BINARY_DIR}/qmap/libqmap)
+target_link_libraries (test_qmap_q65_connection PRIVATE qmap_impl)
+add_test (NAME test_qmap_q65_connection COMMAND test_qmap_q65_connection)
+add_test (NAME test_qmap_q65_connection_30_second_half COMMAND test_qmap_q65_connection 30)
diff --git a/tests/unit/qmap/test_livecq_parser.cpp b/tests/unit/qmap/test_livecq_parser.cpp
index 4f0ff9ea..e3fc7f23 100644
--- a/tests/unit/qmap/test_livecq_parser.cpp
+++ b/tests/unit/qmap/test_livecq_parser.cpp
@@ -77,6 +77,58 @@ private slots:
{"123456", "-10", "0.1", "1234", "-12", "60", "CQ", "DX", "N5", "1200.0"},
100, record));
}
+
+ void spotTimeUsesTodaysUtcDate()
+ {
+ QDateTime const now {QDate {2026, 9, 30}, QTime {18, 7, 10}, Qt::UTC};
+ QCOMPARE(QMapLiveCQ::spotTime("180630", now),
+ QDateTime(QDate {2026, 9, 30}, QTime {18, 6, 30}, Qt::UTC));
+ QCOMPARE(QMapLiveCQ::spotTime("1806", now),
+ QDateTime(QDate {2026, 9, 30}, QTime {18, 6}, Qt::UTC));
+ QCOMPARE(QMapLiveCQ::spotTime("180630", now).toString("yyyy-MM-ddTHH:mm:ss") + "Z",
+ QString {"2026-09-30T18:06:30Z"});
+ }
+
+ void spotTimeIsIndependentOfLocale()
+ {
+ QDateTime const now {QDate {2026, 9, 30}, QTime {18, 7, 10}, Qt::UTC};
+ auto const previous = QLocale {};
+ for (auto const name : {"cs_CZ", "es_AR", "hu_HU", "fr_FR", "de_DE", "zh_TW", "ru_RU"}) {
+ QLocale::setDefault(QLocale {name});
+ QCOMPARE(QMapLiveCQ::spotTime("180630", now).toString("yyyy-MM-ddTHH:mm:ss") + "Z",
+ QString {"2026-09-30T18:06:30Z"});
+ }
+ QLocale::setDefault(previous);
+ }
+
+ void spotTimeAcrossMidnight()
+ {
+ // Early decode of the last period before midnight: still the same day.
+ QCOMPARE(QMapLiveCQ::spotTime("235930", QDateTime(QDate {2026, 9, 30}, QTime {23, 59, 52}, Qt::UTC)),
+ QDateTime(QDate {2026, 9, 30}, QTime {23, 59, 30}, Qt::UTC));
+ // Decoded just after midnight: the period began yesterday.
+ QCOMPARE(QMapLiveCQ::spotTime("235900", QDateTime(QDate {2026, 10, 1}, QTime {0, 0, 5}, Qt::UTC)),
+ QDateTime(QDate {2026, 9, 30}, QTime {23, 59}, Qt::UTC));
+ QCOMPARE(QMapLiveCQ::spotTime("235930", QDateTime(QDate {2026, 10, 1}, QTime {0, 0, 22}, Qt::UTC)),
+ QDateTime(QDate {2026, 9, 30}, QTime {23, 59, 30}, Qt::UTC));
+ // First period of the new day.
+ QCOMPARE(QMapLiveCQ::spotTime("000000", QDateTime(QDate {2026, 10, 1}, QTime {0, 0, 52}, Qt::UTC)),
+ QDateTime(QDate {2026, 10, 1}, QTime {0, 0}, Qt::UTC));
+ // Clock a few seconds behind the decoder: not pushed back a day.
+ QCOMPARE(QMapLiveCQ::spotTime("120000", QDateTime(QDate {2026, 9, 30}, QTime {11, 59, 58}, Qt::UTC)),
+ QDateTime(QDate {2026, 9, 30}, QTime {12, 0}, Qt::UTC));
+ }
+
+ void spotTimeRejectsMalformedTimes()
+ {
+ QDateTime const now {QDate {2026, 9, 30}, QTime {18, 7, 10}, Qt::UTC};
+ for (auto const& decodeTime : {QString {}, QString {"123"}, QString {"1234567"},
+ QString {"2460"}, QString {"1260"}, QString {"126099"},
+ QString {"12x4"}, QString {"12:34"}}) {
+ QVERIFY(!QMapLiveCQ::spotTime(decodeTime, now).isValid());
+ }
+ QVERIFY(!QMapLiveCQ::spotTime("123456", QDateTime {}).isValid());
+ }
};
QTEST_APPLESS_MAIN(TestQMapLiveCQParser)
diff --git a/tests/unit/qmap/test_qmap_candidates.f90 b/tests/unit/qmap/test_qmap_candidates.f90
new file mode 100644
index 00000000..17b29bdc
--- /dev/null
+++ b/tests/unit/qmap/test_qmap_candidates.f90
@@ -0,0 +1,185 @@
+program test_qmap_candidates
+ use qmap_candidates_mod, only: candidate, getcand2
+ implicit none
+
+ integer, parameter :: nfft=32768, first_bin=10000, second_bin=10200
+ integer, parameter :: sync_symbols(22) = [1,9,12,13,15,22,23,26,27,33,35,38,46,50,55,60,62,66,69,74,76,85]
+ real, parameter :: df=96000.0/nfft
+ real, allocatable :: ss(:,:), savg(:)
+ type(candidate) :: found(50), original(50)
+ integer :: ncand, original_count
+
+ allocate(ss(400,nfft),savg(nfft))
+
+ call clear_spectra()
+ call add_sync(first_bin,60,0,11,35.0)
+ call search(390,10,10,.false.,found,ncand)
+ call require(ncand==1,'one Q65-60 candidate')
+ call expect_candidate(found(1),first_bin,60,0,11)
+ original_count=ncand
+ original(1:ncand)=found(1:ncand)
+
+ call clear_spectra()
+ call add_sync(second_bin,60,0,7,35.0)
+ call search(390,10,10,.false.,found,ncand)
+ call require(ncand==1,'alternate Q65-60 candidate')
+ call expect_candidate(found(1),second_bin,60,0,7)
+
+ call clear_spectra()
+ call add_sync(first_bin,60,0,11,35.0)
+ call search(390,10,10,.false.,found,ncand)
+ call require(ncand==original_count,'A-B-A count is stable')
+ call same_candidate(found(1),original(1))
+
+ ! A missing final average-spectrum bin is the searcher's empty-input sentinel.
+ ss=0.0
+ savg=0.0
+ call search(390,10,10,.false.,found,ncand)
+ call require(ncand==0,'empty spectrum clears the previous candidate count')
+
+ call clear_spectra()
+ call add_sync(first_bin,60,0,11,35.0)
+ call add_sync(second_bin,60,0,7,30.0)
+ call search(390,10,10,.false.,found,ncand)
+ call require(ncand==2,'separated Q65 signals survive')
+ call require(has_candidate(found,ncand,first_bin,60,0) .and. &
+ has_candidate(found,ncand,second_bin,60,0),'both separated frequencies survive')
+
+ call clear_spectra()
+ call add_sync(first_bin,60,0,11,35.0)
+ call add_sync(first_bin+2,60,0,11,12.0)
+ call search(390,10,10,.false.,found,ncand)
+ call require(ncand==1,'nearby bins form one candidate')
+ call expect_candidate(found(1),first_bin,60,0,11)
+
+ call clear_spectra()
+ ss(:,first_bin)=ss(:,first_bin)+40.0
+ savg(first_bin)=sum(ss(:,first_bin))
+ call search(390,10,10,.false.,found,ncand)
+ call require(ncand==0,'continuous carrier is not a Q65 candidate')
+
+ call clear_spectra()
+ call add_sync(first_bin,30,0,9,35.0)
+ call search(130,0,10,.true.,found,ncand)
+ call require(ncand==1,'first Q65-30 half is admitted')
+ call expect_candidate(found(1),first_bin,30,0,9)
+ call search(130,6,10,.true.,found,ncand)
+ call require(ncand==0,'first transmit-half gate suppresses reception')
+ call search(201,0,10,.true.,found,ncand)
+ call require(ncand==0,'first half is unavailable after its row boundary')
+
+ call clear_spectra()
+ call add_sync(first_bin,30,1,8,35.0)
+ call search(390,10,0,.true.,found,ncand)
+ call require(ncand==1,'second Q65-30 half is admitted')
+ call expect_candidate(found(1),first_bin,30,1,8)
+ call search(390,10,6,.true.,found,ncand)
+ call require(ncand==0,'second transmit-half gate suppresses reception')
+ call search(329,10,0,.true.,found,ncand)
+ call require(ncand==0,'second half is unavailable before its row boundary')
+
+ call clear_spectra()
+ call add_sync(first_bin,60,0,11,35.0)
+ call search(199,10,10,.false.,found,ncand)
+ call require(ncand==0,'Q65-60 requires its available-row gate')
+ call search(200,10,10,.false.,found,ncand)
+ call require(ncand==1,'Q65-60 opens at its available-row boundary')
+ call search_selected(first_bin,found,ncand)
+ call require(ncand==1,'selected search includes its frequency bin')
+ call search_selected(second_bin,found,ncand)
+ call require(ncand==0,'selected search excludes a distant frequency bin')
+
+ print '(a)', 'QMAP candidate contracts passed'
+
+contains
+
+ subroutine clear_spectra()
+ integer :: bin,row
+ real :: floor(400)
+ do row=1,400
+ floor(row)=1.0+0.002*real(mod(17*row,23))
+ enddo
+ do bin=1,nfft
+ ss(:,bin)=floor+0.0002*real(mod(bin,17))
+ savg(bin)=sum(ss(:,bin))
+ enddo
+ end subroutine clear_spectra
+
+ subroutine add_sync(bin,period,sequence,lag,power)
+ integer, intent(in) :: bin,period,sequence,lag
+ real, intent(in) :: power
+ integer :: i,row,rows,stride
+ rows=4
+ stride=4
+ if(period==30) then
+ rows=2
+ stride=2
+ endif
+ do i=1,size(sync_symbols)
+ row=stride*(sync_symbols(i)-1)+1+lag+sequence*200
+ ss(row:row+rows-1,bin)=ss(row:row+rows-1,bin)+power
+ enddo
+ savg(bin)=sum(ss(:,bin))
+ end subroutine add_sync
+
+ subroutine search(nhsym,ntx30a,ntx30b,also30,candidates,count)
+ integer, intent(in) :: nhsym,ntx30a,ntx30b
+ logical, intent(in) :: also30
+ type(candidate), intent(out) :: candidates(50)
+ integer, intent(out) :: count
+ real :: fresh_savg(nfft)
+ logical(kind=1) :: search30
+ fresh_savg=savg
+ search30=also30
+ count=-1
+ call getcand2(ss,fresh_savg,2,0,nhsym,ntx30a,ntx30b,100,0.0,search30,candidates,count)
+ end subroutine search
+
+ subroutine search_selected(selected_bin,candidates,count)
+ integer, intent(in) :: selected_bin
+ type(candidate), intent(out) :: candidates(50)
+ integer, intent(out) :: count
+ real :: fresh_savg(nfft)
+ logical(kind=1) :: search30
+ fresh_savg=savg
+ search30=.false.
+ count=-1
+ call getcand2(ss,fresh_savg,2,1,390,10,10,0,selected_bin*df/1000.0, &
+ search30,candidates,count)
+ end subroutine search_selected
+
+ logical function has_candidate(candidates,count,bin,period,sequence)
+ type(candidate), intent(in) :: candidates(50)
+ integer, intent(in) :: count,bin,period,sequence
+ integer :: i
+ has_candidate=.false.
+ do i=1,count
+ if(abs(candidates(i)%f-bin*df/1000.0)<df/2000.0 .and. &
+ candidates(i)%ntrperiod==period .and. candidates(i)%iseq==sequence) has_candidate=.true.
+ enddo
+ end function has_candidate
+
+ subroutine expect_candidate(value,bin,period,sequence,lag)
+ type(candidate), intent(in) :: value
+ integer, intent(in) :: bin,period,sequence,lag
+ call require(abs(value%f-bin*df/1000.0)<df/2000.0,'candidate frequency')
+ call require(abs(value%xdt-(0.15*lag-1.0))<0.001,'candidate time offset')
+ call require(value%ntrperiod==period,'candidate period')
+ call require(value%iseq==sequence,'candidate sequence')
+ end subroutine expect_candidate
+
+ subroutine same_candidate(a,b)
+ type(candidate), intent(in) :: a,b
+ call require(a%f==b%f .and. a%xdt==b%xdt .and. a%snr==b%snr .and. &
+ a%ntrperiod==b%ntrperiod .and. a%iseq==b%iseq,'A-B-A candidate fields are stable')
+ end subroutine same_candidate
+
+ subroutine require(condition,description)
+ logical, intent(in) :: condition
+ character(len=*), intent(in) :: description
+ if(.not.condition) then
+ print '(a)', 'FAIL: '//description
+ error stop 1
+ endif
+ end subroutine require
+end program test_qmap_candidates
diff --git a/tests/unit/qmap/test_qmap_q65_connection.f90 b/tests/unit/qmap/test_qmap_q65_connection.f90
new file mode 100644
index 00000000..da8ac94a
--- /dev/null
+++ b/tests/unit/qmap/test_qmap_q65_connection.f90
@@ -0,0 +1,123 @@
+program test_qmap_q65_connection
+ use iso_fortran_env, only: real64
+ use q65_test_fixture, only: q65_tones, q65_nsymbols
+ use qmap_candidates_mod, only: candidate, getcand2
+ use qmap_decode_ipc, only: ndecodes, result
+ use q65_decode, only: msg0, nfreq0, nsnr0, xdt0
+ use timer_impl, only: init_timer, fini_timer
+ implicit none
+
+ integer, parameter :: nfft=32768, nsmax=5760000, sample_rate=96000
+ integer, parameter :: max_candidates=50
+ real(real64), parameter :: sync_hz=16817.0_real64*sample_rate/nfft
+ real(real64), parameter :: twopi=2.0_real64*acos(-1.0_real64)
+ real :: dd(2,nsmax),ss(400,nfft),savg(nfft)
+ real(real64) :: fcenter
+ integer :: nutc
+ integer :: junk(42)
+ common/datcom/dd,ss,savg,fcenter,nutc,junk
+ real :: display(nfft),savg_fresh(nfft)
+ real(real64) :: phase,omega,amplitude,frequency
+ logical(kind=1) :: also30,click,lstrong(0:1023)
+ type(candidate) :: cand(max_candidates)
+ integer :: seed_size,symbol,i,k,nb,nbslider,nkh,ihsym,nzap,ncand,selected,idec
+ integer :: period,iseq,symbol_samples,first_sample,nts_q65
+ integer, allocatable :: seed(:)
+ real :: pxdb,slimit
+ character(len=20) :: datetime
+ character(len=8) :: period_arg
+
+ period=60
+ call get_command_argument(1,period_arg)
+ if(len_trim(period_arg)>0) then
+ if(trim(period_arg)/='30') error stop 'Expected a 30-second Q65 period'
+ period=30
+ endif
+ iseq=0
+ nts_q65=1
+ if(period==30) then
+ iseq=1
+ nts_q65=2
+ endif
+ symbol_samples=period*sample_rate/100
+ first_sample=(1+30*iseq)*sample_rate
+
+ call random_seed(size=seed_size)
+ allocate(seed(seed_size))
+ seed=104729
+ call random_seed(put=seed)
+ call random_number(dd)
+ dd=2.0*(dd-0.5)
+ ss=0.0
+ savg=0.0
+ fcenter=144.125_real64
+ nutc=100
+
+ phase=0.0_real64
+ amplitude=160.0_real64
+ do symbol=1,q65_nsymbols
+ frequency=sync_hz+real(q65_tones(symbol),real64)*real(sample_rate,real64)/real(symbol_samples,real64)
+ omega=twopi*frequency/real(sample_rate,real64)
+ do i=1,symbol_samples
+ k=first_sample+(symbol-1)*symbol_samples+i
+ phase=phase+omega
+ if(phase>twopi) phase=phase-twopi
+ dd(1,k)=dd(1,k)+real(amplitude*cos(phase))
+ dd(2,k)=dd(2,k)-real(amplitude*sin(phase))
+ enddo
+ enddo
+
+ call init_timer()
+ nb=0
+ nbslider=40
+ slimit=0.0
+ ihsym=0
+ do i=1,390
+ k=28800+(i-1)*14400
+ call symspec(k,1,nb,nbslider,sample_rate,pxdb,display,nkh,ihsym,nzap,slimit,lstrong)
+ enddo
+ call require(ihsym==390, 'complete QMAP symbol spectra')
+
+ savg_fresh=savg
+ also30=period==30
+ call getcand2(ss,savg_fresh,nts_q65,1,ihsym,0,0,15,real(sync_hz/1000.0_real64), &
+ also30,cand,ncand)
+ selected=0
+ do i=1,ncand
+ if(cand(i)%ntrperiod/=period .or. cand(i)%iseq/=iseq) cycle
+ if(abs(1000.0*cand(i)%f-real(sync_hz))>10.0) cycle
+ selected=i
+ exit
+ enddo
+ call require(selected>0, 'find generated Q65 sync candidate')
+
+ call fftbig(dd,nsmax)
+ ndecodes=0
+ open(unit=12,status='scratch')
+ datetime='2026-09-23 12:00:00 '
+ click=.false.
+ idec=-1
+ call q65b(nutc,0,fcenter,0,sample_rate,125,0,100,period,iseq, &
+ 'N0CALL ',' ',' ',1,cand(selected)%f,1.270,125, &
+ 1,0,click,0,0,3,datetime,0,0,ihsym,idec)
+ call require(nsnr0 > -99, 'decode generated Q65 signal')
+ call require(trim(msg0)=='K1ABC W9XYZ FN42', 'recover generated Q65 message')
+ call require(abs(nfreq0-1000)<20, 'QMAP decoder reports centered audio frequency')
+ call require(abs(xdt0)<0.5, 'QMAP decoder reports generated timing')
+ call require(ndecodes==1 .and. index(result(1),'K1ABC W9XYZ FN42')>0, &
+ 'QMAP publishes decoded message')
+ if(period==30) call require(result(1)(1:6)=='010030', 'second-half decode uses the :30 time')
+ call fini_timer()
+ print '(a,i0,a)', 'QMAP generated Q65 ',period,'-second connection passed.'
+
+contains
+
+ subroutine require(condition,description)
+ logical, intent(in) :: condition
+ character(len=*), intent(in) :: description
+ if (.not. condition) then
+ print '(a)', 'FAIL: '//description
+ error stop 1
+ endif
+ end subroutine require
+end program test_qmap_q65_connection
diff --git a/tests/unit/qmap/test_qmap_q65_handoff.f90 b/tests/unit/qmap/test_qmap_q65_handoff.f90
new file mode 100644
index 00000000..96d68775
--- /dev/null
+++ b/tests/unit/qmap/test_qmap_q65_handoff.f90
@@ -0,0 +1,116 @@
+program test_qmap_q65_handoff
+ use iso_fortran_env, only: int16, real64
+ use cacb_mod, only: ca, init_cacb
+ use qmap_q65_samples_mod, only: build_q65_samples
+ implicit none
+
+ integer, parameter :: nfft2=336000, nfft1=5376000, k0=2600000, sample_rate=12000
+ real, parameter :: df=96000.0/nfft1
+ real, parameter :: filter_amplitude=100000000.0
+ integer(int16), allocatable :: desired(:), wave(:)
+ complex, allocatable :: spectrum(:)
+ integer :: i,j
+ real(real64) :: t, filter_reference_rms
+
+ allocate(desired(720000),wave(720000),spectrum(0:nfft2))
+ desired=0
+ do i=1,27*sample_rate
+ t=real(i-1,real64)/real(sample_rate,real64)
+ desired(i)=int(nint(100.0_real64*sin(2.0_real64*acos(-1.0_real64)*1000.0_real64*t)),int16)
+ enddo
+ do i=31*sample_rate+1,55*sample_rate
+ t=real(i-1,real64)/real(sample_rate,real64)
+ desired(i)=int(nint(100.0_real64*sin(2.0_real64*acos(-1.0_real64)*1200.0_real64*t)),int16)
+ enddo
+
+ do i=0,nfft2-1
+ j=nfft2-1-i
+ spectrum(j)=cmplx(real(desired(2*i+2)),real(desired(2*i+1)))
+ enddo
+ spectrum(nfft2)=0.
+ call four2a(spectrum,2*nfft2,1,-1,0)
+ call init_cacb(nfft1)
+ ca=0.
+ ca(k0:k0+nfft2-1)=0.5*spectrum(0:nfft2-1)
+
+ call build_q65_samples(k0,nfft2,df,0,wave)
+ call expect_samples(wave,desired,2*sample_rate+1,3*sample_rate,0, &
+ 'first half preserves 1000 Hz level and phase')
+ call require(mean_power(wave,27*sample_rate+1,30*sample_rate) < 1.0_real64, &
+ 'first-half guard is quiet')
+ call require(all(wave(2*nfft2+1:)==0), '56-second extraction has a zero tail')
+ call require(maxval(abs(int(wave))) < 1000, 'samples do not clip')
+
+ call build_q65_samples(k0,nfft2,df,1,wave)
+ call require(mean_power(wave,sample_rate/4+1,3*sample_rate/4) < 1.0_real64, &
+ 'second-half onset begins with quiet samples')
+ call expect_samples(wave,desired,sample_rate+sample_rate/4+1,sample_rate+3*sample_rate/4, &
+ 30*sample_rate,'second-half selection preserves 1200 Hz level, phase, and timing')
+ call require(mean_power(wave,25*sample_rate+1,30*sample_rate) < 1.0_real64, &
+ 'second-half tail is quiet')
+ call require(maxval(abs(int(wave))) < 1000, 'selected samples do not clip')
+
+ call set_filter_tone(1000)
+ call build_q65_samples(k0,nfft2,df,0,wave)
+ filter_reference_rms=sqrt(mean_power(wave,1,sample_rate))
+ call expect_filter(250,0.5_real64)
+ call expect_filter(2750,0.5_real64)
+ call expect_filter(3500,0.0_real64)
+
+ print '(a)', 'QMAP Q65 sample handoff contracts passed.'
+
+contains
+
+ subroutine expect_samples(actual,expected,first,last,offset,description)
+ integer(int16), intent(in) :: actual(:),expected(:)
+ integer, intent(in) :: first,last,offset
+ character(len=*), intent(in) :: description
+ integer :: index
+
+ do index=first,last
+ if(abs(int(actual(index))-int(expected(index+offset)))>2) then
+ print '(a,i0)', 'FAIL: '//description//' at sample ',index
+ error stop 1
+ endif
+ enddo
+ end subroutine expect_samples
+
+ subroutine set_filter_tone(frequency)
+ integer, intent(in) :: frequency
+ ca=0.
+ ca(k0+nint(real(frequency)/df))=cmplx(filter_amplitude,0.0)
+ end subroutine set_filter_tone
+
+ subroutine expect_filter(frequency,expected_ratio)
+ integer, intent(in) :: frequency
+ real(real64), intent(in) :: expected_ratio
+ real(real64) :: ratio
+ character(len=16) :: label
+
+ call set_filter_tone(frequency)
+ call build_q65_samples(k0,nfft2,df,0,wave)
+ ratio=sqrt(mean_power(wave,1,sample_rate))/filter_reference_rms
+ write(label,'(i0,a)') frequency,' Hz'
+ call require(abs(ratio-expected_ratio)<0.01_real64,'filter response at '//trim(label))
+ end subroutine expect_filter
+
+ real(real64) function mean_power(samples,first,last)
+ integer(int16), intent(in) :: samples(:)
+ integer, intent(in) :: first,last
+ integer :: index
+ mean_power=0.0_real64
+ do index=first,last
+ mean_power=mean_power+real(samples(index),real64)**2
+ enddo
+ mean_power=mean_power/real(last-first+1,real64)
+ end function mean_power
+
+ subroutine require(condition,description)
+ logical, intent(in) :: condition
+ character(len=*), intent(in) :: description
+ if (.not. condition) then
+ print '(a)', 'FAIL: '//description
+ error stop 1
+ endif
+ end subroutine require
+end program test_qmap_q65_handoff
diff --git a/tests/unit/qmap/test_qmap_symspec_contract.f90 b/tests/unit/qmap/test_qmap_symspec_contract.f90
new file mode 100644
index 00000000..2373185b
--- /dev/null
+++ b/tests/unit/qmap/test_qmap_symspec_contract.f90
@@ -0,0 +1,67 @@
+program test_qmap_symspec_contract
+ use iso_fortran_env, only: real32, real64
+ implicit none
+
+ integer, parameter :: nfft = 32768, sample_rate = 96000
+ integer, parameter :: bins(3) = [4000, 4300, 4600]
+ real(real32), parameter :: pi = 3.14159265358979323846_real32
+ real(real32) :: dd(2,60*sample_rate), ss(400,nfft), savg(nfft), junk(42)
+ real(real64) :: fcenter
+ integer :: nutc
+ common /datcom/ dd, ss, savg, fcenter, nutc, junk
+ real(real32) :: waterfall(nfft), pxdb, slimit, phase, powers(3)
+ complex(real32) :: x
+ logical(kind=1) :: lstrong(0:1023)
+ integer :: i, k, ihsym, nzap, nkhz
+
+ dd = 0.0
+ ss = 0.0
+ savg = 0.0
+ fcenter = 144.125_real64
+ do i = 1, nfft + 512
+ phase = 2.0_real32*pi*real(i-1, real32)/real(nfft, real32)
+ x = tone(bins(1), phase) + 2.0_real32*tone(bins(2), phase) &
+ + tone(bins(3), phase + 0.71_real32)
+ dd(1,i) = real(x)
+ dd(2,i) = aimag(x)
+ end do
+
+ k = nfft
+ ihsym = 0
+ nzap = 0
+ slimit = 0.0
+ call symspec(k, 1, 0, 40, sample_rate, pxdb, waterfall, nkhz, ihsym, nzap, slimit, lstrong)
+ call require(ihsym == 1, 'first completed row')
+ call require(abs(maxloc(ss(1,:), dim=1) - (bins(2) + 1)) <= 1, 'strongest frequency bin')
+ do i = 1, 3
+ powers(i) = ss(1,bins(i)+1)
+ call require(powers(i) > 0.0_real32, 'tone power')
+ call require(abs(savg(bins(i)+1) / powers(i) - 1.0_real32) < 0.001_real32, &
+ 'savg accumulates completed row')
+ end do
+ call require(abs(powers(2) / powers(1) - 4.0_real32) < 0.12_real32, 'amplitude squared power')
+ call require(abs(powers(3) / powers(1) - 1.0_real32) < 0.03_real32, 'phase preserves power')
+ print '(a)', 'QMAP symspec contract passed.'
+
+contains
+
+ function tone(bin, angle) result(value)
+ integer, intent(in) :: bin
+ real(real32), intent(in) :: angle
+ complex(real32) :: value
+ real(real32) :: theta
+
+ theta = real(bin, real32) * angle
+ value = 300.0_real32 * cmplx(cos(theta), -sin(theta), real32)
+ end function tone
+
+ subroutine require(condition, description)
+ logical, intent(in) :: condition
+ character(len=*), intent(in) :: description
+
+ if (.not. condition) then
+ print '(a)', 'FAIL: '//description
+ error stop 1
+ end if
+ end subroutine require
+end program test_qmap_symspec_contract