2 * Samsung Ukraine R&D Center (SRK under a contract between)
3 * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
4 * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License
18 #include <gmock/gmock.h>
20 #include <dpm/device-policy-manager.h>
21 #include <dpm/administration.h>
22 #include <dpm/application.h>
23 #include <dpm/bluetooth.h>
24 #include <dpm/restriction.h>
25 #include <dpm/security.h>
29 #include "connection.h"
31 #include "policyhandler.h"
32 #include "integer_property_policy.h"
33 #include "restservicemock.h"
34 #include "device_policy_manager_mock.h"
38 using ::testing::Return;
39 using ::testing::Throw;
40 using ::testing::DoAll;
41 using ::testing::Invoke;
42 using ::testing::WithArgs;
43 using ::testing::TypedEq;
47 const std::string TEST_POLICY_URI{"policy-uri"};
48 const std::string TEST_POLICY_CURI{"policy-curi"};
49 const std::string TEST_POLICY_NAME = "camera";
50 const std::string TEST_POLICY{R"-=(
63 TEST(TestPolicyHandler, test_accept)
66 agent::Settings& settings = agent::Settings::instance();
68 communication::Connection conn("", std::chrono::milliseconds(10), &rest, [](){return true;});
69 agent::PolicyHandler policy(conn);
72 dpm::IntegerPropertyPolicy ipp(dpm::PolicyEnforce::GetInstance(), TEST_POLICY_NAME, dpm_restriction_set_camera_state);
75 root["type"] = "policy";
76 root["uri"] = TEST_POLICY_URI;
77 root["curi"] = TEST_POLICY_CURI;
78 communication::Event event1(root, conn);
79 communication::Event event2(root, conn);
81 EXPECT_CALL(dpm, dpm_manager_create()).WillOnce(Return(&dpm));
82 EXPECT_CALL(dpm, dpm_restriction_set_camera_state(1)).WillOnce(Return(0));
83 EXPECT_CALL(dpm, dpm_manager_destroy()).Times(1);
84 EXPECT_CALL(rest, doGet(_, Eq(TEST_POLICY_URI)))
85 .WillOnce(Return(TEST_POLICY));
86 EXPECT_CALL(rest, doPost(_, Eq(TEST_POLICY_CURI), TypedEq<const std::string&>(std::string{})))
89 settings.setLock(false);
90 policy.accept(event1);
91 settings.setLock(true);
92 policy.accept(event2);
93 settings.setLock(false);
95 policy.accept(event2);
96 } catch (std::exception& e) {