alanlxl | 30f15bd | 2020-08-11 21:26:12 +1000 | [diff] [blame] | 1 | // Copyright 2020 The Chromium OS 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. |
| 4 | |
| 5 | #include "federated/test_utils.h" |
| 6 | |
| 7 | #include <string> |
| 8 | #include <vector> |
| 9 | |
| 10 | namespace federated { |
| 11 | namespace { |
| 12 | using chromeos::federated::mojom::Example; |
| 13 | using chromeos::federated::mojom::ExamplePtr; |
| 14 | using chromeos::federated::mojom::Features; |
| 15 | using chromeos::federated::mojom::FloatList; |
| 16 | using chromeos::federated::mojom::Int64List; |
| 17 | using chromeos::federated::mojom::StringList; |
| 18 | using chromeos::federated::mojom::ValueList; |
| 19 | using chromeos::federated::mojom::ValueListPtr; |
| 20 | |
| 21 | ValueListPtr CreateInt64List(const std::vector<int64_t>& values) { |
| 22 | ValueListPtr value_list = ValueList::New(); |
| 23 | value_list->set_int64_list(Int64List::New()); |
| 24 | value_list->get_int64_list()->value = std::vector<int64_t>(); |
| 25 | value_list->get_int64_list()->value = values; |
| 26 | return value_list; |
| 27 | } |
| 28 | |
| 29 | ValueListPtr CreateFloatList(const std::vector<double>& values) { |
| 30 | ValueListPtr value_list = ValueList::New(); |
| 31 | value_list->set_float_list(FloatList::New()); |
| 32 | value_list->get_float_list()->value = std::vector<double>(); |
| 33 | value_list->get_float_list()->value = values; |
| 34 | return value_list; |
| 35 | } |
| 36 | |
| 37 | ValueListPtr CreateStringList(const std::vector<std::string>& values) { |
| 38 | ValueListPtr value_list = ValueList::New(); |
| 39 | value_list->set_string_list(StringList::New()); |
| 40 | value_list->get_string_list()->value = std::vector<std::string>(); |
| 41 | value_list->get_string_list()->value = values; |
| 42 | return value_list; |
| 43 | } |
| 44 | |
| 45 | } // namespace |
| 46 | |
| 47 | ExamplePtr CreateExamplePtr() { |
| 48 | ExamplePtr example = Example::New(); |
| 49 | example->features = Features::New(); |
| 50 | auto& feature_map = example->features->feature; |
| 51 | feature_map["int_feature1"] = CreateInt64List({1, 2, 3, 4, 5}); |
| 52 | feature_map["int_feature2"] = CreateInt64List({10, 20, 30, 40, 50}); |
| 53 | feature_map["float_feature1"] = CreateFloatList({1.1, 2.1, 3.1, 4.1, 5.1}); |
| 54 | feature_map["string_feature1"] = CreateStringList({"abc", "123", "xyz"}); |
| 55 | |
| 56 | return example; |
| 57 | } |
| 58 | |
| 59 | } // namespace federated |