1 //******************************************************************
3 // Copyright 2015 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include "gtest/gtest.h"
24 #include <linux/limits.h>
26 #include "cainterface.h"
27 #include "srmresourcestrings.h"
31 #define PE_UT_TAG "\tPE-UT-message: "
37 #include "policyengine.h"
38 #include "doxmresource.h"
41 PEContext_t g_peContext;
47 OicUuid_t g_subjectIdA = {"SubjectA"};
48 OicUuid_t g_subjectIdB = {"SubjectB"};
50 char g_resource1[] = "Resource1";
51 char g_resource2[] = "Resource2";
53 //Policy Engine Core Tests
54 TEST(PolicyEngineCore, InitPolicyEngine)
56 EXPECT_EQ(OC_STACK_OK, InitPolicyEngine(&g_peContext));
59 TEST(PolicyEngineCore, CheckPermissionNoAcls)
61 EXPECT_EQ(ACCESS_DENIED_SUBJECT_NOT_FOUND,
62 CheckPermission(&g_peContext,
68 //TODO This won't work until we figure out how to OcInit() or equivalent.
69 TEST(PolicyEngineCore, CheckDevOwnerRequest)
71 if(OC_STACK_OK == InitDoxmResource())
73 if(OC_STACK_OK == GetDoxmDevOwnerId(&g_devOwner))
75 printf("%s", PE_UT_TAG);
76 for(int i = 0; i < UUID_LENGTH; i++)
78 printf("%d", g_devOwner.id[i]);
81 EXPECT_EQ(ACCESS_GRANTED,
82 CheckPermission(&g_peContext,
85 PERMISSION_FULL_CONTROL));
89 printf("%s WARNING: InitDoxmResource() returned ERROR!\n", \
95 printf("%s WARNING: GetDoxmDevOwnerId() returned ERROR!\n", PE_UT_TAG);
101 TEST(PolicyEngineCore, DeInitPolicyEngine)
103 DeInitPolicyEngine(&g_peContext);
104 EXPECT_EQ(STOPPED, g_peContext.state);
105 EXPECT_EQ(NULL, g_peContext.subject);
106 EXPECT_EQ(NULL, g_peContext.resource);
107 EXPECT_EQ((uint16_t)0, g_peContext.permission);
108 EXPECT_FALSE(g_peContext.matchingAclFound);
109 EXPECT_EQ(ACCESS_DENIED_POLICY_ENGINE_ERROR, g_peContext.retVal);