Public Types | Static Public Member Functions | Private Types | Static Private Attributes | List of all members
testing::TestSharedGlobalResource< RES > Class Template Reference

Utility class providing singleton objects to the derived classes. More...

#include <unit_test_base.h>

Public Types

using ResourcePtr_t = std::shared_ptr< Resource_t >
 
using ResourcePtr_t = std::shared_ptr< Resource_t >
 

Static Public Member Functions

template<typename... Args>
static ResourcePtr_t CreateResource (std::string res_name, Args &&...args)
 Constructs and registers a new resource with a specified name. More...
 
template<typename... Args>
static void CreateDefaultResource (Args &&...args)
 Constructs and registers a new resource with no name. More...
 
template<typename... Args>
static ResourcePtr_t ProposeSharedResource (std::string res_name, Args &&...args)
 Creates a shared resource only if none exists yet. More...
 
template<typename... Args>
static ResourcePtr_t ProposeDefaultSharedResource (Args &&...args)
 Creates a shared resource as default only if none exists yet. More...
 
static Resource_tDestroyResource (std::string name="")
 Destroys the specified resource (does nothing if no such resource) More...
 
template<typename... Args>
static ResourcePtr_t CreateResource (std::string res_name, Args &&...args)
 Constructs and registers a new resource with a specified name. More...
 
template<typename... Args>
static void CreateDefaultResource (Args &&...args)
 Constructs and registers a new resource with no name. More...
 
template<typename... Args>
static ResourcePtr_t ProposeSharedResource (std::string res_name, Args &&...args)
 Creates a shared resource only if none exists yet. More...
 
template<typename... Args>
static ResourcePtr_t ProposeDefaultSharedResource (Args &&...args)
 Creates a shared resource as default only if none exists yet. More...
 
static Resource_tDestroyResource (std::string name="")
 Destroys the specified resource (does nothing if no such resource) More...
 
Add and share resources
static void AddSharedResource (std::string res_name, ResourcePtr_t res_ptr)
 Adds a shared resource to the resource registry. More...
 
static void AddDefaultSharedResource (ResourcePtr_t res_ptr)
 Adds a shared resource to the resource registry (empty name) More...
 
template<typename... Args>
static ResourcePtr_t ProvideSharedResource (std::string res_name, ResourcePtr_t res_ptr)
 Registers a shared resource only if none exists yet. More...
 
template<typename... Args>
static ResourcePtr_t ProvideDefaultSharedResource (ResourcePtr_t res_ptr)
 Creates a shared resource as default only if none exists yet. More...
 
static bool ReplaceSharedResource (std::string res_name, Resource_t const *old_res_ptr, ResourcePtr_t res_ptr)
 Adds a shared resource only if it is old_res_ptr. More...
 
static bool ReplaceSharedResource (std::string res_name, ResourcePtr_t old_res_ptr, ResourcePtr_t res_ptr)
 
static void AddSharedResource (std::string res_name, ResourcePtr_t res_ptr)
 Adds a shared resource to the resource registry. More...
 
static void AddDefaultSharedResource (ResourcePtr_t res_ptr)
 Adds a shared resource to the resource registry (empty name) More...
 
template<typename... Args>
static ResourcePtr_t ProvideSharedResource (std::string res_name, ResourcePtr_t res_ptr)
 Registers a shared resource only if none exists yet. More...
 
template<typename... Args>
static ResourcePtr_t ProvideDefaultSharedResource (ResourcePtr_t res_ptr)
 Creates a shared resource as default only if none exists yet. More...
 
static bool ReplaceSharedResource (std::string res_name, Resource_t const *old_res_ptr, ResourcePtr_t res_ptr)
 Adds a shared resource only if it is old_res_ptr. More...
 
static bool ReplaceSharedResource (std::string res_name, ResourcePtr_t old_res_ptr, ResourcePtr_t res_ptr)
 
static bool ReplaceDefaultSharedResource (Resource_t const *old_res_ptr, ResourcePtr_t res_ptr)
 Adds a shared resource as default resource only if it is old_res_ptr. More...
 
static bool ReplaceDefaultSharedResource (ResourcePtr_t old_res_ptr, ResourcePtr_t res_ptr)
 
