Add class UserRequest for user API tests 52/32352/5
authorMichal Eljasiewicz <m.eljasiewic@samsung.com>
Wed, 17 Dec 2014 10:19:29 +0000 (11:19 +0100)
committerJan Cybulski <j.cybulski@samsung.com>
Mon, 12 Jan 2015 11:05:41 +0000 (12:05 +0100)
Change-Id: Iee5d068c1ba2601fcaf2c4e9bd25b2ad31005c74
Signed-off-by: Michal Eljasiewicz <m.eljasiewic@samsung.com>
tests/security-manager-tests/CMakeLists.txt
tests/security-manager-tests/common/sm_user_request.cpp [new file with mode: 0644]
tests/security-manager-tests/common/sm_user_request.h [new file with mode: 0644]

index 5ffd2f9..6f8fd74 100644 (file)
@@ -1,5 +1,5 @@
 #
-#Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+#Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
 #
 #   Licensed under the Apache License, Version 2.0 (the "License");
 #   you may not use this file except in compliance with the License.
@@ -40,6 +40,7 @@ SET(SEC_MGR_SOURCES
     ${PROJECT_SOURCE_DIR}/tests/security-manager-tests/common/sm_api.cpp
     ${PROJECT_SOURCE_DIR}/tests/security-manager-tests/common/sm_db.cpp
     ${PROJECT_SOURCE_DIR}/tests/security-manager-tests/common/sm_request.cpp
+    ${PROJECT_SOURCE_DIR}/tests/security-manager-tests/common/sm_user_request.cpp
     ${PROJECT_SOURCE_DIR}/tests/cynara-tests/common/cynara_test_client.cpp
     ${PROJECT_SOURCE_DIR}/tests/libprivilege-control-tests/libprivilege-control_test_common.cpp
    )
diff --git a/tests/security-manager-tests/common/sm_user_request.cpp b/tests/security-manager-tests/common/sm_user_request.cpp
new file mode 100644 (file)
index 0000000..4b176c3
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#include <sm_user_request.h>
+
+#include <dpl/test/test_runner.h>
+
+namespace SecurityManagerTest {
+
+UserRequest::UserRequest()
+    : m_req(nullptr)
+    , m_uid(false, 0)
+    , m_utype(false, static_cast<security_manager_user_type>(0))
+{
+    int result = security_manager_user_req_new(&m_req);
+    RUNNER_ASSERT_MSG((lib_retcode)result == SECURITY_MANAGER_SUCCESS,
+                      "creation of new request failed. Result: " << result);
+    RUNNER_ASSERT_MSG(m_req != nullptr, "creation of new request did not allocate memory");
+}
+
+UserRequest::~UserRequest()
+{
+    security_manager_user_req_free(m_req);
+}
+
+void UserRequest::setUid(const uid_t uid, lib_retcode expectedResult)
+{
+    int result = security_manager_user_req_set_uid(m_req, uid);
+    RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
+                     "setting uid returned wrong value."
+                          << " Uid: " << uid << ";"
+                          << " Result: " << result << ";"
+                          << " Expected result: " << expectedResult);
+    m_uid.first = true;
+    m_uid.second = uid;
+}
+
+void UserRequest::setUserType(const security_manager_user_type utype, lib_retcode expectedResult)
+{
+    int result = security_manager_user_req_set_user_type(m_req, utype);
+    RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
+                     "setting user type returned wrong value."
+                          << " User type: " << utype << ";"
+                          << " Result: " << result << ";"
+                          << " Expected result: " << expectedResult);
+    m_utype.first = true;
+    m_utype.second = utype;
+}
+
+std::ostream& operator<<(std::ostream &os, const UserRequest &request)
+{
+    if (request.m_uid.first)
+        os << "uid: " << request.m_uid.second << "; ";
+
+    if (request.m_utype.first)
+        os << "utype: " << request.m_utype.second << "; ";
+
+    return os;
+}
+
+} // namespace SecurityManagerTest
diff --git a/tests/security-manager-tests/common/sm_user_request.h b/tests/security-manager-tests/common/sm_user_request.h
new file mode 100644 (file)
index 0000000..64da559
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#ifndef SECURITY_MANAGER_TEST_USERREQUEST
+#define SECURITY_MANAGER_TEST_USERREQUEST
+
+#include <iostream>
+#include <sys/types.h>
+#include <utility>
+
+#include <security-manager.h>
+
+namespace SecurityManagerTest {
+
+class UserRequest
+{
+public:
+    UserRequest();
+    UserRequest(const UserRequest&) = delete;
+    UserRequest& operator=(const UserRequest&) = delete;
+    ~UserRequest();
+
+    void setUid(const uid_t uid, lib_retcode expectedresult = SECURITY_MANAGER_SUCCESS);
+    void setUserType(const security_manager_user_type utype,
+                     lib_retcode expectedresult = SECURITY_MANAGER_SUCCESS);
+
+    const user_req *get() const { return m_req; }
+    friend std::ostream& operator<<(std::ostream &, const UserRequest&);
+
+private:
+    user_req *m_req;
+
+    std::pair<bool, uid_t> m_uid;
+    std::pair<bool, security_manager_user_type> m_utype;
+};
+
+std::ostream& operator<<(std::ostream &os, const SecurityManagerTest::UserRequest &request);
+
+} // namespace SecurityManagerTest
+
+#endif // SECURITY_MANAGER_TEST_USERREQUEST