-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_utils.cc
59 lines (49 loc) · 2.01 KB
/
test_utils.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2020 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "federated/test_utils.h"
#include <string>
#include <vector>
namespace federated {
namespace {
using chromeos::federated::mojom::Example;
using chromeos::federated::mojom::ExamplePtr;
using chromeos::federated::mojom::Features;
using chromeos::federated::mojom::FloatList;
using chromeos::federated::mojom::Int64List;
using chromeos::federated::mojom::StringList;
using chromeos::federated::mojom::ValueList;
using chromeos::federated::mojom::ValueListPtr;
ValueListPtr CreateInt64List(const std::vector<int64_t>& values) {
ValueListPtr value_list = ValueList::New();
value_list->set_int64_list(Int64List::New());
value_list->get_int64_list()->value = std::vector<int64_t>();
value_list->get_int64_list()->value = values;
return value_list;
}
ValueListPtr CreateFloatList(const std::vector<double>& values) {
ValueListPtr value_list = ValueList::New();
value_list->set_float_list(FloatList::New());
value_list->get_float_list()->value = std::vector<double>();
value_list->get_float_list()->value = values;
return value_list;
}
ValueListPtr CreateStringList(const std::vector<std::string>& values) {
ValueListPtr value_list = ValueList::New();
value_list->set_string_list(StringList::New());
value_list->get_string_list()->value = std::vector<std::string>();
value_list->get_string_list()->value = values;
return value_list;
}
} // namespace
ExamplePtr CreateExamplePtr() {
ExamplePtr example = Example::New();
example->features = Features::New();
auto& feature_map = example->features->feature;
feature_map["int_feature1"] = CreateInt64List({1, 2, 3, 4, 5});
feature_map["int_feature2"] = CreateInt64List({10, 20, 30, 40, 50});
feature_map["float_feature1"] = CreateFloatList({1.1, 2.1, 3.1, 4.1, 5.1});
feature_map["string_feature1"] = CreateStringList({"abc", "123", "xyz"});
return example;
}
} // namespace federated