Resource access
static bool hasResource (std::string name="")
 
static ResourcePtr_t ShareResource (std::string name="")
 Retrieves the specified resource for sharing (nullptr if none) More...
 
static Resource_tResource (std::string name="")
 Retrieves the specified resource, or throws if not available. More...
 
static bool hasResource (std::string name="")
 
static ResourcePtr_t ShareResource (std::string name="")
 Retrieves the specified resource for sharing (nullptr if none) More...
 
static Resource_tResource (std::string name="")
 Retrieves the specified resource, or throws if not available. More...
 
static bool ReplaceDefaultSharedResource (Resource_t const *old_res_ptr, ResourcePtr_t res_ptr)
 Adds a shared resource as default resource only if it is old_res_ptr. More...
 
static bool ReplaceDefaultSharedResource (ResourcePtr_t old_res_ptr, ResourcePtr_t res_ptr)
 

Private Types

using Resource_t = RES
 
using Resource_t = RES
 

Static Private Attributes

static std::map< std::string, ResourcePtr_tResources
 

Detailed Description

template<typename RES>
class testing::TestSharedGlobalResource< RES >

Utility class providing singleton objects to the derived classes.


Template Parameters
RESthe type of object (include constantness if needed)

The object is expected to be shared.

Definition at line 386 of file unit_test_base.h.

Member Typedef Documentation

template<typename RES >
using testing::TestSharedGlobalResource< RES >::Resource_t = RES
private

Definition at line 387 of file unit_test_base.h.

template<typename RES >
using testing::TestSharedGlobalResource< RES >::Resource_t = RES
private

Definition at line 389 of file unit_test_base.h.

template<typename RES >
using testing::TestSharedGlobalResource< RES >::ResourcePtr_t = std::shared_ptr<Resource_t>

Definition at line 390 of file unit_test_base.h.

template<typename RES >
using testing::TestSharedGlobalResource< RES >::ResourcePtr_t = std::shared_ptr<Resource_t>

Definition at line 392 of file unit_test_base.h.

Member Function Documentation

template<typename RES >
static void testing::TestSharedGlobalResource< RES >::AddDefaultSharedResource ( ResourcePtr_t  res_ptr)
inlinestatic

Adds a shared resource to the resource registry (empty name)

Definition at line 400 of file unit_test_base.h.

401  { AddSharedResource(std::string(), res_ptr); }
std::string string
Definition: nybbler.cc:12
static void AddSharedResource(std::string res_name, ResourcePtr_t res_ptr)
Adds a shared resource to the resource registry.
template<typename RES >
static void testing::TestSharedGlobalResource< RES >::AddDefaultSharedResource ( ResourcePtr_t  res_ptr)
inlinestatic

Adds a shared resource to the resource registry (empty name)

Definition at line 402 of file unit_test_base.h.

403  { AddSharedResource(std::string(), res_ptr); }
std::string string
Definition: nybbler.cc:12
static void AddSharedResource(std::string res_name, ResourcePtr_t res_ptr)
Adds a shared resource to the resource registry.
template<typename RES >
static void testing::TestSharedGlobalResource< RES >::AddSharedResource ( std::string  res_name,
ResourcePtr_t  res_ptr 
)
inlinestatic

Adds a shared resource to the resource registry.

Definition at line 396 of file unit_test_base.h.

397  { Resources[res_name] = res_ptr; }
static std::map< std::string, ResourcePtr_t > Resources
template<typename RES >
static void testing::TestSharedGlobalResource< RES >::AddSharedResource ( std::string  res_name,
ResourcePtr_t  res_ptr 
)
inlinestatic

Adds a shared resource to the resource registry.

Definition at line 398 of file unit_test_base.h.

399  { Resources[res_name] = res_ptr; }
static std::map< std::string, ResourcePtr_t > Resources
template<typename RES >
template<typename... Args>
static void testing::TestSharedGlobalResource< RES >::CreateDefaultResource ( Args &&...  args)
inlinestatic

Constructs and registers a new resource with no name.

Definition at line 456 of file unit_test_base.h.

