1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #include "config_factory.h" 16 #include "gtest/gtest.h" 17 using namespace testing::ext; 18 using namespace OHOS::DistributedData; 19 class ConfigFactoryTest : public testing::Test { 20 public: SetUpTestCase(void)21 static void SetUpTestCase(void) 22 { 23 } TearDownTestCase(void)24 static void TearDownTestCase(void) 25 { 26 } SetUp()27 void SetUp() 28 { 29 } TearDown()30 void TearDown() 31 { 32 } 33 }; 34 35 /** 36 * @tc.name: GlobalConfig 37 * @tc.desc: load the config.json global info. 38 * @tc.type: FUNC 39 * @tc.require: 40 * @tc.author: Sven Wang 41 */ 42 HWTEST_F(ConfigFactoryTest, GlobalConfig, TestSize.Level0) 43 { 44 auto *global = ConfigFactory::GetInstance().GetGlobalConfig(); 45 ASSERT_NE(global, nullptr); 46 ASSERT_EQ(global->processLabel, "distributeddata"); 47 ASSERT_EQ(global->metaData, "service_meta"); 48 ASSERT_EQ(global->version, "000.000.001"); 49 std::vector<std::string> features{ "kvdb", "rdb", "object", "backup", "data_sync" }; 50 ASSERT_EQ(global->features, features); 51 } 52 53 /** 54 * @tc.name: ComponentConfig 55 * @tc.desc: load the config.json component info. 56 * @tc.type: FUNC 57 * @tc.require: 58 * @tc.author: Sven Wang 59 */ 60 HWTEST_F(ConfigFactoryTest, ComponentConfig, TestSize.Level0) 61 { 62 auto *components = ConfigFactory::GetInstance().GetComponentConfig(); 63 ASSERT_NE(components, nullptr); 64 ASSERT_EQ(components->size(), 4); 65 const ComponentConfig &config = (*components)[0]; 66 ASSERT_EQ(config.description, "3rd party adapter"); 67 ASSERT_EQ(config.lib, "libconfigdemo.z.so"); 68 ASSERT_EQ(config.constructor, ""); 69 ASSERT_EQ(config.destructor, ""); 70 ASSERT_EQ(config.params, "{\"count\":1,\"key\":\"value\"}"); 71 } 72 73 /** 74 * @tc.name: CheckerConfig 75 * @tc.desc: load the config.json checkers info. 76 * @tc.type: FUNC 77 * @tc.require: 78 * @tc.author: Sven Wang 79 */ 80 HWTEST_F(ConfigFactoryTest, CheckerConfig, TestSize.Level0) 81 { 82 auto *checker = ConfigFactory::GetInstance().GetCheckerConfig(); 83 ASSERT_NE(checker, nullptr); 84 std::vector<std::string> checkers{"SystemChecker", "BundleChecker"}; 85 ASSERT_EQ(checker->checkers, checkers); 86 ASSERT_EQ(checker->trusts[0].bundleName, "bundle_manager_service"); 87 ASSERT_EQ(checker->trusts[0].appId, "bundle_manager_service"); 88 ASSERT_EQ(checker->trusts[0].checker, "SystemChecker"); 89 } 90 91 /** 92 * @tc.name: NetworkConfig 93 * @tc.desc: load the config.json networks info. 94 * @tc.type: FUNC 95 * @tc.require: 96 * @tc.author: Sven Wang 97 */ 98 HWTEST_F(ConfigFactoryTest, NetworkConfig, TestSize.Level0) 99 { 100 auto *networks = ConfigFactory::GetInstance().GetNetworkConfig(); 101 ASSERT_NE(networks, nullptr); 102 std::vector<std::string> chains{ "loadBalance", "authentication", "traffic-control", "router", "transport", 103 "fault-inject" }; 104 ASSERT_EQ(networks->chains, chains); 105 std::vector<std::string> routers{ "OHOSRouter" }; 106 ASSERT_EQ(networks->routers, routers); 107 std::vector<std::string> transports{ "softbus" }; 108 ASSERT_EQ(networks->transports, transports); 109 ASSERT_EQ(networks->protocols[0].name, "OHOS softbus"); 110 ASSERT_EQ(networks->protocols[0].address, "ohos.distributeddata"); 111 ASSERT_EQ(networks->protocols[0].transport, "softbus"); 112 }