TEST(LoadingAddon, TestAdon)
{
  char* argv[4] = { "test.exe", "--config=./tests/configs", "--log-file=/path/to/log/server.log", "--daemon" };
  OpcUa::UaServer::CommandLine cmdline(4, argv);
  EXPECT_EQ(cmdline.GetLogFile(), "/path/to/log/server.log");
  EXPECT_TRUE(cmdline.IsDaemonMode());

  OpcUa::Application::UniquePtr server = OpcUa::CreateApplication();
  ASSERT_NO_THROW(server->Start(cmdline.GetModules()));
  ASSERT_NO_THROW(server->GetAddonsManager());

  OpcUa::Test::TestAddon::SharedPtr testAddon;
  ASSERT_NO_THROW(testAddon = server->GetAddonsManager().GetAddon<OpcUa::Test::TestAddon>(OpcUa::Test::TestAddonID));
  ASSERT_NE(testAddon, OpcUa::Test::TestAddon::SharedPtr());
  const Common::AddonParameters params = testAddon->GetParameters();
  ASSERT_EQ(params.Parameters.size(), 1);
  ASSERT_EQ(params.Parameters[0].Name, "hello");
  ASSERT_EQ(params.Parameters[0].Value, "world");
}
Esempio n. 2
0
int main(int argc, char** argv)
{
  try
  {
    const char** arv = (const char**)argv;
    OpcUa::UaServer::CommandLine options(argc, arv);
    if (!options.NeedStartServer())
    {
      return 0;
    }

    OpcUa::Daemon daemon;
    if (options.IsDaemonMode())
    {
      daemon.Daemonize(options.GetLogFile());
    }

    std::vector<Common::AddonInformation> addons = options.GetModules();
    AddStandardModules(options.GetParameters(), addons);

    OpcUa::Application::UniquePtr application = OpcUa::CreateApplication();
    application->Start(addons);
    daemon.WaitForTerminate();

    application->Stop();
    return 0;
  }
  catch (const std::exception& exc)
  {
    std::cout << exc.what() << std::endl;
  }
  catch (...)
  {
    std::cout << "Unknown error." << std::endl;
  }
  return -1;
}