457  { CreateResource(std::string(), std::forward<Args>(args)...); }
std::string string
Definition: nybbler.cc:12
static QCString args
Definition: declinfo.cpp:674
static ResourcePtr_t CreateResource(std::string res_name, Args &&...args)
Constructs and registers a new resource with a specified name.
template<typename RES >
template<typename... Args>
static void testing::TestSharedGlobalResource< RES >::CreateDefaultResource ( Args &&...  args)
inlinestatic

Constructs and registers a new resource with no name.

Definition at line 458 of file unit_test_base.h.

459  { CreateResource(std::string(), std::forward<Args>(args)...); }
std::string string
Definition: nybbler.cc:12
static QCString args
Definition: declinfo.cpp:674
static ResourcePtr_t CreateResource(std::string res_name, Args &&...args)
Constructs and registers a new resource with a specified name.
template<typename RES >
template<typename... Args>
static ResourcePtr_t testing::TestSharedGlobalResource< RES >::CreateResource ( std::string  res_name,
Args &&...  args 
)
inlinestatic

Constructs and registers a new resource with a specified name.

Definition at line 447 of file unit_test_base.h.

448  {
449  ResourcePtr_t res_ptr(new Resource_t(std::forward<Args>(args)...));
450  AddSharedResource(res_name, res_ptr);
451  return res_ptr;
452  }
std::shared_ptr< Resource_t > ResourcePtr_t
static QCString args
Definition: declinfo.cpp:674
static void AddSharedResource(std::string res_name, ResourcePtr_t res_ptr)
Adds a shared resource to the resource registry.
template<typename RES >
template<typename... Args>
static ResourcePtr_t testing::TestSharedGlobalResource< RES >::CreateResource ( std::string  res_name,
Args &&...  args 
)
inlinestatic

Constructs and registers a new resource with a specified name.

Definition at line 449 of file unit_test_base.h.

450  {
451  ResourcePtr_t res_ptr(new Resource_t(std::forward<Args>(args)...));
452  AddSharedResource(res_name, res_ptr);
453  return res_ptr;
454  }
std::shared_ptr< Resource_t > ResourcePtr_t
static QCString args
Definition: declinfo.cpp:674
static void AddSharedResource(std::string res_name, ResourcePtr_t res_ptr)
Adds a shared resource to the resource registry.
template<typename RES >
static Resource_t& testing::TestSharedGlobalResource< RES >::DestroyResource ( std::string  name = "")
inlinestatic

Destroys the specified resource (does nothing if no such resource)

Definition at line 505 of file unit_test_base.h.

506  { Resources.erase(name); }
static QCString name
Definition: declinfo.cpp:673
static std::map< std::string, ResourcePtr_t > Resources
template<typename RES >
static Resource_t& testing::TestSharedGlobalResource< RES >::DestroyResource ( std::string  name = "")
inlinestatic

Destroys the specified resource (does nothing if no such resource)

Definition at line 507 of file unit_test_base.h.

508  { Resources.erase(name); }
static QCString name
Definition: declinfo.cpp:673
static std::map< std::string, ResourcePtr_t > Resources
template<typename RES >
static bool testing::TestSharedGlobalResource< RES >::hasResource ( std::string  name = "")
inlinestatic

Returns whether a resource exists

Exceptions
std::out_of_rangeif not available

Definition at line 485 of file unit_test_base.h.

486  {
487  auto iRes = Resources.find(name);
488  return (iRes != Resources.end()) && bool(iRes->second);
489  }
static QCString name
Definition: declinfo.cpp:673
static std::map< std::string, ResourcePtr_t > Resources
template<typename RES >
static bool testing::TestSharedGlobalResource< RES >::hasResource ( std::string  name = "")
inlinestatic

Returns whether a resource exists

Exceptions
std::out_of_rangeif not available

Definition at line 487 of file unit_test_base.h.

488  {
489  auto iRes = Resources.find(name);
490  return (iRes != Resources.end()) && bool(iRes->second);
491  }
static QCString name
Definition: declinfo.cpp:673
static std::map< std::string, ResourcePtr_t > Resources
template<typename RES >
template<typename... Args>
static ResourcePtr_t testing::TestSharedGlobalResource< RES >::ProposeDefaultSharedResource ( Args &&...  args)
inlinestatic

Creates a shared resource as default only if none exists yet.

Definition at line 472 of file unit_test_base.h.

