| // Copyright 2016 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #ifndef COBALT_SRC_ALGORITHMS_RAPPOR_RAPPOR_TEST_UTILS_H_ |
| #define COBALT_SRC_ALGORITHMS_RAPPOR_RAPPOR_TEST_UTILS_H_ |
| |
| #include <string> |
| #include <vector> |
| |
| #include "src/algorithms/rappor/rappor_config.h" |
| #include "src/pb/observation.pb.h" |
| #include "src/registry/report_definition.pb.h" |
| |
| namespace cobalt::rappor { |
| |
| // Returns whether or not the bit with the given |bit_index| is set in |
| // |data|. The bits are indexed "from right-to-left", i.e. from least |
| // significant to most significant. The least significant bit has index 0. |
| bool IsSet(const std::string& data, int bit_index); |
| |
| // Given a string of "0"s and "1"s of length a multiple of 8, returns |
| // the bytes whose binary representation is given by the string. |
| std::string BinaryStringToData(const std::string& binary_string); |
| |
| // Returns a string of "0"s and "1"s that gives the binary representation of the |
| // bytes in |data|. |
| std::string DataToBinaryString(const std::string& data); |
| |
| // Builds a binary string of length |num_bits| in which there are '1''s in |
| // exactly the indices specified by |index_of_1s|. Note that we index bits |
| // "from the right" so that an index of zero refers to the least significant |
| // bit, i.e. the last character of the returned string. |
| std::string BuildBinaryString(size_t num_bits, const std::vector<uint16_t>& index_of_1s); |
| |
| // Builds the string "category<index>" using 4 digits from index. |
| std::string CategoryName(uint32_t index); |
| |
| // Returns a string of characters of length |num_bits| with |index_char| in |
| // position |index| and |other_char| in all other positions. |
| // REQUIRES: 0 <= index < num_bits. |
| std::string BuildBitPatternString(int num_bits, int index, char index_char, char other_char); |
| |
| } // namespace cobalt::rappor |
| |
| #endif // COBALT_SRC_ALGORITHMS_RAPPOR_RAPPOR_TEST_UTILS_H_ |