Skip to content
This repository has been archived by the owner on Jul 16, 2020. It is now read-only.

[Batch - PART2] Batch operations and custom data #80

Open
wants to merge 8 commits into
base: feat/control-updates
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 167 additions & 7 deletions Tests/Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,6 @@ TEST_CLASS(Tests)

ASSERT_NOERR(do_auth(clientId, "", auth));

interactive_session session;
Logger::WriteMessage("Connecting...");
ASSERT_NOERR(interactive_open_session(&session));
ASSERT_NOERR(interactive_set_error_handler(session, handle_error_assert));
Expand All @@ -559,6 +558,7 @@ TEST_CLASS(Tests)

Logger::WriteMessage("Disconnecting...");
interactive_close_session(session);
session = nullptr;

Assert::IsTrue(0 == err);
}
Expand All @@ -577,7 +577,6 @@ TEST_CLASS(Tests)

ASSERT_NOERR(do_auth(clientId, clientSecret, auth));

interactive_session session;
Logger::WriteMessage("Connecting...");
ASSERT_NOERR(interactive_open_session(&session));
ASSERT_NOERR(interactive_set_error_handler(session, handle_error_assert));
Expand All @@ -594,6 +593,7 @@ TEST_CLASS(Tests)

Logger::WriteMessage("Disconnecting...");
interactive_close_session(session);
session = nullptr;

Assert::IsTrue(0 == err);
}
Expand All @@ -611,7 +611,6 @@ TEST_CLASS(Tests)

ASSERT_NOERR(do_auth(clientId, "", auth));

interactive_session session;
ASSERT_NOERR(interactive_open_session(&session));
ASSERT_NOERR(interactive_set_error_handler(session, handle_error_assert));
ASSERT_NOERR(interactive_set_input_handler(session, handle_input));
Expand All @@ -637,6 +636,7 @@ TEST_CLASS(Tests)

Logger::WriteMessage("Disconnecting...");
interactive_close_session(session);
session = nullptr;

Assert::IsTrue(0 == err);
}
Expand All @@ -654,7 +654,6 @@ TEST_CLASS(Tests)

ASSERT_NOERR(do_auth(clientId, "", auth));

interactive_session session;
ASSERT_NOERR(interactive_open_session(&session));
ASSERT_NOERR(interactive_set_error_handler(session, handle_error_assert));
interactive_set_state_changed_handler(session, [](void* context, interactive_session session, interactive_state prevState, interactive_state newState)
Expand Down Expand Up @@ -691,6 +690,7 @@ TEST_CLASS(Tests)

Logger::WriteMessage("Disconnecting...");
interactive_close_session(session);
session = nullptr;

Assert::IsTrue(0 == err);
}
Expand All @@ -708,7 +708,6 @@ TEST_CLASS(Tests)

ASSERT_NOERR(do_auth(clientId, "", auth));

interactive_session session;
Logger::WriteMessage("Connecting...");
ASSERT_NOERR(interactive_open_session(&session));
ASSERT_NOERR(interactive_set_error_handler(session, handle_error_assert));
Expand Down Expand Up @@ -795,6 +794,7 @@ TEST_CLASS(Tests)

Logger::WriteMessage("Disconnecting...");
interactive_close_session(session);
session = nullptr;

Assert::IsTrue(0 == err);
}
Expand All @@ -812,7 +812,6 @@ TEST_CLASS(Tests)

ASSERT_NOERR(do_auth(clientId, "", auth));

interactive_session session;
Logger::WriteMessage("Connecting...");
ASSERT_NOERR(interactive_open_session(&session));
ASSERT_NOERR(interactive_set_error_handler(session, handle_error_assert));
Expand Down Expand Up @@ -857,6 +856,7 @@ TEST_CLASS(Tests)

Logger::WriteMessage("Disconnecting...");
interactive_close_session(session);
session = nullptr;

Assert::IsTrue(0 == err);
}
Expand All @@ -874,7 +874,6 @@ TEST_CLASS(Tests)

