Skip to content

Commit eedde52

Browse files
rbernonjulliard
authored andcommitted
dmime/tests: Test that SendPMsg also converts reference time.
And avoid checking a possibly freed message.
1 parent 9a28dbf commit eedde52

File tree

1 file changed

+77
-32
lines changed

1 file changed

+77
-32
lines changed

dlls/dmime/tests/dmime.c

+77-32
Original file line numberDiff line numberDiff line change
@@ -1730,9 +1730,10 @@ static void test_performance_pmsg(void)
17301730
static const DWORD delivery_flags[] = {DMUS_PMSGF_TOOL_IMMEDIATE, DMUS_PMSGF_TOOL_QUEUE, DMUS_PMSGF_TOOL_ATTIME};
17311731
static const DWORD message_types[] = {DMUS_PMSGT_MIDI, DMUS_PMSGT_USER};
17321732
IDirectMusicPerformance *performance;
1733-
IDirectMusicGraph *graph;
1733+
IDirectMusicGraph *graph, *performance_graph;
17341734
IDirectMusicTool *tool;
17351735
DMUS_PMSG *msg, *clone;
1736+
MUSIC_TIME music_time;
17361737
REFERENCE_TIME time;
17371738
HRESULT hr;
17381739
DWORD ret;
@@ -1744,6 +1745,8 @@ static void test_performance_pmsg(void)
17441745
hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL, CLSCTX_INPROC_SERVER,
17451746
&IID_IDirectMusicPerformance, (void **)&performance);
17461747
ok(hr == S_OK, "got %#lx\n", hr);
1748+
hr = IDirectMusicPerformance_QueryInterface(performance, &IID_IDirectMusicGraph, (void **)&performance_graph);
1749+
ok(hr == S_OK, "got %#lx\n", hr);
17471750

17481751

17491752
hr = IDirectMusicPerformance_AllocPMsg(performance, 0, NULL);
@@ -1826,64 +1829,107 @@ static void test_performance_pmsg(void)
18261829
ok(hr == S_OK, "got %#lx\n", hr);
18271830

18281831

1832+
/* SendPMsg skips all the tools unless messages are stamped beforehand */
1833+
1834+
hr = IDirectMusicPerformance_AllocPMsg(performance, sizeof(DMUS_PMSG), &msg);
1835+
ok(hr == S_OK, "got %#lx\n", hr);
1836+
ok(msg->dwSize == sizeof(DMUS_PMSG), "got %ld\n", msg->dwSize);
1837+
msg->mtTime = 0;
1838+
msg->dwFlags = DMUS_PMSGF_MUSICTIME;
1839+
msg->dwType = DMUS_PMSGT_USER;
1840+
hr = IDirectMusicPerformance_SendPMsg(performance, msg);
1841+
ok(hr == S_OK, "got %#lx\n", hr);
1842+
1843+
ret = test_tool_wait_message(tool, 10, &msg);
1844+
ok(ret == WAIT_TIMEOUT, "got %#lx\n", ret);
1845+
ok(!msg, "got %p\n", msg);
1846+
1847+
1848+
/* SendPMsg converts music time to reference time if it is missing */
1849+
1850+
hr = IDirectMusicPerformance_AllocPMsg(performance, sizeof(DMUS_PMSG), &msg);
1851+
ok(hr == S_OK, "got %#lx\n", hr);
1852+
ok(msg->dwSize == sizeof(DMUS_PMSG), "got %ld\n", msg->dwSize);
1853+
msg->mtTime = 500;
1854+
msg->dwFlags = DMUS_PMSGF_MUSICTIME;
1855+
msg->dwType = DMUS_PMSGT_USER;
1856+
hr = IDirectMusicGraph_StampPMsg(performance_graph, msg);
1857+
ok(hr == S_OK, "got %#lx\n", hr);
1858+
hr = IDirectMusicPerformance_SendPMsg(performance, msg);
1859+
ok(hr == S_OK, "got %#lx\n", hr);
1860+
1861+
ret = test_tool_wait_message(tool, 50, &msg);
1862+
todo_wine ok(!ret, "got %#lx\n", ret);
1863+
todo_wine ok(msg != NULL, "got %p\n", msg);
1864+
if (!msg) goto skip_rtime;
1865+
18291866
time = 0xdeadbeef;
18301867
hr = IDirectMusicPerformance_MusicToReferenceTime(performance, msg->mtTime, &time);
18311868
ok(hr == S_OK, "got %#lx\n", hr);
18321869
ok(msg->dwSize == sizeof(DMUS_PMSG), "got %ld\n", msg->dwSize);
18331870
todo_wine ok(msg->rtTime == time, "got %I64d\n", msg->rtTime);
18341871
ok(msg->mtTime == 500, "got %ld\n", msg->mtTime);
18351872
todo_wine ok(msg->dwFlags & DMUS_PMSGF_REFTIME, "got %#lx\n", msg->dwFlags);
1873+
todo_wine ok(msg->dwFlags & DMUS_PMSGF_MUSICTIME, "got %#lx\n", msg->dwFlags);
18361874
todo_wine ok(msg->dwFlags & (DMUS_PMSGF_TOOL_QUEUE | DMUS_PMSGF_TOOL_IMMEDIATE), "got %#lx\n", msg->dwFlags);
18371875
ok(!msg->dwPChannel, "got %ld\n", msg->dwPChannel);
18381876
ok(!msg->dwVirtualTrackID, "got %ld\n", msg->dwVirtualTrackID);
1839-
ok(!msg->pTool, "got %p\n", msg->pTool);
1840-
ok(!msg->pGraph, "got %p\n", msg->pGraph);
1841-
ok(!msg->dwType, "got %#lx\n", msg->dwType);
1877+
ok(msg->pTool == tool, "got %p\n", msg->pTool);
1878+
ok(msg->pGraph == performance_graph, "got %p\n", msg->pGraph);
1879+
ok(msg->dwType == DMUS_PMSGT_USER, "got %#lx\n", msg->dwType);
18421880
ok(!msg->dwVoiceID, "got %ld\n", msg->dwVoiceID);
18431881
ok(!msg->dwGroupID, "got %ld\n", msg->dwGroupID);
18441882
ok(!msg->punkUser, "got %p\n", msg->punkUser);
18451883

