nds2-client - User 0.16.7
Loading...
Searching...
No Matches
nds_testing.hh
1#ifndef NDS_TESTING_HH
2#define NDS_TESTING_HH
3
4// Function and classes defined within this file are
5// intended to help with testing of the NDS software.
6
7#include <cstdlib>
8#include <memory>
9#include <string>
10#include <iostream>
11
12template < typename T >
13using pointer = std::unique_ptr< T >;
14
15// std::make_unique didn't make it into C++11, so
16// to allow this to work in a pre C++14 world, we
17// provide a simple replacement.
18//
19// A make_unique<> for C++11. Taken from
20// "Effective Modern C++ by Scott Meyers (O'Reilly).
21// Copyright 2015 Scott Meyers, 978-1-491-90399-5"
22//
23// Permission given in the book to reuse code segments.
24//
25// @tparam T The type of the object to be managed by the unique_ptr
26// @tparam Ts The type of the arguments to T's constructor
27// @param params The arguments to forward to the constructor
28// @return a std::unique_ptr<T>
29template < typename T, typename... Ts >
30std::unique_ptr< T >
31make_unique_ptr( Ts&&... params )
32{
33 return std::unique_ptr< T >( new T( std::forward< Ts >( params )... ) );
34}
35
36#define NDS_ASSERT( bool_expression ) \
37 nds_assert( ( bool_expression ), __FILE__, __LINE__ )
38
39static inline void
40nds_assert( bool expression, std::string fname, int lineno )
41{
42 if ( !expression )
43 {
44 std::cerr << "Assertion at " << fname << ":" << lineno << " was false."
45 << std::endl;
46 std::abort( );
47 }
48}
49
50#endif /* NDS_TESTING_HH */