473  {
474  return ProposeSharedResource
475  (std::string(), std::forward<Args>(args)...);
476  }
std::string string
Definition: nybbler.cc:12
static ResourcePtr_t ProposeSharedResource(std::string res_name, Args &&...args)
Creates a shared resource only if none exists yet.
static QCString args
Definition: declinfo.cpp:674
template<typename RES >
template<typename... Args>
static ResourcePtr_t testing::TestSharedGlobalResource< RES >::ProposeDefaultSharedResource ( Args &&...  args)
inlinestatic

Creates a shared resource as default only if none exists yet.

Definition at line 474 of file unit_test_base.h.

475  {
476  return ProposeSharedResource
477  (std::string(), std::forward<Args>(args)...);
478  }
std::string string
Definition: nybbler.cc:12
static ResourcePtr_t ProposeSharedResource(std::string res_name, Args &&...args)
Creates a shared resource only if none exists yet.
static QCString args
Definition: declinfo.cpp:674
template<typename RES >
template<typename... Args>
static ResourcePtr_t testing::TestSharedGlobalResource< RES >::ProposeSharedResource ( std::string  res_name,
Args &&...  args 
)
inlinestatic

Creates a shared resource only if none exists yet.

Definition at line 463 of file unit_test_base.h.

464  {
465  return hasResource(res_name)?
466  ResourcePtr_t():
467  CreateResource(res_name, std::forward<Args>(args)...);
468  }
std::shared_ptr< Resource_t > ResourcePtr_t
STL namespace.
static bool hasResource(std::string name="")
static QCString args
Definition: declinfo.cpp:674
static ResourcePtr_t CreateResource(std::string res_name, Args &&...args)
Constructs and registers a new resource with a specified name.
template<typename RES >
template<typename... Args>
static ResourcePtr_t testing::TestSharedGlobalResource< RES >::ProposeSharedResource ( std::string  res_name,
Args &&...  args 
)
inlinestatic

Creates a shared resource only if none exists yet.

Definition at line 465 of file unit_test_base.h.

466  {
467  return hasResource(res_name)?
468  ResourcePtr_t():
469  CreateResource(res_name, std::forward<Args>(args)...);
470  }
std::shared_ptr< Resource_t > ResourcePtr_t
STL namespace.
static bool hasResource(std::string name="")
static QCString args
Definition: declinfo.cpp:674
static ResourcePtr_t CreateResource(std::string res_name, Args &&...args)
Constructs and registers a new resource with a specified name.
template<typename RES >
template<typename... Args>
static ResourcePtr_t testing::TestSharedGlobalResource< RES >::ProvideDefaultSharedResource ( ResourcePtr_t  res_ptr)
inlinestatic

Creates a shared resource as default only if none exists yet.

Definition at line 415 of file unit_test_base.h.

416  { return ProvideSharedResource(std::string(), res_ptr); }
static ResourcePtr_t ProvideSharedResource(std::string res_name, ResourcePtr_t res_ptr)
Registers a shared resource only if none exists yet.
std::string string
Definition: nybbler.cc:12
template<typename RES >
template<typename... Args>
static ResourcePtr_t testing::TestSharedGlobalResource< RES >::ProvideDefaultSharedResource ( ResourcePtr_t  res_ptr)
inlinestatic

Creates a shared resource as default only if none exists yet.

Definition at line 417 of file unit_test_base.h.

418  { return ProvideSharedResource(std::string(), res_ptr); }
static ResourcePtr_t ProvideSharedResource(std::string res_name, ResourcePtr_t res_ptr)
Registers a shared resource only if none exists yet.
std::string string
Definition: nybbler.cc:12
template<typename RES >
template<typename... Args>
static ResourcePtr_t testing::TestSharedGlobalResource< RES >::ProvideSharedResource ( std::string  res_name,
ResourcePtr_t  res_ptr 
)
inlinestatic

Registers a shared resource only if none exists yet.

Definition at line 406 of file unit_test_base.h.