1846-
1847-
/* SendPMsg skips all the tools unless messages are stamped beforehand */
1848-
1849-
hr = IDirectMusicPerformance_AllocPMsg(performance, sizeof(DMUS_PMSG), &msg);
1850-
ok(hr == S_OK, "got %#lx\n", hr);
1851-
ok(msg->dwSize == sizeof(DMUS_PMSG), "got %ld\n", msg->dwSize);
1852-
msg->rtTime = time;
1853-
msg->dwFlags = DMUS_PMSGF_REFTIME;
1854-
msg->dwType = DMUS_PMSGT_USER;
1855-
hr = IDirectMusicPerformance_SendPMsg(performance, msg);
1884+
hr = IDirectMusicPerformance_FreePMsg(performance, msg);
18561885
ok(hr == S_OK, "got %#lx\n", hr);
18571886

1858-
ret = test_tool_wait_message(tool, 10, &msg);
1859-
ok(ret == WAIT_TIMEOUT, "got %#lx\n", ret);
1860-
ok(!msg, "got %p\n", msg);
18611887

1888+
skip_rtime:
1889+
/* SendPMsg converts reference time to music time if it is missing */
1890+
1891+
hr = IDirectMusicPerformance_GetTime(performance, &time, &music_time);
1892+
ok(hr == S_OK, "got %#lx\n", hr);
18621893

18631894
hr = IDirectMusicPerformance_AllocPMsg(performance, sizeof(DMUS_PMSG), &msg);
18641895
ok(hr == S_OK, "got %#lx\n", hr);
18651896
ok(msg->dwSize == sizeof(DMUS_PMSG), "got %ld\n", msg->dwSize);
18661897
msg->rtTime = time;
18671898
msg->dwFlags = DMUS_PMSGF_REFTIME;
18681899
msg->dwType = DMUS_PMSGT_USER;
1869-
1870-
hr = IDirectMusicPerformance_QueryInterface(performance, &IID_IDirectMusicGraph, (void **)&graph);
1900+
hr = IDirectMusicGraph_StampPMsg(performance_graph, msg);
18711901
ok(hr == S_OK, "got %#lx\n", hr);
1872-
hr = IDirectMusicGraph_StampPMsg(graph, msg);
1873-
ok(hr == S_OK, "got %#lx\n", hr);
1874-
IDirectMusicGraph_Release(graph);
1875-
18761902
hr = IDirectMusicPerformance_SendPMsg(performance, msg);
18771903
ok(hr == S_OK, "got %#lx\n", hr);
18781904

