From d2092b8641b4b2d36d9a94a506ff7cd371529cc2 Mon Sep 17 00:00:00 2001 From: Daniel Collins Date: Wed, 29 Aug 2018 00:25:25 +0100 Subject: [PATCH] Added tests for DirectPlay8Address::GetURL[AW]() and component ordering. --- tests/DirectPlay8Address.cpp | 232 +++++++++++++++++++++++++++++++++++ 1 file changed, 232 insertions(+) diff --git a/tests/DirectPlay8Address.cpp b/tests/DirectPlay8Address.cpp index b38cb65..12907b3 100644 --- a/tests/DirectPlay8Address.cpp +++ b/tests/DirectPlay8Address.cpp @@ -60,6 +60,34 @@ TEST_F(DirectPlay8AddressInitial, GetUserData) ASSERT_EQ(idp8->GetUserData(buf, &size), DPNERR_DOESNOTEXIST); } +TEST_F(DirectPlay8AddressInitial, GetURLW) +{ + wchar_t buf[256] = { 0xFF }; + DWORD size = 256; + + ASSERT_EQ(idp8->GetURLW(buf, &size), S_OK); + + const wchar_t EXPECT[] = L"x-directplay:/"; + const DWORD EXPECT_CHARS = sizeof(EXPECT) / sizeof(wchar_t); + + EXPECT_EQ(size, EXPECT_CHARS); + EXPECT_EQ(std::wstring(buf, size), std::wstring(EXPECT, EXPECT_CHARS)); +} + +TEST_F(DirectPlay8AddressInitial, GetURLA) +{ + char buf[256] = { 0x7F }; + DWORD size = 256; + + ASSERT_EQ(idp8->GetURLA(buf, &size), S_OK); + + const char EXPECT[] = "x-directplay:/"; + const DWORD EXPECT_CHARS = sizeof(EXPECT); + + EXPECT_EQ(size, EXPECT_CHARS); + EXPECT_EQ(std::string(buf, size), std::string(EXPECT, EXPECT_CHARS)); +} + class DirectPlay8AddressWithWStringComponent: public DirectPlay8AddressInitial { protected: @@ -263,6 +291,20 @@ TEST_F(DirectPlay8AddressWithWStringComponent, Clear) } } +TEST_F(DirectPlay8AddressWithWStringComponent, GetURLW) +{ + wchar_t buf[256] = { 0xFF }; + DWORD size = 256; + + ASSERT_EQ(idp8->GetURLW(buf, &size), S_OK); + + const wchar_t EXPECT[] = L"x-directplay:/key=wide%20string%20value"; + const DWORD EXPECT_CHARS = sizeof(EXPECT) / sizeof(wchar_t); + + EXPECT_EQ(size, EXPECT_CHARS); + EXPECT_EQ(std::wstring(buf, size), std::wstring(EXPECT, EXPECT_CHARS)); +} + class DirectPlay8AddressWithAStringComponent: public DirectPlay8AddressInitial { protected: @@ -334,6 +376,20 @@ TEST_F(DirectPlay8AddressWithAStringComponent, ComponentByNameBufferSizeBig) EXPECT_EQ(std::string((const char*)(vbuf), vsize), std::string(REFVAL, REFVSIZE)); } +TEST_F(DirectPlay8AddressWithAStringComponent, GetURLW) +{ + wchar_t buf[256] = { 0xFF }; + DWORD size = 256; + + ASSERT_EQ(idp8->GetURLW(buf, &size), S_OK); + + const wchar_t EXPECT[] = L"x-directplay:/key=ASCII%20string%20value"; + const DWORD EXPECT_CHARS = sizeof(EXPECT) / sizeof(wchar_t); + + EXPECT_EQ(size, EXPECT_CHARS); + EXPECT_EQ(std::wstring(buf, size), std::wstring(EXPECT, EXPECT_CHARS)); +} + class DirectPlay8AddressWithDWORDComponent: public DirectPlay8AddressInitial { protected: @@ -405,6 +461,20 @@ TEST_F(DirectPlay8AddressWithDWORDComponent, ComponentByNameBufferSizeBig) EXPECT_EQ(*(DWORD*)(vbuf), REFVAL); } +TEST_F(DirectPlay8AddressWithDWORDComponent, GetURLW) +{ + wchar_t buf[256] = { 0xFF }; + DWORD size = 256; + + ASSERT_EQ(idp8->GetURLW(buf, &size), S_OK); + + const wchar_t EXPECT[] = L"x-directplay:/key=245874415"; + const DWORD EXPECT_CHARS = sizeof(EXPECT) / sizeof(wchar_t); + + EXPECT_EQ(size, EXPECT_CHARS); + EXPECT_EQ(std::wstring(buf, size), std::wstring(EXPECT, EXPECT_CHARS)); +} + class DirectPlay8AddressWithGUIDComponent: public DirectPlay8AddressInitial { protected: @@ -476,6 +546,20 @@ TEST_F(DirectPlay8AddressWithGUIDComponent, ComponentByNameBufferSizeBig) EXPECT_EQ(*(GUID*)(vbuf), REFVAL); } +TEST_F(DirectPlay8AddressWithGUIDComponent, GetURLW) +{ + wchar_t buf[256] = { 0xFF }; + DWORD size = 256; + + ASSERT_EQ(idp8->GetURLW(buf, &size), S_OK); + + const wchar_t EXPECT[] = L"x-directplay:/key=%7B934A9523-A3CA-4BC5-ADA0-D6D95D979421%7D"; + const DWORD EXPECT_CHARS = sizeof(EXPECT) / sizeof(wchar_t); + + EXPECT_EQ(size, EXPECT_CHARS); + EXPECT_EQ(std::wstring(buf, size), std::wstring(EXPECT, EXPECT_CHARS)); +} + class DirectPlay8AddressSetSP: public DirectPlay8AddressInitial { protected: @@ -583,6 +667,20 @@ TEST_F(DirectPlay8AddressSetDevice, GetComponentByName) EXPECT_EQ(vbuf, CLSID_DP8SP_BLUETOOTH); } +TEST_F(DirectPlay8AddressSetDevice, GetURLW) +{ + wchar_t buf[256] = { 0xFF }; + DWORD size = 256; + + ASSERT_EQ(idp8->GetURLW(buf, &size), S_OK); + + const wchar_t EXPECT[] = L"x-directplay:/device=%7B995513AF-3027-4B9A-956E-C772B3F78006%7D"; + const DWORD EXPECT_CHARS = sizeof(EXPECT) / sizeof(wchar_t); + + EXPECT_EQ(size, EXPECT_CHARS); + EXPECT_EQ(std::wstring(buf, size), std::wstring(EXPECT, EXPECT_CHARS)); +} + class DirectPlay8AddressSetUserData: public DirectPlay8AddressInitial { protected: @@ -647,6 +745,24 @@ TEST_F(DirectPlay8AddressSetUserData, GetNumComponents) EXPECT_EQ(num, (DWORD)(0)); } +TEST_F(DirectPlay8AddressSetUserData, GetURLW) +{ + wchar_t buf[256] = { 0xFF }; + DWORD size = 256; + + ASSERT_EQ(idp8->GetURLW(buf, &size), S_OK); + + /* BUG: This doesn't match the URL scheme described by the DirectX SDK documentation, but + * it matches what DirectX produces. + */ + + const wchar_t EXPECT[] = L"x-directplay:/%00%01%02%030123456789ABCDEF%FF%FE\0"; + const DWORD EXPECT_CHARS = sizeof(EXPECT) / sizeof(wchar_t); + + EXPECT_EQ(size, EXPECT_CHARS); + EXPECT_EQ(std::wstring(buf, size), std::wstring(EXPECT, EXPECT_CHARS)); +} + TEST_F(DirectPlay8AddressSetUserData, Clear) { ASSERT_EQ(idp8->Clear(), S_OK); @@ -656,3 +772,119 @@ TEST_F(DirectPlay8AddressSetUserData, Clear) ASSERT_EQ(idp8->GetUserData(buf, &size), DPNERR_DOESNOTEXIST); } + +class DirectPlay8AddressIPConstructed: public DirectPlay8AddressInitial +{ + protected: + virtual void SetUp() override + { + ASSERT_EQ(idp8->SetDevice(&CLSID_DP8SP_BLUETOOTH), S_OK); + ASSERT_EQ(idp8->SetSP(&CLSID_DP8SP_TCPIP), S_OK); + + DWORD port = 1234; + ASSERT_EQ(idp8->AddComponent(DPNA_KEY_PORT, &port, sizeof(port), DPNA_DATATYPE_DWORD), S_OK); + + const char user_data[] = "user data"; + ASSERT_EQ(idp8->SetUserData(user_data, strlen(user_data)), S_OK); + } +}; + +TEST_F(DirectPlay8AddressIPConstructed, GetNumComponents) +{ + DWORD num; + ASSERT_EQ(idp8->GetNumComponents(&num), S_OK); + EXPECT_EQ(num, (DWORD)(3)); +} + +TEST_F(DirectPlay8AddressIPConstructed, GetComponentByIndex0) +{ + wchar_t kbuf[64]; + unsigned char vbuf[64]; + + DWORD ksize = 64; + DWORD vsize = 64; + DWORD type; + + ASSERT_EQ(idp8->GetComponentByIndex(0, kbuf, &ksize, vbuf, &vsize, &type), S_OK); + + ASSERT_EQ(std::wstring(kbuf, ksize), std::wstring(L"provider", 9)); + + EXPECT_EQ(type, (DWORD)(DPNA_DATATYPE_GUID)); + + EXPECT_EQ(vsize, sizeof(GUID)); + EXPECT_EQ(*(GUID*)(vbuf), CLSID_DP8SP_TCPIP); +} + +TEST_F(DirectPlay8AddressIPConstructed, GetComponentByIndex1) +{ + wchar_t kbuf[64]; + unsigned char vbuf[64]; + + DWORD ksize = 64; + DWORD vsize = 64; + DWORD type; + + ASSERT_EQ(idp8->GetComponentByIndex(1, kbuf, &ksize, vbuf, &vsize, &type), S_OK); + + ASSERT_EQ(std::wstring(kbuf, ksize), std::wstring(L"device", 7)); + + EXPECT_EQ(type, (DWORD)(DPNA_DATATYPE_GUID)); + + EXPECT_EQ(vsize, sizeof(GUID)); + EXPECT_EQ(*(GUID*)(vbuf), CLSID_DP8SP_BLUETOOTH); +} + +TEST_F(DirectPlay8AddressIPConstructed, GetComponentByIndex2) +{ + wchar_t kbuf[64]; + unsigned char vbuf[64]; + + DWORD ksize = 64; + DWORD vsize = 64; + DWORD type; + + ASSERT_EQ(idp8->GetComponentByIndex(2, kbuf, &ksize, vbuf, &vsize, &type), S_OK); + + ASSERT_EQ(std::wstring(kbuf, ksize), std::wstring(L"port", 5)); + + EXPECT_EQ(type, (DWORD)(DPNA_DATATYPE_DWORD)); + + EXPECT_EQ(vsize, sizeof(DWORD)); + EXPECT_EQ(*(DWORD*)(vbuf), (DWORD)(1234)); +} + +TEST_F(DirectPlay8AddressIPConstructed, GetURLW) +{ + wchar_t buf[256] = { 0xFF }; + DWORD size = 256; + + ASSERT_EQ(idp8->GetURLW(buf, &size), S_OK); + + /* BUG: This doesn't match the URL scheme described by the DirectX SDK documentation, but + * it matches what DirectX produces. + */ + + const wchar_t EXPECT[] = L"x-directplay:/provider=%7BEBFE7BA0-628D-11D2-AE0F-006097B01411%7D;device=%7B995513AF-3027-4B9A-956E-C772B3F78006%7D;port=1234user%20data\0"; + const DWORD EXPECT_CHARS = sizeof(EXPECT) / sizeof(wchar_t); + + EXPECT_EQ(size, EXPECT_CHARS); + EXPECT_EQ(std::wstring(buf, size), std::wstring(EXPECT, EXPECT_CHARS)); +} + +TEST_F(DirectPlay8AddressIPConstructed, GetURLA) +{ + char buf[256] = { 0x7F }; + DWORD size = 256; + + ASSERT_EQ(idp8->GetURLA(buf, &size), S_OK); + + /* BUG: This doesn't match the URL scheme described by the DirectX SDK documentation, but + * it matches what DirectX produces. + */ + + const char EXPECT[] = "x-directplay:/provider=%7BEBFE7BA0-628D-11D2-AE0F-006097B01411%7D;device=%7B995513AF-3027-4B9A-956E-C772B3F78006%7D;port=1234user%20data\0"; + const DWORD EXPECT_CHARS = sizeof(EXPECT); + + EXPECT_EQ(size, EXPECT_CHARS); + EXPECT_EQ(std::string(buf, size), std::string(EXPECT, EXPECT_CHARS)); +}