1//
2// Driver.cpp
3//
4// Console-based test driver for Poco NetSSL.
5//
6// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
7// and Contributors.
8//
9// SPDX-License-Identifier: BSL-1.0
10//
11
12
13#include "Poco/CppUnit/TestRunner.h"
14#include "NetSSLTestSuite.h"
15#include "Poco/Path.h"
16#include "Poco/Util/Application.h"
17#include "Poco/Net/HTTPStreamFactory.h"
18#include "Poco/Net/HTTPSStreamFactory.h"
19#include <iostream>
20
21
22class NetSSLApp: public Poco::Util::Application
23{
24public:
25 NetSSLApp()
26 {
27 Poco::Net::initializeSSL();
28 Poco::Net::HTTPStreamFactory::registerFactory();
29 Poco::Net::HTTPSStreamFactory::registerFactory();
30 }
31
32 ~NetSSLApp()
33 {
34 Poco::Net::uninitializeSSL();
35 }
36
37 int main(const std::vector<std::string>& args)
38 {
39 CppUnit::TestRunner runner;
40 runner.addTest("NetSSLTestSuite", NetSSLTestSuite::suite());
41 return runner.run(_targs) ? 0 : 1;
42 }
43
44 void setup(int argc, char** argv)
45 {
46 init(1, argv);
47 for (int i = 0; i < argc; ++i)
48 _targs.push_back(std::string(argv[i]));
49 }
50
51protected:
52 void initialize(Poco::Util::Application& self)
53 {
54#ifdef POCO_OS_FAMILY_UNIX
55 std::string pocoBase(Poco::Environment::get("POCO_BASE"));
56 if (pocoBase.empty())
57 throw Poco::LogicException("POCO_BASE should be defined");
58
59 Poco::Path configPath(pocoBase);
60 configPath.makeDirectory();
61 configPath.pushDirectory("NetSSL_OpenSSL");
62 configPath.pushDirectory("testsuite");
63 configPath.setFileName("TestSuite.xml");
64
65 loadConfiguration(configPath.toString());
66#else
67 loadConfiguration();
68#endif
69 Poco::Util::Application::initialize(self);
70 }
71
72private:
73 std::vector<std::string> _targs;
74};
75
76
77int main(int ac, char **av)
78{
79 NetSSLApp app;
80 try
81 {
82 app.setup(ac, av);
83 return app.run();
84 }
85 catch (Poco::Exception& exc)
86 {
87 std::cout << exc.displayText() << std::endl;
88 return 1;
89 }
90}
91