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