Validates that the constructor ScalarExprsResultsRowLayout() for 'exprs' is correct. - expected_byte_size: total byte size to store all results for exprs - expected_var_begin: byte offset where variable length types begin - expected_offsets: mapping of byte sizes to a set valid offsets exprs that have the same byte size can end up in a number of locations
| 9127 | // - expected_offsets: mapping of byte sizes to a set valid offsets |
| 9128 | // exprs that have the same byte size can end up in a number of locations |
| 9129 | void ValidateLayout(const vector<ScalarExpr*>& exprs, int expected_byte_size, |
| 9130 | int expected_var_begin, const map<int, set<int>>& expected_offsets) { |
| 9131 | set<int> offsets_found; |
| 9132 | |
| 9133 | ScalarExprsResultsRowLayout row_layout(exprs); |
| 9134 | |
| 9135 | EXPECT_EQ(expected_byte_size, row_layout.expr_values_bytes_per_row); |
| 9136 | EXPECT_EQ(expected_var_begin, row_layout.var_results_begin_offset); |
| 9137 | |
| 9138 | // Walk the computed offsets and make sure the resulting sets match expected_offsets |
| 9139 | for (int i = 0; i < exprs.size(); ++i) { |
| 9140 | int expr_byte_size = exprs[i]->type().GetByteSize(); |
| 9141 | map<int, set<int>>::const_iterator iter = expected_offsets.find(expr_byte_size); |
| 9142 | EXPECT_TRUE(iter != expected_offsets.end()); |
| 9143 | |
| 9144 | const set<int>& possible_offsets = iter->second; |
| 9145 | int computed_offset = row_layout.expr_values_offsets[i]; |
| 9146 | // The computed offset has to be one of the possible. Exprs types with the |
| 9147 | // same size are not ordered wrt each other. |
| 9148 | EXPECT_TRUE(possible_offsets.find(computed_offset) != possible_offsets.end()); |
| 9149 | // The offset should not have been found before |
| 9150 | EXPECT_TRUE(offsets_found.find(computed_offset) == offsets_found.end()); |
| 9151 | offsets_found.insert(computed_offset); |
| 9152 | } |
| 9153 | } |
| 9154 | |
| 9155 | TEST_P(ExprTest, ResultsLayoutTest) { |
| 9156 | vector<ScalarExpr*> exprs; |