1
2
3#include "../DiscordSocialSdk.cpp"
4#include <iostream>
5#include <stdexcept>
6
7void Require(bool condition, const char* text)
8{
9 if (!condition) throw std::runtime_error(text);
10}
11
13{
15 Require(buttons.size() == 2, "Every activity must contain exactly two buttons");
16 Require(buttons[0].Label() == "View on Steam" &&
17 buttons[0].Url() == "https://store.steampowered.com/app/795990/", "Steam button changed");
18 Require(buttons[1].Label() == "Join our Discord" &&
19 buttons[1].Url() == "https://discord.gg/BH6zvaw", "Discord button changed");
20}
21
22void TestWikiLinks()
23{
25 fields.
details =
"USV Wayfarer (IVR N123AB)";
26 fields.
state =
"On the ground in Deois - Port District";
28 const struct { const char* key; const char* page; } vehicles[] = {
29 { "type1", "C-98_Construction_MuVER" }, { "type2", "DIHV" },
30 { "type3", "E-10_Saint" }, { "type4", "P-13_Prowler" }, { "type5", "A-4_Wanderer" },
31 { "type6", "C-2A_Dasher" }, { "type7", "T-121_Steerhead" }, { "type8", "E-11_Saint" },
32 { "type21", "C-2A_Dasher" }, { "type22", "Mammoth" }, { "type24", "W-6_Manx" },
33 { "type27", "T-19_Stratomaster" }, { "type29", "T-121_Steerhead" }
34 };
35 for (const auto& vehicle : vehicles)
36 {
38 const auto activity = BuildSocialActivity(fields);
39 const std::string
url = std::string(
"https://www.risetvp.com/") + vehicle.page;
40 Require(activity.
DetailsUrl() == url && activity.
Assets()->SmallUrl() == url,
41 "Vehicle text/image linked to the wrong model reference");
42 Require(activity.
StateUrl() ==
"https://www.risetvp.com/Category:Deois" &&
43 activity.
Assets()->LargeUrl() == activity.
StateUrl(),
"Location link was replaced by the vehicle link");
44 RequireActivityButtons(activity);
45 }
47 const struct { const char* key; const char* page; } locations[] = {
48 { "o4", "O-4" }, { "arcridge", "Arcridge" }, { "mine", "Category:Mining" },
49 { "township", "Category:Township" }, { "farm", "Category:Farming" }, { "estate", "Estate" },
50 { "airfield", "Category:Airfield" }, { "salvage", "Category:Colonies" }, { "refinery", "Category:Refinery" },
51 { "land", "Assessor%27s_Parcel_Number" }, { "water", "Assessor%27s_Parcel_Number" },
52 { "cpoc", "CPOC" }, { "tac", "TAC" }, { "ysp", "YSP" }
53 };
54 for (const auto& location : locations)
55 {
57 const auto activity = BuildSocialActivity(fields);
58 const std::string
url = std::string(
"https://www.risetvp.com/") + location.page;
59 Require(activity.
StateUrl() == url && activity.
Assets()->LargeUrl() == url,
60 "Location text/image linked to the wrong reference");
61 Require(activity.
DetailsUrl() ==
"https://www.risetvp.com/E-10_Saint",
62 "Location update replaced the vehicle reference");
63 }
65 for (const auto unknown : { "type9", "type999", "" })
66 {
68 const auto activity = BuildSocialActivity(fields);
69 Require(!activity.
DetailsUrl() && !activity.
Assets()->SmallUrl(),
"Unknown vehicle linked to a location or missing page");
70 }
72 const auto simulator = BuildSocialActivity(fields);
73 Require(!simulator.DetailsUrl() && !simulator.StateUrl() && !simulator.Assets()->LargeUrl() &&
74 simulator.Assets()->SmallUrl() == "https://www.risetvp.com/E-10_Saint", "Simulator text was linked as a real vehicle/location");
77 const auto apartment = BuildSocialActivity(fields);
78 Require(apartment.DetailsUrl() == "https://www.risetvp.com/Bradbury_Apartments" && !apartment.StateUrl(),
79 "Indoor details linked to a vehicle or empty state retained a link");
81 for (const auto flight : { "bcl", "acl", "inanother" })
82 {
84 const auto activity = BuildSocialActivity(fields);
85 Require(activity.
DetailsUrl() ==
"https://www.risetvp.com/E-10_Saint" &&
87 "Flight/orbit/cargo state lost the vehicle link or retained a surface location");
88 }
89 for (const auto screen : { "splash", "login", "loading", "immigration", "bcl", "acl", "inanother", "unknown" })
90 {
92 const auto activity = BuildSocialActivity(fields);
94 "Unmapped screen or non-location status retained wiki links");
95 }
96 std::cout << "PASS independent vehicle/location text and image links, canonical pages, and link clearing\n";
97}
98
99int main(
int argc,
char** argv)
100{
101 try
102 {
103 std::string log;
105 if (argc == 2 && std::string(argv[1]) == "--unavailable")
106 {
107 Require(!backend, "An unavailable or mismatched SDK was loaded");
108 Require(log.find("unavailable") != std::string::npos || log.find("mismatch") != std::string::npos,
109 "Missing runtime diagnostic");
110 std::cout << "PASS optional runtime: " << log << '\n';
111 return 0;
112 }
113 Require(backend != nullptr, "Official SDK could not initialize");
114 backend->Pump();
115 TestWikiLinks();
117 fields.
state =
"On the ground in Deois";
118 fields.
details =
"USV Wayfarer (IVR N123AB)";
125 const auto assets = activity.
Assets();
128 const auto timestamps = activity.
Timestamps();
129 Require(timestamps && timestamps->Start() == 1724512345000ULL && timestamps->End() == 0,
130 "Elapsed time must use Unix milliseconds and no countdown");
131 Require(!activity.
Party() && !activity.
Secrets(),
"Unsupported game invites were added");
132 RequireActivityButtons(activity);
133 const auto empty = BuildSocialActivity({});
134 Require(!empty.State() && !empty.Details() && !empty.Assets() && !empty.Timestamps() &&
135 !empty.StateUrl() && !empty.DetailsUrl(),
136 "Empty activity retained previous fields");
137 RequireActivityButtons(empty);
138
139 for (int i = 0; i < 1000; ++i)
140 {
141 fields.
state = (i % 2) ?
"Viewing Main Menu" :
"On the ground in Deois";
143 Require(value.State() == fields.
state && value.Details() == fields.
details,
144 "Repeated SDK payload conversion failed");
145 RequireActivityButtons(value);
146 }
147 backend.reset();
149 std::cout << "PASS official Social SDK 1.10.19337 x64 initialization, payload conversion, activity buttons, and teardown\n";
150 return 0;
151 }
152 catch (const std::exception& error) { std::cerr << "FAIL " << error.what() << '\n'; return 1; }
153}
An Activity represents one "thing" a user is doing on Discord and is part of their rich presence.
std::vector< discordpp::ActivityButton > GetButtons() const
Returns the custom buttons for the rich presence.
std::optional< discordpp::ActivityAssets > Assets() const
Images used to customize how the Activity is displayed in the Discord client.
std::optional< discordpp::ActivityTimestamps > Timestamps() const
The timestamps struct can be used to render either:
std::optional< discordpp::ActivityParty > Party() const
The party struct is used to indicate the size and members of the people the current user is playing w...
std::optional< std::string > DetailsUrl() const
A URL that opens when the user clicks/taps the details text.
std::optional< std::string > Details() const
The state of the what the user is doing for this activity.
std::optional< std::string > StateUrl() const
A URL that opens when the user clicks/taps the state text.
std::optional< discordpp::ActivitySecrets > Secrets() const
The secrets struct is used in combination with the party struct to make an Activity joinable.
std::optional< std::string > State() const
The state of the party for this activity.
discordpp::ActivityTypes Type() const
The type of activity this is.
Activity BuildActivity(const Fields &fields)
std::unique_ptr< SocialSdk > CreateSocialSdk(const Log &log)
std::string largeImageKey
std::string smallImageKey
const char * smallImageKey
const char * largeImageKey
std::int64_t startTimestamp
const char * smallImageText
const char * largeImageText