/usr/include/ns3.26/ns3/test.h is in libns3-dev 3.26+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2009 University of Washington
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef NS3_TEST_H
#define NS3_TEST_H
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <limits>
#include <stdint.h>
#include "non-copyable.h"
#include "system-wall-clock-ms.h"
/**
* \file
* \ingroup testing
* \brief Definition of the testing macros and declaration of
* the testing classes.
*/
/**
* \ingroup core
* \defgroup testing Testing
* \brief Tools to define and execute unit tests.
*
* This module lists the normal Testing API. Most of these
* macros forward to the implementation macros in testingimpl.
* You should generally use these macros only.
*/
/**
* \ingroup testing
* \defgroup testingimpl Testing Implementation
* \brief Internal implementation of the Testing system.
*/
//
// Note on below macros:
//
// When multiple statements are used in a macro, they should be bound
// together in a loop syntactically, so the macro can appear safely
// inside if clauses or other places that expect a single statement or
// a statement block. The "strange" do while construct is a generally
// expected best practice for defining a robust macro.
//
/**
* \ingroup testing
* \brief Check if we should assert on errors, and do so
*/
#define ASSERT_ON_FAILURE \
do { \
if (MustAssertOnFailure ()) \
{ \
*(volatile int *)0 = 0; \
} \
} while (false)
/**
* \ingroup testing
* \brief If we shouldn't continue on errors, return
*/
#define CONTINUE_ON_FAILURE \
do { \
if (!MustContinueOnFailure ()) \
{ \
return; \
} \
} while (false)
/**
* \ingroup testing
* \brief If we shouldn't continue on errors, return test status
*/
#define CONTINUE_ON_FAILURE_RETURNS_BOOL \
do { \
if (!MustContinueOnFailure ()) \
{ \
return IsStatusFailure (); \
} \
} while (false)
// ===========================================================================
// Test for equality (generic version)
// ===========================================================================
/**
* \ingroup testingimpl
* \brief Test that an actual and expected (limit) value are equal and report
* and abort if not.
*/
#define NS_TEST_ASSERT_MSG_EQ_INTERNAL(actual, limit, msg, file, line) \
do { \
if (!((actual) == (limit))) \
{ \
ASSERT_ON_FAILURE; \
std::ostringstream msgStream; \
msgStream << msg; \
std::ostringstream actualStream; \
actualStream << actual; \
std::ostringstream limitStream; \
limitStream << limit; \
ReportTestFailure (std::string (#actual) + " (actual) == " + \
std::string (#limit) + " (limit)", \
actualStream.str (), limitStream.str (), \
msgStream.str (), file, line); \
CONTINUE_ON_FAILURE; \
} \
} while (false)
/**
* \ingroup testing
*
* \brief Test that an actual and expected (limit) value are equal and
* report and abort if not.
*
* Check to see if the expected (limit) value is equal to the actual
* value found in a test case. If the two values are equal nothing
* happens, but if the comparison fails, an error is reported in a
* consistent way and the execution of the current test case is
* aborted.
*
* The message is interpreted as a stream, for example:
*
* \code
* NS_TEST_ASSERT_MSG_EQ (result, true,
* "cannot open file " << filename << " in test");
* \endcode
*
* is legal.
*
* \param [in] actual Expression for the actual value found during the test.
* \param [in] limit Expression for the expected value of the test.
* \param [in] msg Message that is output if the test does not pass.
*
* \warning Do not use this macro if you are comparing floating point
* numbers (float or double) as it is unlikely to do what you expect.
* Use NS_TEST_ASSERT_MSG_EQ_TOL instead.
*/
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg) \
NS_TEST_ASSERT_MSG_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
/**
* \ingroup testingimpl
* \brief Test that an actual and expected (limit) value are equal and report
* and abort if not.
*/
#define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL_INTERNAL(actual, limit, msg, file, line) \
do { \
if (!((actual) == (limit))) \
{ \
ASSERT_ON_FAILURE; \
std::ostringstream msgStream; \
msgStream << msg; \
std::ostringstream actualStream; \
actualStream << actual; \
std::ostringstream limitStream; \
limitStream << limit; \
ReportTestFailure (std::string (#actual) + " (actual) == " + \
std::string (#limit) + " (limit)", \
actualStream.str (), limitStream.str (), \
msgStream.str (), file, line); \
CONTINUE_ON_FAILURE_RETURNS_BOOL; \
} \
} while (false)
/**
* \ingroup testing
*
* \brief Test that an actual and expected (limit) value are equal and
* report and abort if not.
*
* Check to see if the expected (limit) value is equal to the actual
* value found in a test case. If the two values are equal nothing
* happens, but if the comparison fails, an error is reported in a
* consistent way and the execution of the current test case is
* aborted.
*
* The message is interpreted as a stream, for example:
*
* \code
* NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL (result, true,
* "cannot open file " << filename << " in test");
* \endcode
*
* is legal.
*
* \param [in] actual Expression for the actual value found during the test.
* \param [in] limit Expression for the expected value of the test.
* \param [in] msg Message that is output if the test does not pass.
*
* \warning Do not use this macro if you are comparing floating point
* numbers (float or double) as it is unlikely to do what you expect.
* Use NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL_TOL instead.
*
* This function returns a boolean value.
*
*/
#define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL(actual, limit, msg) \
NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
/**
* \ingroup testingimpl
* \brief Test that an actual and expected (limit) value are equal and
* report if not.
*
* Required to avoid use of return statement which allows use in
* methods (esp. callbacks) returning void.
*/
#define NS_TEST_EXPECT_MSG_EQ_INTERNAL(actual, limit, msg, file, line) \
do { \
if (!((actual) == (limit))) \
{ \
ASSERT_ON_FAILURE; \
std::ostringstream msgStream; \
msgStream << msg; \
std::ostringstream actualStream; \
actualStream << actual; \
std::ostringstream limitStream; \
limitStream << limit; \
ReportTestFailure (std::string (#actual) + " (actual) == " + \
std::string (#limit) + " (limit)", \
actualStream.str (), limitStream.str (), \
msgStream.str (), file, line); \
} \
} while (false)
/**
* \ingroup testing
*
* \brief Test that an actual and expected (limit) value are equal and
* report if not.
*
* Check to see if the expected (lmit) value is equal to the actual
* value found in a test case. If the two values are equal nothing
* happens, but if the comparison fails, an error is reported in a
* consistent way. EXPECT* macros do not return if an error is
* detected.
*
* The message is interpreted as a stream, for example:
*
* \code
* NS_TEST_EXPECT_MSG_EQUAL (result, true,
* "cannot open file " << filename << " in test");
* \endcode
*
* is legal.
*
* \param [in] actual Expression for the actual value found during the test.
* \param [in] limit Expression for the expected value of the test.
* \param [in] msg Message that is output if the test does not pass.
*
* \warning Do not use this macro if you are comparing floating point
* numbers (float or double) as it is unlikely to do what you expect.
* Use NS_TEST_EXPECT_MSG_EQ_TOL instead.
*/
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg) \
NS_TEST_EXPECT_MSG_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
// ===========================================================================
// Test for equality with a provided tolerance (use for floating point
// comparisons -- both float and double)
// ===========================================================================
/**
* \ingroup testingimpl
* \brief Test that actual and expected (limit) values are equal to
* plus or minus some tolerance and report and abort if not.
*/
#define NS_TEST_ASSERT_MSG_EQ_TOL_INTERNAL(actual, limit, tol, msg, file, line) \
do { \
if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
{ \
ASSERT_ON_FAILURE; \
std::ostringstream msgStream; \
msgStream << msg; \
std::ostringstream actualStream; \
actualStream << actual; \
std::ostringstream limitStream; \
limitStream << limit << " +- " << tol; \
std::ostringstream condStream; \
condStream << #actual << " (actual) < " << #limit \
<< " (limit) + " << #tol << " (tol) && " \
<< #actual << " (actual) > " << #limit \
<< " (limit) - " << #tol << " (tol)"; \
ReportTestFailure (condStream.str (), actualStream.str (), \
limitStream.str (), msgStream.str (), \
file, line); \
CONTINUE_ON_FAILURE; \
} \
} while (false)
/**
* \ingroup testing
*
* \brief Test that actual and expected (limit) values are equal to
* plus or minus some tolerance and report and abort if not.
*
* Check to see if the expected (limit) value is equal to the actual
* value found in a test case to some tolerance. This is not the same
* thing as asking if two floating point are equal to within some
* epsilon, but is useful for that case. This assertion is geared
* toward more of a measurement problem. Consider measuring a
* physical rod of some kind that you have ordered. You need to
* determine if it is "good." You want to measure the rod to an
* arbitrary precision of sixteen significant figures, you will
* measure the rod to determine if its length is within the tolerances
* you provided. For example, 12.00 inches plus or minus .005 inch
* may be just fine.
*
* In ns-3, you might want to measure a signal to noise ratio and
* check to see if the answer is what you expect. If you naively
* measure (double)1128.93 and compare this number with a constant
* 1128.93 you are almost certainly going to have your test fail
* because of floating point rounding errors. We provide a floating
* point comparison function ns3::TestDoubleIsEqual() but you will
* probably quickly find that is not what you want either. It may
* turn out to be the case that when you measured an snr that printed
* as 1128.93, what was actually measured was something more like
* 1128.9287653857625442 for example. Given that the double epsilon
* is on the order of 0.0000000000000009, you would need to provide
* sixteen significant figures of expected value for this kind of test
* to pass even with a typical test for floating point "approximate
* equality." That is clearly not required or desired. You really
* want to be able to provide 1128.93 along with a tolerance just like
* you provided 12 inches +- 0.005 inch above.
*
* This assertion is designed for real measurements by taking into
* account measurement tolerances. By doing so it also automatically
* compensates for floating point rounding errors. If you really want
* to check floating point equality down to the
* numeric_limits<double>::epsilon () range, consider using
* ns3::TestDoubleIsEqual().
*
* \note Mixing signed and unsigned types can lead to misleading
* results.
*
* The message is interpreted as a stream, for example:
*
* \code
* NS_TEST_ASSERT_MSG_EQ_TOL (snr, 1128.93, 0.005,
* "wrong snr (" << snr << ") in test");
* \endcode
*
* is legal.
*
* \param [in] actual Expression for the actual value found during the test.
* \param [in] limit Expression for the expected value of the test.
* \param [in] tol Tolerance of the test.
* \param [in] msg Message that is output if the test does not pass.
*/
#define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg) \
NS_TEST_ASSERT_MSG_EQ_TOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
/**
* \ingroup testingimpl
* \brief Test that actual and expected (limit) values are equal to
* plus or minus some tolerance and report and abort if not.
*/
#define NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL_INTERNAL(actual, limit, tol, msg, file, line) \
do { \
if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
{ \
ASSERT_ON_FAILURE; \
std::ostringstream msgStream; \
msgStream << msg; \
std::ostringstream actualStream; \
actualStream << actual; \
std::ostringstream limitStream; \
limitStream << limit << " +- " << tol; \
std::ostringstream condStream; \
condStream << #actual << " (actual) < " << #limit \
<< " (limit) + " << #tol << " (tol) && " \
<< #actual << " (actual) > " << #limit \
<< " (limit) - " << #tol << " (tol)"; \
ReportTestFailure (condStream.str (), actualStream.str (), \
limitStream.str (), msgStream.str (), \
file, line); \
CONTINUE_ON_FAILURE_RETURNS_BOOL; \
} \
} while (false)
/**
* \ingroup testing
*
* \brief Test that actual and expected (limit) values are equal to
* plus or minus some tolerance and report and abort if not.
*
* Check to see if the expected (limit) value is equal to the actual
* value found in a test case to some tolerance. This is not the same
* thing as asking if two floating point are equal to within some
* epsilon, but is useful for that case. This assertion is geared
* toward more of a measurement problem. Consider measuring a
* physical rod of some kind that you have ordered. You need to
* determine if it is "good." You want to measure the rod to an
* arbitrary precision of sixteen significant figures, you will
* measure the rod to determine if its length is within the tolerances
* you provided. For example, 12.00 inches plus or minus .005 inch
* may be just fine.
*
* In ns-3, you might want to measure a signal to noise ratio and
* check to see if the answer is what you expect. If you naively
* measure (double)1128.93 and compare this number with a constant
* 1128.93 you are almost certainly going to have your test fail
* because of floating point rounding errors. We provide a floating
* point comparison function ns3::TestDoubleIsEqual() but you will
* probably quickly find that is not what you want either. It may
* turn out to be the case that when you measured an snr that printed
* as 1128.93, what was actually measured was something more like
* 1128.9287653857625442 for example. Given that the double epsilon
* is on the order of 0.0000000000000009, you would need to provide
* sixteen significant figures of expected value for this kind of test
* to pass even with a typical test for floating point "approximate
* equality." That is clearly not required or desired. You really
* want to be able to provide 1128.93 along with a tolerance just like
* you provided 12 inches +- 0.005 inch above.
*
* This assertion is designed for real measurements by taking into
* account measurement tolerances. By doing so it also automatically
* compensates for floating point rounding errors. If you really want
* to check floating point equality down to the
* numeric_limits<double>::epsilon () range, consider using
* ns3::TestDoubleIsEqual().
*
* \note Mixing signed and unsigned types can lead to misleading
* results.
*
* The message is interpreted as a stream, for example:
*
* \code
* NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL (snr, 1128.93, 0.005,
* "wrong snr (" << snr << ") in test");
* \endcode
*
* is legal.
*
* \param [in] actual Expression for the actual value found during the test.
* \param [in] limit Expression for the expected value of the test.
* \param [in] tol Tolerance of the test.
* \param [in] msg Message that is output if the test does not pass.
*
* This function returns a boolean value.
*
*/
#define NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL(actual, limit, tol, msg) \
NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
/**
* \ingroup testingimpl
* \brief Test that actual and expected (limit) values are equal to
* plus or minus some tolerance and report if not.
*
* Required to avoid use of return statement which allows use in
* methods (esp. callbacks) returning void.
*/
#define NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL(actual, limit, tol, msg, file, line) \
do { \
if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
{ \
ASSERT_ON_FAILURE; \
std::ostringstream msgStream; \
msgStream << msg; \
std::ostringstream actualStream; \
actualStream << actual; \
std::ostringstream limitStream; \
limitStream << limit << " +- " << tol; \
std::ostringstream condStream; \
condStream << #actual << " (actual) < " << #limit \
<< " (limit) + " << #tol << " (tol) && " \
<< #actual << " (actual) > " << #limit \
<< " (limit) - " << #tol << " (tol)"; \
ReportTestFailure (condStream.str (), actualStream.str (), \
limitStream.str (), msgStream.str (), \
file, line); \
} \
} while (false)
/**
* \ingroup testing
*
* \brief Test that actual and expected (limit) values are equal to
* plus or minus some tolerance and report if not.
*
* Check to see if the expected (limit) value is equal to the actual
* value found in a test case to some tolerance. This is not the same
* thing as asking if two floating point are equal to within some
* epsilon, but is useful for that case. This assertion is geared
* toward more of a measurement problem. Consider measuring a
* physical rod of some kind that you have ordered. You need to
* determine if it is "good." You want to measure the rod to an
* arbitrary precision of sixteen significant figures, you will
* measure the rod to determine if its length is within the tolerances
* you provided. For example, 12.00 inches plus or minus .005 inch
* may be just fine.
*
* In ns-3, you might want to measure a signal to noise ratio and
* check to see if the answer is what you expect. If you naively
* measure (double)1128.93 and compare this number with a constant
* 1128.93 you are almost certainly going to have your test fail
* because of floating point rounding errors. We provide a floating
* point comparison function ns3::TestDoubleIsEqual() but you will
* probably quickly find that is not what you want either. It may
* turn out to be the case that when you measured an snr that printed
* as 1128.93, what was actually measured was something more like
* 1128.9287653857625442 for example. Given that the double epsilon
* is on the order of 0.0000000000000009, you would need to provide
* sixteen significant figures of expected value for this kind of test
* to pass even with a typical test for floating point "approximate
* equality." That is clearly not required or desired. You really
* want to be able to provide 1128.93 along with a tolerance just like
* you provided 12 inches +- 0.005 inch above.
*
* This assertion is designed for real measurements by taking into
* account measurement tolerances. By doing so it also automatically
* compensates for floating point rounding errors. If you really want
* to check floating point equality down to the
* numeric_limits<double>::epsilon () range, consider using
* ns3::TestDoubleIsEqual().
*
* \note Mixing signed and unsigned types can lead to misleading
* results.
*
* The message is interpreted as a stream, for example:
*
* \code
* NS_TEST_EXPECT_MSG_EQ_TOL (snr, 1128.93, 0.005,
* "wrong snr (" << snr << ") in test");
* \endcode
*
* is legal.
*
* \param [in] actual Expression for the actual value found during the test.
* \param [in] limit Expression for the expected value of the test.
* \param [in] tol Tolerance of the test.
* \param [in] msg Message that is output if the test does not pass.
*/
#define NS_TEST_EXPECT_MSG_EQ_TOL(actual, limit, tol, msg) \
NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
// ===========================================================================
// Test for inequality
// ===========================================================================
/**
* \ingroup testingimpl
* \brief Test that an actual and expected (limit) value are not equal and
* report and abort if not.
*/
#define NS_TEST_ASSERT_MSG_NE_INTERNAL(actual, limit, msg, file, line) \
do { \
if (!((actual) != (limit))) \
{ \
ASSERT_ON_FAILURE; \
std::ostringstream msgStream; \
msgStream << msg; \
std::ostringstream actualStream; \
actualStream << actual; \
std::ostringstream limitStream; \
limitStream << limit; \
ReportTestFailure (std::string (#actual) + " (actual) != " + \
std::string (#limit) + " (limit)", \
actualStream.str (), limitStream.str (), \
msgStream.str (), file, line); \
CONTINUE_ON_FAILURE; \
} \
} while (false)
/**
* \ingroup testing
*
* \brief Test that an actual and expected (limit) value are not equal
* and report and abort if not.
*
* Check to see if the expected (limit) value is not equal to the
* actual value found in a test case. If the two values are not equal
* nothing happens, but if the comparison fails, an error is reported
* in a consistent way and the execution of the current test case is
* aborted.
*
* The message is interpreted as a stream, for example:
*
* \code
* NS_TEST_ASSERT_MSG_NE (result, false,
* "cannot open file " << filename << " in test");
* \endcode
*
* is legal.
*
* \param [in] actual Expression for the actual value found during the test.
* \param [in] limit Expression for the value that actual is tested against.
* \param [in] msg Message that is output if the test does not pass.
*
* \warning Do not use this macro if you are comparing floating point
* numbers (float or double). Use NS_TEST_ASSERT_MSG_FLNE instead.
*/
#define NS_TEST_ASSERT_MSG_NE(actual, limit, msg) \
NS_TEST_ASSERT_MSG_NE_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
/**
* \ingroup testingimpl
* \brief Test that an actual and expected (limit) value are not equal and
* report and abort if not.
*/
#define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL_INTERNAL(actual, limit, msg, file, line) \
do { \
if (!((actual) != (limit))) \
{ \
ASSERT_ON_FAILURE; \
std::ostringstream msgStream; \
msgStream << msg; \
std::ostringstream actualStream; \
actualStream << actual; \
std::ostringstream limitStream; \
limitStream << limit; \
ReportTestFailure (std::string (#actual) + " (actual) != " + \
std::string (#limit) + " (limit)", \
actualStream.str (), limitStream.str (), \
msgStream.str (), file, line); \
CONTINUE_ON_FAILURE_RETURNS_BOOL; \
} \
} while (false)
/**
* \ingroup testing
*
* \brief Test that an actual and expected (limit) value are not equal
* and report and abort if not.
*
* Check to see if the expected (limit) value is not equal to the
* actual value found in a test case. If the two values are equal
* nothing happens, but if the comparison fails, an error is reported
* in a consistent way and the execution of the current test case is
* aborted.
*
* The message is interpreted as a stream, for example:
*
* \code
* NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL (result, false,
* "cannot open file " << filename << " in test");
* \endcode
*
* is legal.
*
* \param [in] actual Expression for the actual value found during the test.
* \param [in] limit Expression for the expected value of the test.
* \param [in] msg Message that is output if the test does not pass.
*
* \warning Do not use this macro if you are comparing floating point
* numbers (float or double). Use NS_TEST_ASSERT_MSG_FLNE instead.
*
* This function returns a boolean value.
*
*/
#define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL(actual, limit, msg) \
NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
/**
* \ingroup testingimpl
* \brief Test that an actual and expected (limit) value are not equal and
* report if not.
*
* Required to avoid use of return statement which allows use in methods
* (callbacks) returning void.
*/
#define NS_TEST_EXPECT_MSG_NE_INTERNAL(actual, limit, msg, file, line) \
do { \
if (!((actual) != (limit))) \
{ \
ASSERT_ON_FAILURE; \
std::ostringstream msgStream; \
msgStream << msg; \
std::ostringstream actualStream; \
actualStream << actual; \
std::ostringstream limitStream; \
limitStream << limit; \
ReportTestFailure (std::string (#actual) + " (actual) != " + \
std::string (#limit) + " (limit)", \
actualStream.str (), limitStream.str (), \
msgStream.str (), file, line); \
} \
} while (false)
/**
* \ingroup testing
*
* \brief Test that an actual and expected (limit) value are not equal
* and report if not.
*
* Check to see if the expected (limit) value is not equal to the
* actual value found in a test case. If the two values are not equal
* nothing happens, but if the comparison fails, an error is reported
* in a consistent way. EXPECT* macros do not return if an error is
* detected.
*
* The message is interpreted as a stream, for example:
*
* \code
* NS_TEST_EXPECT_MSG_NE (result, false,
* "cannot open file " << filename << " in test");
* \endcode
*
* is legal.
*
* \param [in] actual Expression for the actual value found during the test.
* \param [in] limit Expression for the value that actual is tested against.
* \param [in] msg Message that is output if the test does not pass.
*
* \warning Do not use this macro if you are comparing floating point
* numbers (float or double). Use NS_TEST_EXPECT_MSG_FLNE instead.
*/
#define NS_TEST_EXPECT_MSG_NE(actual, limit, msg) \
NS_TEST_EXPECT_MSG_NE_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
// ===========================================================================
// Test for less than relation
// ===========================================================================
/**
* \ingroup testingimpl
* \brief Test that an actual value is less than a limit and report and abort
* if not.
*/
#define NS_TEST_ASSERT_MSG_LT_INTERNAL(actual, limit, msg, file, line) \
do { \
if (!((actual) < (limit))) \
{ \
ASSERT_ON_FAILURE; \
std::ostringstream msgStream; \
msgStream << msg; \
std::ostringstream actualStream; \
actualStream << actual; \
std::ostringstream limitStream; \
limitStream << limit; \
ReportTestFailure (std::string (#actual) + " (actual) < " + \
std::string (#limit) + " (limit)", \
actualStream.str (), limitStream.str (), \
msgStream.str (), file, line); \
CONTINUE_ON_FAILURE; \
} \
} while (false)
/**
* \ingroup testingimpl
* \brief Test that an actual value is less than or equal to a limit and report
* and abort if not.
*/
#define NS_TEST_ASSERT_MSG_LT_OR_EQ_INTERNAL(actual, limit, msg, file, line) \
do { \
if (!((actual) <= (limit))) \
{ \
ASSERT_ON_FAILURE; \
std::ostringstream msgStream; \
msgStream << msg; \
std::ostringstream actualStream; \
actualStream << actual; \
std::ostringstream limitStream; \
limitStream << limit; \
ReportTestFailure (std::string (#actual) + " (actual) < " + \
std::string (#limit) + " (limit)", \
actualStream.str (), limitStream.str (), \
msgStream.str (), file, line); \
CONTINUE_ON_FAILURE; \
} \
} while (false)
/**
* \ingroup testing
*
* \brief Test that an actual value is less than a limit and report
* and abort if not.
*
* Check to see if the actual value found in a test case is less than
* the limit value. If the actual value is lesser nothing happens,
* but if the check fails, an error is reported in a consistent way
* and the execution of the current test case is aborted.
*
* The message is interpreted as a stream.
*
* \param [in] actual Expression for the actual value found during the test.
* \param [in] limit Expression for the limit value of the test.
* \param [in] msg Message that is output if the test does not pass.
*/
#define NS_TEST_ASSERT_MSG_LT(actual, limit, msg) \
NS_TEST_ASSERT_MSG_LT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
/**
* \ingroup testing
*
* \brief Test that an actual value is less than or equal to a limit
* and report and abort if not.
*
* Check to see if the actual value found in a test case is less than
* or equal to the limit value. If the actual value is lesser or
* equal nothing happens, but if the check fails, an error is reported
* in a consistent way and the execution of the current test case is
* aborted.
*
* The message is interpreted as a stream.
*
* \param [in] actual Expression for the actual value found during the test.
* \param [in] limit Expression for the limit value of the test.
* \param [in] msg Message that is output if the test does not pass.
*/
#define NS_TEST_ASSERT_MSG_LT_OR_EQ(actual, limit, msg) \
NS_TEST_ASSERT_MSG_LT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
/**
* \ingroup testingimpl
* \brief Test that an actual value is less than a limit and report if not.
*
* Required to avoid use of return statement which allows use in methods
* (callbacks) returning void.
*/
#define NS_TEST_EXPECT_MSG_LT_INTERNAL(actual, limit, msg, file, line) \
do { \
if (!((actual) < (limit))) \
{ \
ASSERT_ON_FAILURE; \
std::ostringstream msgStream; \
msgStream << msg; \
std::ostringstream actualStream; \
actualStream << actual; \
std::ostringstream limitStream; \
limitStream << limit; \
ReportTestFailure (std::string (#actual) + " (actual) < " + \
std::string (#limit) + " (limit)", \
actualStream.str (), limitStream.str (), \
msgStream.str (), file, line); \
} \
} while (false)
/**
* \ingroup testingimpl
* \brief Test that an actual value is less than or equal to a limit
* and report if not.
*
* Required to avoid use of return statement which allows use in
* methods (callbacks) returning void.
*/
#define NS_TEST_EXPECT_MSG_LT_OR_EQ_INTERNAL(actual, limit, msg, file, line) \
do { \
if (!((actual) <= (limit))) \
{ \
ASSERT_ON_FAILURE; \
std::ostringstream msgStream; \
msgStream << msg; \
std::ostringstream actualStream; \
actualStream << actual; \
std::ostringstream limitStream; \
limitStream << limit; \
ReportTestFailure (std::string (#actual) + " (actual) < " + \
std::string (#limit) + " (limit)", \
actualStream.str (), limitStream.str (), \
msgStream.str (), file, line); \
} \
} while (false)
/**
* \ingroup testing
*
* \brief Test that an actual value is less than a limit and report if
* not.
*
* Check to see if the actual value found in a test case is less than
* the limit value. If the actual value is lesser nothing happens,
* but if the check fails, an error is reported in a consistent way.
* EXPECT* macros do not return if an error is detected.
*
* The message is interpreted as a stream.
*
* \param [in] actual Expression for the actual value found during the test.
* \param [in] limit Expression for the limit value of the test.
* \param [in] msg Message that is output if the test does not pass.
*/
#define NS_TEST_EXPECT_MSG_LT(actual, limit, msg) \
NS_TEST_EXPECT_MSG_LT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
/**
* \ingroup testing
*
* \brief Test that an actual value is less than or equal to a limit
* and report if not.
*
* Check to see if the actual value found in a test case is less than
* or equal to the limit value. If the actual value is lesser or
* equal nothing happens, but if the check fails, an error is reported
* in a consistent way. EXPECT* macros do not return if an error is
* detected.
*
* The message is interpreted as a stream.
*
* \param [in] actual Expression for the actual value found during the test.
* \param [in] limit Expression for the limit value of the test.
* \param [in] msg Message that is output if the test does not pass.
*/
#define NS_TEST_EXPECT_MSG_LT_OR_EQ(actual, limit, msg) \
NS_TEST_EXPECT_MSG_LT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
// ===========================================================================
// Test for greater than relation
// ===========================================================================
/**
* \ingroup testingimpl
* \brief Test that an actual value is greater than a limit and report and abort
* if not.
*/
#define NS_TEST_ASSERT_MSG_GT_INTERNAL(actual, limit, msg, file, line) \
do { \
if (!((actual) > (limit))) \
{ \
ASSERT_ON_FAILURE; \
std::ostringstream msgStream; \
msgStream << msg; \
std::ostringstream actualStream; \
actualStream << actual; \
std::ostringstream limitStream; \
limitStream << limit; \
ReportTestFailure (std::string (#actual) + " (actual) > " + \
std::string (#limit) + " (limit)", \
actualStream.str (), limitStream.str (), \
msgStream.str (), file, line); \
CONTINUE_ON_FAILURE; \
} \
} while (false)
/**
* \ingroup testingimpl
* \brief Test that an actual value is greater than or equal to a
* limit and report and abort if not.
*/
#define NS_TEST_ASSERT_MSG_GT_OR_EQ_INTERNAL(actual, limit, msg, file, line) \
do { \
if (!((actual) >= (limit))) \
{ \
ASSERT_ON_FAILURE; \
std::ostringstream msgStream; \
msgStream << msg; \
std::ostringstream actualStream; \
actualStream << actual; \
std::ostringstream limitStream; \
limitStream << limit; \
ReportTestFailure (std::string (#actual) + " (actual) > " + \
std::string (#limit) + " (limit)", \
actualStream.str (), limitStream.str (), \
msgStream.str (), file, line); \
CONTINUE_ON_FAILURE; \
} \
} while (false)
/**
* \ingroup testing
*
* \brief Test that an actual value is greater than a limit and report
* and abort if not.
*
* Check to see if the actual value found in a test case is greater
* than the limit value. If the actual value is greater nothing
* happens, but if the check fails, an error is reported in a
* consistent way and the execution of the current test case is
* aborted.
*
* The message is interpreted as a stream.
*
* \param [in] actual Expression for the actual value found during the test.
* \param [in] limit Expression for the limit value of the test.
* \param [in] msg Message that is output if the test does not pass.
*/
#define NS_TEST_ASSERT_MSG_GT(actual, limit, msg) \
NS_TEST_ASSERT_MSG_GT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
/**
* \ingroup testing
*
* \brief Test that an actual value is greater than or equal to a
* limit and report and abort if not.
*
* Check to see if the actual value found in a test case is greater
* than or equal to the limit value. If the actual value is greater
* nothing happens, but if the check fails, an error is reported in a
* consistent way and the execution of the current test case is
* aborted.
*
* The message is interpreted as a stream.
*
* \param [in] actual Expression for the actual value found during the test.
* \param [in] limit Expression for the limit value of the test.
* \param [in] msg Message that is output if the test does not pass.
*/
#define NS_TEST_ASSERT_MSG_GT_OR_EQ(actual, limit, msg) \
NS_TEST_ASSERT_MSG_GT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
/**
* \ingroup testingimpl
* \brief Test that an actual value is greater than a limit and report if not.
*
* Required to avoid use of return statement which allows use in methods
* (callbacks) returning void.
*/
#define NS_TEST_EXPECT_MSG_GT_INTERNAL(actual, limit, msg, file, line) \
do { \
if (!((actual) > (limit))) \
{ \
ASSERT_ON_FAILURE; \
std::ostringstream msgStream; \
msgStream << msg; \
std::ostringstream actualStream; \
actualStream << actual; \
std::ostringstream limitStream; \
limitStream << limit; \
ReportTestFailure (std::string (#actual) + " (actual) > " + \
std::string (#limit) + " (limit)", \
actualStream.str (), limitStream.str (), \
msgStream.str (), file, line); \
} \
} while (false)
/**
* \ingroup testingimpl
* \brief Test that an actual value is greater than or equal to limit
* and report if not.
*
* Required to avoid use of return statement which allows use in
* methods (callbacks) returning void.
*/
#define NS_TEST_EXPECT_MSG_GT_OR_EQ_INTERNAL(actual, limit, msg, file, line) \
do { \
if (!((actual) >= (limit))) \
{ \
ASSERT_ON_FAILURE; \
std::ostringstream msgStream; \
msgStream << msg; \
std::ostringstream actualStream; \
actualStream << actual; \
std::ostringstream limitStream; \
limitStream << limit; \
ReportTestFailure (std::string (#actual) + " (actual) > " + \
std::string (#limit) + " (limit)", \
actualStream.str (), limitStream.str (), \
msgStream.str (), file, line); \
} \
} while (false)
/**
* \ingroup testing
*
* \brief Test that an actual value is greater than a limit and report
* if not.
*
* Check to see if the actual value found in a test case is greater
* than the limit value. If the actual value is greater nothing
* happens, but if the check fails, an error is reported in a
* consistent way. EXPECT* macros do not return if an error is
* detected.
*
* The message is interpreted as a stream.
*
* \param [in] actual Expression for the actual value found during the test.
* \param [in] limit Expression for the limit value of the test.
* \param [in] msg Message that is output if the test does not pass.
*/
#define NS_TEST_EXPECT_MSG_GT(actual, limit, msg) \
NS_TEST_EXPECT_MSG_GT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
/**
* \ingroup testing
*
* \brief Test that an actual value is greater than or equal to limit
* and report if not.
*
* Check to see if the actual value found in a test case is greater
* than or equal to the limit value. If the actual value is greater
* nothing happens, but if the check fails, an error is reported in a
* consistent way. EXPECT* macros do not return if an error is
* detected.
*
* The message is interpreted as a stream.
*
* \param [in] actual Expression for the actual value found during the test.
* \param [in] limit Expression for the limit value of the test.
* \param [in] msg Message that is output if the test does not pass.
*/
#define NS_TEST_EXPECT_MSG_GT_OR_EQ(actual, limit, msg) \
NS_TEST_EXPECT_MSG_GT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
namespace ns3 {
/**
* \ingroup testing
* \brief Compare two double precision floating point numbers and
* declare them equal if they are within some epsilon of each other.
*
* Approximate comparison of floating point numbers near equality is
* trickier than one may expect and is well-discussed in the
* literature. Basic strategies revolve around a suggestion by Knuth
* to compare the floating point numbers as binary integers, supplying
* a maximum difference between them . This max difference is
* specified in Units in the Last Place (ulps) or a floating point
* epsilon.
*
* This routine is based on the GNU Scientific Library function
* gsl_fcmp.
*
* \param [in] a The first of double precision floating point
* numbers to compare
* \param [in] b The second of double precision floating point
* numbers to compare
* \param [in] epsilon The tolerance to use in the comparison.
* \returns Returns \c true if the doubles are equal to a precision
* defined by epsilon
*/
bool TestDoubleIsEqual (const double a, const double b,
const double epsilon = std::numeric_limits<double>::epsilon ());
class TestRunnerImpl;
/**
* \ingroup testing
*
* \brief encapsulates test code
*
* To allow a new test to be run within the ns-3 test framework, users
* need to create subclasses of this base class, override the DoRun
* method, and use the NS_TEST_* macros within DoRun.
*/
class TestCase : private NonCopyable
{
public:
/** \brief How long the test takes to execute. */
enum TestDuration {
QUICK = 1, //!< Fast test.
EXTENSIVE = 2, //!< Medium length test.
TAKES_FOREVER = 3 //!< Very long running test.
};
/**
* Destructor
*/
virtual ~TestCase ();
/**
* \return The name of this test
*/
std::string GetName (void) const;
protected:
/**
* \brief Constructor.
*
* \param [in] name The name of the new TestCase created
*/
TestCase (std::string name);
/**
* \brief Add an individual child TestCase to this test suite.
*
* \param [in] testCase Pointer to the TestCase object to be added.
* \param [in] duration Amount of time this test takes to execute.
*/
void AddTestCase (TestCase *testCase, enum TestDuration duration);
/**
* \brief Set the data directory where reference trace files can be
* found.
*
* \param [in] directory The directory where the test data is
* located
*
* In general, this method is invoked as SetDataDir
* (NS_TEST_SOURCEDIR); However, if a module contains a test
* directory with subdirectories (e.g. src/mesh/test), and the test
* data (e.g. pcap traces) is located in one of these
* subdirectories, then the variable NS_TEST_SOURCEDIR may not work
* and the user may want to explicitly pass in a directory string.
*
* Note that NS_TEST_SOURCEDIR is set in src/wscript for each module
*/
void SetDataDir (std::string directory);
/**
* \brief Check if any tests failed.
*
* \return \c true if any of the tests have failed, \c false otherwise.
*/
bool IsStatusFailure (void) const;
/**
* \brief Check if all tests passed.
*
* \return \c true if the tests have succeeded, \c false otherwise.
*/
bool IsStatusSuccess (void) const;
/**
* \brief Get the parent of this TestCsse.
*
* \return A pointer to the parent of this test.
*/
TestCase * GetParent () const;
/**
* \name Internal Interface
* These methods are the interface used by test macros and should not
* be used directly by normal test code.
* @{
*/
/**
* \brief Log the failure of this TestCase.
*
* \param [in] cond The test condition.
* \param [in] actual Actual value of the test.
* \param [in] limit Expected value of the test.
* \param [in] message Message indicating the type of failure.
* \param [in] file The file where the test failed.
* \param [in] line The line number in \p file where the test failed.
*/
void ReportTestFailure (std::string cond, std::string actual,
std::string limit, std::string message,
std::string file, int32_t line);
/**
* \brief Check if this run should assert on failure.
*
* \return \c true if we should assert on failure.
*/
bool MustAssertOnFailure (void) const;
/**
* \brief Check if this run should continue on failure.
*
* \return \c true if we should continue on failure.
*/
bool MustContinueOnFailure (void) const;
/**
* \brief Construct the full path to a file in the data directory.
*
* The data directory is configured by SetDataDirectory().
*
* \param [in] filename The bare (no path) file name
* \return The full path to \p filename in the data directory
*/
std::string CreateDataDirFilename (std::string filename);
/**
* \brief Construct the full path to a file in a temporary directory.
*
* If the TestRunner is invoked with "--update-data", this will be
* the data directory instead.
*
* \param [in] filename The bare (no path) file name
* \return The full path to \p filename in the temporary directory.
*/
std::string CreateTempDirFilename (std::string filename);
/**@}*/
private:
friend class TestRunnerImpl;
/**
* \brief Implementation to do any local setup required for this
* TestCase.
*
* Subclasses should override this method to perform any costly
* per-test setup before DoRun is invoked.
*/
virtual void DoSetup (void);
/**
* \brief Implementation to actually run this TestCase.
*
* Subclasses should override this method to conduct their tests.
*/
virtual void DoRun (void) = 0;
/**
* \brief Implementation to do any local setup required for this
* TestCase.
*
* Subclasses should override this method to perform any costly
* per-test teardown
*/
virtual void DoTeardown (void);
// methods called by TestRunnerImpl
/**
* \brief Actually run this TestCase
*
* \param [in] runner The test runner implementation.
*/
void Run (TestRunnerImpl *runner);
/**
* \copydoc IsStatusFailure()
*/
bool IsFailed (void) const;
/**
* \ingroup testingimpl
* \brief Container for results from a TestCase.
*/
struct Result;
TestCase *m_parent; //!< Pointer to my parent TestCase
std::vector<TestCase *> m_children; //!< Vector of my children
std::string m_dataDir; //!< My data directory
TestRunnerImpl *m_runner; //!< Pointer to the TestRunner
struct Result *m_result; //!< Results data
std::string m_name; //!< TestCase name
enum TestDuration m_duration; //!< TestCase duration
};
/**
* \ingroup testing
*
* \brief A suite of tests to run.
*/
class TestSuite : public TestCase
{
public:
/**
* \enum Type
* \brief Type of test.
*/
enum Type {
ALL = 0, //!<
BVT = 1, //!< This test suite implements a Build Verification Test
UNIT, //!< This test suite implements a Unit Test
SYSTEM, //!< This test suite implements a System Test
EXAMPLE, //!< This test suite implements an Example Test
PERFORMANCE //!< This test suite implements a Performance Test
};
/**
* \brief Constuct a new test suite.
*
* \param [in] name The name of the test suite.
* \param [in] type The TestType of the test suite (defaults to UNIT test).
*/
TestSuite (std::string name, Type type = UNIT);
/**
* \brief get the kind of test this test suite implements
*
* \returns The Type of the suite.
*/
TestSuite::Type GetTestType (void);
private:
// Inherited
virtual void DoRun (void);
TestSuite::Type m_type; //!< Type of this TestSuite
};
/**
* \ingroup testingimpl
*
* \brief A runner to execute tests.
*/
class TestRunner
{
public:
/**
* Run the requested suite of tests,
* according to the given command line arguments.
*
* \param [in] argc The number of elements in \pname{argv}
* \param [in] argv The vector of command line arguments
* \returns Success status
*/
static int Run (int argc, char *argv[]);
};
/**
* \ingroup testing
*
* \brief A simple way to store test vectors (for stimulus or from responses)
*/
template <typename T>
class TestVectors : private NonCopyable
{
public:
/**
* Constructor
*/
TestVectors ();
/**
* Virtual desctructor
*/
virtual ~TestVectors ();
/**
* \brief Set the expected length of this vector.
*
* \param [in] reserve The number of entries to reserve
*/
void Reserve (uint32_t reserve);
/**
* \param [in] vector The test vector to add
*
* \returns The new test vector index
*/
uint32_t Add (T vector);
/**
* \brief Get the total number of test vectors.
* \return The number of test vectors
*/
uint32_t GetN (void) const;
/**
* \brief Get the i'th test vector
* \param [in] i The requested vector index
* \return The requested vector
*/
T Get (uint32_t i) const;
private:
typedef std::vector<T> TestVector; //!< Container type
TestVector m_vectors; //!< The list of test vectors
};
template <typename T>
TestVectors<T>::TestVectors ()
: m_vectors ()
{
}
template <typename T>
void
TestVectors<T>::Reserve (uint32_t reserve)
{
m_vectors.reserve (reserve);
}
template <typename T>
TestVectors<T>::~TestVectors ()
{
}
template <typename T>
uint32_t
TestVectors<T>::Add (T vector)
{
uint32_t index = m_vectors.size ();
m_vectors.push_back (vector);
return index;
}
template <typename T>
uint32_t
TestVectors<T>::GetN (void) const
{
return m_vectors.size ();
}
template <typename T>
T
TestVectors<T>::Get (uint32_t i) const
{
NS_ABORT_MSG_UNLESS (m_vectors.size () > i, "TestVectors::Get(): Bad index");
return m_vectors[i];
}
} // namespace ns3
#endif /* NS3_TEST_H */
|