diff options
author | josh.macdonald <jmacd@users.noreply.github.com> | 2009-02-10 03:49:57 +0000 |
---|---|---|
committer | josh.macdonald <jmacd@users.noreply.github.com> | 2009-02-10 03:49:57 +0000 |
commit | 1b96ad8ae09b53cdcd7dd03d4bac09ba8c61e5a6 (patch) | |
tree | 33aae63f229f1def8cd036dd4ec4fe3ec36a3055 /xdelta3/testing/segment.h | |
parent | 0b19bfedbd1f17004bdc6766a7ba5e61dddc20b0 (diff) |
Templatize the test, expose issue 79.
Diffstat (limited to 'xdelta3/testing/segment.h')
-rw-r--r-- | xdelta3/testing/segment.h | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/xdelta3/testing/segment.h b/xdelta3/testing/segment.h index 1dabf5c..a743bfd 100644 --- a/xdelta3/testing/segment.h +++ b/xdelta3/testing/segment.h | |||
@@ -1,7 +1,5 @@ | |||
1 | // -*- Mode: C++ -*- | 1 | // -*- Mode: C++ -*- |
2 | 2 | ||
3 | namespace regtest { | ||
4 | |||
5 | class Segment { | 3 | class Segment { |
6 | public: | 4 | public: |
7 | Segment(size_t size, MTRandom *rand) | 5 | Segment(size_t size, MTRandom *rand) |
@@ -58,6 +56,22 @@ class Segment { | |||
58 | } | 56 | } |
59 | } | 57 | } |
60 | 58 | ||
59 | string ToString() const { | ||
60 | string r; | ||
61 | if (data_) { | ||
62 | for (size_t i = 0; i < size_; i++) { | ||
63 | char buf[10]; | ||
64 | sprintf(buf, "%02x ", data_[i]); | ||
65 | r.append(buf); | ||
66 | } | ||
67 | } else { | ||
68 | char buf[256]; | ||
69 | sprintf(buf, "size=%ld,seed=%ld,skip=%ld", size_, seed_, seed_offset_); | ||
70 | r.append(buf); | ||
71 | } | ||
72 | return r; | ||
73 | } | ||
74 | |||
61 | private: | 75 | private: |
62 | // Used by Subseg() | 76 | // Used by Subseg() |
63 | Segment(size_t size, uint32_t seed, size_t seed_offset) | 77 | Segment(size_t size, uint32_t seed, size_t seed_offset) |
@@ -68,8 +82,6 @@ private: | |||
68 | CHECK_GT(size_, 0); | 82 | CHECK_GT(size_, 0); |
69 | } | 83 | } |
70 | 84 | ||
71 | friend ostream& operator<<(ostream& os, const Segment &seg); | ||
72 | |||
73 | size_t size_; // Size of this segment | 85 | size_t size_; // Size of this segment |
74 | 86 | ||
75 | // For random segments | 87 | // For random segments |
@@ -81,20 +93,6 @@ private: | |||
81 | uint8_t *data_; | 93 | uint8_t *data_; |
82 | }; | 94 | }; |
83 | 95 | ||
84 | ostream& operator<<(ostream& os, const Segment &seg) { | ||
85 | if (seg.data_) { | ||
86 | for (size_t i = 0; i < seg.size_; i++) { | ||
87 | char buf[10]; | ||
88 | sprintf(buf, "%02x ", seg.data_[i]); | ||
89 | os << buf; | ||
90 | } | ||
91 | return os; | ||
92 | } else { | ||
93 | return os << "size=" << seg.size_ << ",seed=" << seg.seed_ | ||
94 | << ",skip=" << seg.seed_offset_; | ||
95 | } | ||
96 | } | ||
97 | |||
98 | typedef map<xoff_t, Segment> SegmentMap; | 96 | typedef map<xoff_t, Segment> SegmentMap; |
99 | 97 | typedef typename SegmentMap::const_iterator ConstSegmentMapIterator; | |
100 | } // namespace regtest | 98 | typedef typename SegmentMap::iterator SegmentMapIterator; |