407  {
408  if (hasResource(res_name)) return ResourcePtr_t();
409  AddSharedResource(res_name, res_ptr);
410  return res_ptr;
411  }
std::shared_ptr< Resource_t > ResourcePtr_t
static bool hasResource(std::string name="")
static void AddSharedResource(std::string res_name, ResourcePtr_t res_ptr)
Adds a shared resource to the resource registry.
template<typename RES >
template<typename... Args>
static ResourcePtr_t testing::TestSharedGlobalResource< RES >::ProvideSharedResource ( std::string  res_name,
ResourcePtr_t  res_ptr 
)
inlinestatic

Registers a shared resource only if none exists yet.

Definition at line 408 of file unit_test_base.h.

409  {
410  if (hasResource(res_name)) return ResourcePtr_t();
411  AddSharedResource(res_name, res_ptr);
412  return res_ptr;
413  }
std::shared_ptr< Resource_t > ResourcePtr_t
static bool hasResource(std::string name="")
static void AddSharedResource(std::string res_name, ResourcePtr_t res_ptr)
Adds a shared resource to the resource registry.
template<typename RES >
static bool testing::TestSharedGlobalResource< RES >::ReplaceDefaultSharedResource ( Resource_t const *  old_res_ptr,
ResourcePtr_t  res_ptr 
)
inlinestatic

Adds a shared resource as default resource only if it is old_res_ptr.

Definition at line 438 of file unit_test_base.h.

439  { return ReplaceSharedResource(std::string(), old_res_ptr, res_ptr); }
std::string string
Definition: nybbler.cc:12
static bool ReplaceSharedResource(std::string res_name, Resource_t const *old_res_ptr, ResourcePtr_t res_ptr)
Adds a shared resource only if it is old_res_ptr.
template<typename RES >
static bool testing::TestSharedGlobalResource< RES >::ReplaceDefaultSharedResource ( Resource_t const *  old_res_ptr,
ResourcePtr_t  res_ptr 
)
inlinestatic

Adds a shared resource as default resource only if it is old_res_ptr.

Definition at line 440 of file unit_test_base.h.

441  { return ReplaceSharedResource(std::string(), old_res_ptr, res_ptr); }
std::string string
Definition: nybbler.cc:12
static bool ReplaceSharedResource(std::string res_name, Resource_t const *old_res_ptr, ResourcePtr_t res_ptr)
Adds a shared resource only if it is old_res_ptr.
template<typename RES >
static bool testing::TestSharedGlobalResource< RES >::ReplaceDefaultSharedResource ( ResourcePtr_t  old_res_ptr,
ResourcePtr_t  res_ptr 
)
inlinestatic

Definition at line 441 of file unit_test_base.h.

442  { return ReplaceSharedResource(std::string(), old_res_ptr, res_ptr); }
std::string string
Definition: nybbler.cc:12
static bool ReplaceSharedResource(std::string res_name, Resource_t const *old_res_ptr, ResourcePtr_t res_ptr)
Adds a shared resource only if it is old_res_ptr.
template<typename RES >
static bool testing::TestSharedGlobalResource< RES >::ReplaceDefaultSharedResource ( ResourcePtr_t  old_res_ptr,
ResourcePtr_t  res_ptr 
)
inlinestatic

Definition at line 443 of file unit_test_base.h.

444  { return ReplaceSharedResource(std::string(), old_res_ptr, res_ptr); }
std::string string
Definition: nybbler.cc:12
static bool ReplaceSharedResource(std::string res_name, Resource_t const *old_res_ptr, ResourcePtr_t res_ptr)
Adds a shared resource only if it is old_res_ptr.
template<typename RES >
static bool testing::TestSharedGlobalResource< RES >::ReplaceSharedResource ( std::string  res_name,
Resource_t const *  old_res_ptr,
ResourcePtr_t  res_ptr 
)
inlinestatic

Adds a shared resource only if it is old_res_ptr.

Definition at line 420 of file unit_test_base.h.

424  {
425  ResourcePtr_t current_res_ptr = ShareResource();
426  if (current_res_ptr.get() != old_res_ptr) return false;
427  AddSharedResource(res_name, res_ptr);
428  return true;
429  }
std::shared_ptr< Resource_t > ResourcePtr_t
static ResourcePtr_t ShareResource(std::string name="")
Retrieves the specified resource for sharing (nullptr if none)
static void AddSharedResource(std::string res_name, ResourcePtr_t res_ptr)
Adds a shared resource to the resource registry.
template<typename RES >
static bool testing::TestSharedGlobalResource< RES >::ReplaceSharedResource ( std::string  res_name,
Resource_t const *  old_res_ptr,
ResourcePtr_t  res_ptr 
)
inlinestatic

