diff options
author | 2014-11-21 14:38:06 -0800 | |
---|---|---|
committer | 2014-11-21 14:38:06 -0800 | |
commit | 77d77f446d1685cd21465627a747341c3c3665e4 (patch) | |
tree | 3d771f0dd9ab2a38d17cd9a280eb2e799327ac7f /tests | |
parent | ebacb6127a952910f43a59460af43427d93df46c (diff) |
Add pop_back to GrTRecorder.h
Review URL: https://codereview.chromium.org/750613002
Diffstat (limited to 'tests')
-rw-r--r-- | tests/GrTRecorderTest.cpp | 56 |
1 files changed, 39 insertions, 17 deletions
diff --git a/tests/GrTRecorderTest.cpp b/tests/GrTRecorderTest.cpp index 83bc445b5f..fde70ac8e8 100644 --- a/tests/GrTRecorderTest.cpp +++ b/tests/GrTRecorderTest.cpp @@ -7,9 +7,10 @@ #if SK_SUPPORT_GPU +#include "GrTRecorder.h" #include "SkMatrix.h" +#include "SkRandom.h" #include "SkString.h" -#include "GrTRecorder.h" #include "Test.h" //////////////////////////////////////////////////////////////////////////////// @@ -25,22 +26,43 @@ private: int fValue; }; -static void test_empty_back(skiatest::Reporter* reporter) { - GrTRecorder<IntWrapper, int> recorder(0); - - REPORTER_ASSERT(reporter, recorder.empty()); - - for (int i = 0; i < 100; ++i) { - REPORTER_ASSERT(reporter, i == *GrNEW_APPEND_TO_RECORDER(recorder, IntWrapper, (i))); - REPORTER_ASSERT(reporter, !recorder.empty()); - REPORTER_ASSERT(reporter, i == recorder.back()); +static void test_empty_back_and_pop(skiatest::Reporter* reporter) { + SkRandom rand; + for (int data = 0; data < 2; ++data) { + // Do this with different starting sizes to have different alignment between blocks and pops. + // pops. We want to test poping the first guy off, guys in the middle of the block, and the + // first guy on a non-head block. + for (int j = 0; j < 8; ++j) { + GrTRecorder<IntWrapper, int> recorder(j); + + REPORTER_ASSERT(reporter, recorder.empty()); + + for (int i = 0; i < 100; ++i) { + if (data) { + REPORTER_ASSERT(reporter, i == *GrNEW_APPEND_TO_RECORDER(recorder, + IntWrapper, (i))); + } else { + REPORTER_ASSERT(reporter, i == + *GrNEW_APPEND_WITH_DATA_TO_RECORDER(recorder, + IntWrapper, (i), + rand.nextULessThan(10))); + } + REPORTER_ASSERT(reporter, !recorder.empty()); + REPORTER_ASSERT(reporter, i == recorder.back()); + if (0 == (i % 7)) { + recorder.pop_back(); + if (i > 0) { + REPORTER_ASSERT(reporter, !recorder.empty()); + REPORTER_ASSERT(reporter, i-1 == recorder.back()); + } + } + } + + REPORTER_ASSERT(reporter, !recorder.empty()); + recorder.reset(); + REPORTER_ASSERT(reporter, recorder.empty()); + } } - - REPORTER_ASSERT(reporter, !recorder.empty()); - - recorder.reset(); - - REPORTER_ASSERT(reporter, recorder.empty()); } struct ExtraData { @@ -233,7 +255,7 @@ static void test_subclasses(skiatest::Reporter* reporter) { } DEF_GPUTEST(GrTRecorder, reporter, factory) { - test_empty_back(reporter); + test_empty_back_and_pop(reporter); test_extra_data(reporter); REPORTER_ASSERT(reporter, 0 == activeRecorderItems); // test_extra_data should call reset(). |