Ticket #18130: test_getenv_xdgvars.cpp

File test_getenv_xdgvars.cpp, 1.2 KB (added by bipolar, 2 years ago)
Line 
1// compile with:
2// g++ test_getenv_xdgvars.cpp -o test_getenv_xdgvars -lbe
3
4#include <cstdio>
5
6#include <Application.h>
7#include <Window.h>
8
9
10static const char* XDG_VARS[] = {
11 "XDG_CONFIG_HOME",
12 "XDG_DATA_HOME",
13 "XDG_CONFIG_DIRS",
14 "XDG_DATA_DIRS",
15 "XDG_CACHE_HOME"
16};
17
18
19void dump_vars()
20{
21 for (int i=0; i < 5; i++) {
22 printf("%s = %s\n", XDG_VARS[i], getenv(XDG_VARS[i]));
23 }
24}
25
26
27class TestView : public BView {
28public:
29 TestView(BRect frame)
30 : BView(frame, "TestView", B_FOLLOW_ALL, B_WILL_DRAW)
31 {
32 }
33
34 void Draw(BRect updateRect)
35 {
36 const float kSpacing = 20.0;
37 const float kTopOffset = kSpacing + 5;
38 BPoint point(10, kTopOffset);
39
40 for (uint32 i = 0; i < 5; i++) {
41 BString tmp;
42 tmp.SetToFormat("%s = %s", XDG_VARS[i], getenv(XDG_VARS[i]));
43 DrawString(tmp.String(), point);
44 point.y += kSpacing;
45 }
46 }
47};
48
49
50int
51main()
52{
53 BApplication app("application/x-vnd.Haiku-Test_XDG_VARS");
54
55 BRect frame(100, 200, 600, 350);
56 BWindow* window = new BWindow(frame, "Test getenv of XDG_VARS", B_TITLED_WINDOW,
57 B_QUIT_ON_WINDOW_CLOSE);
58
59 TestView* view = new TestView(frame.OffsetToSelf(0, 0));
60 window->AddChild(view);
61
62 window->Show();
63 app.Run();
64
65 dump_vars();
66
67 return 0;
68}