Adds a shared resource only if it is old_res_ptr.

Definition at line 422 of file unit_test_base.h.

426  {
427  ResourcePtr_t current_res_ptr = ShareResource();
428  if (current_res_ptr.get() != old_res_ptr) return false;
429  AddSharedResource(res_name, res_ptr);
430  return true;
431  }
std::shared_ptr< Resource_t > ResourcePtr_t
static ResourcePtr_t ShareResource(std::string name="")
Retrieves the specified resource for sharing (nullptr if none)
static void AddSharedResource(std::string res_name, ResourcePtr_t res_ptr)
Adds a shared resource to the resource registry.
template<typename RES >
static bool testing::TestSharedGlobalResource< RES >::ReplaceSharedResource ( std::string  res_name,
ResourcePtr_t  old_res_ptr,
ResourcePtr_t  res_ptr 
)
inlinestatic

Definition at line 431 of file unit_test_base.h.

432  { return ReplaceSharedResource(res_name, old_res_ptr.get(), res_ptr); }
static bool ReplaceSharedResource(std::string res_name, Resource_t const *old_res_ptr, ResourcePtr_t res_ptr)
Adds a shared resource only if it is old_res_ptr.
template<typename RES >
static bool testing::TestSharedGlobalResource< RES >::ReplaceSharedResource ( std::string  res_name,
ResourcePtr_t  old_res_ptr,
ResourcePtr_t  res_ptr 
)
inlinestatic

Definition at line 433 of file unit_test_base.h.

434  { return ReplaceSharedResource(res_name, old_res_ptr.get(), res_ptr); }
static bool ReplaceSharedResource(std::string res_name, Resource_t const *old_res_ptr, ResourcePtr_t res_ptr)
Adds a shared resource only if it is old_res_ptr.
template<typename RES >
static Resource_t& testing::TestSharedGlobalResource< RES >::Resource ( std::string  name = "")
inlinestatic

Retrieves the specified resource, or throws if not available.

Definition at line 499 of file unit_test_base.h.

500  { return *(Resources.at(name).get()); }
static QCString name
Definition: declinfo.cpp:673
static std::map< std::string, ResourcePtr_t > Resources
template<typename RES >
static Resource_t& testing::TestSharedGlobalResource< RES >::Resource ( std::string  name = "")
inlinestatic

Retrieves the specified resource, or throws if not available.

Definition at line 501 of file unit_test_base.h.

502  { return *(Resources.at(name).get()); }
static QCString name
Definition: declinfo.cpp:673
static std::map< std::string, ResourcePtr_t > Resources
template<typename RES >
static ResourcePtr_t testing::TestSharedGlobalResource< RES >::ShareResource ( std::string  name = "")
inlinestatic

Retrieves the specified resource for sharing (nullptr if none)

Definition at line 492 of file unit_test_base.h.

493  {
494  auto iRes = Resources.find(name);
495  return (iRes == Resources.end())? ResourcePtr_t(): iRes->second;
496  }
static QCString name
Definition: declinfo.cpp:673
std::shared_ptr< Resource_t > ResourcePtr_t
static std::map< std::string, ResourcePtr_t > Resources
template<typename RES >
static ResourcePtr_t testing::TestSharedGlobalResource< RES >::ShareResource ( std::string  name = "")
inlinestatic

Retrieves the specified resource for sharing (nullptr if none)

Definition at line 494 of file unit_test_base.h.

495  {
496  auto iRes = Resources.find(name);
497  return (iRes == Resources.end())? ResourcePtr_t(): iRes->second;
498  }
static QCString name
Definition: declinfo.cpp:673
std::shared_ptr< Resource_t > ResourcePtr_t
static std::map< std::string, ResourcePtr_t > Resources

Member Data Documentation

template<typename RES >
std::map< std::string, typename TestSharedGlobalResource< RES >::ResourcePtr_t > testing::TestSharedGlobalResource< RES >::Resources
staticprivate

Definition at line 509 of file unit_test_base.h.


The documentation for this class was generated from the following file: