xref: /aosp_15_r20/external/federated-compute/fcp/aggregation/core/tensor_aggregator_registry_test.cc (revision 14675a029014e728ec732f129a32e299b2da0601)
1 /*
2  * Copyright 2022 Google LLC
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "fcp/aggregation/core/tensor_aggregator_registry.h"
18 
19 #include "gmock/gmock.h"
20 #include "gtest/gtest.h"
21 #include "fcp/aggregation/core/tensor_aggregator_factory.h"
22 #include "fcp/base/monitoring.h"
23 #include "fcp/testing/testing.h"
24 
25 namespace fcp {
26 namespace aggregation {
27 namespace {
28 
29 class MockFactory : public TensorAggregatorFactory {
30   MOCK_METHOD(StatusOr<std::unique_ptr<TensorAggregator>>, Create,
31               (DataType dtype, TensorShape shape), (const override));
32 };
33 
34 REGISTER_AGGREGATOR_FACTORY("foobar", MockFactory);
35 
TEST(TensorAggregatorRegistryTest,FactoryRegistrationSuccessful)36 TEST(TensorAggregatorRegistryTest, FactoryRegistrationSuccessful) {
37   EXPECT_THAT(GetAggregatorFactory("foobar"), IsOk());
38   EXPECT_THAT(GetAggregatorFactory("xyz"), IsCode(NOT_FOUND));
39 }
40 
TEST(TensorAggregatorRegistryTest,RepeatedRegistrationUnsuccessful)41 TEST(TensorAggregatorRegistryTest, RepeatedRegistrationUnsuccessful) {
42   MockFactory factory2;
43   EXPECT_DEATH(RegisterAggregatorFactory("foobar", &factory2),
44                "already registered");
45 }
46 
47 }  // namespace
48 }  // namespace aggregation
49 }  // namespace fcp
50