ASSERT_NOERR(do_auth(clientId, "", auth));

interactive_session session;
ASSERT_NOERR(interactive_open_session(&session));

std::string controlId = "GiveHealth";
Expand Down Expand Up @@ -929,6 +928,167 @@ TEST_CLASS(Tests)

Logger::WriteMessage("Disconnecting...");
interactive_close_session(session);
session = nullptr;
}

TEST_METHOD(ControlBatchTest)
{
g_start = std::chrono::high_resolution_clock::now();
interactive_config_debug(interactive_debug_trace, handle_debug_message);

int err = 0;
std::string clientId = CLIENT_ID;
std::string versionId = VERSION_ID;
std::string shareCode = SHARE_CODE;
std::string auth;

ASSERT_NOERR(do_auth(clientId, "", auth));

Logger::WriteMessage("Connecting...");
ASSERT_NOERR(interactive_open_session(&session));
ASSERT_NOERR(interactive_set_error_handler(session, handle_error_assert));
ASSERT_NOERR(interactive_connect(session, auth.c_str(), versionId.c_str(), shareCode.c_str(), true));
ASSERT_NOERR(interactive_set_participants_changed_handler(session, handle_participants_changed));

// Simulate 60 frames/sec for 1 second.
const int fps = 60;
const int seconds = 1;
for (int i = 0; i < fps * seconds; ++i)
{
ASSERT_NOERR(interactive_run(session, 1));
std::this_thread::sleep_for(std::chrono::milliseconds(1000 / fps));
}

interactive_batch_op batch;
ASSERT_NOERR(interactive_control_batch_begin(session, "default", &batch));

interactive_batch_entry entry;
ASSERT_NOERR(interactive_control_batch_add(batch, "GiveHealth", &entry));
ASSERT_NOERR(interactive_batch_add_param_str(&entry.obj, "foo", "bar"));
ASSERT_NOERR(interactive_batch_add_param_uint(&entry.obj, "number", 42));

{
// Invalid Entry
interactive_batch_entry entryDupe;
ASSERT_ERR(MIXER_ERROR_DUPLICATE_ENTRY, interactive_control_batch_add(batch, "GiveHealth", &entryDupe));
ASSERT_ERR(MIXER_ERROR_INVALID_BATCH_TYPE, interactive_participant_batch_add(batch, "GiveHealth", &entryDupe));
}

interactive_batch_array entryArray;
interactive_batch_add_param_array(&entry.obj, "array", &entryArray);

interactive_batch_object entryArrayObject;
interactive_batch_array_push_object(&entryArray, &entryArrayObject);
ASSERT_NOERR(interactive_batch_add_param_str(&entryArrayObject, "foo", "bar"));
ASSERT_NOERR(interactive_batch_add_param_uint(&entryArrayObject, "number", 42));

ASSERT_NOERR(interactive_batch_array_push_str(&entryArray, "bar"));
ASSERT_NOERR(interactive_batch_array_push_uint(&entryArray, 42));

interactive_batch_array entryArrayArray;
interactive_batch_array_push_array(&entryArray, &entryArrayArray);

interactive_batch_object entryArrayArrayObject;
interactive_batch_array_push_object(&entryArrayArray, &entryArrayArrayObject);
ASSERT_NOERR(interactive_batch_add_param_str(&entryArrayArrayObject, "foo", "bar"));
ASSERT_NOERR(interactive_batch_add_param_uint(&entryArrayArrayObject, "number", 42));

ASSERT_NOERR(interactive_batch_array_push_str(&entryArrayArray, "bar"));
ASSERT_NOERR(interactive_batch_array_push_uint(&entryArrayArray, 42));

interactive_batch_object entryObject;
ASSERT_NOERR(interactive_batch_add_param_object(&entry.obj, "object", &entryObject));
ASSERT_NOERR(interactive_batch_add_param_str(&entryObject, "foo", "bar"));
ASSERT_NOERR(interactive_batch_add_param_uint(&entryObject, "number", 42));
ASSERT_NOERR(interactive_control_batch_commit(batch));
ASSERT_NOERR(interactive_batch_close(batch));

// Simulate 60 frames/sec for 1 second.
for (int i = 0; i < fps * seconds; ++i)
{
ASSERT_NOERR(interactive_run(session, 1));
std::this_thread::sleep_for(std::chrono::milliseconds(1000 / fps));
}

Logger::WriteMessage("Validating custom properties");
ASSERT_NOERR(interactive_get_scenes(session, [](void* context, interactive_session session, interactive_scene* scene)
{
char foo[4];
size_t nameLength = 4;
int number = 0;
memset(foo, 0, sizeof(char[4]));
Assert::AreEqual((int)MIXER_OK, interactive_control_get_property_string(session, "GiveHealth", "foo", foo, &nameLength));
Assert::AreEqual((int)MIXER_OK, interactive_control_get_property_int(session, "GiveHealth", "number", &number));
Assert::AreEqual("bar", foo);
Assert::AreEqual(42, number);
memset(foo, 0, sizeof(char[4]));
number = 0;
Assert::AreEqual((int)MIXER_OK, interactive_control_get_property_string(session, "GiveHealth", "array/0/foo", foo, &nameLength));
Assert::AreEqual((int)MIXER_OK, interactive_control_get_property_int(session, "GiveHealth", "array/0/number", &number));
Assert::AreEqual("bar", foo);
Assert::AreEqual(42, number);
memset(foo, 0, sizeof(char[4]));
number = 0;
Assert::AreEqual((int)MIXER_OK, interactive_control_get_property_string(session, "GiveHealth", "array/1", foo, &nameLength));
Assert::AreEqual((int)MIXER_OK, interactive_control_get_property_int(session, "GiveHealth", "array/2", &number));
Assert::AreEqual("bar", foo);
Assert::AreEqual(42, number);
memset(foo, 0, sizeof(char[4]));
number = 0;
Assert::AreEqual((int)MIXER_OK, interactive_control_get_property_string(session, "GiveHealth", "array/3/0/foo", foo, &nameLength));
Assert::AreEqual((int)MIXER_OK, interactive_control_get_property_int(session, "GiveHealth", "array/3/0/number", &number));
Assert::AreEqual("bar", foo);
Assert::AreEqual(42, number);
memset(foo, 0, sizeof(char[4]));
number = 0;
Assert::AreEqual((int)MIXER_OK, interactive_control_get_property_string(session, "GiveHealth", "array/3/1", foo, &nameLength));
Assert::AreEqual((int)MIXER_OK, interactive_control_get_property_int(session, "GiveHealth", "array/3/2", &number));
Assert::AreEqual("bar", foo);
Assert::AreEqual(42, number);
memset(foo, 0, sizeof(char[4]));
number = 0;
Assert::AreEqual((int)MIXER_OK, interactive_control_get_property_string(session, "GiveHealth", "object/foo", foo, &nameLength));
Assert::AreEqual((int)MIXER_OK, interactive_control_get_property_int(session, "GiveHealth", "object/number", &number));
Assert::AreEqual("bar", foo);
Assert::AreEqual(42, number);
}));

for (int i = 0; i < fps * seconds; ++i)
{
ASSERT_NOERR(interactive_run(session, 1));
std::this_thread::sleep_for(std::chrono::milliseconds(1000 / fps));
}

Logger::WriteMessage("Disconnecting...");
interactive_close_session(session);
session = nullptr;

Assert::IsTrue(0 == err);
}

