~ubuntu-branches/ubuntu/quantal/ceph/quantal

« back to all changes in this revision

Viewing changes to src/leveldb/util/testutil.cc

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-07-19 08:28:18 UTC
  • Revision ID: package-import@ubuntu.com-20120719082818-rdnt9r2hc0ced8n5
Tags: 0.48-1ubuntu2
* Drop use of in-tree dependencies, re-align with Debian:
  - d/patches/{intree_leveldb|add-powerpc-support}.patch: Dropped.
  - d/patches/series: Use patches to support lib{leveldb|s3}-dev usage.
  - d/control: BD on libsnappy-dev, liblevedb-dev, libs3-dev.
  - d/rules: Use system provided leveldb and libs3.
  - d/rules: Enable hardening.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2
 
// Use of this source code is governed by a BSD-style license that can be
3
 
// found in the LICENSE file. See the AUTHORS file for names of contributors.
4
 
 
5
 
#include "util/testutil.h"
6
 
 
7
 
#include "util/random.h"
8
 
 
9
 
namespace leveldb {
10
 
namespace test {
11
 
 
12
 
Slice RandomString(Random* rnd, int len, std::string* dst) {
13
 
  dst->resize(len);
14
 
  for (int i = 0; i < len; i++) {
15
 
    (*dst)[i] = static_cast<char>(' ' + rnd->Uniform(95));   // ' ' .. '~'
16
 
  }
17
 
  return Slice(*dst);
18
 
}
19
 
 
20
 
std::string RandomKey(Random* rnd, int len) {
21
 
  // Make sure to generate a wide variety of characters so we
22
 
  // test the boundary conditions for short-key optimizations.
23
 
  static const char kTestChars[] = {
24
 
    '\0', '\1', 'a', 'b', 'c', 'd', 'e', '\xfd', '\xfe', '\xff'
25
 
  };
26
 
  std::string result;
27
 
  for (int i = 0; i < len; i++) {
28
 
    result += kTestChars[rnd->Uniform(sizeof(kTestChars))];
29
 
  }
30
 
  return result;
31
 
}
32
 
 
33
 
 
34
 
extern Slice CompressibleString(Random* rnd, double compressed_fraction,
35
 
                                int len, std::string* dst) {
36
 
  int raw = static_cast<int>(len * compressed_fraction);
37
 
  if (raw < 1) raw = 1;
38
 
  std::string raw_data;
39
 
  RandomString(rnd, raw, &raw_data);
40
 
 
41
 
  // Duplicate the random data until we have filled "len" bytes
42
 
  dst->clear();
43
 
  while (dst->size() < len) {
44
 
    dst->append(raw_data);
45
 
  }
46
 
  dst->resize(len);
47
 
  return Slice(*dst);
48
 
}
49
 
 
50
 
}  // namespace test
51
 
}  // namespace leveldb