Skip to content

Commit

Permalink
Add tests for non-Steam shortcut app IDs
Browse files Browse the repository at this point in the history
As of #78, there are now two methods to derive the pseudo app ID for
non-Steam shortcuts. Ensure both methods are tested.
  • Loading branch information
Matoking committed Dec 28, 2020
1 parent fff5882 commit 040b43d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
7 changes: 6 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def shortcut_factory(steam_dir, steam_user):
"""
shortcuts_by_user = defaultdict(list)

def func(install_dir, name, steamid64=None):
def func(install_dir, name, steamid64=None, appid_in_vdf=False):
if not steamid64:
steamid64 = steam_user

Expand Down Expand Up @@ -169,6 +169,11 @@ def func(install_dir, name, steamid64=None):
result = result | 0x80000000
shortcut_id = (result << 32) | 0x02000000

if appid_in_vdf:
# Store the app ID in `shortcuts.vdf`. This is similar
# in behavior to newer Steam releases.
entry["appid"] = ~(result ^ 0xffffffff)

data["shortcuts"][str(shortcut_id)] = entry

shortcut_path.write_bytes(vdf.binary_dumps(data))
Expand Down
1 change: 1 addition & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def test_run_winetricks_shortcut(
assert command.env["WINEPREFIX"] == str(
steam_dir / "steamapps" / "compatdata" / "4149337689" / "pfx")


def test_run_winetricks_select_proton(
self, cli, steam_app_factory, default_proton,
custom_proton_factory, command, home_dir):
Expand Down
41 changes: 38 additions & 3 deletions tests/test_steam.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import time
from pathlib import Path

import pytest

from protontricks.steam import (SteamApp, find_appid_proton_prefix,
find_steam_path, find_steam_proton_app,
get_custom_proton_installations,
get_steam_apps)

import pytest
get_custom_windows_shortcuts, get_steam_apps)


class TestSteamApp:
Expand Down Expand Up @@ -332,3 +332,38 @@ def test_get_steam_apps_steamapps_case_warning(
"directories were found at {}".format(str(steam_dir))
in log.getMessage()
)


class TestGetWindowsShortcuts:
def test_get_custom_windows_shortcuts_derive_appid(
self, steam_dir, shortcut_factory):
"""
Retrieve custom Windows shortcut. The app ID is derived from the
executable name since it's not found in shortcuts.vdf.
"""
shortcut_factory(install_dir="fake/path/", name="fakegame.exe")

shortcut_apps = get_custom_windows_shortcuts(steam_dir)

assert len(shortcut_apps) == 1
assert shortcut_apps[0].name == "Non-Steam shortcut: fakegame.exe"
assert shortcut_apps[0].appid == 4149337689

def test_get_custom_windows_shortcuts_read_vdf(
self, steam_dir, shortcut_factory):
"""
Retrieve custom Windows shortcut. The app ID is read and derived
directly from the shortcuts.vdf, which is used on newer Steam versions.
"""
shortcut_factory(
install_dir="fake/path/", name="fakegame.exe",
appid_in_vdf=True
)

shortcut_apps = get_custom_windows_shortcuts(steam_dir)

assert len(shortcut_apps) == 1
assert shortcut_apps[0].name == "Non-Steam shortcut: fakegame.exe"
assert shortcut_apps[0].appid == 4149337689


0 comments on commit 040b43d

Please sign in to comment.