Index: test/cctest/test-utils.cc |
diff --git a/test/cctest/test-utils.cc b/test/cctest/test-utils.cc |
index bcb185d24fbcc6344c43e22abacdd9a9a42ca871..88ef0a204da7a113b36ac641ef6f97b0ef360fd1 100644 |
--- a/test/cctest/test-utils.cc |
+++ b/test/cctest/test-utils.cc |
@@ -131,3 +131,64 @@ TEST(MemCopy) { |
buffer2.Dispose(); |
buffer1.Dispose(); |
} |
+ |
+ |
+TEST(Collector) { |
+ Collector<int> collector(8); |
+ const int kLoops = 5; |
+ const int kSequentialSize = 1000; |
+ const int kBlockSize = 7; |
+ for (int loop = 0; loop < kLoops; loop++) { |
+ Vector<int> block = collector.AddBlock(7, 0xbadcafe); |
+ for (int i = 0; i < kSequentialSize; i++) { |
+ collector.Add(i); |
+ } |
+ for (int i = 0; i < kBlockSize - 1; i++) { |
+ block[i] = i * 7; |
+ } |
+ } |
+ Vector<int> result = collector.ToVector(); |
+ CHECK_EQ(kLoops * (kBlockSize + kSequentialSize), result.length()); |
+ for (int i = 0; i < kLoops; i++) { |
+ int offset = i * (kSequentialSize + kBlockSize); |
+ for (int j = 0; j < kBlockSize - 1; j++) { |
+ CHECK_EQ(j * 7, result[offset + j]); |
+ } |
+ CHECK_EQ(0xbadcafe, result[offset + kBlockSize - 1]); |
+ for (int j = 0; j < kSequentialSize; j++) { |
+ CHECK_EQ(j, result[offset + kBlockSize + j]); |
+ } |
+ } |
+ result.Dispose(); |
+} |
+ |
+ |
+TEST(SequenceCollector) { |
+ SequenceCollector<int> collector(8); |
+ const int kLoops = 5000; |
+ const int kMaxSequenceSize = 13; |
+ int total_length = 0; |
+ for (int loop = 0; loop < kLoops; loop++) { |
+ int seq_length = loop % kMaxSequenceSize; |
+ collector.StartSequence(); |
+ for (int j = 0; j < seq_length; j++) { |
+ collector.Add(j); |
+ } |
+ Vector<int> sequence = collector.EndSequence(); |
+ for (int j = 0; j < seq_length; j++) { |
+ CHECK_EQ(j, sequence[j]); |
+ } |
+ total_length += seq_length; |
+ } |
+ Vector<int> result = collector.ToVector(); |
+ CHECK_EQ(total_length, result.length()); |
+ int offset = 0; |
+ for (int loop = 0; loop < kLoops; loop++) { |
+ int seq_length = loop % kMaxSequenceSize; |
+ for (int j = 0; j < seq_length; j++) { |
+ CHECK_EQ(j, result[offset]); |
+ offset++; |
+ } |
+ } |
+ result.Dispose(); |
+} |