Skip to content

Commit 2778f85

Browse files
committed
Unit tests for the tGetXDG functions that parse the XDG Base Directories environment variable specifications.
1 parent 03fedba commit 2778f85

File tree

4 files changed

+60
-10
lines changed

4 files changed

+60
-10
lines changed

Modules/System/Inc/System/tMachine.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,14 @@ bool tOpenSystemFileExplorer(const tString& fullFilename);
4646
// in Tacent's path format with trailing / for directories. All paths are absolute as defined by the spec. Clients using
4747
// these functions should NOT place data directly in the returned directories -- they should make a subdirectory,
4848
// usually the name of the app in lowercase, and put their files there.
49-
bool tGetXDGDataHome(tString& xdgDataHome); // $XDG_DATA_HOME
50-
bool tGetXDGConfigHome(tString& xdgConfigHome); // $XDG_CONFIG_HOME
51-
bool tGetXDGStateHome(tString& xdgStateHome); // $XDG_STATE_HOME
52-
void tGetXDGExeHome(tString& xdgExeHome); // Not defined by an XDG env variable. Always: $HOME/.local/bin/
53-
49+
bool tGetXDGDataHome(tString& xdgDataHome); // $XDG_DATA_HOME
50+
bool tGetXDGConfigHome(tString& xdgConfigHome); // $XDG_CONFIG_HOME
51+
bool tGetXDGStateHome(tString& xdgStateHome); // $XDG_STATE_HOME
52+
void tGetXDGExeHome(tString& xdgExeHome); // Not defined by an XDG env variable. Always: $HOME/.local/bin/
5453
bool tGetXDGDataDirs(tList<tStringItem>& xdgDataDirs); // $XDG_DATA_DIRS. Priority list of directories to search.
5554
bool tGetXDGConfigDirs(tList<tStringItem>& xdgConfigDirs); // $XDG_CONFIG_DIRS. Priority list of directories to search.
56-
bool tGetXDGCacheHome(tString& xdgCacheHome); // $XDG_CACHE_HOME
57-
bool tGetXDGRuntimeDir(tString& xdgRuntimeDir); // $XDG_RUNTIME_DIR
55+
bool tGetXDGCacheHome(tString& xdgCacheHome); // $XDG_CACHE_HOME
56+
bool tGetXDGRuntimeDir(tString& xdgRuntimeDir); // $XDG_RUNTIME_DIR
5857
#endif
5958

6059
}

Modules/System/Inc/System/tPrint.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ namespace tSystem
138138
// Using the 0 prefix flag works differently on Linux vs Windows with non-integral types like %c.
139139
// Tacent behaves (on purpose) like Windows where the leading 0s are printed even though the type is
140140
// not integral.
141-
// Enhanced: Underscore (_) or single-quote (') chooses a more readable decorative or alternative printing method.
141+
// Enhanced: Underscore (_) or single-quote (') chooses a more readable decorative or alternative printing
142+
// method. They do not necessarily do the same thing as each other.
142143
// Integral Types:
143144
// For built-in integral types, an _ inserts an underscore every 4 characters starting from the
144145
// right. Handy for making binary values readable. For Tacent integer types like tint128 and
@@ -196,7 +197,8 @@ namespace tSystem
196197
// String: s You must call pod(string) or string.Pod() for tStrings, or use char*.
197198
// t Windows only. Allows passing of non-POD tString directly. Warning: You cannot pass
198199
// in an tStringItem! You must either cast to an tString or call pod() and use %s.
199-
// Boolean: B For printing a bool as either "true" or "false".
200+
// Boolean: B For printing a bool as either "true" or "false" or the alternate formats T or F
201+
// when _ used and Y or N when ' used.
200202
// Percent: % Displays percent sign.
201203
//
202204
// The functions return the number of characters printed. They do NOT care about channels in that they always report

UnitTests/Src/TestSystem.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,54 @@ tTestUnit(Machine)
14401440

14411441
tString pathEnvVar = tSystem::tGetEnvVar("PATH");
14421442
tPrintf("PATH Env Var:%s\n", pathEnvVar.Chr());
1443+
1444+
#ifdef PLATFORM_LINUX
1445+
tPrintf("Testing XDG Base Directories\n");
1446+
1447+
tString dataHome;
1448+
bool dataHomeSet = tSystem::tGetXDGDataHome(dataHome);
1449+
tPrintf("XDGDataHome Set:%'B Dir:%s\n", dataHomeSet, dataHome.Chr());
1450+
tRequire(tIsAbsolutePath(dataHome));
1451+
1452+
tString configHome;
1453+
bool configHomeSet = tSystem::tGetXDGConfigHome(configHome);
1454+
tPrintf("XDGConfigHome Set:%'B Dir:%s\n", configHomeSet, configHome.Chr());
1455+
tRequire(tIsAbsolutePath(configHome));
1456+
1457+
tString stateHome;
1458+
bool stateHomeSet = tSystem::tGetXDGStateHome(stateHome);
1459+
tPrintf("XDGStateHome Set:%'B Dir:%s\n", stateHomeSet, stateHome.Chr());
1460+
tRequire(tIsAbsolutePath(stateHome));
1461+
1462+
tString exeHome;
1463+
tSystem::tGetXDGExeHome(exeHome);
1464+
tPrintf("XDGExeHome Dir:%s\n", exeHome.Chr());
1465+
tRequire(tIsAbsolutePath(exeHome));
1466+
1467+
tList<tStringItem> dataDirs;
1468+
bool dataDirsSet = tSystem::tGetXDGDataDirs(dataDirs);
1469+
tPrintf("XDGDataDirs Set:%'B\n", dataDirsSet);
1470+
for (tStringItem* dir = dataDirs.First(); dir; dir = dir->Next())
1471+
tPrintf(" Dir:%s\n", dir->Chr());
1472+
tRequire(!dataDirs.IsEmpty());
1473+
1474+
tList<tStringItem> configDirs;
1475+
bool configDirsSet = tSystem::tGetXDGConfigDirs(configDirs);
1476+
tPrintf("XDGConfigDirs Set:%'B\n", configDirsSet);
1477+
for (tStringItem* dir = configDirs.First(); dir; dir = dir->Next())
1478+
tPrintf(" Dir:%s\n", dir->Chr());
1479+
tRequire(!configDirs.IsEmpty());
1480+
1481+
tString cacheHome;
1482+
bool cacheHomeSet = tSystem::tGetXDGCacheHome(cacheHome);
1483+
tPrintf("XDGCacheHome Set:%'B Dir:%s\n", cacheHomeSet, cacheHome.Chr());
1484+
tRequire(tIsAbsolutePath(cacheHome));
1485+
1486+
tString runtimeDir;
1487+
bool runtimeDirSet = tSystem::tGetXDGRuntimeDir(runtimeDir);
1488+
tPrintf("XDGRuntimeDir Set:%'B Dir:%s\n", runtimeDirSet, runtimeDir.Chr());
1489+
tRequire(tIsAbsolutePath(runtimeDir) || runtimeDir.IsEmpty());
1490+
#endif
14431491
}
14441492

14451493

UnitTests/Src/UnitTests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,12 @@ int main(int argc, char** argv)
201201
// tTest(FindRec);
202202
// tTest(Network);
203203
// tTest(Time);
204+
tTest(Machine);
204205
// tTest(CmdLine);
205206
// tTest(String);
206207
// tTest(List);
207208
// tTest(ListExtra);
208-
tTest(ListSort);
209+
// tTest(ListSort);
209210
// tTest(Colour);
210211
// tTest(Print);
211212
// tTest(Map);

0 commit comments

Comments
 (0)