-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgtest.h.gcov
2241 lines (2241 loc) · 119 KB
/
gtest.h.gcov
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
-: 0:Source:/Users/vanpana/Google Drive/Uni/An 1/Semestrul 2 - Mac/DSA/MultiMapSLL/lib/googletest-master/googletest/include/gtest/gtest.h
-: 0:Graph:./CMakeFiles/Multimap.dir/main.gcno
-: 0:Data:./CMakeFiles/Multimap.dir/main.gcda
-: 0:Runs:4
-: 0:Programs:1
-: 1:// Copyright 2005, Google Inc.
-: 2:// All rights reserved.
-: 3://
-: 4:// Redistribution and use in source and binary forms, with or without
-: 5:// modification, are permitted provided that the following conditions are
-: 6:// met:
-: 7://
-: 8:// * Redistributions of source code must retain the above copyright
-: 9:// notice, this list of conditions and the following disclaimer.
-: 10:// * Redistributions in binary form must reproduce the above
-: 11:// copyright notice, this list of conditions and the following disclaimer
-: 12:// in the documentation and/or other materials provided with the
-: 13:// distribution.
-: 14:// * Neither the name of Google Inc. nor the names of its
-: 15:// contributors may be used to endorse or promote products derived from
-: 16:// this software without specific prior written permission.
-: 17://
-: 18:// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-: 19:// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-: 20:// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-: 21:// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-: 22:// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-: 23:// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-: 24:// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-: 25:// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-: 26:// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-: 27:// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-: 28:// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-: 29://
-: 30:// Author: wan@google.com (Zhanyong Wan)
-: 31://
-: 32:// The Google C++ Testing Framework (Google Test)
-: 33://
-: 34:// This header file defines the public API for Google Test. It should be
-: 35:// included by any test program that uses Google Test.
-: 36://
-: 37:// IMPORTANT NOTE: Due to limitation of the C++ language, we have to
-: 38:// leave some internal implementation details in this header file.
-: 39:// They are clearly marked by comments like this:
-: 40://
-: 41:// // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
-: 42://
-: 43:// Such code is NOT meant to be used by a user directly, and is subject
-: 44:// to CHANGE WITHOUT NOTICE. Therefore DO NOT DEPEND ON IT in a user
-: 45:// program!
-: 46://
-: 47:// Acknowledgment: Google Test borrowed the idea of automatic test
-: 48:// registration from Barthelemy Dagenais' (barthelemy@prologique.com)
-: 49:// easyUnit framework.
-: 50:
-: 51:#ifndef GTEST_INCLUDE_GTEST_GTEST_H_
-: 52:#define GTEST_INCLUDE_GTEST_GTEST_H_
-: 53:
-: 54:#include <limits>
-: 55:#include <ostream>
-: 56:#include <vector>
-: 57:
-: 58:#include "gtest/internal/gtest-internal.h"
-: 59:#include "gtest/internal/gtest-string.h"
-: 60:#include "gtest/gtest-death-test.h"
-: 61:#include "gtest/gtest-message.h"
-: 62:#include "gtest/gtest-param-test.h"
-: 63:#include "gtest/gtest-printers.h"
-: 64:#include "gtest/gtest_prod.h"
-: 65:#include "gtest/gtest-test-part.h"
-: 66:#include "gtest/gtest-typed-test.h"
-: 67:
-: 68:// Depending on the platform, different string classes are available.
-: 69:// On Linux, in addition to ::std::string, Google also makes use of
-: 70:// class ::string, which has the same interface as ::std::string, but
-: 71:// has a different implementation.
-: 72://
-: 73:// You can define GTEST_HAS_GLOBAL_STRING to 1 to indicate that
-: 74:// ::string is available AND is a distinct type to ::std::string, or
-: 75:// define it to 0 to indicate otherwise.
-: 76://
-: 77:// If ::std::string and ::string are the same class on your platform
-: 78:// due to aliasing, you should define GTEST_HAS_GLOBAL_STRING to 0.
-: 79://
-: 80:// If you do not define GTEST_HAS_GLOBAL_STRING, it is defined
-: 81:// heuristically.
-: 82:
-: 83:namespace testing {
-: 84:
-: 85:// Declares the flags.
-: 86:
-: 87:// This flag temporary enables the disabled tests.
-: 88:GTEST_DECLARE_bool_(also_run_disabled_tests);
-: 89:
-: 90:// This flag brings the debugger on an assertion failure.
-: 91:GTEST_DECLARE_bool_(break_on_failure);
-: 92:
-: 93:// This flag controls whether Google Test catches all test-thrown exceptions
-: 94:// and logs them as failures.
-: 95:GTEST_DECLARE_bool_(catch_exceptions);
-: 96:
-: 97:// This flag enables using colors in terminal output. Available values are
-: 98:// "yes" to enable colors, "no" (disable colors), or "auto" (the default)
-: 99:// to let Google Test decide.
-: 100:GTEST_DECLARE_string_(color);
-: 101:
-: 102:// This flag sets up the filter to select by name using a glob pattern
-: 103:// the tests to run. If the filter is not given all tests are executed.
-: 104:GTEST_DECLARE_string_(filter);
-: 105:
-: 106:// This flag causes the Google Test to list tests. None of the tests listed
-: 107:// are actually run if the flag is provided.
-: 108:GTEST_DECLARE_bool_(list_tests);
-: 109:
-: 110:// This flag controls whether Google Test emits a detailed XML report to a file
-: 111:// in addition to its normal textual output.
-: 112:GTEST_DECLARE_string_(output);
-: 113:
-: 114:// This flags control whether Google Test prints the elapsed time for each
-: 115:// test.
-: 116:GTEST_DECLARE_bool_(print_time);
-: 117:
-: 118:// This flag specifies the random number seed.
-: 119:GTEST_DECLARE_int32_(random_seed);
-: 120:
-: 121:// This flag sets how many times the tests are repeated. The default value
-: 122:// is 1. If the value is -1 the tests are repeating forever.
-: 123:GTEST_DECLARE_int32_(repeat);
-: 124:
-: 125:// This flag controls whether Google Test includes Google Test internal
-: 126:// stack frames in failure stack traces.
-: 127:GTEST_DECLARE_bool_(show_internal_stack_frames);
-: 128:
-: 129:// When this flag is specified, tests' order is randomized on every iteration.
-: 130:GTEST_DECLARE_bool_(shuffle);
-: 131:
-: 132:// This flag specifies the maximum number of stack frames to be
-: 133:// printed in a failure message.
-: 134:GTEST_DECLARE_int32_(stack_trace_depth);
-: 135:
-: 136:// When this flag is specified, a failed assertion will throw an
-: 137:// exception if exceptions are enabled, or exit the program with a
-: 138:// non-zero code otherwise.
-: 139:GTEST_DECLARE_bool_(throw_on_failure);
-: 140:
-: 141:// When this flag is set with a "host:port" string, on supported
-: 142:// platforms test results are streamed to the specified port on
-: 143:// the specified host machine.
-: 144:GTEST_DECLARE_string_(stream_result_to);
-: 145:
-: 146:// The upper limit for valid stack trace depths.
-: 147:const int kMaxStackTraceDepth = 100;
-: 148:
-: 149:namespace internal {
-: 150:
-: 151:class AssertHelper;
-: 152:class DefaultGlobalTestPartResultReporter;
-: 153:class ExecDeathTest;
-: 154:class NoExecDeathTest;
-: 155:class FinalSuccessChecker;
-: 156:class GTestFlagSaver;
-: 157:class StreamingListenerTest;
-: 158:class TestResultAccessor;
-: 159:class TestEventListenersAccessor;
-: 160:class TestEventRepeater;
-: 161:class UnitTestRecordPropertyTestHelper;
-: 162:class WindowsDeathTest;
-: 163:class UnitTestImpl* GetUnitTestImpl();
-: 164:void ReportFailureInUnknownLocation(TestPartResult::Type result_type,
-: 165: const std::string& message);
-: 166:
-: 167:} // namespace internal
-: 168:
-: 169:// The friend relationship of some of these classes is cyclic.
-: 170:// If we don't forward declare them the compiler might confuse the classes
-: 171:// in friendship clauses with same named classes on the scope.
-: 172:class Test;
-: 173:class TestCase;
-: 174:class TestInfo;
-: 175:class UnitTest;
-: 176:
-: 177:// A class for indicating whether an assertion was successful. When
-: 178:// the assertion wasn't successful, the AssertionResult object
-: 179:// remembers a non-empty message that describes how it failed.
-: 180://
-: 181:// To create an instance of this class, use one of the factory functions
-: 182:// (AssertionSuccess() and AssertionFailure()).
-: 183://
-: 184:// This class is useful for two purposes:
-: 185:// 1. Defining predicate functions to be used with Boolean test assertions
-: 186:// EXPECT_TRUE/EXPECT_FALSE and their ASSERT_ counterparts
-: 187:// 2. Defining predicate-format functions to be
-: 188:// used with predicate assertions (ASSERT_PRED_FORMAT*, etc).
-: 189://
-: 190:// For example, if you define IsEven predicate:
-: 191://
-: 192:// testing::AssertionResult IsEven(int n) {
-: 193:// if ((n % 2) == 0)
-: 194:// return testing::AssertionSuccess();
-: 195:// else
-: 196:// return testing::AssertionFailure() << n << " is odd";
-: 197:// }
-: 198://
-: 199:// Then the failed expectation EXPECT_TRUE(IsEven(Fib(5)))
-: 200:// will print the message
-: 201://
-: 202:// Value of: IsEven(Fib(5))
-: 203:// Actual: false (5 is odd)
-: 204:// Expected: true
-: 205://
-: 206:// instead of a more opaque
-: 207://
-: 208:// Value of: IsEven(Fib(5))
-: 209:// Actual: false
-: 210:// Expected: true
-: 211://
-: 212:// in case IsEven is a simple Boolean predicate.
-: 213://
-: 214:// If you expect your predicate to be reused and want to support informative
-: 215:// messages in EXPECT_FALSE and ASSERT_FALSE (negative assertions show up
-: 216:// about half as often as positive ones in our tests), supply messages for
-: 217:// both success and failure cases:
-: 218://
-: 219:// testing::AssertionResult IsEven(int n) {
-: 220:// if ((n % 2) == 0)
-: 221:// return testing::AssertionSuccess() << n << " is even";
-: 222:// else
-: 223:// return testing::AssertionFailure() << n << " is odd";
-: 224:// }
-: 225://
-: 226:// Then a statement EXPECT_FALSE(IsEven(Fib(6))) will print
-: 227://
-: 228:// Value of: IsEven(Fib(6))
-: 229:// Actual: true (8 is even)
-: 230:// Expected: false
-: 231://
-: 232:// NB: Predicates that support negative Boolean assertions have reduced
-: 233:// performance in positive ones so be careful not to use them in tests
-: 234:// that have lots (tens of thousands) of positive Boolean assertions.
-: 235://
-: 236:// To use this class with EXPECT_PRED_FORMAT assertions such as:
-: 237://
-: 238:// // Verifies that Foo() returns an even number.
-: 239:// EXPECT_PRED_FORMAT1(IsEven, Foo());
-: 240://
-: 241:// you need to define:
-: 242://
-: 243:// testing::AssertionResult IsEven(const char* expr, int n) {
-: 244:// if ((n % 2) == 0)
-: 245:// return testing::AssertionSuccess();
-: 246:// else
-: 247:// return testing::AssertionFailure()
-: 248:// << "Expected: " << expr << " is even\n Actual: it's " << n;
-: 249:// }
-: 250://
-: 251:// If Foo() returns 5, you will see the following message:
-: 252://
-: 253:// Expected: Foo() is even
-: 254:// Actual: it's 5
-: 255://
-: 256:class GTEST_API_ AssertionResult {
-: 257: public:
-: 258: // Copy constructor.
-: 259: // Used in EXPECT_TRUE/FALSE(assertion_result).
-: 260: AssertionResult(const AssertionResult& other);
-: 261:
-: 262: GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800 /* forcing value to bool */)
-: 263:
-: 264: // Used in the EXPECT_TRUE/FALSE(bool_expression).
-: 265: //
-: 266: // T must be contextually convertible to bool.
-: 267: //
-: 268: // The second parameter prevents this overload from being considered if
-: 269: // the argument is implicitly convertible to AssertionResult. In that case
-: 270: // we want AssertionResult's copy constructor to be used.
-: 271: template <typename T>
-: 272: explicit AssertionResult(
-: 273: const T& success,
-: 274: typename internal::EnableIf<
-: 275: !internal::ImplicitlyConvertible<T, AssertionResult>::value>::type*
-: 276: /*enabler*/ = NULL)
-: 277: : success_(success) {}
-: 278:
-: 279: GTEST_DISABLE_MSC_WARNINGS_POP_()
-: 280:
-: 281: // Assignment operator.
-: 282: AssertionResult& operator=(AssertionResult other) {
-: 283: swap(other);
-: 284: return *this;
-: 285: }
-: 286:
-: 287: // Returns true iff the assertion succeeded.
-: 288: operator bool() const { return success_; } // NOLINT
-: 289:
-: 290: // Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE.
-: 291: AssertionResult operator!() const;
-: 292:
-: 293: // Returns the text streamed into this AssertionResult. Test assertions
-: 294: // use it when they fail (i.e., the predicate's outcome doesn't match the
-: 295: // assertion's expectation). When nothing has been streamed into the
-: 296: // object, returns an empty string.
-: 297: const char* message() const {
-: 298: return message_.get() != NULL ? message_->c_str() : "";
-: 299: }
-: 300: // TODO(vladl@google.com): Remove this after making sure no clients use it.
-: 301: // Deprecated; please use message() instead.
-: 302: const char* failure_message() const { return message(); }
-: 303:
-: 304: // Streams a custom failure message into this object.
-: 305: template <typename T> AssertionResult& operator<<(const T& value) {
-: 306: AppendMessage(Message() << value);
-: 307: return *this;
-: 308: }
-: 309:
-: 310: // Allows streaming basic output manipulators such as endl or flush into
-: 311: // this object.
-: 312: AssertionResult& operator<<(
-: 313: ::std::ostream& (*basic_manipulator)(::std::ostream& stream)) {
-: 314: AppendMessage(Message() << basic_manipulator);
-: 315: return *this;
-: 316: }
-: 317:
-: 318: private:
-: 319: // Appends the contents of message to message_.
-: 320: void AppendMessage(const Message& a_message) {
-: 321: if (message_.get() == NULL)
-: 322: message_.reset(new ::std::string);
-: 323: message_->append(a_message.GetString().c_str());
-: 324: }
-: 325:
-: 326: // Swap the contents of this AssertionResult with other.
-: 327: void swap(AssertionResult& other);
-: 328:
-: 329: // Stores result of the assertion predicate.
-: 330: bool success_;
-: 331: // Stores the message describing the condition in case the expectation
-: 332: // construct is not satisfied with the predicate's outcome.
-: 333: // Referenced via a pointer to avoid taking too much stack frame space
-: 334: // with test assertions.
-: 335: internal::scoped_ptr< ::std::string> message_;
-: 336:};
-: 337:
-: 338:// Makes a successful assertion result.
-: 339:GTEST_API_ AssertionResult AssertionSuccess();
-: 340:
-: 341:// Makes a failed assertion result.
-: 342:GTEST_API_ AssertionResult AssertionFailure();
-: 343:
-: 344:// Makes a failed assertion result with the given failure message.
-: 345:// Deprecated; use AssertionFailure() << msg.
-: 346:GTEST_API_ AssertionResult AssertionFailure(const Message& msg);
-: 347:
-: 348:// The abstract class that all tests inherit from.
-: 349://
-: 350:// In Google Test, a unit test program contains one or many TestCases, and
-: 351:// each TestCase contains one or many Tests.
-: 352://
-: 353:// When you define a test using the TEST macro, you don't need to
-: 354:// explicitly derive from Test - the TEST macro automatically does
-: 355:// this for you.
-: 356://
-: 357:// The only time you derive from Test is when defining a test fixture
-: 358:// to be used a TEST_F. For example:
-: 359://
-: 360:// class FooTest : public testing::Test {
-: 361:// protected:
-: 362:// void SetUp() override { ... }
-: 363:// void TearDown() override { ... }
-: 364:// ...
-: 365:// };
-: 366://
-: 367:// TEST_F(FooTest, Bar) { ... }
-: 368:// TEST_F(FooTest, Baz) { ... }
-: 369://
-: 370:// Test is not copyable.
-: 371:class GTEST_API_ Test {
-: 372: public:
-: 373: friend class TestInfo;
-: 374:
-: 375: // Defines types for pointers to functions that set up and tear down
-: 376: // a test case.
-: 377: typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc;
-: 378: typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc;
-: 379:
-: 380: // The d'tor is virtual as we intend to inherit from Test.
-: 381: virtual ~Test();
-: 382:
-: 383: // Sets up the stuff shared by all tests in this test case.
-: 384: //
-: 385: // Google Test will call Foo::SetUpTestCase() before running the first
-: 386: // test in test case Foo. Hence a sub-class can define its own
-: 387: // SetUpTestCase() method to shadow the one defined in the super
-: 388: // class.
-: 389: static void SetUpTestCase() {}
-: 390:
-: 391: // Tears down the stuff shared by all tests in this test case.
-: 392: //
-: 393: // Google Test will call Foo::TearDownTestCase() after running the last
-: 394: // test in test case Foo. Hence a sub-class can define its own
-: 395: // TearDownTestCase() method to shadow the one defined in the super
-: 396: // class.
-: 397: static void TearDownTestCase() {}
-: 398:
-: 399: // Returns true iff the current test has a fatal failure.
-: 400: static bool HasFatalFailure();
-: 401:
-: 402: // Returns true iff the current test has a non-fatal failure.
-: 403: static bool HasNonfatalFailure();
-: 404:
-: 405: // Returns true iff the current test has a (either fatal or
-: 406: // non-fatal) failure.
-: 407: static bool HasFailure() { return HasFatalFailure() || HasNonfatalFailure(); }
-: 408:
-: 409: // Logs a property for the current test, test case, or for the entire
-: 410: // invocation of the test program when used outside of the context of a
-: 411: // test case. Only the last value for a given key is remembered. These
-: 412: // are public static so they can be called from utility functions that are
-: 413: // not members of the test fixture. Calls to RecordProperty made during
-: 414: // lifespan of the test (from the moment its constructor starts to the
-: 415: // moment its destructor finishes) will be output in XML as attributes of
-: 416: // the <testcase> element. Properties recorded from fixture's
-: 417: // SetUpTestCase or TearDownTestCase are logged as attributes of the
-: 418: // corresponding <testsuite> element. Calls to RecordProperty made in the
-: 419: // global context (before or after invocation of RUN_ALL_TESTS and from
-: 420: // SetUp/TearDown method of Environment objects registered with Google
-: 421: // Test) will be output as attributes of the <testsuites> element.
-: 422: static void RecordProperty(const std::string& key, const std::string& value);
-: 423: static void RecordProperty(const std::string& key, int value);
-: 424:
-: 425: protected:
-: 426: // Creates a Test object.
-: 427: Test();
-: 428:
-: 429: // Sets up the test fixture.
-: 430: virtual void SetUp();
-: 431:
-: 432: // Tears down the test fixture.
-: 433: virtual void TearDown();
-: 434:
-: 435: private:
-: 436: // Returns true iff the current test has the same fixture class as
-: 437: // the first test in the current test case.
-: 438: static bool HasSameFixtureClass();
-: 439:
-: 440: // Runs the test after the test fixture has been set up.
-: 441: //
-: 442: // A sub-class must implement this to define the test logic.
-: 443: //
-: 444: // DO NOT OVERRIDE THIS FUNCTION DIRECTLY IN A USER PROGRAM.
-: 445: // Instead, use the TEST or TEST_F macro.
-: 446: virtual void TestBody() = 0;
-: 447:
-: 448: // Sets up, executes, and tears down the test.
-: 449: void Run();
-: 450:
-: 451: // Deletes self. We deliberately pick an unusual name for this
-: 452: // internal method to avoid clashing with names used in user TESTs.
-: 453: void DeleteSelf_() { delete this; }
-: 454:
-: 455: const internal::scoped_ptr< GTEST_FLAG_SAVER_ > gtest_flag_saver_;
-: 456:
-: 457: // Often a user misspells SetUp() as Setup() and spends a long time
-: 458: // wondering why it is never called by Google Test. The declaration of
-: 459: // the following method is solely for catching such an error at
-: 460: // compile time:
-: 461: //
-: 462: // - The return type is deliberately chosen to be not void, so it
-: 463: // will be a conflict if void Setup() is declared in the user's
-: 464: // test fixture.
-: 465: //
-: 466: // - This method is private, so it will be another compiler error
-: 467: // if the method is called from the user's test fixture.
-: 468: //
-: 469: // DO NOT OVERRIDE THIS FUNCTION.
-: 470: //
-: 471: // If you see an error about overriding the following function or
-: 472: // about it being private, you have mis-spelled SetUp() as Setup().
-: 473: struct Setup_should_be_spelled_SetUp {};
-: 474: virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; }
-: 475:
-: 476: // We disallow copying Tests.
-: 477: GTEST_DISALLOW_COPY_AND_ASSIGN_(Test);
-: 478:};
-: 479:
-: 480:typedef internal::TimeInMillis TimeInMillis;
-: 481:
-: 482:// A copyable object representing a user specified test property which can be
-: 483:// output as a key/value string pair.
-: 484://
-: 485:// Don't inherit from TestProperty as its destructor is not virtual.
-: 486:class TestProperty {
-: 487: public:
-: 488: // C'tor. TestProperty does NOT have a default constructor.
-: 489: // Always use this constructor (with parameters) to create a
-: 490: // TestProperty object.
-: 491: TestProperty(const std::string& a_key, const std::string& a_value) :
-: 492: key_(a_key), value_(a_value) {
-: 493: }
-: 494:
-: 495: // Gets the user supplied key.
-: 496: const char* key() const {
-: 497: return key_.c_str();
-: 498: }
-: 499:
-: 500: // Gets the user supplied value.
-: 501: const char* value() const {
-: 502: return value_.c_str();
-: 503: }
-: 504:
-: 505: // Sets a new value, overriding the one supplied in the constructor.
-: 506: void SetValue(const std::string& new_value) {
-: 507: value_ = new_value;
-: 508: }
-: 509:
-: 510: private:
-: 511: // The key supplied by the user.
-: 512: std::string key_;
-: 513: // The value supplied by the user.
-: 514: std::string value_;
-: 515:};
-: 516:
-: 517:// The result of a single Test. This includes a list of
-: 518:// TestPartResults, a list of TestProperties, a count of how many
-: 519:// death tests there are in the Test, and how much time it took to run
-: 520:// the Test.
-: 521://
-: 522:// TestResult is not copyable.
-: 523:class GTEST_API_ TestResult {
-: 524: public:
-: 525: // Creates an empty TestResult.
-: 526: TestResult();
-: 527:
-: 528: // D'tor. Do not inherit from TestResult.
-: 529: ~TestResult();
-: 530:
-: 531: // Gets the number of all test parts. This is the sum of the number
-: 532: // of successful test parts and the number of failed test parts.
-: 533: int total_part_count() const;
-: 534:
-: 535: // Returns the number of the test properties.
-: 536: int test_property_count() const;
-: 537:
-: 538: // Returns true iff the test passed (i.e. no test part failed).
-: 539: bool Passed() const { return !Failed(); }
-: 540:
-: 541: // Returns true iff the test failed.
-: 542: bool Failed() const;
-: 543:
-: 544: // Returns true iff the test fatally failed.
-: 545: bool HasFatalFailure() const;
-: 546:
-: 547: // Returns true iff the test has a non-fatal failure.
-: 548: bool HasNonfatalFailure() const;
-: 549:
-: 550: // Returns the elapsed time, in milliseconds.
-: 551: TimeInMillis elapsed_time() const { return elapsed_time_; }
-: 552:
-: 553: // Returns the i-th test part result among all the results. i can range
-: 554: // from 0 to test_property_count() - 1. If i is not in that range, aborts
-: 555: // the program.
-: 556: const TestPartResult& GetTestPartResult(int i) const;
-: 557:
-: 558: // Returns the i-th test property. i can range from 0 to
-: 559: // test_property_count() - 1. If i is not in that range, aborts the
-: 560: // program.
-: 561: const TestProperty& GetTestProperty(int i) const;
-: 562:
-: 563: private:
-: 564: friend class TestInfo;
-: 565: friend class TestCase;
-: 566: friend class UnitTest;
-: 567: friend class internal::DefaultGlobalTestPartResultReporter;
-: 568: friend class internal::ExecDeathTest;
-: 569: friend class internal::TestResultAccessor;
-: 570: friend class internal::UnitTestImpl;
-: 571: friend class internal::WindowsDeathTest;
-: 572:
-: 573: // Gets the vector of TestPartResults.
-: 574: const std::vector<TestPartResult>& test_part_results() const {
-: 575: return test_part_results_;
-: 576: }
-: 577:
-: 578: // Gets the vector of TestProperties.
-: 579: const std::vector<TestProperty>& test_properties() const {
-: 580: return test_properties_;
-: 581: }
-: 582:
-: 583: // Sets the elapsed time.
-: 584: void set_elapsed_time(TimeInMillis elapsed) { elapsed_time_ = elapsed; }
-: 585:
-: 586: // Adds a test property to the list. The property is validated and may add
-: 587: // a non-fatal failure if invalid (e.g., if it conflicts with reserved
-: 588: // key names). If a property is already recorded for the same key, the
-: 589: // value will be updated, rather than storing multiple values for the same
-: 590: // key. xml_element specifies the element for which the property is being
-: 591: // recorded and is used for validation.
-: 592: void RecordProperty(const std::string& xml_element,
-: 593: const TestProperty& test_property);
-: 594:
-: 595: // Adds a failure if the key is a reserved attribute of Google Test
-: 596: // testcase tags. Returns true if the property is valid.
-: 597: // TODO(russr): Validate attribute names are legal and human readable.
-: 598: static bool ValidateTestProperty(const std::string& xml_element,
-: 599: const TestProperty& test_property);
-: 600:
-: 601: // Adds a test part result to the list.
-: 602: void AddTestPartResult(const TestPartResult& test_part_result);
-: 603:
-: 604: // Returns the death test count.
-: 605: int death_test_count() const { return death_test_count_; }
-: 606:
-: 607: // Increments the death test count, returning the new count.
-: 608: int increment_death_test_count() { return ++death_test_count_; }
-: 609:
-: 610: // Clears the test part results.
-: 611: void ClearTestPartResults();
-: 612:
-: 613: // Clears the object.
-: 614: void Clear();
-: 615:
-: 616: // Protects mutable state of the property vector and of owned
-: 617: // properties, whose values may be updated.
-: 618: internal::Mutex test_properites_mutex_;
-: 619:
-: 620: // The vector of TestPartResults
-: 621: std::vector<TestPartResult> test_part_results_;
-: 622: // The vector of TestProperties
-: 623: std::vector<TestProperty> test_properties_;
-: 624: // Running count of death tests.
-: 625: int death_test_count_;
-: 626: // The elapsed time, in milliseconds.
-: 627: TimeInMillis elapsed_time_;
-: 628:
-: 629: // We disallow copying TestResult.
-: 630: GTEST_DISALLOW_COPY_AND_ASSIGN_(TestResult);
-: 631:}; // class TestResult
-: 632:
-: 633:// A TestInfo object stores the following information about a test:
-: 634://
-: 635:// Test case name
-: 636:// Test name
-: 637:// Whether the test should be run
-: 638:// A function pointer that creates the test object when invoked
-: 639:// Test result
-: 640://
-: 641:// The constructor of TestInfo registers itself with the UnitTest
-: 642:// singleton such that the RUN_ALL_TESTS() macro knows which tests to
-: 643:// run.
-: 644:class GTEST_API_ TestInfo {
-: 645: public:
-: 646: // Destructs a TestInfo object. This function is not virtual, so
-: 647: // don't inherit from TestInfo.
-: 648: ~TestInfo();
-: 649:
-: 650: // Returns the test case name.
-: 651: const char* test_case_name() const { return test_case_name_.c_str(); }
-: 652:
-: 653: // Returns the test name.
-: 654: const char* name() const { return name_.c_str(); }
-: 655:
-: 656: // Returns the name of the parameter type, or NULL if this is not a typed
-: 657: // or a type-parameterized test.
-: 658: const char* type_param() const {
-: 659: if (type_param_.get() != NULL)
-: 660: return type_param_->c_str();
-: 661: return NULL;
-: 662: }
-: 663:
-: 664: // Returns the text representation of the value parameter, or NULL if this
-: 665: // is not a value-parameterized test.
-: 666: const char* value_param() const {
-: 667: if (value_param_.get() != NULL)
-: 668: return value_param_->c_str();
-: 669: return NULL;
-: 670: }
-: 671:
-: 672: // Returns the file name where this test is defined.
-: 673: const char* file() const { return location_.file.c_str(); }
-: 674:
-: 675: // Returns the line where this test is defined.
-: 676: int line() const { return location_.line; }
-: 677:
-: 678: // Returns true if this test should run, that is if the test is not
-: 679: // disabled (or it is disabled but the also_run_disabled_tests flag has
-: 680: // been specified) and its full name matches the user-specified filter.
-: 681: //
-: 682: // Google Test allows the user to filter the tests by their full names.
-: 683: // The full name of a test Bar in test case Foo is defined as
-: 684: // "Foo.Bar". Only the tests that match the filter will run.
-: 685: //
-: 686: // A filter is a colon-separated list of glob (not regex) patterns,
-: 687: // optionally followed by a '-' and a colon-separated list of
-: 688: // negative patterns (tests to exclude). A test is run if it
-: 689: // matches one of the positive patterns and does not match any of
-: 690: // the negative patterns.
-: 691: //
-: 692: // For example, *A*:Foo.* is a filter that matches any string that
-: 693: // contains the character 'A' or starts with "Foo.".
-: 694: bool should_run() const { return should_run_; }
-: 695:
-: 696: // Returns true iff this test will appear in the XML report.
-: 697: bool is_reportable() const {
-: 698: // For now, the XML report includes all tests matching the filter.
-: 699: // In the future, we may trim tests that are excluded because of
-: 700: // sharding.
-: 701: return matches_filter_;
-: 702: }
-: 703:
-: 704: // Returns the result of the test.
-: 705: const TestResult* result() const { return &result_; }
-: 706:
-: 707: private:
-: 708:#if GTEST_HAS_DEATH_TEST
-: 709: friend class internal::DefaultDeathTestFactory;
-: 710:#endif // GTEST_HAS_DEATH_TEST
-: 711: friend class Test;
-: 712: friend class TestCase;
-: 713: friend class internal::UnitTestImpl;
-: 714: friend class internal::StreamingListenerTest;
-: 715: friend TestInfo* internal::MakeAndRegisterTestInfo(
-: 716: const char* test_case_name,
-: 717: const char* name,
-: 718: const char* type_param,
-: 719: const char* value_param,
-: 720: internal::CodeLocation code_location,
-: 721: internal::TypeId fixture_class_id,
-: 722: Test::SetUpTestCaseFunc set_up_tc,
-: 723: Test::TearDownTestCaseFunc tear_down_tc,
-: 724: internal::TestFactoryBase* factory);
-: 725:
-: 726: // Constructs a TestInfo object. The newly constructed instance assumes
-: 727: // ownership of the factory object.
-: 728: TestInfo(const std::string& test_case_name,
-: 729: const std::string& name,
-: 730: const char* a_type_param, // NULL if not a type-parameterized test
-: 731: const char* a_value_param, // NULL if not a value-parameterized test
-: 732: internal::CodeLocation a_code_location,
-: 733: internal::TypeId fixture_class_id,
-: 734: internal::TestFactoryBase* factory);
-: 735:
-: 736: // Increments the number of death tests encountered in this test so
-: 737: // far.
-: 738: int increment_death_test_count() {
-: 739: return result_.increment_death_test_count();
-: 740: }
-: 741:
-: 742: // Creates the test object, runs it, records its result, and then
-: 743: // deletes it.
-: 744: void Run();
-: 745:
-: 746: static void ClearTestResult(TestInfo* test_info) {
-: 747: test_info->result_.Clear();
-: 748: }
-: 749:
-: 750: // These fields are immutable properties of the test.
-: 751: const std::string test_case_name_; // Test case name
-: 752: const std::string name_; // Test name
-: 753: // Name of the parameter type, or NULL if this is not a typed or a
-: 754: // type-parameterized test.
-: 755: const internal::scoped_ptr<const ::std::string> type_param_;
-: 756: // Text representation of the value parameter, or NULL if this is not a
-: 757: // value-parameterized test.
-: 758: const internal::scoped_ptr<const ::std::string> value_param_;
-: 759: internal::CodeLocation location_;
-: 760: const internal::TypeId fixture_class_id_; // ID of the test fixture class
-: 761: bool should_run_; // True iff this test should run
-: 762: bool is_disabled_; // True iff this test is disabled
-: 763: bool matches_filter_; // True if this test matches the
-: 764: // user-specified filter.
-: 765: internal::TestFactoryBase* const factory_; // The factory that creates
-: 766: // the test object
-: 767:
-: 768: // This field is mutable and needs to be reset before running the
-: 769: // test for the second time.
-: 770: TestResult result_;
-: 771:
-: 772: GTEST_DISALLOW_COPY_AND_ASSIGN_(TestInfo);
-: 773:};
-: 774:
-: 775:// A test case, which consists of a vector of TestInfos.
-: 776://
-: 777:// TestCase is not copyable.
-: 778:class GTEST_API_ TestCase {
-: 779: public:
-: 780: // Creates a TestCase with the given name.
-: 781: //
-: 782: // TestCase does NOT have a default constructor. Always use this
-: 783: // constructor to create a TestCase object.
-: 784: //
-: 785: // Arguments:
-: 786: //
-: 787: // name: name of the test case
-: 788: // a_type_param: the name of the test's type parameter, or NULL if
-: 789: // this is not a type-parameterized test.
-: 790: // set_up_tc: pointer to the function that sets up the test case
-: 791: // tear_down_tc: pointer to the function that tears down the test case
-: 792: TestCase(const char* name, const char* a_type_param,
-: 793: Test::SetUpTestCaseFunc set_up_tc,
-: 794: Test::TearDownTestCaseFunc tear_down_tc);
-: 795:
-: 796: // Destructor of TestCase.
-: 797: virtual ~TestCase();
-: 798:
-: 799: // Gets the name of the TestCase.
-: 800: const char* name() const { return name_.c_str(); }
-: 801:
-: 802: // Returns the name of the parameter type, or NULL if this is not a
-: 803: // type-parameterized test case.
-: 804: const char* type_param() const {
-: 805: if (type_param_.get() != NULL)
-: 806: return type_param_->c_str();
-: 807: return NULL;
-: 808: }
-: 809:
-: 810: // Returns true if any test in this test case should run.
-: 811: bool should_run() const { return should_run_; }
-: 812:
-: 813: // Gets the number of successful tests in this test case.
-: 814: int successful_test_count() const;
-: 815:
-: 816: // Gets the number of failed tests in this test case.
-: 817: int failed_test_count() const;
-: 818:
-: 819: // Gets the number of disabled tests that will be reported in the XML report.
-: 820: int reportable_disabled_test_count() const;
-: 821:
-: 822: // Gets the number of disabled tests in this test case.
-: 823: int disabled_test_count() const;
-: 824:
-: 825: // Gets the number of tests to be printed in the XML report.
-: 826: int reportable_test_count() const;
-: 827:
-: 828: // Get the number of tests in this test case that should run.
-: 829: int test_to_run_count() const;
-: 830:
-: 831: // Gets the number of all tests in this test case.
-: 832: int total_test_count() const;
-: 833:
-: 834: // Returns true iff the test case passed.
-: 835: bool Passed() const { return !Failed(); }
-: 836:
-: 837: // Returns true iff the test case failed.
-: 838: bool Failed() const { return failed_test_count() > 0; }
-: 839:
-: 840: // Returns the elapsed time, in milliseconds.
-: 841: TimeInMillis elapsed_time() const { return elapsed_time_; }
-: 842:
-: 843: // Returns the i-th test among all the tests. i can range from 0 to
-: 844: // total_test_count() - 1. If i is not in that range, returns NULL.
-: 845: const TestInfo* GetTestInfo(int i) const;
-: 846:
-: 847: // Returns the TestResult that holds test properties recorded during
-: 848: // execution of SetUpTestCase and TearDownTestCase.
-: 849: const TestResult& ad_hoc_test_result() const { return ad_hoc_test_result_; }
-: 850:
-: 851: private:
-: 852: friend class Test;
-: 853: friend class internal::UnitTestImpl;
-: 854:
-: 855: // Gets the (mutable) vector of TestInfos in this TestCase.
-: 856: std::vector<TestInfo*>& test_info_list() { return test_info_list_; }
-: 857:
-: 858: // Gets the (immutable) vector of TestInfos in this TestCase.
-: 859: const std::vector<TestInfo*>& test_info_list() const {
-: 860: return test_info_list_;
-: 861: }
-: 862:
-: 863: // Returns the i-th test among all the tests. i can range from 0 to
-: 864: // total_test_count() - 1. If i is not in that range, returns NULL.
-: 865: TestInfo* GetMutableTestInfo(int i);
-: 866:
-: 867: // Sets the should_run member.
-: 868: void set_should_run(bool should) { should_run_ = should; }
-: 869:
-: 870: // Adds a TestInfo to this test case. Will delete the TestInfo upon
-: 871: // destruction of the TestCase object.
-: 872: void AddTestInfo(TestInfo * test_info);
-: 873:
-: 874: // Clears the results of all tests in this test case.
-: 875: void ClearResult();
-: 876:
-: 877: // Clears the results of all tests in the given test case.
-: 878: static void ClearTestCaseResult(TestCase* test_case) {
-: 879: test_case->ClearResult();
-: 880: }
-: 881:
-: 882: // Runs every test in this TestCase.
-: 883: void Run();
-: 884:
-: 885: // Runs SetUpTestCase() for this TestCase. This wrapper is needed
-: 886: // for catching exceptions thrown from SetUpTestCase().
-: 887: void RunSetUpTestCase() { (*set_up_tc_)(); }
-: 888:
-: 889: // Runs TearDownTestCase() for this TestCase. This wrapper is
-: 890: // needed for catching exceptions thrown from TearDownTestCase().
-: 891: void RunTearDownTestCase() { (*tear_down_tc_)(); }
-: 892:
-: 893: // Returns true iff test passed.
-: 894: static bool TestPassed(const TestInfo* test_info) {
-: 895: return test_info->should_run() && test_info->result()->Passed();
-: 896: }
-: 897:
-: 898: // Returns true iff test failed.
-: 899: static bool TestFailed(const TestInfo* test_info) {
-: 900: return test_info->should_run() && test_info->result()->Failed();
-: 901: }
-: 902:
-: 903: // Returns true iff the test is disabled and will be reported in the XML
-: 904: // report.
-: 905: static bool TestReportableDisabled(const TestInfo* test_info) {
-: 906: return test_info->is_reportable() && test_info->is_disabled_;
-: 907: }
-: 908:
-: 909: // Returns true iff test is disabled.
-: 910: static bool TestDisabled(const TestInfo* test_info) {
-: 911: return test_info->is_disabled_;
-: 912: }
-: 913:
-: 914: // Returns true iff this test will appear in the XML report.
-: 915: static bool TestReportable(const TestInfo* test_info) {
-: 916: return test_info->is_reportable();
-: 917: }
-: 918:
-: 919: // Returns true if the given test should run.
-: 920: static bool ShouldRunTest(const TestInfo* test_info) {
-: 921: return test_info->should_run();
-: 922: }
-: 923:
-: 924: // Shuffles the tests in this test case.
-: 925: void ShuffleTests(internal::Random* random);
-: 926:
-: 927: // Restores the test order to before the first shuffle.
-: 928: void UnshuffleTests();
-: 929:
-: 930: // Name of the test case.
-: 931: std::string name_;
-: 932: // Name of the parameter type, or NULL if this is not a typed or a
-: 933: // type-parameterized test.
-: 934: const internal::scoped_ptr<const ::std::string> type_param_;
-: 935: // The vector of TestInfos in their original order. It owns the
-: 936: // elements in the vector.
-: 937: std::vector<TestInfo*> test_info_list_;
-: 938: // Provides a level of indirection for the test list to allow easy
-: 939: // shuffling and restoring the test order. The i-th element in this
-: 940: // vector is the index of the i-th test in the shuffled test list.
-: 941: std::vector<int> test_indices_;
-: 942: // Pointer to the function that sets up the test case.
-: 943: Test::SetUpTestCaseFunc set_up_tc_;
-: 944: // Pointer to the function that tears down the test case.
-: 945: Test::TearDownTestCaseFunc tear_down_tc_;
-: 946: // True iff any test in this test case should run.
-: 947: bool should_run_;
-: 948: // Elapsed time, in milliseconds.
-: 949: TimeInMillis elapsed_time_;
-: 950: // Holds test properties recorded during execution of SetUpTestCase and
-: 951: // TearDownTestCase.
-: 952: TestResult ad_hoc_test_result_;
-: 953:
-: 954: // We disallow copying TestCases.
-: 955: GTEST_DISALLOW_COPY_AND_ASSIGN_(TestCase);
-: 956:};
-: 957:
-: 958:// An Environment object is capable of setting up and tearing down an
-: 959:// environment. You should subclass this to define your own
-: 960:// environment(s).
-: 961://
-: 962:// An Environment object does the set-up and tear-down in virtual
-: 963:// methods SetUp() and TearDown() instead of the constructor and the
-: 964:// destructor, as:
-: 965://
-: 966:// 1. You cannot safely throw from a destructor. This is a problem
-: 967:// as in some cases Google Test is used where exceptions are enabled, and
-: 968:// we may want to implement ASSERT_* using exceptions where they are
-: 969:// available.
-: 970:// 2. You cannot use ASSERT_* directly in a constructor or
-: 971:// destructor.
-: 972:class Environment {
-: 973: public:
-: 974: // The d'tor is virtual as we need to subclass Environment.
-: 975: virtual ~Environment() {}
-: 976:
-: 977: // Override this to define how to set up the environment.
-: 978: virtual void SetUp() {}
-: 979:
-: 980: // Override this to define how to tear down the environment.
-: 981: virtual void TearDown() {}
-: 982: private:
-: 983: // If you see an error about overriding the following function or
-: 984: // about it being private, you have mis-spelled SetUp() as Setup().
-: 985: struct Setup_should_be_spelled_SetUp {};
-: 986: virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; }
-: 987:};
-: 988:
-: 989:// The interface for tracing execution of tests. The methods are organized in
-: 990:// the order the corresponding events are fired.
-: 991:class TestEventListener {
-: 992: public:
-: 993: virtual ~TestEventListener() {}
-: 994:
-: 995: // Fired before any test activity starts.