TEST_METHOD_CLEANUP(CleanupSession) {
if (nullptr != session)
{
try {
Logger::WriteMessage("Disconnecting in cleanup...");
interactive_close_session(session);
}
catch (std::exception e) {
Logger::WriteMessage((std::string("Error in cleanup handler: ") + e.what()).c_str());
}
catch (std::string e) {
Logger::WriteMessage(("Error in cleanup handler: " + e).c_str());
}
catch (...)
{
Logger::WriteMessage("Unknown error in cleanup handler. You should debug this.");
}
}

session = nullptr;
}

private:
interactive_session session = nullptr;
};
}
7 changes: 7 additions & 0 deletions builds/Interactivity.UWP.Cpp/Interactivity.UWP.Cpp.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\source\internal\interactive_batch.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\source\internal\interactive_control.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
Expand Down Expand Up @@ -125,6 +131,7 @@
<ClInclude Include="..\..\source\internal\common.h" />
<ClInclude Include="..\..\source\internal\debugging.h" />
<ClInclude Include="..\..\source\internal\http_client.h" />
<ClInclude Include="..\..\source\internal\interactive_batch.h" />
<ClInclude Include="..\..\source\internal\interactive_session.h" />
<ClInclude Include="..\..\source\internal\websocket.h" />
<ClInclude Include="..\..\source\internal\winapp_http_client.h" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
<ClCompile Include="..\..\Source\interactivity.cpp">
<Filter>C++ Source</Filter>
</ClCompile>
<ClCompile Include="..\..\source\internal\interactive_batch.cpp">
<Filter>C++ Source</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\source\interactivity.h">
Expand All @@ -68,5 +71,8 @@
<ClInclude Include="..\..\source\internal\debugging.h">
<Filter>Includes</Filter>
</ClInclude>
<ClInclude Include="..\..\source\internal\interactive_batch.h">
<Filter>Includes</Filter>
</ClInclude>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\source\internal\interactive_batch.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\source\internal\interactive_control.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
Expand Down Expand Up @@ -121,6 +127,7 @@
<ClInclude Include="..\..\source\internal\common.h" />
<ClInclude Include="..\..\source\internal\debugging.h" />
<ClInclude Include="..\..\source\internal\http_client.h" />
<ClInclude Include="..\..\source\internal\interactive_batch.h" />
<ClInclude Include="..\..\source\internal\interactive_session.h" />
<ClInclude Include="..\..\source\internal\json.h" />
<ClInclude Include="..\..\source\internal\websocket.h" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
<ClCompile Include="..\..\source\internal\win_websocket.cpp">
<Filter>C++ Source</Filter>
</ClCompile>
<ClCompile Include="..\..\source\internal\interactive_batch.cpp">
<Filter>C++ Source</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\source\interactivity.h">
Expand All @@ -71,5 +74,8 @@
<ClInclude Include="..\..\source\internal\websocket.h">
<Filter>Includes</Filter>
</ClInclude>
<ClInclude Include="..\..\source\internal\interactive_batch.h">
<Filter>Includes</Filter>
</ClInclude>
</ItemGroup>
</Project>
5 changes: 5 additions & 0 deletions builds/Interactivity.Xbox.Cpp/Interactivity.Xbox.Cpp.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
<ClCompile Include="..\..\source\internal\interactive_auth.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Durango'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Durango'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\source\internal\interactive_batch.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Durango'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Durango'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\source\internal\interactive_control.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Durango'">true</ExcludedFromBuild>
Expand Down Expand Up @@ -98,6 +102,7 @@
<ClInclude Include="..\..\source\interactivity.h" />
<ClInclude Include="..\..\source\internal\common.h" />
<ClInclude Include="..\..\source\internal\http_client.h" />
<ClInclude Include="..\..\source\internal\interactive_batch.h" />
<ClInclude Include="..\..\source\internal\interactive_session.h" />
<ClInclude Include="..\..\source\internal\winapp_http_client.h" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
<ClCompile Include="..\..\source\internal\winapp_http_client.cpp">
<Filter>C++ Source</Filter>
</ClCompile>
<ClCompile Include="..\..\source\internal\interactive_batch.cpp">
<Filter>C++ Source</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\source\interactivity.h">
Expand All @@ -59,5 +62,8 @@
<ClInclude Include="..\..\source\internal\winapp_http_client.h">
<Filter>Includes</Filter>
</ClInclude>
<ClInclude Include="..\..\source\internal\interactive_batch.h">
<Filter>Includes</Filter>
</ClInclude>
</ItemGroup>
</Project>
Loading