[SM] Tests for trusted dir.
[platform/core/test/security-tests.git] / src / security-manager-tests / common / sm_db.cpp
index 2f420bf..7eb6f3f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2016 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.
@@ -187,15 +187,79 @@ void TestSecurityManagerDatabase::setup_privilege_groups(const std::string &priv
     if (!m_base.is_open())
         m_base.open();
 
-    sql << "INSERT OR IGNORE INTO privilege (name) VALUES ('" << privilege << "')";
-    m_base.execute(sql.str(), result);
-
     for (const auto &group : groups) {
         sql.clear();
         sql.str("");
-        sql << "INSERT OR IGNORE INTO privilege_group (privilege_id, name) "
-               "VALUES ((SELECT privilege_id FROM privilege WHERE name = '"
-                << privilege << "'), '" << group << "')";
+        sql << "INSERT INTO privilege_group_view (privilege_name, group_name) "
+               "VALUES ("
+                << "'" << privilege << "'" << ","
+                << "'" << group << "'" << ")";
         m_base.execute(sql.str(), result);
     }
 }
+
+void TestSecurityManagerDatabase::setup_privilege_mapping(const std::string &version_from,
+                                                          const std::string &version_to,
+                                                          const std::string &privilege,
+                                                          const std::string &mapping)
+{
+    Sqlite3DBaseSelectResult result;
+    std::ostringstream sql;
+
+    if (!m_base.is_open())
+        m_base.open();
+
+    sql.clear();
+    sql.str("");
+    sql << "INSERT INTO privilege_mapping_view (version_from_name, version_to_name, privilege_name, privilege_mapping_name) "
+           "VALUES ("
+            << "'" << version_from << "'" << ","
+            << "'" << version_to << "'" << ","
+            << "'" << privilege << "'" << ","
+            << "'" << mapping << "'" << ")";
+    m_base.execute(sql.str(), result);
+}
+
+void TestSecurityManagerDatabase::setup_default_version_privilege(const std::string &version_from,
+                                                                  const std::string &version_to,
+                                                                  const std::string &privilege)
+{
+    Sqlite3DBaseSelectResult result;
+    std::ostringstream sql;
+
+    if (!m_base.is_open())
+        m_base.open();
+
+        sql.clear();
+        sql.str("");
+        sql << "INSERT INTO privilege_mapping_view (version_from_name, version_to_name, privilege_name, privilege_mapping_name) "
+               "VALUES ("
+                << "'" << version_from << "'" << ","
+                << "'" << version_to << "'" << ","
+                << "NULL,"
+                << "'" << privilege << "'" << ")";
+        m_base.execute(sql.str(), result);
+
+}
+
+int64_t TestSecurityManagerDatabase::get_author_id(const std::string &authorName)
+{
+    Sqlite3DBaseSelectResult result;
+    std::ostringstream sql;
+
+    if (!m_base.is_open())
+        m_base.open();
+
+    sql.clear();
+    sql.str("SELECT author_id FROM author where name=\"" + authorName + "\"");
+    m_base.execute(sql.str(), result);
+
+    if(result.rows.empty())
+        return 0;
+
+    std::istringstream os(result.rows[0][0]);
+    int64_t id;
+    os >> id;
+    return id;
+}
+