1//
2// SystemConfigurationTest.cpp
3//
4// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
5// and Contributors.
6//
7// SPDX-License-Identifier: BSL-1.0
8//
9
10
11#include "SystemConfigurationTest.h"
12#include "Poco/CppUnit/TestCaller.h"
13#include "Poco/CppUnit/TestSuite.h"
14#include "Poco/Util/SystemConfiguration.h"
15#include "Poco/AutoPtr.h"
16#include "Poco/Exception.h"
17#include "Poco/Environment.h"
18#include "Poco/Path.h"
19#if !defined(POCO_VXWORKS)
20#include "Poco/Process.h"
21#endif
22#include "Poco/NumberParser.h"
23#include <algorithm>
24
25
26using Poco::Util::SystemConfiguration;
27using Poco::Util::AbstractConfiguration;
28using Poco::AutoPtr;
29using Poco::Environment;
30using Poco::Path;
31using Poco::InvalidAccessException;
32using Poco::NotFoundException;
33
34
35SystemConfigurationTest::SystemConfigurationTest(const std::string& name): CppUnit::TestCase(name)
36{
37}
38
39
40SystemConfigurationTest::~SystemConfigurationTest()
41{
42}
43
44
45void SystemConfigurationTest::testProperties()
46{
47 AutoPtr<SystemConfiguration> pConf = new SystemConfiguration;
48
49 assertTrue (pConf->getString("system.osName") == Environment::osName());
50 assertTrue (pConf->getString("system.osVersion") == Environment::osVersion());
51 assertTrue (pConf->getString("system.osArchitecture") == Environment::osArchitecture());
52 assertTrue (pConf->getString("system.nodeName") == Environment::nodeName());
53 assertTrue (pConf->getString("system.currentDir") == Path::current());
54 assertTrue (pConf->getString("system.homeDir") == Path::home());
55 assertTrue (pConf->getString("system.tempDir") == Path::temp());
56
57 std::string dateTime = pConf->getString("system.dateTime");
58 assertTrue (dateTime.size() == 20);
59
60#if !defined(POCO_VXWORKS)
61 std::string pid = pConf->getString("system.pid");
62 assertTrue (Poco::NumberParser::parse64(pid) == Poco::Process::id());
63#endif
64
65#if defined(POCO_OS_FAMILY_WINDOWS)
66 std::string home = pConf->getString("system.env.HOMEPATH");
67#else
68 std::string home = pConf->getString("system.env.HOME");
69#endif
70 assertTrue (!home.empty());
71}
72
73
74void SystemConfigurationTest::testKeys()
75{
76 AutoPtr<SystemConfiguration> pConf = new SystemConfiguration;
77
78 AbstractConfiguration::Keys keys;
79 pConf->keys(keys);
80 assertTrue (keys.size() == 1);
81 assertTrue (std::find(keys.begin(), keys.end(), "system") != keys.end());
82
83 pConf->keys("system", keys);
84#if defined(POCO_VXWORKS)
85 assertTrue (keys.size() == 14);
86#else
87 assertTrue (keys.size() == 15);
88#endif
89
90 assertTrue (std::find(keys.begin(), keys.end(), "osName") != keys.end());
91 assertTrue (std::find(keys.begin(), keys.end(), "osVersion") != keys.end());
92 assertTrue (std::find(keys.begin(), keys.end(), "osArchitecture") != keys.end());
93 assertTrue (std::find(keys.begin(), keys.end(), "nodeName") != keys.end());
94 assertTrue (std::find(keys.begin(), keys.end(), "nodeId") != keys.end());
95 assertTrue (std::find(keys.begin(), keys.end(), "currentDir") != keys.end());
96 assertTrue (std::find(keys.begin(), keys.end(), "homeDir") != keys.end());
97 assertTrue (std::find(keys.begin(), keys.end(), "configHomeDir") != keys.end());
98 assertTrue (std::find(keys.begin(), keys.end(), "cacheHomeDir") != keys.end());
99 assertTrue (std::find(keys.begin(), keys.end(), "dataHomeDir") != keys.end());
100 assertTrue (std::find(keys.begin(), keys.end(), "tempDir") != keys.end());
101 assertTrue (std::find(keys.begin(), keys.end(), "configDir") != keys.end());
102 assertTrue (std::find(keys.begin(), keys.end(), "dateTime") != keys.end());
103#if !defined(POCO_VXWORKS)
104 assertTrue (std::find(keys.begin(), keys.end(), "pid") != keys.end());
105#endif
106 assertTrue (std::find(keys.begin(), keys.end(), "env") != keys.end());
107}
108
109
110void SystemConfigurationTest::setUp()
111{
112}
113
114
115void SystemConfigurationTest::tearDown()
116{
117}
118
119
120CppUnit::Test* SystemConfigurationTest::suite()
121{
122 CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SystemConfigurationTest");
123
124 CppUnit_addTest(pSuite, SystemConfigurationTest, testProperties);
125 CppUnit_addTest(pSuite, SystemConfigurationTest, testKeys);
126
127 return pSuite;
128}
129