Skip to content

Commit

Permalink
treat 'Unknown Game' as NO_GAME_LOADED for state serialization (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamiras authored Jun 16, 2024
1 parent 2adf8f4 commit 8ac8aa4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/rc_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ void rc_client_get_user_game_summary(const rc_client_t* client, rc_client_user_g
}
#endif

if (!client->game)
if (!rc_client_is_game_loaded(client))
return;

rc_mutex_lock((rc_mutex_t*)&client->state.mutex); /* remove const cast for mutex access */
Expand Down Expand Up @@ -2861,7 +2861,7 @@ rc_client_async_handle_t* rc_client_begin_load_subset(rc_client_t* client, uint3
return client->state.external_client->begin_load_subset(client, subset_id, callback, callback_userdata);
#endif

if (!client->game) {
if (!rc_client_is_game_loaded(client)) {
callback(RC_NO_GAME_LOADED, rc_error_str(RC_NO_GAME_LOADED), client, callback_userdata);
return NULL;
}
Expand Down Expand Up @@ -5384,7 +5384,7 @@ size_t rc_client_progress_size(rc_client_t* client)
return client->state.external_client->progress_size();
#endif

if (!client->game)
if (!rc_client_is_game_loaded(client))
return 0;

rc_mutex_lock(&client->state.mutex);
Expand All @@ -5411,7 +5411,7 @@ int rc_client_serialize_progress_sized(rc_client_t* client, uint8_t* buffer, siz
return client->state.external_client->serialize_progress(buffer, buffer_size);
#endif

if (!client->game)
if (!rc_client_is_game_loaded(client))
return RC_NO_GAME_LOADED;

if (!buffer)
Expand Down Expand Up @@ -5535,7 +5535,7 @@ int rc_client_deserialize_progress_sized(rc_client_t* client, const uint8_t* ser
return client->state.external_client->deserialize_progress(serialized, serialized_size);
#endif

if (!client->game)
if (!rc_client_is_game_loaded(client))
return RC_NO_GAME_LOADED;

rc_mutex_lock(&client->state.mutex);
Expand Down
18 changes: 18 additions & 0 deletions test/test_rc_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -8675,6 +8675,23 @@ static void test_deserialize_progress_sized(void)
rc_client_destroy(g_client);
}

static void test_deserialize_progress_unknown_game(void)
{
uint8_t buffer[128];

g_client = mock_client_logged_in();

reset_mock_api_handlers();
mock_api_response("r=gameid&m=0123456789ABCDEF", "{\"Success\":true,\"GameID\":0}");
rc_client_begin_load_game(g_client, "0123456789ABCDEF", rc_client_callback_expect_unknown_game, g_callback_userdata);

ASSERT_NUM_EQUALS(rc_client_progress_size(g_client), 0);
ASSERT_NUM_EQUALS(rc_client_serialize_progress_sized(g_client, buffer, sizeof(buffer)), RC_NO_GAME_LOADED);
ASSERT_NUM_EQUALS(rc_client_deserialize_progress_sized(g_client, buffer, sizeof(buffer)), RC_NO_GAME_LOADED);

rc_client_destroy(g_client);
}

/* ----- processing required ----- */

static void test_processing_required(void)
Expand Down Expand Up @@ -9315,6 +9332,7 @@ void test_client(void) {
TEST(test_deserialize_progress_null);
TEST(test_deserialize_progress_invalid);
TEST(test_deserialize_progress_sized);
TEST(test_deserialize_progress_unknown_game);

/* processing required */
TEST(test_processing_required);
Expand Down

0 comments on commit 8ac8aa4

Please sign in to comment.