Writes a randomized value in 'tuple'.
| 243 | |
| 244 | // Writes a randomized value in 'tuple'. |
| 245 | void WriteValue(Tuple* tuple, const SlotDescriptor& slot_desc, MemPool* pool) { |
| 246 | switch (slot_desc.type().type) { |
| 247 | case TYPE_INT: { |
| 248 | int val = rand(); |
| 249 | RawValue::Write(&val, tuple, &slot_desc, pool); |
| 250 | break; |
| 251 | } |
| 252 | case TYPE_STRING: { |
| 253 | // Via http://stackoverflow.com/questions/440133/ |
| 254 | // how-do-i-create-a-random-alpha-numeric-string-in-c |
| 255 | static const char chars[] = |
| 256 | "0123456789" |
| 257 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 258 | "abcdefghijklmnopqrstuvwxyz"; |
| 259 | int len = rand() % (MAX_STRING_LEN + 1); |
| 260 | char buf[MAX_STRING_LEN]; |
| 261 | for (int i = 0; i < len; ++i) { |
| 262 | buf[i] = chars[rand() % (sizeof(chars) - 1)]; |
| 263 | } |
| 264 | |
| 265 | StringValue sv(&buf[0], len); |
| 266 | RawValue::Write(&sv, tuple, &slot_desc, pool); |
| 267 | break; |
| 268 | } |
| 269 | case TYPE_ARRAY: { |
| 270 | const TupleDescriptor* item_desc = slot_desc.children_tuple_descriptor(); |
| 271 | int array_len = rand() % (MAX_ARRAY_LEN + 1); |
| 272 | CollectionValue cv; |
| 273 | CollectionValueBuilder builder(&cv, *item_desc, pool, runtime_state_, array_len); |
| 274 | Tuple* tuple_mem; |
| 275 | int n; |
| 276 | EXPECT_OK(builder.GetFreeMemory(&tuple_mem, &n)); |
| 277 | ASSERT_GE(n, array_len); |
| 278 | memset(tuple_mem, 0, item_desc->byte_size() * array_len); |
| 279 | for (int i = 0; i < array_len; ++i) { |
| 280 | for (int slot_idx = 0; slot_idx < item_desc->slots().size(); ++slot_idx) { |
| 281 | SlotDescriptor* item_slot_desc = item_desc->slots()[slot_idx]; |
| 282 | WriteValue(tuple_mem, *item_slot_desc, pool); |
| 283 | } |
| 284 | tuple_mem += item_desc->byte_size(); |
| 285 | } |
| 286 | builder.CommitTuples(array_len); |
| 287 | // Array data already lives in 'pool' |
| 288 | RawValue::Write(&cv, tuple, &slot_desc, NULL); |
| 289 | break; |
| 290 | } |
| 291 | default: |
| 292 | ASSERT_TRUE(false) << "NYI: " << slot_desc.type().DebugString(); |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | // Creates a row batch with randomized values. |
| 297 | RowBatch* CreateRowBatch(const RowDescriptor& row_desc) { |
nothing calls this directly
no test coverage detected