@@ -192,3 +192,86 @@ string OSUtility::MakeMachineIdentString(uint64_t ident)
192192
193193 return ret;
194194}
195+
196+ #if ENABLED(ENABLE_UNIT_TESTS)
197+
198+ #include " 3rdparty/catch/catch.hpp"
199+
200+ TEST_CASE (" Test Process functions" , " [osspecific]" )
201+ {
202+ SECTION (" Environment Variables" )
203+ {
204+ const char *var = Process::GetEnvVariable (" TMP" );
205+
206+ if (!var)
207+ var = Process::GetEnvVariable (" TEMP" );
208+
209+ if (!var)
210+ var = Process::GetEnvVariable (" HOME" );
211+
212+ CHECK (var);
213+ CHECK (strlen (var) > 1 );
214+
215+ var = Process::GetEnvVariable (" __renderdoc__unit_test_var" );
216+
217+ CHECK_FALSE (var);
218+
219+ EnvironmentModification mod;
220+ mod.name = " __renderdoc__unit_test_var" ;
221+ mod.value = " test_value" ;
222+ mod.sep = EnvSep::SemiColon;
223+ mod.mod = EnvMod::Append;
224+
225+ Process::RegisterEnvironmentModification (mod);
226+ Process::ApplyEnvironmentModification ();
227+
228+ var = Process::GetEnvVariable (" __renderdoc__unit_test_var" );
229+
230+ CHECK (var);
231+ CHECK (var == std::string (" test_value" ));
232+
233+ Process::RegisterEnvironmentModification (mod);
234+ Process::ApplyEnvironmentModification ();
235+
236+ var = Process::GetEnvVariable (" __renderdoc__unit_test_var" );
237+
238+ CHECK (var);
239+ CHECK (var == std::string (" test_value;test_value" ));
240+
241+ mod.sep = EnvSep::Colon;
242+
243+ Process::RegisterEnvironmentModification (mod);
244+ Process::ApplyEnvironmentModification ();
245+
246+ var = Process::GetEnvVariable (" __renderdoc__unit_test_var" );
247+
248+ CHECK (var);
249+ CHECK (var == std::string (" test_value;test_value:test_value" ));
250+
251+ mod.value = " prepend" ;
252+ mod.sep = EnvSep::SemiColon;
253+ mod.mod = EnvMod::Prepend;
254+
255+ Process::RegisterEnvironmentModification (mod);
256+ Process::ApplyEnvironmentModification ();
257+
258+ var = Process::GetEnvVariable (" __renderdoc__unit_test_var" );
259+
260+ CHECK (var);
261+ CHECK (var == std::string (" prepend;test_value;test_value:test_value" ));
262+
263+ mod.value = " reset" ;
264+ mod.sep = EnvSep::SemiColon;
265+ mod.mod = EnvMod::Set;
266+
267+ Process::RegisterEnvironmentModification (mod);
268+ Process::ApplyEnvironmentModification ();
269+
270+ var = Process::GetEnvVariable (" __renderdoc__unit_test_var" );
271+
272+ CHECK (var);
273+ CHECK (var == std::string (" reset" ));
274+ };
275+ };
276+
277+ #endif // ENABLED(ENABLE_UNIT_TESTS)
0 commit comments