aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/testing/unittest/plugin.cpp
blob: 543112f7ac6959130bc5e45ae71f4f7bec4f67d5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "plugin.h"

#include <util/generic/singleton.h>
#include <util/generic/vector.h>
#include <util/generic/utility.h>

namespace NUnitTest {
    namespace NPlugin {
        namespace {
            class TPlugins {
            public:
                void OnStartMain(int argc, char* argv[]) const {
                    for (const auto& plugin : Plugins) {
                        plugin->OnStartMain(argc, argv);
                    }
                }

                void OnStopMain(int argc, char* argv[]) const {
                    for (const auto& plugin : Plugins) {
                        plugin->OnStopMain(argc, argv);
                    }
                }

                void Register(TSimpleSharedPtr<IPlugin> plugin) {
                    Plugins.emplace_back(std::move(plugin));
                }

                static TPlugins& Instance() {
                    return *Singleton<TPlugins>();
                }

            private:
                TVector<TSimpleSharedPtr<IPlugin>> Plugins;
            };
        } // anonymous namespace

        TPluginRegistrator::TPluginRegistrator(TSimpleSharedPtr<IPlugin> plugin) {
            TPlugins::Instance().Register(std::move(plugin));
        }

        void OnStartMain(int argc, char* argv[]) {
            TPlugins::Instance().OnStartMain(argc, argv);
        }

        void OnStopMain(int argc, char* argv[]) {
            TPlugins::Instance().OnStopMain(argc, argv);
        }

    }
}