A Discrete-Event Network Simulator
API
spectrum-test.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 University of Washington
3  * Copyright (c) 2011 CTTC
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Nicola Baldo <nbaldo@cttc.es>
19  * part of the code copied from test.h
20  */
21 
22 #include <ns3/spectrum-value.h>
23 #include <ns3/test.h>
24 
45 #define NS_TEST_ASSERT_MSG_SPECTRUM_MODEL_EQ_TOL(actual, expected, tol, msg) \
46  do \
47  { \
48  Bands::const_iterator i = (actual).Begin(); \
49  Bands::const_iterator j = (expected).Begin(); \
50  uint32_t k = 0; \
51  while (i != (actual).End() && j != (expected).End()) \
52  { \
53  if ((i->fl > j->fl + (tol)) || (i->fl < j->fl - (tol)) || (i->fc > j->fc + (tol)) || \
54  (i->fc < j->fc - (tol)) || (i->fh > j->fh + (tol)) || (i->fh < j->fh - (tol))) \
55  { \
56  ASSERT_ON_FAILURE; \
57  std::ostringstream indexStream; \
58  indexStream << "[" << k << "]"; \
59  std::ostringstream msgStream; \
60  msgStream << (msg); \
61  std::ostringstream actualStream; \
62  actualStream << i->fl << " <-- " << i->fc << " --> " << i->fh; \
63  std::ostringstream expectedStream; \
64  expectedStream << j->fl << " <-- " << j->fc << " --> " << j->fh; \
65  ReportTestFailure(std::string(#actual) + indexStream.str() + \
66  " == " + std::string(#expected) + indexStream.str(), \
67  actualStream.str(), \
68  expectedStream.str(), \
69  msgStream.str(), \
70  (__FILE__), \
71  (__LINE__)); \
72  CONTINUE_ON_FAILURE; \
73  } \
74  ++i; \
75  ++j; \
76  ++k; \
77  } \
78  if (i != (actual).End() || j != (expected).End()) \
79  { \
80  std::ostringstream msgStream; \
81  msgStream << (msg); \
82  std::ostringstream actualStream; \
83  actualStream << (i != (actual).End()); \
84  std::ostringstream expectedStream; \
85  expectedStream << (j != (expected).End()); \
86  ReportTestFailure("Bands::iterator == End ()", \
87  actualStream.str(), \
88  expectedStream.str(), \
89  msgStream.str(), \
90  (__FILE__), \
91  (__LINE__)); \
92  } \
93  } while (false);
94 
110 #define NS_TEST_ASSERT_MSG_SPECTRUM_VALUE_EQ_TOL(actual, expected, tol, msg) \
111  do \
112  { \
113  Values::const_iterator i = (actual).ConstValuesBegin(); \
114  Values::const_iterator j = (expected).ConstValuesBegin(); \
115  uint32_t k = 0; \
116  while (i != (actual).ConstValuesEnd() && j != (expected).ConstValuesEnd()) \
117  { \
118  if ((*i) > (*j) + (tol) || (*i) < (*j) - (tol)) \
119  { \
120  ASSERT_ON_FAILURE; \
121  std::ostringstream indexStream; \
122  indexStream << "[" << k << "]"; \
123  std::ostringstream msgStream; \
124  msgStream << msg; \
125  std::ostringstream actualStream; \
126  actualStream << actual; \
127  std::ostringstream expectedStream; \
128  expectedStream << expected; \
129  ReportTestFailure(std::string(#actual) + indexStream.str() + \
130  " == " + std::string(#expected) + indexStream.str(), \
131  actualStream.str(), \
132  expectedStream.str(), \
133  msgStream.str(), \
134  __FILE__, \
135  __LINE__); \
136  CONTINUE_ON_FAILURE; \
137  } \
138  ++i; \
139  ++j; \
140  ++k; \
141  } \
142  if (i != (actual).ConstValuesEnd() || j != (expected).ConstValuesEnd()) \
143  { \
144  std::ostringstream msgStream; \
145  msgStream << (msg); \
146  std::ostringstream actualStream; \
147  actualStream << (i != (actual).ConstValuesEnd()); \
148  std::ostringstream expectedStream; \
149  expectedStream << (j != (expected).ConstValuesEnd()); \
150  ReportTestFailure("Values::const_iterator == ConstValuesEnd ()", \
151  actualStream.str(), \
152  expectedStream.str(), \
153  msgStream.str(), \
154  (__FILE__), \
155  (__LINE__)); \
156  } \
157  } while (false);