18791905
ret = test_tool_wait_message(tool, 50, &msg);
18801906
todo_wine ok(!ret, "got %#lx\n", ret);
18811907
todo_wine ok(msg != NULL, "got %p\n", msg);
1882-
if (!msg) hr = S_OK;
1883-
else hr = IDirectMusicPerformance_FreePMsg(performance, msg);
1908+
if (!msg) goto skip_mtime;
1909+
1910+
music_time = 0xdeadbeef;
1911+
hr = IDirectMusicPerformance_ReferenceToMusicTime(performance, msg->rtTime, &music_time);
1912+
ok(hr == S_OK, "got %#lx\n", hr);
1913+
ok(msg->dwSize == sizeof(DMUS_PMSG), "got %ld\n", msg->dwSize);
1914+
todo_wine ok(msg->rtTime == time, "got %I64d\n", msg->rtTime);
1915+
todo_wine ok(msg->mtTime == music_time, "got %ld\n", msg->mtTime);
1916+
todo_wine ok(msg->dwFlags & DMUS_PMSGF_REFTIME, "got %#lx\n", msg->dwFlags);
1917+
todo_wine ok(msg->dwFlags & DMUS_PMSGF_MUSICTIME, "got %#lx\n", msg->dwFlags);
1918+
todo_wine ok(msg->dwFlags & (DMUS_PMSGF_TOOL_QUEUE | DMUS_PMSGF_TOOL_IMMEDIATE), "got %#lx\n", msg->dwFlags);
1919+
ok(!msg->dwPChannel, "got %ld\n", msg->dwPChannel);
1920+
ok(!msg->dwVirtualTrackID, "got %ld\n", msg->dwVirtualTrackID);
1921+
ok(msg->pTool == tool, "got %p\n", msg->pTool);
1922+
ok(msg->pGraph == performance_graph, "got %p\n", msg->pGraph);
1923+
ok(msg->dwType == DMUS_PMSGT_USER, "got %#lx\n", msg->dwType);
1924+
ok(!msg->dwVoiceID, "got %ld\n", msg->dwVoiceID);
1925+
ok(!msg->dwGroupID, "got %ld\n", msg->dwGroupID);
1926+
ok(!msg->punkUser, "got %p\n", msg->punkUser);
1927+
1928+
hr = IDirectMusicPerformance_FreePMsg(performance, msg);
18841929
ok(hr == S_OK, "got %#lx\n", hr);
18851930

18861931

1932+
skip_mtime:
18871933
for (i = 0; i < ARRAY_SIZE(delivery_flags); i++)
18881934
{
18891935
DWORD duration = 0;
@@ -1896,12 +1942,8 @@ static void test_performance_pmsg(void)
18961942
msg->rtTime = time + 150 * 10000;
18971943
msg->dwFlags = DMUS_PMSGF_REFTIME;
18981944
msg->dwType = DMUS_PMSGT_USER;
1899-
1900-
hr = IDirectMusicPerformance_QueryInterface(performance, &IID_IDirectMusicGraph, (void **)&graph);
1901-
ok(hr == S_OK, "got %#lx\n", hr);
1902-
hr = IDirectMusicGraph_StampPMsg(graph, msg);
1945+
hr = IDirectMusicGraph_StampPMsg(performance_graph, msg);
19031946
ok(hr == S_OK, "got %#lx\n", hr);
1904-
IDirectMusicGraph_Release(graph);
19051947

19061948
msg->dwFlags &= ~(DMUS_PMSGF_TOOL_IMMEDIATE | DMUS_PMSGF_TOOL_QUEUE | DMUS_PMSGF_TOOL_ATTIME);
19071949
msg->dwFlags |= delivery_flags[i];
@@ -1921,8 +1963,8 @@ static void test_performance_pmsg(void)
19211963
switch (delivery_flags[i])
19221964
{
19231965
case DMUS_PMSGF_TOOL_IMMEDIATE: todo_wine ok(duration <= 50, "got %lu\n", duration); break;
1924-
case DMUS_PMSGF_TOOL_QUEUE: todo_wine ok(duration >= 50 && duration <= 100, "got %lu\n", duration); break;
1925-
case DMUS_PMSGF_TOOL_ATTIME: todo_wine ok(duration >= 150 && duration <= 500, "got %lu\n", duration); break;
1966+
case DMUS_PMSGF_TOOL_QUEUE: todo_wine ok(duration >= 50 && duration <= 125, "got %lu\n", duration); break;
1967+
case DMUS_PMSGF_TOOL_ATTIME: todo_wine ok(duration >= 125 && duration <= 500, "got %lu\n", duration); break;
19261968
}
19271969
}
19281970

@@ -1931,7 +1973,10 @@ static void test_performance_pmsg(void)
19311973
ok(hr == S_OK, "got %#lx\n", hr);
19321974

19331975

1976+
IDirectMusicGraph_Release(performance_graph);
1977+
19341978
IDirectMusicPerformance_Release(performance);
1979+
IDirectMusicTool_Release(tool);
19351980
}
19361981

19371982
START_TEST(dmime)

0 commit comments

Comments
 (0)